#1183 swig builtin class is incompatible with stackless python

open
nobody
python (259)
5
2012-12-21
2011-07-25
No

The cxx code generated by swig with -builtin option will not be compiled in stackless python environment.
I have searched through the stackless python source code and found the reason:
In stackless python, the PyHeapTypeObject and PyTypeObject are the same type. In the 'object.h' it defines:
#define PyHeapTypeObject PyTypeObject

In swig, the builtin object implemented as a PyHeapTypeObject and the object's layout is slighty different with stackless python's PyTypeObject.
so the cxx code can't be compiled.

Maybe this bug is mainly caused by stackless python, but I think it is more easy to be fixed in swig.
I will upload a patch in short a while.

Discussion

  • szager

    szager - 2011-07-26

    Looks like you're missing a comma in the third line of the patch:

    - Printf(f, " },\n");
    + Printf(f, "#if !defined(STACKLESS)\n");
    + Printf(f, " }\n");
    + Printf(f, "#endif\n");

    Is STACKLESS #defined by the header file of the stackless python implementation, or are you setting it elsewhere? If you're setting it elsewhere, I would be concerned that this patch introduces a non-standard convention.

     
  • Tang Yaguang

    Tang Yaguang - 2011-07-27

    Yes, I miss a comma, sorry for that. I have update the patch.

    The 'STACKLESS' is a standard macro defined in stackless python source tree 'Stackless\stackless.h'. Stackless itself use this macro to perform conditional compilations.

     
  • Tang Yaguang

    Tang Yaguang - 2011-07-27

    Following two code snap is grabbed from stackless python's 'object.h', It clearly show the cause of the problem

    The definition of PyHeapTypeObject:

    //------------------------------------------------------------------------------------------------
    #ifdef STACKLESS

    /* in Stackless, this is just a synonym */
    #define PyHeapTypeObject PyTypeObject

    #else

    /* The *real* layout of a type object when allocated on the heap */
    typedef struct _heaptypeobject {
    /* Note: there's a dependency on the order of these members
    in slotptr() in typeobject.c . */
    PyTypeObject ht_type;
    PyNumberMethods as_number;
    PyMappingMethods as_mapping;
    PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
    so that the mapping wins when both
    the mapping and the sequence define
    a given operator (e.g. __getitem__).
    see add_operators() in typeobject.c . */
    PyBufferProcs as_buffer;
    PyObject *ht_name, *ht_slots;
    /* here are optional user slots, followed by the members. */
    } PyHeapTypeObject;

    #endif
    //------------------------------------------------------------------------------------------------
    And the definition of PyTypeObject:

    //------------------------------------------------------------------------------------------------
    typedef struct _typeobject {
    //...
    //...
    //...as standard, omitted
    /* Type attribute cache version tag. Added in version 2.6 */
    unsigned int tp_version_tag;

    #ifdef COUNT_ALLOCS
    /* these must be last and never explicitly initialized */
    Py_ssize_t tp_allocs;
    Py_ssize_t tp_frees;
    Py_ssize_t tp_maxalloc;
    struct _typeobject *tp_prev;
    struct _typeobject *tp_next;
    #endif
    #ifdef STACKLESS
    /* we need the extended structure right here */
    PyNumberMethods as_number;
    PyMappingMethods as_mapping;
    PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
    so that the mapping wins when both
    the mapping and the sequence define
    a given operator (e.g. __getitem__).
    see add_operators() in typeobject.c . */
    PyBufferProcs as_buffer;
    PyObject *ht_name, *ht_slots;
    /* here are optional user slots, followed by the members. */
    slp_methodflags slpflags;
    #endif
    } PyTypeObject;
    #endif

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks