Menu

#976 "print mymodule.cvar" crashes Python on Windows (not Linux)

None
closed-fixed
nobody
python (260)
5
2022-03-15
2008-12-27
No

"print mymodule.cvar" crashes Python on Windows XP (Swig 1.3.36, Python 2.5, VC++ 2005) but works fine on Debian 4.0 (Swig 1.3.36, Python 2.4, gcc).

This looks like an old SWIG bug that was never fixed. See for example Bug#1058361 (Nov 2004) and http://www.nabble.com/simple-cvar-bug-td2636426.html#a2636794 (Jan 2006). These issues were resolved with a "Works for me on Linux" and "Does it work with the development version?", respectively.

The reason this is important is that that dir(mymodule.cvar) just returns an empty array, so the only way to find out what are the names of the global variables is with the print statement. (I'd actually prefer that the dir command worked, but I'll take what I get.)

Please let me know what other information you need to squash this bug.

Discussion

  • Olly Betts

    Olly Betts - 2022-03-15
    • status: open --> closed-fixed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-03-15

    With Python 3 and SWIG git master print("Variables =", example.cvar) on the variables example gives:

    Variables = (path, status, pt, ptptr, name, iptrvar, cstrvar, strvar, dvar, fvar, cvar, ucvar, scvar, ulvar, usvar, uivar, lvar, svar, ivar)
    

    (see https://ci.appveyor.com/project/swig/swig/builds/42898050/job/dkix6bohlmttv6r2#L740 at least until the log expires)

    With Python 2.7 this gives:

    ('Variables =', <Swig global variables>)
    

    I think that's calling repr() instead of str() due to differences in how print works between Python 2 and Python 3. Anyway the crash is gone so closing.

     
  • Olly Betts

    Olly Betts - 2022-03-15

    With Python 2.7 or 3.x and SWIG git master the print("Variables = " + str(example.cvar)) I've now added to the variables example gives:

    Variables = (path, status, pt, ptptr, name, iptrvar, cstrvar, strvar, dvar, fvar, cvar, ucvar, scvar, ulvar, usvar, uivar, lvar, svar, ivar)
    

    (e.g. see https://ci.appveyor.com/project/swig/swig/builds/42898050/job/dkix6bohlmttv6r2#L740 at least until the log expires.)

    The crash is gone and the list of variables returned so closing.

     

Log in to post a comment.

MongoDB Logo MongoDB