Bugs item #1574584, was opened at 2006-10-10 17:11 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574584&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.5 Status: Open Resolution: None Priority: 5 Submitted By: Albert Strasheim (albertstrasheim) Assigned to: Nobody/Anonymous (nobody) Summary: Error with callback function and as_parameter with NumPy ndp Initial Comment: 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: http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/ctypeslib.py http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/core/_internal.py Creating a callback function as follows works: stuff = [] import numpy def allocator1(): x = numpy.array([...], dtype='f4') stuff.append(x) return x.ctypes.data_as(POINTER(c_float)) CFUNCTYPE(POINTER(c_float))(allocator1) However, if one adds ndpointer to the mix, an error occurs: stuff = [] import numpy def allocator2(): x = numpy.array([...], dtype='f4') stuff.append(x) return x CFUNCTYPE(numpy.ctypeslib.ndpointer('f4'))(allocator2) The error is: SystemError: NULL result without error in PyObject_Call Thomas Heller has a patch for this issue. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1574584&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com