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
32c7e432
Commit
32c7e432
authored
Apr 24, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merged in latest cython-devel
parents
907288d8
62a6348b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
287 additions
and
29 deletions
+287
-29
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+35
-17
Cython/Includes/numpy.pxd
Cython/Includes/numpy.pxd
+2
-2
Tools/site_scons/site_tools/cython.py
Tools/site_scons/site_tools/cython.py
+0
-1
Tools/site_scons/site_tools/pyext.py
Tools/site_scons/site_tools/pyext.py
+12
-9
tests/run/cpp_nonstdint.h
tests/run/cpp_nonstdint.h
+89
-0
tests/run/cpp_nonstdint.pyx
tests/run/cpp_nonstdint.pyx
+149
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
32c7e432
...
...
@@ -721,8 +721,8 @@ static CYTHON_INLINE %(type)s __Pyx_PyInt_from_py_%(TypeName)s(PyObject *);
"""
,
impl
=
"""
static CYTHON_INLINE %(type)s __Pyx_PyInt_from_py_%(TypeName)s(PyObject* x) {
const %(type)s neg_one = (%(type)s)-1, const_zero = 0;
const int is_unsigned =
neg_one > const_zero
;
const %(type)s neg_one = (%(type)s)-1, const_zero =
(%(type)s)
0;
const int is_unsigned =
const_zero < neg_one
;
if (sizeof(%(type)s) == sizeof(char)) {
if (is_unsigned)
return (%(type)s)__Pyx_PyInt_AsUnsignedChar(x);
...
...
@@ -748,17 +748,28 @@ static CYTHON_INLINE %(type)s __Pyx_PyInt_from_py_%(TypeName)s(PyObject* x) {
return (%(type)s)__Pyx_PyInt_AsUnsignedLongLong(x);
else
return (%(type)s)__Pyx_PyInt_AsSignedLongLong(x);
#if 0
} else if (sizeof(%(type)s) > sizeof(short) &&
sizeof(%(type)s) < sizeof(int)) { /* __int32 ILP64 ? */
if (is_unsigned)
return (%(type)s)__Pyx_PyInt_AsUnsignedInt(x);
else
return (%(type)s)__Pyx_PyInt_AsSignedInt(x);
#endif
} else {
%(type)s val;
PyObject *v = __Pyx_PyNumber_Int(x);
#if PY_VERSION_HEX < 0x03000000
if (likely(v) && !PyLong_Check(v)) {
PyObject *tmp = v;
v = PyNumber_Long(tmp);
Py_DECREF(tmp);
}
#endif
if (likely(v)) {
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
int ret = _PyLong_AsByteArray((PyLongObject *)v,
bytes, sizeof(val),
is_little, !is_unsigned);
Py_DECREF(v);
if (likely(!ret))
return val;
}
return (%(type)s)-1;
}
PyErr_SetString(PyExc_TypeError, "%(TypeName)s");
return (%(type)s)-1;
}
"""
)
...
...
@@ -768,20 +779,27 @@ static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_%(TypeName)s(%(type)s);
"""
,
impl
=
"""
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_%(TypeName)s(%(type)s val) {
const %(type)s neg_one = (%(type)s)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(%(type)s) < sizeof(long)) {
const %(type)s neg_one = (%(type)s)-1, const_zero = (%(type)s)0;
const int is_unsigned = const_zero < neg_one;
if ((sizeof(%(type)s) == sizeof(char)) ||
(sizeof(%(type)s) == sizeof(short))) {
return PyInt_FromLong((long)val);
} else if (sizeof(%(type)s) == sizeof(long)) {
} else if ((sizeof(%(type)s) == sizeof(int)) ||
(sizeof(%(type)s) == sizeof(long))) {
if (is_unsigned)
return PyLong_FromUnsignedLong((unsigned long)val);
else
return PyInt_FromLong((long)val);
} else
{ /* (sizeof(%(type)s) > sizeof(long)) */
} else
if (sizeof(%(type)s) == sizeof(PY_LONG_LONG)) {
if (is_unsigned)
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
else
return PyLong_FromLongLong((PY_LONG_LONG)val);
} else {
int one = 1; int little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
return _PyLong_FromByteArray(bytes, sizeof(%(type)s),
little, !is_unsigned);
}
}
"""
)
...
...
Cython/Includes/numpy.pxd
View file @
32c7e432
...
...
@@ -481,8 +481,8 @@ cdef extern from "numpy/arrayobject.h":
bint
PyArray_FROM_OT
(
object
m
,
int
type
)
bint
PyArray_FROM_OTF
(
object
m
,
int
type
,
int
flags
)
object
PyArray_FROMANY
(
object
m
,
int
type
,
int
min
,
int
max
,
int
flags
)
bint
PyArray_ZEROS
(
ndarray
m
,
npy_intp
*
dims
,
int
type
,
int
fortran
)
object
PyArray_EMPTY
(
object
m
,
npy_intp
*
dims
,
int
type
,
int
fortran
)
object
PyArray_ZEROS
(
int
nd
,
npy_intp
*
dims
,
int
type
,
int
fortran
)
object
PyArray_EMPTY
(
int
nd
,
npy_intp
*
dims
,
int
type
,
int
fortran
)
void
PyArray_FILLWBYTE
(
object
,
int
val
)
npy_intp
PyArray_REFCOUNT
(
object
)
object
PyArray_ContiguousFromAny
(
op
,
int
,
int
min_depth
,
int
max_depth
)
...
...
Tools/site_scons/site_tools/cython.py
View file @
32c7e432
...
...
@@ -41,7 +41,6 @@ def create_builder(env):
return
cython
def
cython_suffix_emitter
(
env
,
source
):
print
'emitter called'
return
"$CYTHONCFILESUFFIX"
def
generate
(
env
):
...
...
Tools/site_scons/site_tools/pyext.py
View file @
32c7e432
...
...
@@ -178,13 +178,13 @@ def set_configuration(env, use_distutils):
# We define commands as strings so that we can either execute them using
# eval (same python for scons and distutils) or by executing them through
# the shell.
dist_cfg
=
{
'PYEXTCC'
:
"sysconfig.get_config_var('CC')"
,
'PYEXTCFLAGS'
:
"sysconfig.get_config_var('CFLAGS')"
,
'PYEXTCCSHARED'
:
"sysconfig.get_config_var('CCSHARED')"
,
'PYEXTLINKFLAGS'
:
"sysconfig.get_config_var('LDFLAGS')"
,
'PYEXTLINK'
:
"sysconfig.get_config_var('LDSHARED')"
,
'PYEXTINCPATH'
:
"sysconfig.get_python_inc()"
,
'PYEXTSUFFIX'
:
"sysconfig.get_config_var('SO')"
}
dist_cfg
=
{
'PYEXTCC'
:
(
"sysconfig.get_config_var('CC')"
,
False
)
,
'PYEXTCFLAGS'
:
(
"sysconfig.get_config_var('CFLAGS')"
,
True
)
,
'PYEXTCCSHARED'
:
(
"sysconfig.get_config_var('CCSHARED')"
,
False
)
,
'PYEXTLINKFLAGS'
:
(
"sysconfig.get_config_var('LDFLAGS')"
,
True
)
,
'PYEXTLINK'
:
(
"sysconfig.get_config_var('LDSHARED')"
,
False
)
,
'PYEXTINCPATH'
:
(
"sysconfig.get_python_inc()"
,
False
)
,
'PYEXTSUFFIX'
:
(
"sysconfig.get_config_var('SO')"
,
False
)
}
from
distutils
import
sysconfig
...
...
@@ -193,8 +193,11 @@ def set_configuration(env, use_distutils):
ifnotset
(
env
,
'PYEXTINCPATH'
,
sysconfig
.
get_python_inc
())
if
use_distutils
:
for
k
,
v
in
dist_cfg
.
items
():
ifnotset
(
env
,
k
,
eval
(
v
))
for
k
,
(
v
,
should_split
)
in
dist_cfg
.
items
():
val
=
eval
(
v
)
if
should_split
:
val
=
val
.
split
()
ifnotset
(
env
,
k
,
val
)
else
:
_set_configuration_nodistutils
(
env
)
...
...
tests/run/cpp_nonstdint.h
0 → 100644
View file @
32c7e432
// -*- c++ -*-
#include <stdio.h>
template
<
unsigned
int
N
>
class
Integral
{
unsigned
char
bytes
[
N
];
public:
Integral
()
{
for
(
unsigned
int
i
=
0
;
i
<
N
;
i
++
)
bytes
[
i
]
=
0
;
}
Integral
(
const
Integral
&
I
)
{
for
(
unsigned
int
i
=
0
;
i
<
N
;
i
++
)
bytes
[
i
]
=
I
.
bytes
[
i
];
}
Integral
(
signed
char
I
)
{
unsigned
char
p
=
(
I
<
0
)
?
0xFF
:
0x00
;
for
(
unsigned
int
i
=
0
;
i
<
N
;
i
++
)
bytes
[
i
]
=
p
;
bytes
[
lsb
()]
=
*
(
unsigned
char
*
)
&
I
;
}
operator
signed
char
()
const
{
return
*
(
signed
char
*
)
&
bytes
[
lsb
()];
}
Integral
&
operator
=
(
const
Integral
&
I
)
{
for
(
unsigned
int
i
=
0
;
i
<
N
;
i
++
)
bytes
[
i
]
=
I
.
bytes
[
i
];
return
*
this
;
}
bool
operator
<
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
<
0
;
}
bool
operator
>
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
>
0
;
}
bool
operator
<=
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
<=
0
;
}
bool
operator
>=
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
>=
0
;
}
bool
operator
==
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
==
0
;
}
bool
operator
!=
(
const
Integral
&
I
)
const
{
return
cmp
(
I
)
!=
0
;
}
private:
static
bool
is_le
()
{
int
one
=
1
;
return
(
int
)
*
(
unsigned
char
*
)
&
one
;
}
static
unsigned
int
lsb
()
{
return
is_le
()
?
0
:
N
-
1
;
}
static
unsigned
int
msb
()
{
return
is_le
()
?
N
-
1
:
0
;
}
int
cmp
(
const
Integral
&
J
)
const
{
const
Integral
&
I
=
*
this
;
unsigned
char
sI
=
I
.
bytes
[
msb
()]
&
0x80
;
unsigned
char
sJ
=
J
.
bytes
[
msb
()]
&
0x80
;
if
(
sI
>
sJ
)
return
-
1
;
if
(
sI
<
sJ
)
return
+
1
;
unsigned
char
bI
=
I
.
bytes
[
msb
()]
&
0x7F
;
unsigned
char
bJ
=
J
.
bytes
[
msb
()]
&
0x7F
;
int
cmpabs
=
0
;
if
(
bI
<
bJ
)
cmpabs
=
-
1
;
else
if
(
bI
>
bJ
)
cmpabs
=
+
1
;
else
{
int
incr
=
is_le
()
?
-
1
:
1
;
unsigned
int
i
=
msb
()
+
incr
;
while
(
i
!=
lsb
())
{
if
(
I
.
bytes
[
i
]
<
J
.
bytes
[
i
])
{
cmpabs
=
-
1
;
break
;
}
if
(
I
.
bytes
[
i
]
>
J
.
bytes
[
i
])
{
cmpabs
=
+
1
;
break
;
}
i
+=
incr
;
}
}
if
(
sI
)
return
-
cmpabs
;
else
return
+
cmpabs
;
}
};
typedef
Integral
<
3
>
Int24
;
typedef
Integral
<
7
>
Int56
;
typedef
Integral
<
11
>
Int88
;
typedef
Integral
<
64
>
Int512
;
tests/run/cpp_nonstdint.pyx
0 → 100644
View file @
32c7e432
cdef
extern
from
"cpp_nonstdint.h"
:
ctypedef
int
Int24
ctypedef
int
Int56
ctypedef
int
Int88
ctypedef
int
Int512
cdef
object
one
=
1
# ---
INT24_MAX
=
(
one
<<
(
sizeof
(
Int24
)
*
8
-
1
))
-
one
INT24_MIN
=
(
-
INT24_MAX
-
one
)
def
test_int24
(
Int24
i
):
"""
>>> str(test_int24(-1))
'-1'
>>> str(test_int24(0))
'0'
>>> str(test_int24(1))
'1'
>>> test_int24(INT24_MAX) == INT24_MAX
True
>>> test_int24(INT24_MIN) == INT24_MIN
True
>>> test_int24(INT24_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int24(INT24_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int24("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return
i
# ---
INT56_MAX
=
(
one
<<
(
sizeof
(
Int56
)
*
8
-
1
))
-
one
INT56_MIN
=
(
-
INT56_MAX
-
one
)
def
test_int56
(
Int56
i
):
"""
>>> str(test_int56(-1))
'-1'
>>> str(test_int56(0))
'0'
>>> str(test_int56(1))
'1'
>>> test_int56(INT56_MAX) == INT56_MAX
True
>>> test_int56(INT56_MIN) == INT56_MIN
True
>>> test_int56(INT56_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int56(INT56_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int56("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return
i
# ---
INT88_MAX
=
(
one
<<
(
sizeof
(
Int88
)
*
8
-
1
))
-
one
INT88_MIN
=
(
-
INT88_MAX
-
one
)
def
test_int88
(
Int88
i
):
"""
>>> str(test_int88(-1))
'-1'
>>> str(test_int88(0))
'0'
>>> str(test_int88(1))
'1'
>>> test_int88(INT88_MAX) == INT88_MAX
True
>>> test_int88(INT88_MIN) == INT88_MIN
True
>>> test_int88(INT88_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int88(INT88_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int88("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return
i
# ---
INT512_MAX
=
(
one
<<
(
sizeof
(
Int512
)
*
8
-
1
))
-
one
INT512_MIN
=
(
-
INT512_MAX
-
one
)
def
test_int512
(
Int512
i
):
"""
>>> str(test_int512(-1))
'-1'
>>> str(test_int512(0))
'0'
>>> str(test_int512(1))
'1'
>>> test_int512(INT512_MAX) == INT512_MAX
True
>>> test_int512(INT512_MIN) == INT512_MIN
True
>>> test_int512(INT512_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int512(INT512_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int512("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return
i
# ---
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