[Python-bugs-list] [Bug #132008] PyList_Reverse fails with C Extensions

noreply@sourceforge.net noreply@sourceforge.net
Mon, 12 Feb 2001 14:15:14 -0800


Bug #132008, was updated on 2001-Feb-12 08:45
Here is a current snapshot of the bug.

Project: Python
Category: Python Interpreter Core
Status: Open
Resolution: None
Bug Group: None
Priority: 7
Submitted by: whack
Assigned to : gvanrossum
Summary: PyList_Reverse fails with C Extensions

Details: The C API function 'PyList_Reverse()' causes a 'Segmentation
Fault(core dump)' when used under:
Python 2.0 (#1, Oct 27 2000, 09:38:44) [C] on sunos5

A simple C function was written to accept a Python list as
input and return it in reverse using 'PyList_Reverse()'.
When compiled under Python1.5.2, this code works flawlessly.
I use the function under Python in this manner:
Python 1.5.2 (#2, Apr 17 1999, 11:16:17) [C] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import casette
>>> shape = casette.casette([1,2,3,4])
>>> shape
[4, 3, 2, 1]

However, when compiled under Python2.0, it returns the
following error:
Python 2.0 (#1, Oct 27 2000, 09:38:44) [C] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> import casette
>>> shape = casette.casette([1,2,3,4])
Segmentation fault (core dumped)

and exits from Python altogether. 

I can provide the test program (with Makefile) if it 
would help track down the bug. Any indication of the
cause of this bug or a work around would be appreciated.


Follow-Ups:

Date: 2001-Feb-12 14:15
By: tim_one

Comment:
Related patches checked in:
_testcapimodule.c rev 1.2
    make sure PyList_Reverse doesn't blow up again
getargs.c rev 2.54
    assert args isn't NULL at the top of vgetargs1 instead of
    waiting for a NULL-pointer dereference at the end
-------------------------------------------------------

Date: 2001-Feb-12 13:43
By: gvanrossum

Comment:
I'll take care of this.
-------------------------------------------------------

Date: 2001-Feb-12 12:21
By: tim_one

Comment:
Raised priority, assigned to me.

Offhand, looks like one of those cases where the worker function
(listreverse) was changed to use PyArg_ParseTuple, but the API wrapper
function (PyList_Reverse) passes NULL for args instead of an empty tuple. 
Boom.  list.reverse() at Python level uses the worker function directly. so
only an extension module would bump into this (PyList_Reverse isn't used
anywhere within Python).

whack, this should get fixed for the 2.1b1 release.  In the meantime, try
invoking the reverse *method* on your list object.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=132008&group_id=5470