[Pyrex] A riddle
Tomasz Primke
tprimke at interia.pl
Tue Apr 18 19:27:57 CEST 2006
Hello!
I'm totally confused. In the zip file, that is attached to this message,
there are source files of a Pyrex extension module (slightly powered with a
C code).
The C code contains of some simple functions, that can be used to
(low-level) memory management. Those functions are used to allocate memory
for structures defined in ea.pxd file. In ea.pyx file there are
"constructors" and "destructors" of the structures. This is also one
extension type in this file, used for testing purposes. The extension type
is used in two test functions (accessible from Python): test() and test2().
Both of these functions are supposed to create a SPop structure instance and
to show its simple usage: get and set some value. This is only one
difference between these functions: the test() function creates a SPop
structure with 70 SInd structures, while the test2() function creates a
SPop structure with 20 SInd structures.
The problem can be inspected with help of the program.py file. This simple
program imports the module and calls the test2() function, followed by the
test() one.
The problem is that while the test2() function works as expected, the test()
function causes a serious error: the error, that occurs, when program tries
to reach a memory address, that hadn't been allocated before. (The last
seen message is "Population 0 individual 67 chromosome 0".) If the "write"
code is removed, all will work OK.
The riddle is: why on earth the test2() function works OK, while the test()
function causes the error, if the only difference between these two
functions is the number of SInd structure instances? I just don't get it.
I have tested the code using Python 2.4.2 and Pyrex 0.9.3.1, on two
different GNU/Linux boxes. And I just can't imagine any reasonable reason,
why this code doesn't work. Could anyone explain it?
Best regards,
Tomek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyrex_riddle.zip
Type: application/x-zip
Size: 8592 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20060418/99888a1f/pyrex_riddle.bin
More information about the Pyrex
mailing list