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
97d42bce
Commit
97d42bce
authored
May 04, 2018
by
Robert Bradshaw
Committed by
GitHub
May 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2234 from jdemeyer/longint
Allow access to long/int internals (and other builtin types).
parents
a59bda8c
4bd2c9b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
9 deletions
+23
-9
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+10
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+5
-0
Cython/Includes/cpython/longintrepr.pxd
Cython/Includes/cpython/longintrepr.pxd
+4
-5
tests/run/longintrepr.pyx
tests/run/longintrepr.pyx
+4
-4
No files found.
Cython/Compiler/Code.py
View file @
97d42bce
...
...
@@ -54,6 +54,16 @@ non_portable_builtins_map = {
'raw_input'
:
(
'PY_MAJOR_VERSION >= 3'
,
'input'
),
}
ctypedef_builtins_map
=
{
# types of builtins in "ctypedef class" statements which we don't
# import either because the names conflict with C types or because
# the type simply is not exposed.
'py_int'
:
'&PyInt_Type'
,
'py_long'
:
'&PyLong_Type'
,
'py_float'
:
'&PyFloat_Type'
,
'wrapper_descriptor'
:
'&PyWrapperDescr_Type'
,
}
basicsize_builtins_map
=
{
# builtins whose type has a different tp_basicsize than sizeof(...)
'PyTypeObject'
:
'PyHeapTypeObject'
,
...
...
Cython/Compiler/ModuleNode.py
View file @
97d42bce
...
...
@@ -2995,6 +2995,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
condition
=
replacement
=
None
if
module_name
not
in
(
'__builtin__'
,
'builtins'
):
module_name
=
'"%s"'
%
module_name
elif
type
.
name
in
Code
.
ctypedef_builtins_map
:
# Fast path for special builtins, don't actually import
ctypename
=
Code
.
ctypedef_builtins_map
[
type
.
name
]
code
.
putln
(
'%s = %s;'
%
(
type
.
typeptr_cname
,
ctypename
))
return
else
:
module_name
=
'__Pyx_BUILTIN_MODULE_NAME'
if
type
.
name
in
Code
.
non_portable_builtins_map
:
...
...
Cython/Includes/cpython/longintrepr.pxd
View file @
97d42bce
...
...
@@ -2,14 +2,13 @@
# This is not part of Python's published API.
cdef
extern
from
"longintrepr.h"
:
# Add explicit cast to avoid compiler warnings
cdef
_PyLong_New
"(PyObject*)_PyLong_New"
(
Py_ssize_t
s
)
ctypedef
unsigned
int
digit
ctypedef
int
sdigit
# Python >= 2.7 only
ctypedef
struct
PyLongObject
:
digit
*
ob_digit
ctypedef
class
__builtin__
.
py_long
[
object
PyLongObject
]:
cdef
digit
*
ob_digit
cdef
py_long
_PyLong_New
(
Py_ssize_t
s
)
cdef
long
PyLong_SHIFT
cdef
digit
PyLong_BASE
...
...
tests/run/longintrepr.pyx
View file @
97d42bce
...
...
@@ -48,15 +48,15 @@ def lshift(long a, unsigned long n):
if
high
==
0
:
ret
=
_PyLong_New
(
index
+
1
)
(
<
PyLongObject
*>
ret
)
.
ob_digit
[
index
]
=
low
ret
.
ob_digit
[
index
]
=
low
else
:
ret
=
_PyLong_New
(
index
+
2
)
(
<
PyLongObject
*>
ret
)
.
ob_digit
[
index
]
=
low
(
<
PyLongObject
*>
ret
)
.
ob_digit
[
index
+
1
]
=
high
ret
.
ob_digit
[
index
]
=
low
ret
.
ob_digit
[
index
+
1
]
=
high
while
index
>=
1
:
index
-=
1
(
<
PyLongObject
*>
ret
)
.
ob_digit
[
index
]
=
0
ret
.
ob_digit
[
index
]
=
0
if
a
<
0
:
Py_SIZE_PTR
(
ret
)[
0
]
*=
-
1
...
...
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