[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pygame] Problem with Pygame c api (bad crashes)
- To: pygame-users@seul.org
- Subject: [pygame] Problem with Pygame c api (bad crashes)
- From: Riccardo Trocca <rtrocca@libero.it>
- Date: Wed, 14 Aug 2002 11:41:46 +0200
- Delivered-To: archiver@seul.org
- Delivered-To: pygame-users-outgoing@seul.org
- Delivered-To: pygame-users@seul.org
- Delivery-Date: Wed, 14 Aug 2002 05:43:22 -0400
- Reply-To: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.1b) Gecko/20020721
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