Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1707:3ce0431464af
Date: 2015-04-14 18:55 +0200
http://bitbucket.org/cffi/cffi/changeset/3ce0431464af/
Log: clarify error message
diff --git a/new/cffi1_module.c b/new/cffi1_module.c
--- a/new/cffi1_module.c
+++ b/new/cffi1_module.c
@@ -1,3 +1,5 @@
+static PyObject *FFIError;
+
#include "parse_c_type.c"
#include "realize_c_type.c"
@@ -7,8 +9,6 @@
static PyTypeObject FFI_Type; /* forward */
static PyTypeObject Lib_Type; /* forward */
-static PyObject *FFIError;
-
#include "ffi_obj.c"
#include "lib_obj.c"
diff --git a/new/realize_c_type.c b/new/realize_c_type.c
--- a/new/realize_c_type.c
+++ b/new/realize_c_type.c
@@ -31,8 +31,8 @@
static PyObject *
-_realize_c_type(const struct _cffi_type_context_s *ctx,
- _cffi_opcode_t opcodes[], int index); /* forward */
+_realize_c_type_or_func(const struct _cffi_type_context_s *ctx,
+ _cffi_opcode_t opcodes[], int index); /* forward */
/* Interpret an opcodes[] array. If opcodes == ctx->types, store all
@@ -43,17 +43,25 @@
realize_c_type(const struct _cffi_type_context_s *ctx,
_cffi_opcode_t opcodes[], int index)
{
- PyObject *x = _realize_c_type(ctx, opcodes, index);
- if (x != NULL && !CTypeDescr_Check(x)) {
- PyErr_SetString(PyExc_NotImplementedError, "unexpected type");
- x = NULL;
+ PyObject *x = _realize_c_type_or_func(ctx, opcodes, index);
+ if (x == NULL || CTypeDescr_Check(x)) {
+ return x;
}
- return x;
+ else {
+ PyObject *y;
+ assert(PyTuple_Check(x));
+ y = PyTuple_GET_ITEM(x, 0);
+ PyErr_Format(FFIError, "the type '%s' is a function type, not a "
+ "pointer-to-function type",
+ ((CTypeDescrObject *)y)->ct_name);
+ Py_DECREF(x);
+ return NULL;
+ }
}
static PyObject *
-_realize_c_type(const struct _cffi_type_context_s *ctx,
- _cffi_opcode_t opcodes[], int index)
+_realize_c_type_or_func(const struct _cffi_type_context_s *ctx,
+ _cffi_opcode_t opcodes[], int index)
{
PyObject *x, *y, *z;
_cffi_opcode_t op = opcodes[index];
@@ -75,7 +83,7 @@
break;
case _CFFI_OP_POINTER:
- y = _realize_c_type(ctx, opcodes, _CFFI_GETARG(op));
+ y = _realize_c_type_or_func(ctx, opcodes, _CFFI_GETARG(op));
if (y == NULL)
return NULL;
if (CTypeDescr_Check(y)) {
@@ -148,7 +156,7 @@
}
case _CFFI_OP_NOOP:
- x = _realize_c_type(ctx, opcodes, _CFFI_GETARG(op));
+ x = _realize_c_type_or_func(ctx, opcodes, _CFFI_GETARG(op));
break;
default:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit