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
8aedb60c
Commit
8aedb60c
authored
Apr 23, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes int/long type slots in Py2/Py3 (ticket #287)
parent
e49d3c7a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
10 deletions
+97
-10
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+5
-5
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+15
-5
tests/run/c_int_types_T255.pyx
tests/run/c_int_types_T255.pyx
+11
-0
tests/run/type_slots_int_long_T287.pyx
tests/run/type_slots_int_long_T287.pyx
+66
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
8aedb60c
...
...
@@ -1741,14 +1741,14 @@ static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
return Py_INCREF(x), x;
m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
if (m && m->nb_long) {
name = "long";
res = PyNumber_Long(x);
}
else if (m && m->nb_int) {
if (m && m->nb_int) {
name = "int";
res = PyNumber_Int(x);
}
else if (m && m->nb_long) {
name = "long";
res = PyNumber_Long(x);
}
#else
if (m && m->nb_int) {
name = "int";
...
...
Cython/Compiler/TypeSlots.py
View file @
8aedb60c
...
...
@@ -154,7 +154,14 @@ class SlotDescriptor(object):
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
if
flag
:
code
.
putln
(
"#if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & %s)"
%
flag
)
if
py3k
==
'<RESERVED>'
:
code
.
putln
(
"#if PY_MAJOR_VERSION >= 3"
)
code
.
putln
(
"0, /*reserved*/"
)
code
.
putln
(
"#else"
)
code
.
putln
(
"%s, /*%s*/"
%
(
value
,
self
.
slot_name
))
if
py3k
==
'<RESERVED>'
:
code
.
putln
(
"#endif"
)
if
flag
or
(
not
py3k
or
not
py2
)
or
self
.
ifdef
:
code
.
putln
(
"#endif"
)
...
...
@@ -212,9 +219,12 @@ class MethodSlot(SlotDescriptor):
def
slot_code
(
self
,
scope
):
entry
=
scope
.
lookup_here
(
self
.
method_name
)
if
entry
:
if
entry
and
entry
.
func_cname
:
return
entry
.
func_cname
if
self
.
default
is
not
None
:
entry
=
scope
.
lookup_here
(
self
.
default
)
if
entry
and
entry
.
func_cname
:
return
entry
.
func_cname
else
:
return
"0"
...
...
@@ -557,8 +567,8 @@ PyNumberMethods = (
MethodSlot
(
binaryfunc
,
"nb_xor"
,
"__xor__"
),
MethodSlot
(
binaryfunc
,
"nb_or"
,
"__or__"
),
EmptySlot
(
"nb_coerce"
,
py3k
=
False
),
MethodSlot
(
unaryfunc
,
"nb_int"
,
"__int__"
),
MethodSlot
(
unaryfunc
,
"nb_long"
,
"__long__"
),
MethodSlot
(
unaryfunc
,
"nb_int"
,
"__int__"
,
default
=
"__long__"
),
MethodSlot
(
unaryfunc
,
"nb_long"
,
"__long__"
,
default
=
"__int__"
,
py3k
=
"<RESERVED>"
),
MethodSlot
(
unaryfunc
,
"nb_float"
,
"__float__"
),
MethodSlot
(
unaryfunc
,
"nb_oct"
,
"__oct__"
,
py3k
=
False
),
MethodSlot
(
unaryfunc
,
"nb_hex"
,
"__hex__"
,
py3k
=
False
),
...
...
tests/run/c_int_types_T255.pyx
View file @
8aedb60c
...
...
@@ -666,6 +666,17 @@ class MyBadInt(MyInt):
def
__int__
(
self
):
return
u"%s"
%
self
.
value
class
MyInt2
:
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__int__
(
self
):
print
(
u"MyInt.__int__()"
)
return
self
.
value
class
MyBadInt2
(
MyInt2
):
def
__int__
(
self
):
return
u"%s"
%
self
.
value
def
test_convert_pyint
(
x
):
u"""
>>> test_convert_pyint(None)
...
...
tests/run/type_slots_int_long_T287.pyx
0 → 100644
View file @
8aedb60c
__doc__
=
u"""
>>> print( "%d" % Int() )
2
>>> print( "%d" % Long() )
3
>>> print( "%d" % IntLongA() )
2
>>> print( "%d" % IntLongB() )
2
>>> print( "%d" % IntLongC() )
3
>>> getint( Int() )
2
>>> getint( Long() )
3
>>> getint( IntLongA() )
2
>>> getint( IntLongB() )
2
>>> getint( IntLongC() )
3
>>> getlong( Int() )
2
>>> getlong( Long() )
3
>>> getlong( IntLongA() )
2
>>> getlong( IntLongB() )
2
>>> getlong( IntLongC() )
3
"""
def
getint
(
int
i
):
return
i
def
getlong
(
long
long
i
):
return
<
int
>
i
cdef
class
Int
:
def
__int__
(
self
):
return
2
cdef
class
Long
:
def
__long__
(
self
):
return
3
cdef
class
IntLongA
:
def
__int__
(
self
):
return
2
def
__long__
(
self
):
return
3
cdef
class
IntLongB
:
def
__int__
(
self
):
return
2
__long__
=
__int__
cdef
class
IntLongC
:
def
__long__
(
self
):
return
3
__int__
=
__long__
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