summaryrefslogtreecommitdiff
path: root/c/call_python.c
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-11-13 18:06:28 +0100
committerArmin Rigo <arigo@tunes.org>2015-11-13 18:06:28 +0100
commitb3bd49df97b7f6ce1a644b385e19d82b63d65d6f (patch)
treeff9b07c91f3712ae34bf4c2239bd04812fd6b703 /c/call_python.c
parent0640d0c8015b9000e9845a4f5c21782cb5e2c94e (diff)
downloadcffi-b3bd49df97b7f6ce1a644b385e19d82b63d65d6f.tar.gz
More tests, make the name optional in ffi.call_python()
Diffstat (limited to 'c/call_python.c')
-rw-r--r--c/call_python.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/c/call_python.c b/c/call_python.c
index 3e2a781..9ed3e4d 100644
--- a/c/call_python.c
+++ b/c/call_python.c
@@ -12,12 +12,20 @@ static PyObject *_ffi_call_python_decorator(PyObject *outer_args, PyObject *fn)
CTypeDescrObject *ct;
FFIObject *ffi;
builder_c_t *types_builder;
+ PyObject *name = NULL;
if (!PyArg_ParseTuple(outer_args, "OzOO", &ffi, &s, &error, &onerror))
return NULL;
if (s == NULL) {
- abort();
+ PyObject *name = PyObject_GetAttrString(fn, "__name__");
+ if (name == NULL)
+ return NULL;
+ s = PyString_AsString(name);
+ if (s == NULL) {
+ Py_DECREF(name);
+ return NULL;
+ }
}
types_builder = &ffi->types_builder;
@@ -27,6 +35,7 @@ static PyObject *_ffi_call_python_decorator(PyObject *outer_args, PyObject *fn)
g = &types_builder->ctx.globals[index];
if (_CFFI_GETOP(g->type_op) != _CFFI_OP_CALL_PYTHON)
goto not_found;
+ Py_XDECREF(name);
ct = realize_c_type(types_builder, types_builder->ctx.types,
_CFFI_GETARG(g->type_op));
@@ -53,7 +62,9 @@ static PyObject *_ffi_call_python_decorator(PyObject *outer_args, PyObject *fn)
return x;
not_found:
- abort();
+ PyErr_Format(FFIError, "ffi.call_python('%s'): name not found as a "
+ "CFFI_CALL_PYTHON line from the cdef", s);
+ Py_XDECREF(name);
return NULL;
}