Python - SystemError: NULL result without errors in a PyObject call

History: I am trying to interact with C in Python in order to use the faster computational speed of C for existing Python code. I already had some success, also with skipping NumPy arrays - but now it seems to be a problem, and I cannot solve it. This is the code:

#define FORMAT_VALUE_T "d" char format_buffer[32]; typedef struct { PyObject_HEAD PyArrayObject *invmat; unsigned order; value_t weight, *buffer; } Det; typedef double value_t; typedef struct { PyObject_HEAD Det *det; value_t *row, *covs, ratio, star; } DetAppendMove; static int append_init(DetAppendMove *self, PyObject *args, PyObject *kwds) { value_t star, *temp; PyArrayObject *row, *col; PyObject *result = Py_BuildValue("(i)",1); Det *dete; snprintf(format_buffer, sizeof(format_buffer), "%s%s", "O!O!O!", FORMAT_VALUE_T); if (PyArg_ParseTuple(args, format_buffer, &DetType, &dete, &PyArray_Type, &row, &PyArray_Type, &col, &star)) { self->det = dete; temp = (value_t*)self->det->buffer; } else { result = Py_BuildValue("(i)",-1); } return result; } 

It actually does nothing, I just wanted to check if I can pass these arrays. As the header says, I get the following error message:

SystemError: NULL result without errors in PyObject call

This is interesting since I already passed multiple arrays once (did it the exact same way). Usually these arrays are probably 100x100, if even. Usually people complained about very large arrays.

I am using Ubuntu 14.04 on a 64 bit machine, Python V2.7.6 and Numpy 1.8.2

It would be great if one of you could help me - I have no idea what is wrong here.

EDIT: I still do not understand this problem, but sometimes it works, sometimes it crashes with an error from above. I have absolutely no idea what it could be - anyone?

+6
source share
1 answer

Recently, someone showed me the answer in another post:

When you return NULL from a function c affected by python, you must set the error message before that, since returning NULL means an error has occurred.

If an error occurs and you return NULL because of this, use PyErr_SetString (); if an error does not occur, use

 Py_RETURN_NONE; 

Thanks iharob, helped a lot!

L.

+1
source

Source: https://habr.com/ru/post/983812/


All Articles