[pypy-commit] cffi cffi-1.0: Fix the argument types (function -> ptr_to_function; array -> pointer)

arigo noreply at buildbot.pypy.org
Fri Apr 10 19:06:16 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1689:95d687f8e1bd
Date: 2015-04-10 19:06 +0200
http://bitbucket.org/cffi/cffi/changeset/95d687f8e1bd/

Log:	Fix the argument types (function -> ptr_to_function; array ->
	pointer)

diff --git a/new/parse_c_type.c b/new/parse_c_type.c
--- a/new/parse_c_type.c
+++ b/new/parse_c_type.c
@@ -285,8 +285,21 @@
                         break;
                     }
                     int arg = parse_complete(tok);
+                    _cffi_opcode_t oarg;
                     assert(arg_next - base_index <= arg_total);
-                    tok->output[arg_next++] = _CFFI_OP(_CFFI_OP_NOOP, arg);
+                    switch (_CFFI_GETOP(tok->output[arg])) {
+                    case _CFFI_OP_ARRAY:
+                    case _CFFI_OP_OPEN_ARRAY:
+                        arg = _CFFI_GETARG(tok->output[arg]);
+                        /* fall-through */
+                    case _CFFI_OP_FUNCTION:
+                        oarg = _CFFI_OP(_CFFI_OP_POINTER, arg);
+                        break;
+                    default:
+                        oarg = _CFFI_OP(_CFFI_OP_NOOP, arg);
+                        break;
+                    }
+                    tok->output[arg_next++] = oarg;
                     if (tok->kind != TOK_COMMA)
                         break;
                     next_token(tok);
diff --git a/new/test_parse_c_type.py b/new/test_parse_c_type.py
--- a/new/test_parse_c_type.py
+++ b/new/test_parse_c_type.py
@@ -150,3 +150,17 @@
         Func(4), NoOp(11), NoOp(12), FuncEnd(0),
         Prim(lib._CFFI_PRIM_LONG),
         Prim(lib._CFFI_PRIM_SHORT)]
+
+def test_fix_arg_types():
+    assert parse("int(char(long, short))") == [
+        Prim(lib._CFFI_PRIM_INT),
+        '->', Func(0), Pointer(5), FuncEnd(0),
+        Prim(lib._CFFI_PRIM_CHAR),
+        Func(4), NoOp(9), NoOp(10), FuncEnd(0),
+        Prim(lib._CFFI_PRIM_LONG),
+        Prim(lib._CFFI_PRIM_SHORT)]
+    assert parse("int(char[])") == [
+        Prim(lib._CFFI_PRIM_INT),
+        '->', Func(0), Pointer(4), FuncEnd(0),
+        Prim(lib._CFFI_PRIM_CHAR),
+        OpenArray(4)]


More information about the pypy-commit mailing list