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
2ed9e546
Commit
2ed9e546
authored
Apr 16, 2010
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for all C scalar types in pure mode
parent
a0fc7f72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
35 deletions
+114
-35
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+59
-29
Cython/Shadow.py
Cython/Shadow.py
+16
-6
tests/run/pure.pyx
tests/run/pure.pyx
+39
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
2ed9e546
...
@@ -2141,38 +2141,43 @@ c_py_buffer_ptr_type = CPtrType(c_py_buffer_type)
...
@@ -2141,38 +2141,43 @@ c_py_buffer_ptr_type = CPtrType(c_py_buffer_type)
error_type
=
ErrorType
()
error_type
=
ErrorType
()
unspecified_type
=
UnspecifiedType
()
unspecified_type
=
UnspecifiedType
()
modifiers_and_name_to_type
=
{
modifiers_and_name_to_type
=
{
#(signed, longness, name)
#(signed, longness, name) : type
(
0
,
0
,
"char"
):
c_uchar_type
,
(
0
,
0
,
"char"
):
c_uchar_type
,
(
1
,
0
,
"char"
):
c_char_type
,
(
2
,
0
,
"char"
):
c_schar_type
,
(
0
,
-
1
,
"int"
):
c_ushort_type
,
(
0
,
-
1
,
"int"
):
c_ushort_type
,
(
0
,
0
,
"int"
):
c_uint_type
,
(
0
,
0
,
"int"
):
c_uint_type
,
(
0
,
1
,
"int"
):
c_ulong_type
,
(
0
,
1
,
"int"
):
c_ulong_type
,
(
0
,
2
,
"int"
):
c_ulonglong_type
,
(
0
,
2
,
"int"
):
c_ulonglong_type
,
(
1
,
0
,
"void"
):
c_void_type
,
(
1
,
0
,
"char"
):
c_char_type
,
(
1
,
-
1
,
"int"
):
c_short_type
,
(
1
,
-
1
,
"int"
):
c_short_type
,
(
1
,
0
,
"int"
):
c_int_type
,
(
1
,
0
,
"int"
):
c_int_type
,
(
1
,
1
,
"int"
):
c_long_type
,
(
1
,
1
,
"int"
):
c_long_type
,
(
1
,
2
,
"int"
):
c_longlong_type
,
(
1
,
2
,
"int"
):
c_longlong_type
,
(
1
,
0
,
"float"
):
c_float_type
,
(
1
,
0
,
"double"
):
c_double_type
,
(
1
,
1
,
"double"
):
c_longdouble_type
,
(
1
,
0
,
"object"
):
py_object_type
,
(
1
,
0
,
"bint"
):
c_bint_type
,
(
2
,
0
,
"char"
):
c_schar_type
,
(
2
,
-
1
,
"int"
):
c_sshort_type
,
(
2
,
-
1
,
"int"
):
c_sshort_type
,
(
2
,
0
,
"int"
):
c_sint_type
,
(
2
,
0
,
"int"
):
c_sint_type
,
(
2
,
1
,
"int"
):
c_slong_type
,
(
2
,
1
,
"int"
):
c_slong_type
,
(
2
,
2
,
"int"
):
c_slonglong_type
,
(
2
,
2
,
"int"
):
c_slonglong_type
,
(
1
,
0
,
"bint"
):
c_bint_type
,
(
0
,
0
,
"size_t"
)
:
c_size_t_type
,
(
2
,
0
,
"Py_ssize_t"
):
c_py_ssize_t_type
,
(
2
,
0
,
"Py_ssize_t"
):
c_py_ssize_t_type
,
(
1
,
0
,
"float"
):
c_float_type
,
(
0
,
0
,
"size_t"
)
:
c_size_t_type
,
(
1
,
0
,
"double"
):
c_double_type
,
(
1
,
1
,
"double"
):
c_longdouble_type
,
(
1
,
0
,
"long"
):
c_long_type
,
(
1
,
0
,
"complex"
):
c_float_complex_type
,
(
1
,
0
,
"short"
):
c_short_type
,
(
1
,
0
,
"floatcomplex"
):
c_float_complex_type
,
(
1
,
0
,
"longlong"
):
c_longlong_type
,
(
1
,
0
,
"doublecomplex"
):
c_double_complex_type
,
(
1
,
0
,
"bint"
):
c_bint_type
,
(
1
,
1
,
"doublecomplex"
):
c_longdouble_complex_type
,
#
(
1
,
0
,
"void"
):
c_void_type
,
(
1
,
0
,
"object"
):
py_object_type
,
}
}
def
is_promotion
(
src_type
,
dst_type
):
def
is_promotion
(
src_type
,
dst_type
):
...
@@ -2367,10 +2372,35 @@ def parse_basic_type(name):
...
@@ -2367,10 +2372,35 @@ def parse_basic_type(name):
base
=
parse_basic_type
(
name
[:
-
1
])
base
=
parse_basic_type
(
name
[:
-
1
])
if
base
:
if
base
:
return
CPtrType
(
base
)
return
CPtrType
(
base
)
elif
name
.
startswith
(
'u'
):
#
return
simple_c_type
(
0
,
0
,
name
[
1
:])
basic_type
=
simple_c_type
(
1
,
0
,
name
)
if
basic_type
:
return
basic_type
#
signed
=
1
longness
=
0
if
name
==
'Py_ssize_t'
:
signed
=
2
elif
name
==
'size_t'
:
signed
=
0
else
:
else
:
return
simple_c_type
(
1
,
0
,
name
)
if
name
.
startswith
(
'u'
):
name
=
name
[
1
:]
signed
=
0
elif
(
name
.
startswith
(
's'
)
and
not
name
.
startswith
(
'short'
)):
name
=
name
[
1
:]
signed
=
2
longness
=
0
while
name
.
startswith
(
'short'
):
name
=
name
.
replace
(
'short'
,
''
,
1
).
strip
()
longness
-=
1
while
name
.
startswith
(
'long'
):
name
=
name
.
replace
(
'long'
,
''
,
1
).
strip
()
longness
+=
1
if
longness
!=
0
and
not
name
:
name
=
'int'
return
simple_c_type
(
signed
,
longness
,
name
)
def
c_array_type
(
base_type
,
size
):
def
c_array_type
(
base_type
,
size
):
# Construct a C array type.
# Construct a C array type.
...
...
Cython/Shadow.py
View file @
2ed9e546
...
@@ -153,12 +153,13 @@ class typedef(CythonType):
...
@@ -153,12 +153,13 @@ class typedef(CythonType):
py_float
=
float
py_int
=
int
py_int
=
int
try
:
try
:
py_long
=
long
py_long
=
long
except
NameError
:
# Py3
except
NameError
:
# Py3
py_long
=
int
py_long
=
int
py_float
=
float
py_complex
=
complex
try
:
try
:
# Python 3
# Python 3
...
@@ -173,20 +174,29 @@ except ImportError:
...
@@ -173,20 +174,29 @@ except ImportError:
# Predefined types
# Predefined types
int_types
=
[
'char'
,
'short'
,
'int'
,
'long'
,
'longlong'
,
'Py_ssize_t'
]
int_types
=
[
'char'
,
'short'
,
'int'
,
'long'
,
'longlong'
,
'Py_ssize_t'
,
'size_t'
]
float_types
=
[
'double'
,
'float'
]
float_types
=
[
'longdouble'
,
'double'
,
'float'
]
complex_types
=
[
'longdoublecomplex'
,
'doublecomplex'
,
'floatcomplex'
,
'complex'
]
other_types
=
[
'bint'
,
'void'
]
other_types
=
[
'bint'
,
'void'
]
gs
=
globals
()
gs
=
globals
()
for
name
in
int_types
:
for
name
in
int_types
:
gs
[
name
]
=
typedef
(
py_int
)
gs
[
name
]
=
typedef
(
py_int
)
gs
[
'u'
+
name
]
=
typedef
(
py_int
)
if
not
name
.
endswith
(
'size_t'
):
gs
[
'u'
+
name
]
=
typedef
(
py_int
)
gs
[
's'
+
name
]
=
typedef
(
py_int
)
double
=
float
=
typedef
(
py_float
)
for
name
in
float_types
:
gs
[
name
]
=
typedef
(
py_float
)
for
name
in
complex_types
:
gs
[
name
]
=
typedef
(
py_complex
)
bint
=
typedef
(
bool
)
bint
=
typedef
(
bool
)
void
=
typedef
(
int
)
void
=
typedef
(
int
)
for
t
in
int_types
+
float_types
+
other_types
:
for
t
in
int_types
+
float_types
+
complex_types
+
other_types
:
for
i
in
range
(
1
,
4
):
for
i
in
range
(
1
,
4
):
gs
[
"%s_%s"
%
(
'p'
*
i
,
t
)]
=
globals
()[
t
].
_pointer
(
i
)
gs
[
"%s_%s"
%
(
'p'
*
i
,
t
)]
=
globals
()[
t
].
_pointer
(
i
)
...
...
tests/run/pure.pyx
View file @
2ed9e546
...
@@ -104,3 +104,42 @@ def test_imports():
...
@@ -104,3 +104,42 @@ def test_imports():
MyStruct3
=
typedef
(
MyStruct
[
3
])
MyStruct3
=
typedef
(
MyStruct
[
3
])
MyStruct4
=
my_typedef
(
MyStruct
[
4
])
MyStruct4
=
my_typedef
(
MyStruct
[
4
])
MyStruct5
=
cy
.
typedef
(
MyStruct
[
5
])
MyStruct5
=
cy
.
typedef
(
MyStruct
[
5
])
def
test_declare_c_types
(
n
):
"""
>>> test_declare_c_types(0)
>>> test_declare_c_types(1)
>>> test_declare_c_types(2)
"""
#
b00
=
cython
.
declare
(
cython
.
bint
,
0
)
b01
=
cython
.
declare
(
cython
.
bint
,
1
)
b02
=
cython
.
declare
(
cython
.
bint
,
2
)
#
i00
=
cython
.
declare
(
cython
.
uchar
,
n
)
i01
=
cython
.
declare
(
cython
.
char
,
n
)
i02
=
cython
.
declare
(
cython
.
schar
,
n
)
i03
=
cython
.
declare
(
cython
.
ushort
,
n
)
i04
=
cython
.
declare
(
cython
.
short
,
n
)
i05
=
cython
.
declare
(
cython
.
sshort
,
n
)
i06
=
cython
.
declare
(
cython
.
uint
,
n
)
i07
=
cython
.
declare
(
cython
.
int
,
n
)
i08
=
cython
.
declare
(
cython
.
sint
,
n
)
i09
=
cython
.
declare
(
cython
.
slong
,
n
)
i10
=
cython
.
declare
(
cython
.
long
,
n
)
i11
=
cython
.
declare
(
cython
.
ulong
,
n
)
i12
=
cython
.
declare
(
cython
.
slonglong
,
n
)
i13
=
cython
.
declare
(
cython
.
longlong
,
n
)
i14
=
cython
.
declare
(
cython
.
ulonglong
,
n
)
i20
=
cython
.
declare
(
cython
.
Py_ssize_t
,
n
)
i21
=
cython
.
declare
(
cython
.
size_t
,
n
)
#
f00
=
cython
.
declare
(
cython
.
float
,
n
)
f01
=
cython
.
declare
(
cython
.
double
,
n
)
f02
=
cython
.
declare
(
cython
.
longdouble
,
n
)
#
#z00 = cython.declare(cython.complex, n+1j)
#z01 = cython.declare(cython.floatcomplex, n+1j)
#z02 = cython.declare(cython.doublecomplex, n+1j)
#z03 = cython.declare(cython.longdoublecomplex, n+1j)
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