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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
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):
attributes
=
None
if
s
.
sy
==
':'
:
s
.
next
()
s
.
expect
(
'NEWLINE'
)
s
.
expect_indent
()
attributes
=
[]
body_ctx
=
Ctx
()
while
s
.
sy
!=
'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
()
if
s
.
sy
==
'pass'
:
s
.
next
()
s
.
expect_newline
(
"Expected a newline"
,
ignore_semicolon
=
True
)
else
:
s
.
expect
(
'NEWLINE'
)
s
.
expect_indent
()
body_ctx
=
Ctx
()
while
s
.
sy
!=
'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
:
s
.
expect_newline
(
"Syntax error in struct or union definition"
)
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"
:
ctypedef
int
camembert
...
...
@@ -9,11 +12,12 @@ cdef extern from "cheese.h":
void
cheddar
()
class
external
.
runny
[
object
runny_obj
]:
cdef
int
a
def
__init__
(
self
):
pass
# FIXME: find a real declaration here.
#class external.runny [object runny_obj]:
# cdef int a
# def __init__(self):
# pass
cdef
runny
r
r
=
x
r
.
a
=
42
#cdef runny r = runny()
#r.a = 42
tests/errors/e_cdefemptysue.pyx
View file @
573f3fe4
...
...
@@ -8,8 +8,21 @@ ctypedef union eggs:
cdef
enum
ham
:
pass
cdef
struct
flat_spam
:
pass
ctypedef
union
flat_eggs
:
pass
cdef
enum
flat_ham
:
pass
_ERRORS
=
u"""
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
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