
On Tue, 2003-11-18 at 13:34, Leo Breebaart wrote:
Hi all,
Using the numarray C API, I am trying to create an array containing Python strings from an existing C (char **) array.
In Numeric 23.1, the following code fragment works fine:
PyObject *pdata = NULL; // num_elements has been defined earlier PyStringObject **strarray = malloc(num_elements * sizeof(PyStringObject *)); if (strarray != NULL) { int e; for (e = 0; e < num_elements; e++) { strarray[e] = (PyStringObject *) PyString_FromString(((char **)data)[e]); }
// num_dims and the dim array have been defined earlier pdata = PyArray_FromDimsAndData(num_dims, dim, PyArray_OBJECT, (char *)strarray); }
In numarray 0.7, the same code yields the runtime error:
libnumarray.error: Type object lookup returned NULL for type 14
in the PyArray_FromDimsAndData() call.
Using the current numarray CVS head instead of the 0.7 release makes no difference.
Is there somebody who knows what is going or what I am doing wrong?
Yes and no. You're in an area that numarray supports differently than Numeric. numarray's support for character arrays is in the Python numarray.strings module. There's no direct support for using it from C.
Many thanks in advance,
You're welcome, Todd -- Todd Miller <jmiller@stsci.edu>