Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: ExtUtils::ParseXS has changed (PREINIT:)

by syphilis (Archbishop)
on Aug 18, 2011 at 01:02 UTC ( [id://920826]=note: print w/replies, xml ) Need Help??


in reply to Re: ExtUtils::ParseXS has changed (PREINIT:)
in thread ExtUtils::ParseXS has changed

The fact that it used to work is certainly an accident

Ok - that makes good sense to me, and is one of the things I was hoping to establish.

Then you can also replace "ST(1)" with "position" in the code.

Some of us were wondering what this unused "position" argument was doing. Obviously it wasn't doing anything, but I think I start to understand a purpose for it. (Update: Duh !! It's just an arg that can now be accessed by its name instead of its position on the stack.)

As I now understand it, it's *all* of the other variables (not just 'pos') that should be declared in PREINIT instead of CODE.

I'll rewrite the file in accordance with tye's advice and give it a run.
Many thanks to all respondents.

Cheers,
Rob
  • Comment on Re^2: ExtUtils::ParseXS has changed (PREINIT:)

Replies are listed 'Best First'.
Re^3: ExtUtils::ParseXS has changed (PREINIT:)
by tsee (Curate) on Aug 24, 2011 at 06:30 UTC
    Being the guy who did the changes to ExtUtils::ParseXS, let me add my support for what tye said: The code in question worked purely by accident. The proper way to declare or initialize variables in an XSUB is in a PRE_INIT block! ExtUtils::ParseXS 3.XX just became strict in telling you about the problem in your code. It could have instead broken your code to segfault because of the old behaviour being an accidental misfeature and side-effect of the horrors that lurk in EU::ParseXS' code generation.
      let me add my support for what tye said

      Yep - the file in question has now been amended in line with tye's recommendation, and all is well.
      Interestingly enough, that file had been in that state since 1998, and had produced no ill effects (afawk). There was even one abomination that did essentially this:
      void foo(x,dims) pdl *x PDL_Long *dims = NO_INIT CODE: dims = bar(ST(1)); ...
      'dims' (the 2nd argument supplied to foo) is an SV* ... but then there's a second 'dims' which is a PDL_Long*.
      Dunno how that worked ...

      ExtUtils::ParseXS 3.XX just became strict in telling you about the problem in your code

      Which is a good thing - though it didn't exactly complain in the right way.
      It merely told us that there was no typemap entry for PDL_Long*. And, sure enough, inserting a typemap entry for PDL_Long* fixed the problem, though that's the wrong fix.

      Cheers,
      Rob
Re^3: ExtUtils::ParseXS has changed (PREINIT:)
by ikegami (Patriarch) on Aug 18, 2011 at 03:35 UTC

    As I now understand it, it's *all* of the other variables (not just 'pos') that should be declared in PREINIT instead of CODE.

    C doesn't allow intermixing of vars declarations and code like Perl and C++. Var declarations can just be placed globally or at the start of the block. PREINIT will be placed before any code. CODE can be preceded by other code. Therefore, declarations must be placed in PREINIT or you must add curlies to CODE.

    The PREINIT section of perlxs explains this in more detail and gives example.

      C99 does in fact allow declarations anywhere.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found