Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
573f3fe4
Commit
573f3fe4
authored
Feb 10, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the short form "cdef struct xyz: pass" instead of always requiring a block for it.
Closes #2802.
parent
0907d71f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
25 deletions
+94
-25
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+15
-11
tests/broken/cdefemptysue.pyx
tests/broken/cdefemptysue.pyx
+0
-14
tests/compile/cdefemptysue.pyx
tests/compile/cdefemptysue.pyx
+43
-0
tests/compile/cdefexternblock.pyx
tests/compile/cdefexternblock.pyx
+23
-0
tests/errors/e_cdefemptysue.pyx
tests/errors/e_cdefemptysue.pyx
+13
-0
No files found.
Cython/Compiler/Parsing.py
View file @
573f3fe4
...
@@ -3184,18 +3184,22 @@ def p_c_struct_or_union_definition(s, pos, ctx):
...
@@ -3184,18 +3184,22 @@ def p_c_struct_or_union_definition(s, pos, ctx):
attributes
=
None
attributes
=
None
if
s
.
sy
==
':'
:
if
s
.
sy
==
':'
:
s
.
next
()
s
.
next
()
s
.
expect
(
'NEWLINE'
)
s
.
expect_indent
()
attributes
=
[]
attributes
=
[]
body_ctx
=
Ctx
()
if
s
.
sy
==
'pass'
:
while
s
.
sy
!=
'DEDENT'
:
s
.
next
()
if
s
.
sy
!=
'pass'
:
s
.
expect_newline
(
"Expected a newline"
,
ignore_semicolon
=
True
)
attributes
.
append
(
else
:
p_c_func_or_var_declaration
(
s
,
s
.
position
(),
body_ctx
))
s
.
expect
(
'NEWLINE'
)
else
:
s
.
expect_indent
()
s
.
next
()
body_ctx
=
Ctx
()
s
.
expect_newline
(
"Expected a newline"
)
while
s
.
sy
!=
'DEDENT'
:
s
.
expect_dedent
()
if
s
.
sy
!=
'pass'
:
attributes
.
append
(
p_c_func_or_var_declaration
(
s
,
s
.
position
(),
body_ctx
))
else
:
s
.
next
()
s
.
expect_newline
(
"Expected a newline"
)
s
.
expect_dedent
()
else
:
else
:
s
.
expect_newline
(
"Syntax error in struct or union definition"
)
s
.
expect_newline
(
"Syntax error in struct or union definition"
)
return
Nodes
.
CStructOrUnionDefNode
(
pos
,
return
Nodes
.
CStructOrUnionDefNode
(
pos
,
...
...
tests/broken/cdefemptysue.pyx
deleted
100644 → 0
View file @
0907d71f
cdef
extern
from
"cdefemptysue.h"
:
cdef
struct
spam
:
pass
ctypedef
union
eggs
:
pass
cdef
enum
ham
:
pass
cdef
extern
spam
s
cdef
extern
eggs
e
cdef
extern
ham
h
tests/compile/cdefemptysue.pyx
0 → 100644
View file @
573f3fe4
# mode: compile
# tag: struct, union, enum, cdefextern
cdef
extern
from
*
:
"""
struct spam { int a; };
struct flat_spam { int a; };
typedef struct { int a; } flat_spam_type;
typedef union { int a; long b; } eggs;
typedef union { int a; long b; } flat_eggs;
enum ham { TOAST };
enum flat_ham { FLAT_TOAST };
"""
cdef
struct
spam
:
pass
cdef
struct
flat_spam
:
pass
ctypedef
struct
flat_spam_type
:
pass
ctypedef
union
eggs
:
pass
ctypedef
union
flat_eggs
:
pass
cdef
enum
ham
:
pass
cdef
enum
flat_ham
:
pass
cdef
extern
spam
s
cdef
extern
flat_spam
fs
cdef
extern
flat_spam_type
fst
cdef
extern
eggs
e
cdef
extern
flat_eggs
fe
cdef
extern
ham
h
cdef
extern
flat_ham
fh
tests/
broken
/cdefexternblock.pyx
→
tests/
compile
/cdefexternblock.pyx
View file @
573f3fe4
# mode: compile
# tag: struct, union, enum, cdefextern
cdef
extern
from
"cheese.h"
:
cdef
extern
from
"cheese.h"
:
ctypedef
int
camembert
ctypedef
int
camembert
...
@@ -9,11 +12,12 @@ cdef extern from "cheese.h":
...
@@ -9,11 +12,12 @@ cdef extern from "cheese.h":
void
cheddar
()
void
cheddar
()
class
external
.
runny
[
object
runny_obj
]:
# FIXME: find a real declaration here.
cdef
int
a
#class external.runny [object runny_obj]:
def
__init__
(
self
):
# cdef int a
pass
# def __init__(self):
# pass
cdef
runny
r
#cdef runny r = runny()
r
=
x
#r.a = 42
r
.
a
=
42
tests/errors/e_cdefemptysue.pyx
View file @
573f3fe4
...
@@ -8,8 +8,21 @@ ctypedef union eggs:
...
@@ -8,8 +8,21 @@ ctypedef union eggs:
cdef
enum
ham
:
cdef
enum
ham
:
pass
pass
cdef
struct
flat_spam
:
pass
ctypedef
union
flat_eggs
:
pass
cdef
enum
flat_ham
:
pass
_ERRORS
=
u"""
_ERRORS
=
u"""
3:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
3:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
6:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
6:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
9:5: Empty enum definition not allowed outside a 'cdef extern from' block
9:5: Empty enum definition not allowed outside a 'cdef extern from' block
13:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
15:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
17:5: Empty enum definition not allowed outside a 'cdef extern from' block
"""
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment