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
e9f4217b
Commit
e9f4217b
authored
Aug 18, 2010
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conditional compilation for {Py2|Py3}-only special methods
parent
b3a72122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
17 deletions
+36
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+16
-0
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+20
-17
No files found.
Cython/Compiler/Nodes.py
View file @
e9f4217b
...
...
@@ -1237,6 +1237,18 @@ class FuncDefNode(StatNode, BlockNode):
self
.
generate_cached_builtins_decls
(
lenv
,
code
)
# ----- Function header
code
.
putln
(
""
)
preprocessor_guard
=
None
if
self
.
entry
.
is_special
:
slot
=
TypeSlots
.
method_name_to_slot
.
get
(
self
.
entry
.
name
)
if
slot
:
preprocessor_guard
=
slot
.
preprocessor_guard_code
()
if
(
self
.
entry
.
name
==
'__long__'
and
not
self
.
entry
.
scope
.
lookup_here
(
'__int__'
)):
preprocessor_guard
=
None
if
preprocessor_guard
:
code
.
putln
(
preprocessor_guard
)
with_pymethdef
=
self
.
needs_assignment_synthesis
(
env
,
code
)
if
self
.
py_func
:
self
.
py_func
.
generate_function_header
(
code
,
...
...
@@ -1464,6 +1476,10 @@ class FuncDefNode(StatNode, BlockNode):
code
.
putln
(
"return %s;"
%
Naming
.
retval_cname
)
code
.
putln
(
"}"
)
if
preprocessor_guard
:
code
.
putln
(
"#endif /*!(%s)*/"
%
preprocessor_guard
)
# ----- Go back and insert temp variable declarations
tempvardecl_code
.
put_temp_declarations
(
code
.
funcstate
)
# ----- Python version
...
...
Cython/Compiler/TypeSlots.py
View file @
e9f4217b
...
...
@@ -142,29 +142,32 @@ class SlotDescriptor(object):
self
.
py3
=
py3
self
.
py2
=
py2
def
preprocessor_guard_code
(
self
):
ifdef
=
self
.
ifdef
py2
=
self
.
py2
py3
=
self
.
py3
guard
=
None
if
ifdef
:
guard
=
(
"#if %s"
%
ifdef
)
elif
not
py3
or
py3
==
'<RESERVED>'
:
guard
=
(
"#if PY_MAJOR_VERSION < 3"
)
elif
not
py2
:
guard
=
(
"#if PY_MAJOR_VERSION >= 3"
)
return
guard
def
generate
(
self
,
scope
,
code
):
if
self
.
is_initialised_dynamically
:
value
=
0
else
:
value
=
self
.
slot_code
(
scope
)
py3
=
self
.
py3
py2
=
self
.
py2
if
self
.
ifdef
:
code
.
putln
(
"#if %s"
%
self
.
ifdef
)
else
:
if
not
py3
:
code
.
putln
(
"#if PY_MAJOR_VERSION < 3"
)
elif
not
py2
:
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
if
py3
==
'<RESERVED>'
:
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"0, /*reserved*/"
)
code
.
putln
(
"#else"
)
preprocessor_guard
=
self
.
preprocessor_guard_code
()
if
preprocessor_guard
:
code
.
putln
(
preprocessor_guard
)
code
.
putln
(
"%s, /*%s*/"
%
(
value
,
self
.
slot_name
))
if
py3
==
'<RESERVED>'
:
code
.
putln
(
"#endif"
)
if
(
not
py3
or
not
py2
)
or
self
.
ifdef
:
if
self
.
py3
==
'<RESERVED>'
:
code
.
putln
(
"#else"
)
code
.
putln
(
"0, /*reserved*/"
)
if
preprocessor_guard
:
code
.
putln
(
"#endif"
)
# Some C implementations have trouble statically
...
...
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