Ulrich Eckhardt | 30 Sep 14:26
Favicon

when is path==NULL?

Hi!

I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that 
function, there is code like this:

  PyObject* path = PySys_GetObject("path");
  ...
  if (path != NULL) {
    ...
  }

My intuition says that if path==NULL, something is very wrong. At least I 
would expect to get 'None', but never NULL, except when out of memory. So, 
for the case that path==NULL', I would simply invoke Py_FatalError("no mem 
for sys.path"), similarly to the other call there.

Sounds reasonable?

Uli

--

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

**************************************************************************************
           Visit our website at <http://www.satorlaser.de/>
**************************************************************************************
Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten bestimmt und kann
vertrauliche Informationen enthalten. Bitte benachrichtigen Sie den Absender umgehend, falls Sie
nicht der beabsichtigte Empfänger sein sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder
(Continue reading)

Christian Heimes | 30 Sep 14:48
Favicon

Re: when is path==NULL?

Ulrich Eckhardt wrote:
> Hi!
> 
> I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that 
> function, there is code like this:
> 
>   PyObject* path = PySys_GetObject("path");
>   ...
>   if (path != NULL) {
>     ...
>   }
> 
> My intuition says that if path==NULL, something is very wrong. At least I 
> would expect to get 'None', but never NULL, except when out of memory. So, 
> for the case that path==NULL', I would simply invoke Py_FatalError("no mem 
> for sys.path"), similarly to the other call there.

PySys_GetObject may return NULL after the user has removed sys.path with 
delattr(sys, 'path'). There are valid applications for removing sys.path.

Christian

_______________________________________________
Python-Dev mailing list
Python-Dev <at> python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-python-dev%40m.gmane.org

Guido van Rossum | 30 Sep 16:27
Favicon

Re: when is path==NULL?

On Tue, Sep 30, 2008 at 5:48 AM, Christian Heimes <lists <at> cheimes.de> wrote:
> Ulrich Eckhardt wrote:
>>
>> Hi!
>>
>> I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that
>> function, there is code like this:
>>
>>  PyObject* path = PySys_GetObject("path");
>>  ...
>>  if (path != NULL) {
>>    ...
>>  }
>>
>> My intuition says that if path==NULL, something is very wrong. At least I
>> would expect to get 'None', but never NULL, except when out of memory. So,
>> for the case that path==NULL', I would simply invoke Py_FatalError("no mem
>> for sys.path"), similarly to the other call there.
>
> PySys_GetObject may return NULL after the user has removed sys.path with
> delattr(sys, 'path'). There are valid applications for removing sys.path.

Or before sys.path is initialized using PySys_SetPath(). Trust me,
this code is as it should be.

--

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev <at> python.org
(Continue reading)

Thomas Lee | 30 Sep 14:42

Re: when is path==NULL?

Ulrich Eckhardt wrote:
> Hi!
>
> I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that 
> function, there is code like this:
>
>   PyObject* path = PySys_GetObject("path");
>   ...
>   if (path != NULL) {
>     ...
>   }
>
> My intuition says that if path==NULL, something is very wrong. At least I 
> would expect to get 'None', but never NULL, except when out of memory. So, 
> for the case that path==NULL', I would simply invoke Py_FatalError("no mem 
> for sys.path"), similarly to the other call there.
>
> Sounds reasonable?
>
> Uli
>
>   
Maybe it's just being safe?

 From Python/sysmodule.c:

    PyThreadState *tstate = PyThreadState_GET();
    PyObject *sd = tstate->interp->sysdict;
    if (sd == NULL)
        return NULL;
(Continue reading)

Thomas Lee | 30 Sep 14:46

Re: when is path==NULL?

Ulrich Eckhardt wrote:
> Hi!
>
> I'm looking at trunk/Python/sysmodule.c, function PySys_SetArgv(). In that 
> function, there is code like this:
>
>   PyObject* path = PySys_GetObject("path");
>   ...
>   if (path != NULL) {
>     ...
>   }
>
> My intuition says that if path==NULL, something is very wrong. At least I 
> would expect to get 'None', but never NULL, except when out of memory. So, 
> for the case that path==NULL', I would simply invoke Py_FatalError("no mem 
> for sys.path"), similarly to the other call there.
>
> Sounds reasonable?
>
> Uli
>
>   
I also meant to mention that there might be a reason why we want the out 
of memory error to bubble up to the caller should that happen while 
attempting to allocate the PyString in PyDict_GetItemString, rather than 
just bailing out with a generic FatalError.

Cheers,
T
_______________________________________________
(Continue reading)


Gmane