Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Inline::C and NULL pointers ( override default xsubpp ExtUtils::ParseXS::Utilities::process_typemaps )

by syphilis (Archbishop)
on Dec 20, 2021 at 04:30 UTC ( [id://11139760]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Inline::C and NULL pointers ( override default xsubpp ExtUtils::ParseXS::Utilities::process_typemaps )
in thread Inline::C and NULL pointers

Indicates that a user-supplied typemap should take precedence over the default typemaps. This option may be used multiple times, with the last typemap having the highest precedence.

Thanks for digging that up.
I really do think it would be better if our user-supplied typemap took precedence over ExtUtils/typemap. (This is something that should probably be investigated further.)

But it seems by using unmapped T_PTR you're getting the old T_PTR, not the new one, you can't redefine T_PTR, which makes sense.

My T_PTR is the same as the original T_PTR, as there was nothing wrong with the original.
I just had to change the typing of unsigned char* from T_PV to T_PTR. I could only make that switch for the unmapped type, which was a typedef of unsigned char*.
Seems I won't need that typedef if I can get the two typemaps to load in the reverse order.

I've just checked and found that I didn't need to provide the T_PTR "INPUT" and "OUTPUT" routines in my custom typemap ("nullmap.txt").
That file needs only to consist of:
unmapped T_PTR
and the T_PTR "INPUT" and "OUTPUT" routines will be read from ExtUtils/typemap.
Apologies - I did wonder about that at the time, but didn't spend the 10 seconds it takes to find out.
'Twould have been much clearer if I had presented the one-line "nullmap.txt" instead of the multi-line version with its "INPUT" and "OUTPUT" sections.

Cheers,
Rob
  • Comment on Re^5: Inline::C and NULL pointers ( override default xsubpp ExtUtils::ParseXS::Utilities::process_typemaps )
  • Select or Download Code

Replies are listed 'Best First'.
Re^6: Inline::C and NULL pointers ( override default xsubpp ExtUtils::ParseXS::Utilities::process_typemaps )
by syphilis (Archbishop) on Dec 20, 2021 at 09:21 UTC
    I really do think it would be better if our user-supplied typemap took precedence over ExtUtils/typemap.

    Turns out it does ... but only if it's named "typemap" and is in the current working directory. (Calling it something else is alone insufficient - on my Windows 7 system, at least.)
    It then turns out that there's no need for the typedeffing either.

    This is a much simpler way of ensuring that undef is passed as a NULL:
    1) Have a file named exactly "typemap" in the cwd that contains the following single line (ending in a newline):
    unsigned char * T_PTR
    2) The following demo script then passes 'undef' as a NULL to the C function foo():
    use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, # verbose build FORCE_BUILD => 1, # re-build whenever the script is run CLEAN_AFTER_BUILD => 0, # don't clean up the build directory ; use Inline C =><<'EOC'; unsigned char *foo(unsigned char *name) { if(name) printf("True\n"); else printf("False\n"); return(NULL); } EOC foo(undef); __END__ Outputs: Use of uninitialized value in subroutine entry at try2.pl line 20. False
    I don't know why naming the typemap to something other than "typemap" should be inadequate - even stranger that it then could be made to work if unsigned char* was typedeffed to something else.
    Unless I can find some documentation that explains that weirdness, then I can only think that it's an Inline::C bug.
    I'll investigate that this issue and try to come up with a patch that fixes it if it's indeed a bug.

    Note that the file named "typemap" gets found automatically if it's located in the CWD. There's no need to engage the "TYPEMAPS" configuration option.

    UPDATE: It seems that a file named "typemap" will also be found and used automatically if it's in the .. or the lib/ExtUtils directory.
    If it's not called "typemap" && it's not in lib/ExtUtils or . or .. directories, then its location will be passed on to xsubpp (which will acknowledge that it has been informed of the file's existence) if and only if the file's location is specified in the 'TYPEMAPS' Config entry.
    But then xsubpp just silently ignores it completely unless it maps a type not covered by the files named "typemap" that were automatically found. (Hence my "nullmap.txt" from a previous post was able to be used.)
    As Bill Burroughs once said, "this is *insane* ... this *is* insane ... *this* is insane".
    Where should issues/PRs for EU::ParseXS be filed ? .

    Cheers,
    Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139760]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found