[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] Problem with Pygame c api (bad crashes)



Hello I'm developing a python extension using SWIG and c++ on win32 with 
the latest pygame.
I have some problems with the compilation (with distutils) due to 
import_pygame_base() and import_pygame_surface().
The fact is that in C++ the compiler (VC 6 SP5) complains about "void** 
localptr = (void*)PyCObject_AsVoidPtr(c_api);"
Well, I decided to try to fix this.
Therefore I changed those lines in pygame.h (for import_pygame_base()) in:
int i; void** localptr;\
localptr=new void*;\
*localptr= (void*)PyCObject_AsVoidPtr(c_api); \

This works. I had to allocate explicitily localptr because otherwise I 
had a warning saying that I was using an unitialized var, and then 
python crashed as soon as I imported my module.

Anyway the pains starts when I import_pygame_surface().

I had to change those lines again and I obtained a:

#define import_pygame_surface() { \
    PyObject *module = PyImport_ImportModule("pygame.surface"); \
    if (module != NULL) { \
        PyObject *dict = PyModule_GetDict(module); \
        PyObject *c_api = PyDict_GetItemString(dict, 
PYGAMEAPI_LOCAL_ENTRY); \
        if(PyCObject_Check(c_api)) {\
            int i; void** localptr;\
            localptr=new void*;\
            *localptr= (void*)PyCObject_AsVoidPtr(c_api); \
            for(i = 0; i < PYGAMEAPI_SURFACE_NUMSLOTS; ++i) \
                PyGAME_C_API[i + PYGAMEAPI_SURFACE_FIRSTSLOT] = 
localptr[i]; \
    } Py_DECREF(module); } \
    module = PyImport_ImportModule("pygame.surflock"); \
    if (module != NULL) { \
        PyObject *dict = PyModule_GetDict(module); \
        PyObject *c_api = PyDict_GetItemString(dict, 
PYGAMEAPI_LOCAL_ENTRY); \
        if(PyCObject_Check(c_api)) {\
            int i; void** localptr;\
            localptr=new void*;\
            *localptr= (void*)PyCObject_AsVoidPtr(c_api); \
           
            for(i = 0; i < PYGAMEAPI_SURFLOCK_NUMSLOTS; ++i) {\
                printf("slot %d\n",i);\
                PyGAME_C_API[i + PYGAMEAPI_SURFLOCK_FIRSTSLOT] = 
localptr[i]; \
            }\
            printf("4\n");\
} Py_DECREF(module); } }

The problem is that this code charshes badly.
I' ve found that  the first part (pygame.surface) works, then when we 
are in pygame.surflock, python crashes when i==2.
I've set NUMSLOTS to 2, and I can import the module without crashes, but 
I still didn't try to use it.
What do you think?
Any workaround?
Would it be possible to change pygame.h in order to make it work with VC6?
I can contribute those patches, but I need help to fix this, bacause I'm 
stuck.

Riccardo



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org