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
a3536927
Commit
a3536927
authored
Sep 13, 2007
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support method slots specific to a Python version
parent
974520e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+4
-1
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+14
-6
No files found.
Cython/Compiler/Code.py
View file @
a3536927
...
@@ -89,6 +89,9 @@ class CCodeWriter:
...
@@ -89,6 +89,9 @@ class CCodeWriter:
self
.
input_file_contents
[
file
]
=
F
self
.
input_file_contents
[
file
]
=
F
return
F
return
F
def
get_py_version_hex
(
self
,
pyversion
):
return
"0x%02X%02X%02X%02X"
%
(
tuple
(
pyversion
)
+
(
0
,
0
,
0
,
0
))[:
4
]
def
mark_pos
(
self
,
pos
):
def
mark_pos
(
self
,
pos
):
file
,
line
,
col
=
pos
file
,
line
,
col
=
pos
contents
=
self
.
file_contents
(
file
)
contents
=
self
.
file_contents
(
file
)
...
...
Cython/Compiler/TypeSlots.py
View file @
a3536927
...
@@ -104,16 +104,22 @@ class SlotDescriptor:
...
@@ -104,16 +104,22 @@ class SlotDescriptor:
# slot_name string Member name of the slot in the type object
# slot_name string Member name of the slot in the type object
# is_initialised_dynamically Is initialised by code in the module init function
# is_initialised_dynamically Is initialised by code in the module init function
def
__init__
(
self
,
slot_name
,
dynamic
=
0
):
def
__init__
(
self
,
slot_name
,
dynamic
=
0
,
min_python_version
=
None
):
self
.
slot_name
=
slot_name
self
.
slot_name
=
slot_name
self
.
is_initialised_dynamically
=
dynamic
self
.
is_initialised_dynamically
=
dynamic
self
.
min_python_version
=
min_python_version
def
generate
(
self
,
scope
,
code
):
def
generate
(
self
,
scope
,
code
):
if
self
.
is_initialised_dynamically
:
if
self
.
is_initialised_dynamically
:
value
=
0
value
=
0
else
:
else
:
value
=
self
.
slot_code
(
scope
)
value
=
self
.
slot_code
(
scope
)
if
self
.
min_python_version
is
not
None
:
code
.
putln
(
"#if PY_VERSION_HEX >= "
+
code
.
get_py_version_hex
(
self
.
min_python_version
))
code
.
putln
(
"%s, /*%s*/"
%
(
value
,
self
.
slot_name
))
code
.
putln
(
"%s, /*%s*/"
%
(
value
,
self
.
slot_name
))
if
self
.
min_python_version
is
not
None
:
code
.
putln
(
"#endif"
)
# Some C implementations have trouble statically
# Some C implementations have trouble statically
# initialising a global with a pointer to an extern
# initialising a global with a pointer to an extern
...
@@ -175,8 +181,10 @@ class MethodSlot(SlotDescriptor):
...
@@ -175,8 +181,10 @@ class MethodSlot(SlotDescriptor):
# method_name string The __xxx__ name of the method
# method_name string The __xxx__ name of the method
# default string or None Default value of the slot
# default string or None Default value of the slot
def
__init__
(
self
,
signature
,
slot_name
,
method_name
,
default
=
None
):
def
__init__
(
self
,
signature
,
slot_name
,
method_name
,
SlotDescriptor
.
__init__
(
self
,
slot_name
)
default
=
None
,
min_python_version
=
None
):
SlotDescriptor
.
__init__
(
self
,
slot_name
,
min_python_version
=
min_python_version
)
self
.
signature
=
signature
self
.
signature
=
signature
self
.
slot_name
=
slot_name
self
.
slot_name
=
slot_name
self
.
method_name
=
method_name
self
.
method_name
=
method_name
...
@@ -493,7 +501,7 @@ PyNumberMethods = (
...
@@ -493,7 +501,7 @@ PyNumberMethods = (
MethodSlot
(
ibinaryfunc
,
"nb_inplace_true_divide"
,
"__itruediv__"
),
MethodSlot
(
ibinaryfunc
,
"nb_inplace_true_divide"
,
"__itruediv__"
),
# Added in release 2.5
# Added in release 2.5
MethodSlot
(
unaryfunc
,
"nb_index"
,
"__index__"
),
MethodSlot
(
unaryfunc
,
"nb_index"
,
"__index__"
,
min_python_version
=
(
2
,
5
)
),
)
)
PySequenceMethods
=
(
PySequenceMethods
=
(
...
...
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