PQueue and Python 2.5

B

Berteun Damman

Hello,

Recently I was looking for a Priority Queue module, and I've found
Pqueue by Andrew Snare [1]. When I use it with Python 2.4 everything
works okay, at least on the two system I've tested it on (Debian based
AMD 64) and OS PPC.

However, when I use it with Python 2.5 - again on the same machines,
exiting always gives a pointer error. The easiest to demonstrate this
is:

python2.5 -c 'from pqueue import PQueue; PQueue()'

On the Debian system:
$ python2.5 -c 'from pqueue import PQueue; PQueue()'
*** glibc detected *** free(): invalid pointer: 0x00002ad7b5720288 ***
Abort

And on my PowerBook:
python2.5(8124) malloc: *** Deallocation of a pointer not malloced:
0x3b4218; This could be a double free(), or free() called with the
middle of an allocated block;

A memory fault can also be immediately triggered by apply 'del' to a
PQueue-instance. As said, with Python 2.4 it seems to perform without
problems.

I haven't got a clue how to investigate this, but I would be willing to
help if someone has any ideas.

Berteun

[1] http://py.vaults.ca/apyllo.py/514463245.769244789.44776582
 
G

Gabriel Genellina

Recently I was looking for a Priority Queue module, and I've found
Pqueue by Andrew Snare [1].
That appears to be rather ancient, from 1999. Is it a pure Python
implementation or has some C code too?

Python got in 2.3 a heapq module in its standard library; I think it is what
you want, no need for an additional module.
*** glibc detected *** free(): invalid pointer: 0x00002ad7b5720288 ***
Abort

And on my PowerBook:
python2.5(8124) malloc: *** Deallocation of a pointer not malloced:
0x3b4218; This could be a double free(), or free() called with the
middle of an allocated block;

A memory fault can also be immediately triggered by apply 'del' to a
PQueue-instance. As said, with Python 2.4 it seems to perform without
problems.

Ah! then I bet:
- There is some C code involved.
- It carelessly mixes PyMem_Malloc with PyObject_Free or similar as
described in
http://docs.python.org/whatsnew/ports.html

So do yourself a favor and forget about such old piece of code...
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Berteun said:
I haven't got a clue how to investigate this, but I would be willing to
help if someone has any ideas.

There are a number of problems in this code; the most significant one is
the incorrect usage of memory management API. In pqueue_dealloc, the
call PyMem_DEL(pqp) should read PyObject_DEL(pqp), as the object was
allocated with PyObject_NEW. Because this was a common error once,
Python up to 2.4 detected that error and silently corrected it (at some
runtime cost); Python 2.5 now has removed this work-around.

I'll contact the author.

Regards,
Martin
 
G

Giovanni Bajo

There are a number of problems in this code; the most significant one is
the incorrect usage of memory management API. In pqueue_dealloc, the
call PyMem_DEL(pqp) should read PyObject_DEL(pqp), as the object was
allocated with PyObject_NEW. Because this was a common error once,
Python up to 2.4 detected that error and silently corrected it (at some
runtime cost); Python 2.5 now has removed this work-around.

And by the way, this is also a FAQ:

http://effbot.org/pyfaq/why-does-my-c-extension-suddenly-crash-under-2.5.htm

and even explained in the Misc/NEWS of Python 2.5.
 
B

Berteun Damman

Gabriel said:
Python got in 2.3 a heapq module in its standard library; I think it is what
Ah! then I bet:
- There is some C code involved.
- It carelessly mixes PyMem_Malloc with PyObject_Free or similar as
described in
http://docs.python.org/whatsnew/ports.html

So do yourself a favor and forget about such old piece of code...

I would be happy to do so, but it does suit my needs quite well. :) But
everybody thanks for pointing out the probable cause, I never did
anything with C-extentions before, so I wasn't aware of the 2.5
changes. But I'll look into the code.

Berteun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top