I created ruby method in C using Ruby API which receive 3 string arguments:
VALUE cache_class = rb_define_class_under(class, CACHE_CLASS_NAME, rb_cObject);
rb_define_method(cache_class, "cache_test_result", cache_test_result, 3);
In test.rb I called method:
Cache.new.cache_test_result("str1", "str2", "str3")
And C cache_test_result function works strange:
VALUE cache_test_result(VALUE str1, VALUE str2, VALUE str3) {
int rstr1_len = RSTRING_LEN(str1) + 1;
char buf_str1[rstr1_len];
strlcpy(buf_str1, RSTRING_PTR(str1), rstr1_len);
int rstr2_len = RSTRING_LEN(str2) + 1;
char buf_str2[rstr2_len];
strlcpy(buf_str2, RSTRING_PTR(str2), rstr2_len);
int rstr3_len = RSTRING_LEN(str3) + 1;
char buf_str3[rstr3_len];
strlcpy(buf_str3, RSTRING_PTR(str3), rstr3_len);
printf("buf_str1: %s\n", buf_str1);
printf("buf_str2: %s\n", buf_str2);
printf("buf_str3: %s\n", buf_str3);
}
output of this function:
buf_str1:
buf_str2: str1
buf_str3: str2
why args has offset...?