defining extern variables in pyrex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thys Meintjes

    #1

    defining extern variables in pyrex

    Hi All,

    I've inherited a c library and is the process of wrapping it using
    Pyrex. The library code is a state machine and remembers previous values
    in order to determine new values on, for example, a decode() call. These
    "state-full" variables were all implemented using 'extern' in the c
    code.

    My wrapper works fine if I have only one instance of my new type
    myclass. However, when I create more than one instance of myclass it
    seems that the different instances each share the same extern variables.
    And of course when one method call on a instance manipulates the
    internal state machine it invalidates the other instance's state. I
    guess this makes sense...

    So, how do I define variables in the pyrex wrapper that is visible as
    extern c values but are private to a instance ? Take a look at the
    example, both val2 and val1 are defined as extern in some .h or .c files
    in the library, val2 is visible but not private to myclass, val1 is
    private to myclass but when I import myclasslib I get undefined symbol
    errors like these:

    ImportError: ./codex/efr/src/libgsmefr.so: undefined symbol: past_gain

    example:
    cdef short val2
    cdef class myclass:
    cdef short val1


    I reckon that if I can define all the state-full vars in the same scope
    as val1 and convince Pyrex (and the linker, I guess) that these are the
    elusive externs I wouldn't need to go through the pain of passing these
    state-full vars down each method call,

    Do I have any hope of doing it this way ?

    regards
    Thys


Working...