In XS I can pass the length of a string argument to a C function using the length keyword:
static int foo(const char *s, size_t len)
{
return 1;
}
MODULE = Foo PACKAGE = Foo
void
foo(char *s, STRLEN length(s))
However how can I get the length of the string if I need it inside the CODE block?
void
foo(char *s, STRLEN length(s))
CODE:
...
foo(s, ???);
I can use STRLEN_length_of_s
or XSauto_length_of_s
variable autogenerated
by xsubpp but it feels a bit hardcoded. Is there a way (possibly a predefined macro) I can use to get the variable name? Or can I assign my own name to the length argument? Or do I need to resort to declaring the argument as SV *
and then get the length myself with SvPV
in CODE section?