pyrex backport, accept ctypedef public api declarations
authorLisandro Dalcin <dalcinl@gmail.com>
Wed, 15 Oct 2008 15:10:09 +0000 (12:10 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Wed, 15 Oct 2008 15:10:09 +0000 (12:10 -0300)
Cython/Compiler/Parsing.py
tests/compile/ctypedefpubapi.pyx [new file with mode: 0644]

index 2a2a5ac71d7404015504c4bc5d89172fb4eb0fb7..8ef8277abd8e9c8de4660f1370f1e8e8620e6e14 100644 (file)
@@ -1406,8 +1406,8 @@ def p_statement(s, ctx, first_statement = 0):
     if s.sy == 'ctypedef':
         if ctx.level not in ('module', 'module_pxd'):
             s.error("ctypedef statement not allowed here")
-        if ctx.api:
-            error(s.position(), "'api' not allowed with 'ctypedef'")
+        #if ctx.api:
+        #    error(s.position(), "'api' not allowed with 'ctypedef'")
         return p_ctypedef_statement(s, ctx)
     elif s.sy == 'DEF':
         return p_DEF_statement(s)
@@ -2166,7 +2166,10 @@ def p_ctypedef_statement(s, ctx):
     pos = s.position()
     s.next()
     visibility = p_visibility(s, ctx.visibility)
+    api = p_api(s)
     ctx = ctx(typedef_flag = 1, visibility = visibility)
+    if api:
+        ctx.api = 1
     if s.sy == 'class':
         return p_c_class_definition(s, pos, ctx)
     elif s.sy == 'IDENT' and s.systring in ('struct', 'union', 'enum'):
diff --git a/tests/compile/ctypedefpubapi.pyx b/tests/compile/ctypedefpubapi.pyx
new file mode 100644 (file)
index 0000000..091dc3d
--- /dev/null
@@ -0,0 +1,10 @@
+ctypedef public api class Foo [type PyFoo_Type, object PyFooObject]:
+    pass
+
+cdef api:
+    ctypedef public class Bar [type PyBar_Type, object PyBarObject]:
+        pass
+
+cdef public api:
+    ctypedef class Baz [type PyBaz_Type, object PyBazObject]:
+        pass