Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: SWIG and conflicting definitions

by hexcoder (Curate)
on Jan 07, 2016 at 17:30 UTC ( [id://1152219]=note: print w/replies, xml ) Need Help??


in reply to SWIG and conflicting definitions

Hello jdv!

Lets see if I got this correctly:

  1. XSUB.h is included in line 745 of pwiz_swigbindings_wrap.cxx, defining typedef struct cv CV and macro XS.
  2. cv.hpp is included in line 1862 of pwiz_swigbindings_wrap.cxx, defining a different struct CV.
  3. the XS macro from Perl is used first in line 2149 of pwiz_swigbindings_wrap.cxx

It is ugly, but the preprocessor can help to move the conflicting identifiers around. To do so I would manually modify the file pwiz_swigbindings_wrap.cxx and insert this line before
#define CV __perl_CV
and these ones after
#undef XSPROTO
#define XSPROTO(name) void name(pTHX_ __perl_CV* cv)
#undef CV
line 745.

I checked this roughly with the following C code:
#define CV __perl_CV /* beginning of include XSUB.h */ struct cv { int i; }; typedef struct cv CV; #define XSPROTO(name) CV name /* end of include XSUB.h */ #undef XSPROTO #define XSPROTO(name) __perl_CV name #undef CV struct CV { char c; }; XSPROTO(x); int main() { struct CV y; x.i = 0; y.c = '!'; return 0; }

Replies are listed 'Best First'.
Re^2: SWIG and conflicting definitions
by jdv (Sexton) on Jan 07, 2016 at 19:17 UTC

    Thanks for the reply. This is all black magic to me (plus I think some newlines got lost in the code in your first paragraph) so I'm not sure if I got it right. Here is what I tried around the section you suggested:

    #include "EXTERN.h" #include "perl.h" #define CV __perl_CV #include "XSUB.h" #undef XSPROTO #define XSPROTO(name) void name(pTHX_ __perl_CV* cv) #undef CV

    That's just copying what you wrote and guessing at the newlines, so I'm not sure if the syntax is correct. If I try to compile this, the STDERR is down to ~ 1500 lines with a lot of messages like this:

    pwiz_swigbindings_wrap.cxx:748:39: error: ‘__perl_CV’ has not been dec +lared #define XSPROTO(name) void name(pTHX_ __perl_CV* cv)
      My error, sorry. I should have said to put the line

      #define CV __perl_CV

      before this one

      #include "perl.h"

      otherwise it looks ok.

      Update: some explanations added

      What I intend to do, is this:

      1. for the processing of perl.h, XSUB.h and the included header files therein, substitute the offending identifier CV by __perl_CV. This is done by the preprocessor directive #define CV __perl_CV
      2. Afterwards redeclare the macro XSPROTO, which was using CV also. Unfortunately the above substitution affects only C code, but not subsequent preprocessor directives, so we need to adjust this macro definition.
        This is done by first deleting the old macro definition (#undef XSPROTO), and then by defining it again, but this time with __perl_CV instead of CV.
      3. Finally delete the substitution for identifier CV (#undef CV, so that the following code can use it exclusively.
      4. This in total should remove the conflict between the two different definitions of CV by using __perl_CV for the first one instead.

      If you are curious, you can look at the difference of the preprocessed outputs with and without the modification (gcc -E -dDfile should produce them).

        Thanks - that is progress. After making that change, STDERR is down to 21 lines. This is the full output:

        Here is the context refered to in the first line:

        I really appreciate the help so far. I'd love to get this working but troubleshooting at this level is beyond me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found