[Python-bugs-list] [ python-Bugs-489872 ] PyString_FromString(NULL) seg faults

noreply@sourceforge.net noreply@sourceforge.net
Thu, 06 Dec 2001 08:09:24 -0800


Bugs item #489872, was opened at 2001-12-06 07:25
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=489872&group_id=5470

Category: Python Interpreter Core
Group: Feature Request
>Status: Closed
Resolution: Rejected
Priority: 5
Submitted By: John Merritt (jmerritt5)
Assigned to: Nobody/Anonymous (nobody)
Summary: PyString_FromString(NULL) seg faults

Initial Comment:
Python 1.5.4 and Python 2.0.1, the only two I have
installed, produce a segmentation violation when a NULL
is passed to, at least, PyString_FromString.  

The solution is to check the argument and return
Py_None.

I saw in FAQ (wizard) 8.16 that you should return
Py_Build(""), but, on Python 1.5.4, I don't have
Py_Build.

I use SWIG 1.3.*, and I have modified my version of
SWIG to generate code to check the arguement prior to
calling PyString_FromString.

   if (result == NULL) return Py_None;
   resultobj = PyString_FromString(result);
   return resultobj;

This works like a charm.

John


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-06 08:08

Message:
Logged In: YES 
user_id=6380

I'm rejecting the feature request.  This would unnecessarily
slow it down.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-12-06 07:51

Message:
Logged In: YES 
user_id=3066

The FAQ should refer to Py_BuildValue() instead of
Py_Build(); I've fixed that in the FAQ.

I'm not sure that PyString_FromString() should return None
if passed NULL; I'd expect a separate call about be
appropriate for that behavior.  It would not be unreasonable
for PyString_FromString() to check for NULL and raise a
SystemError though.

Categorizing as a feature request.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-06 07:38

Message:
Logged In: YES 
user_id=6380

Where in the docs does it say that you're allowed to pass
NULL to PyString_FromString()?


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=489872&group_id=5470