in reply to Re^2: Inline::C and NULL pointers
in thread Inline::C and NULL pointers
The question is: "How can I call foo() directly from perl such that it will output "False" ? One way is to call bar() which then calls foo() - and I think that the OP's existing enctypex_msname function could be accessed (as is) via this technique of calling a wrapper function . But that's still not a direct call to foo().use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, ; use Inline C =><<'EOC'; unsigned char * foo(unsigned char * name) { if(name) printf("True\n"); else printf("False\n"); return(NULL); } unsigned char * bar() { return (foo(NULL)); } EOC foo(undef); bar(); __END__ Outputs: True False
Then, in the script, I typedeffed the "unsigned char *" to "unmapped", and replaced "unsigned char *" with "unmapped" in the function declaration:# plagiarised from default perl typemap unmapped T_PTR INPUT T_PTR $var = INT2PTR($type,SvIV($arg)) OUTPUT T_PTR sv_setiv($arg, PTR2IV($var));
So we have 2 essentially identical scripts that output different results. One of them specifies an "unmapped" type where the other specifies "unsigned char *" - yet the two types are the same thing. The difference occurs because the two types employ different typemapping.use strict; use warnings; use Inline C => Config => TYPEMAPS => "nullmap.txt", BUILD_NOISY => 1, ; use Inline C =><<'EOC'; typedef unsigned char * unmapped; unmapped foo(unmapped name) { if(name) printf("True\n"); else printf("False\n"); return(NULL); } unsigned char * bar() { return (foo(NULL)); } EOC foo(undef); bar(); __END__ Outputs: False False
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Inline::C and NULL pointers ( override default xsubpp ExtUtils::ParseXS::Utilities::process_typemaps )
by Anonymous Monk on Dec 20, 2021 at 03:28 UTC | |
by syphilis (Archbishop) on Dec 20, 2021 at 04:30 UTC | |
by syphilis (Archbishop) on Dec 20, 2021 at 09:21 UTC | |
by etj (Priest) on Dec 20, 2021 at 19:49 UTC |