Menu

#494 Accessing cvar alone causes write-fault.

closed-works-for-me
nobody
python (260)
5
2004-11-03
2004-11-01
Anonymous
No

The python interface file:

%module my_mod

extern int xxx;

results in the addition of the global variable 'xxx' to the
module. This is normally accessed in python as

>>> my_mod.cvar.xxx
0

And this works. However if you write in python:

>>> my_mod.cvar
<CRASH>

the program crashes with a write-fault.

I compiled my module with VC6.0 and VC2003 with the
same results.

I'm using python 2.3 and associated includes and libs.

Kevin Collins
kac@thinksrs.com

Discussion

  • Marcelo Matus

    Marcelo Matus - 2004-11-01

    Logged In: YES
    user_id=246059

    Maybe you need to add 'xxx', the following works fine
    here (gcc3.2.2+python2.3.2):

    %module caca

    %inline
    {
    extern int xxx;
    }

    %{
    int xxx = 1;
    %}

     
  • Nobody/Anonymous

    Logged In: NO

    I had my xxx varable defined in another file. In any case, just
    so we are on the same page, I get the same behavior with
    the example code in python/simple/example.i.

    /* File : example.i */
    %module example

    extern int gcd(int x, int y);
    extern double Foo;

    /* File : example.c */

    /* A global variable */
    double Foo = 3.0;

    /* Compute the greatest common divisor of positive integers
    */
    int gcd(int x, int y) {
    int g;
    g = y;
    while (x > 0) {
    g = x;
    x = y % x;
    y = g;
    }
    return g;
    }

    And now when you go to use it:

    >>> import example
    >>> example.cvar.gcd(12,8)
    4
    >>> example.cvar.Foo
    3.0
    >>> example.cvar
    <CRASH>

    Perhaps it is an operating system dependent bug. I'm on
    Windows 2000, using VC2003+Python2.3.2. It crashes in the
    middle of fprintf(fp,"Global variables { ") while trying to lock
    the file stream.

    Kevin Collins
    kac@thinksrs.com

     
  • Marcelo Matus

    Marcelo Matus - 2004-11-02

    Logged In: YES
    user_id=246059

    With python2.3.2 and gcc seems to be working too

    cd python/simple
    make

    python
    import example
    print example.cvar

    => Global variables { Foo }

    I don't know why is crashing in your case, and since I don't
    have the compiler you are using, you are mainly the
    only one that can provide more information :).

    Could you try to debug the seg. fault a little more,
    if at least you can identify where it occurs, inside
    python or swig wrapped code.

    Also, maybe you can try another python version.

    We now python 2.3.2 is working (at least with gcc in Linux)....

    Marcelo

     
  • Nobody/Anonymous

    Logged In: NO

    I got it to work!

    Apparently it is a compiler issue. I must have been using a
    switch that was incompatible with the python dll or
    something. I had originally just created my project in the IDE
    and I got the results I described previously.

    However, when I switched over to letting distutils and
    setup.py compile my module, it worked!

    This implies that the problem is either the compiler (disutils
    uses VC6 and I was using VC2003.NET: Perhaps FILE *
    doesn't port) or an incompatible compiler switch.

    In any case, now that it works, I'm rapidly losing interest in
    the why's and wherefore's.

    Thanks for the responses.

    Kevin Collins
    kac@thinksrs.com

     
  • Marcelo Matus

    Marcelo Matus - 2004-11-03
    • status: open --> closed
     
  • Marcelo Matus

    Marcelo Matus - 2004-11-03
    • status: closed --> closed-works-for-me
     

Log in to post a comment.