This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Error with callback function and as_parameter with NumPy ndp
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: albertstrasheim, theller
Priority: normal Keywords:

Created on 2006-10-10 15:11 by albertstrasheim, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
callbacks.c.diff albertstrasheim, 2006-10-10 15:13
Messages (2)
msg30202 - (view) Author: Albert Strasheim (albertstrasheim) Date: 2006-10-10 15:11
I posted to the ctypes-users mailing list about this
problem, but SourceForge failed to make that post and
its replies available in the ctypes-users archive, so
I'm repeating it here.

I'm using NumPy with ctypes. I would like to create a
callback function that calls into Python, allocates a
NumPy array and returns a suitable pointer to the C code.

NumPy has a function called ndpointer that allows one
to specify some details of NumPy arrays when dealing
with argtypes. This function also takes care of
extracting the array's data pointer.

Details here:

Creating a callback function as follows works:

stuff = []
import numpy
def allocator1():
    x = numpy.array([...], dtype='f4')
    return x.ctypes.data_as(POINTER(c_float))

However, if one adds ndpointer to the mix, an error occurs:

stuff = []
import numpy
def allocator2():
    x = numpy.array([...], dtype='f4')
    return x

The error is:

SystemError: NULL result without error in PyObject_Call

Thomas Heller has a patch for this issue.
msg30203 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-10-17 19:47
Logged In: YES 

At least the 'SystemError: NULL result without error in
PyObject_Call' is fixed now in SVN revision 52367
(release25-maint), and revision 52365 (trunk).

You will now get a 'TypeError: unsupported result type for
callback function'.

That's all I can do for Python 2.5, anyway.

I suggest that possible workarounds should be discussed on
the ctypes-users list.
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44109
2006-10-10 15:11:35albertstrasheimcreate