[Pyrex] Bug? SystemError: error return without exception set

Lenard Lindstrom len-l at telus.net
Mon Dec 13 20:04:11 CET 2004


On Mon, 13 Dec 2004 11:20:22 -0500 Charles Moad <cmoad at indiana.edu> wrote:

> The subject is the same as one already in the list with the same
> problem.  Someone posted a patch, but it appears the correction has been
> made in the latest version of pyrex.  I am getting the error:
> 
> Traceback (most recent call last):
>   File "./test.py", line 140, in ?
>     initShader('mandelbrot.frag')
>   File "./test.py", line 104, in initShader
>     print glGetActiveUniformARB(shaderProgram, 1)
> SystemError: error return without exception set
> 
> And the c code has appearance of returning 0:
> 
>  __pyx_r = 0;
>   __pyx_L0:;
>   Py_DECREF(__pyx_v_programObj);
>   Py_DECREF(__pyx_v_index);
>   return __pyx_r;
> }
> 
On success execution jumps to label __pyx_L0. The code immediately
preceding __pyx_L0 should only be executed for an error. It sets up
the nice traceback that accompanies an exception raised within a
Pyrex module. Since there is no traceback from within
glGetActiveUniformARB then __pyx_r was set 0 somewhere else.

> Here is the pyrex code generating the error:
> 
> cdef extern c_glGetActiveUniformARB "glGetActiveUniformARB"(GLhandleARB
> programObj, GLuint index, GLsizei maxLength, GLsizei* length, GLint
> *size, GLenum *type, GLcharARB *name)
> def glGetActiveUniformARB(programObj, index):
>    cdef GLsizei maxLength
>    cdef GLint size
>    cdef GLenum type
>    cdef GLcharARB *name
> 
>    c_glGetObjectParameterivARB(programObj,
> GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB, &maxLength)
>    name = <GLcharARB*>PyMem_Malloc(maxLength+1)
>    c_glGetActiveUniformARB(programObj, index, maxLength, NULL, &size,
> &type, name)
> 
>    return (size, type, name)
> 
> 
> Any help would be greatly appreciated!
> 
I can only suggest adding some debug statements and see what happens:

    print maxLength ## Length OK?
    name = <GLcharARB*>PyMem_Malloc(maxLength+1)
    if name == NULL: ## Memory allocated?
        raise MemoryError, "PyMem_Malloc returned NULL pointer"
    c_glGetActiveUniformARB( ... )
    print size, type, name ##
    return (size, type, name)

The null name pointer check should be left in, with an appropriate
error message. I also note that allocated memory is not freed.
This should do it, making sure psname is a python variable (no
declaration):

    c_glGetActiveUniformARB( ... )
    psname = name  # Copy name C string to python string
    PyMem_Free(<void *>name)
    return (size, type, psname)

or:
    rval = (size, type, name)
    PyMem_Free(<void *>name)
    return rval

Lenard Lindstrom
<len-l at telus.net>





More information about the Pyrex mailing list