Egil Moeller wrote: > Hi! > > I've written a C-module for Python, and it works as intended, but > obviously does something wrong with its memmory management (refference > counting), as it causes Python to segfault now and then (randomly, > whey :S) > > The module source code is available at > http://grimoire.takeit.se/files/CReader.c > > The code isn't _that_ long, so someone experienced with writing Python C > modules should probably not have that hard a time finding what I do > wrong :)
What you are doing wrong: 1. Unless getting the source to/from a web page has stuffed up the indentation [which you should have checked before posting your message], it appears to be indented only ONE space per level. Are you using tabs? Don't. They are intrinsically evil. 2. Your code's over 1200 lines long, and even after allowing for the indentation problem it certainly doesn't read like the poetry of your namesake, Skalla-Grim's son. 3. Expecting people to debug your code remotely when it exhibits problems (1) and (2) 4. Not stating what (if anything) you have tried yourself before posting. 5. Using system free() and realloc() instead the Python-supplied memory API functions. 6. Using *ANY* free() or realloc() function on memory that has *NOT* been allocated with the allocator function from the same family. 7. Not checking whether a buffer has even been allocated before trying to deallocate it. -- http://mail.python.org/mailman/listinfo/python-list