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
Kirill Smelkov
cython
Commits
4f8a75c1
Commit
4f8a75c1
authored
Mar 02, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
95e19f49
a3038580
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
42 deletions
+67
-42
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+34
-37
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+7
-5
tests/run/cdef_bool_T227.pyx
tests/run/cdef_bool_T227.pyx
+26
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
4f8a75c1
...
@@ -201,7 +201,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -201,7 +201,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for
entry
in
api_funcs
:
for
entry
in
api_funcs
:
sig
=
entry
.
type
.
signature_string
()
sig
=
entry
.
type
.
signature_string
()
h_code
.
putln
(
h_code
.
putln
(
'if (__Pyx_ImportFunction(module, "%s", (void
(**)(void)
)&%s, "%s") < 0) goto bad;'
%
(
'if (__Pyx_ImportFunction(module, "%s", (void
**
)&%s, "%s") < 0) goto bad;'
%
(
entry
.
name
,
entry
.
name
,
entry
.
cname
,
entry
.
cname
,
sig
))
sig
))
...
@@ -1800,7 +1800,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1800,7 +1800,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
entry
.
api
or
entry
.
defined_in_pxd
:
if
entry
.
api
or
entry
.
defined_in_pxd
:
env
.
use_utility_code
(
function_export_utility_code
)
env
.
use_utility_code
(
function_export_utility_code
)
signature
=
entry
.
type
.
signature_string
()
signature
=
entry
.
type
.
signature_string
()
code
.
putln
(
'if (__Pyx_ExportFunction("%s", (void
(*)(void)
)%s, "%s") < 0) %s'
%
(
code
.
putln
(
'if (__Pyx_ExportFunction("%s", (void
*
)%s, "%s") < 0) %s'
%
(
entry
.
name
,
entry
.
name
,
entry
.
cname
,
entry
.
cname
,
signature
,
signature
,
...
@@ -1832,7 +1832,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1832,7 +1832,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
error_goto
(
self
.
pos
)))
code
.
error_goto
(
self
.
pos
)))
for
entry
in
entries
:
for
entry
in
entries
:
code
.
putln
(
code
.
putln
(
'if (__Pyx_ImportFunction(%s, "%s", (void
(**)(void)
)&%s, "%s") < 0) %s'
%
(
'if (__Pyx_ImportFunction(%s, "%s", (void
**
)&%s, "%s") < 0) %s'
%
(
temp
,
temp
,
entry
.
name
,
entry
.
name
,
entry
.
cname
,
entry
.
cname
,
...
@@ -1971,23 +1971,24 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1971,23 +1971,24 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
c_method_entries
=
[
c_method_entries
=
[
entry
for
entry
in
type
.
scope
.
cfunc_entries
entry
for
entry
in
type
.
scope
.
cfunc_entries
if
entry
.
func_cname
]
if
entry
.
func_cname
]
code
.
putln
(
'#if PY_MAJOR_VERSION >= 3'
)
if
c_method_entries
:
for
meth_entry
in
c_method_entries
:
code
.
putln
(
'#if PY_MAJOR_VERSION >= 3'
)
cast
=
meth_entry
.
type
.
signature_cast_string
()
for
meth_entry
in
c_method_entries
:
code
.
putln
(
cast
=
meth_entry
.
type
.
signature_cast_string
()
"%s.%s = %s%s;"
%
(
code
.
putln
(
type
.
vtable_cname
,
"%s.%s = %s%s;"
%
(
meth_entry
.
cname
,
type
.
vtable_cname
,
cast
,
meth_entry
.
cname
,
meth_entry
.
func_cname
))
cast
,
code
.
putln
(
'#else'
)
meth_entry
.
func_cname
))
for
meth_entry
in
c_method_entries
:
code
.
putln
(
'#else'
)
code
.
putln
(
for
meth_entry
in
c_method_entries
:
"*(void(**)(void))&%s.%s = (void(*)(void))%s;"
%
(
code
.
putln
(
type
.
vtable_cname
,
"*(void(**)(void))&%s.%s = (void(*)(void))%s;"
%
(
meth_entry
.
cname
,
type
.
vtable_cname
,
meth_entry
.
func_cname
))
meth_entry
.
cname
,
code
.
putln
(
'#endif'
)
meth_entry
.
func_cname
))
code
.
putln
(
'#endif'
)
def
generate_typeptr_assignment_code
(
self
,
entry
,
code
):
def
generate_typeptr_assignment_code
(
self
,
entry
,
code
):
# Generate code to initialise the typeptr of an extension
# Generate code to initialise the typeptr of an extension
...
@@ -2115,18 +2116,17 @@ bad:
...
@@ -2115,18 +2116,17 @@ bad:
function_export_utility_code
=
UtilityCode
(
function_export_utility_code
=
UtilityCode
(
proto
=
"""
proto
=
"""
static int __Pyx_ExportFunction(const char *name, void
(*f)(void)
, const char *sig); /*proto*/
static int __Pyx_ExportFunction(const char *name, void
*f
, const char *sig); /*proto*/
"""
,
"""
,
impl
=
r"""
impl
=
r"""
static int __Pyx_ExportFunction(const char *name, void
(*f)(void)
, const char *sig) {
static int __Pyx_ExportFunction(const char *name, void
*f
, const char *sig) {
#if PY_VERSION_HEX < 0x02050000
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
char *api = (char *)"%(API)s";
#else
#else
const char *api = "%(API)s";
const char *api = "%(API)s";
#endif
#endif
PyObject *d = 0;
PyObject *d = 0;
PyObject *cobj = 0;
PyObject *p = 0;
void *p = 0;
d = PyObject_GetAttrString(%(MODULE)s, api);
d = PyObject_GetAttrString(%(MODULE)s, api);
if (!d) {
if (!d) {
...
@@ -2138,17 +2138,16 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s
...
@@ -2138,17 +2138,16 @@ static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *s
if (PyModule_AddObject(%(MODULE)s, api, d) < 0)
if (PyModule_AddObject(%(MODULE)s, api, d) < 0)
goto bad;
goto bad;
}
}
p = *(void **)&f;
p = PyCObject_FromVoidPtrAndDesc(f, (void *)sig, 0);
cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
if (!p)
if (!cobj)
goto bad;
goto bad;
if (PyDict_SetItemString(d, name,
cobj
) < 0)
if (PyDict_SetItemString(d, name,
p
) < 0)
goto bad;
goto bad;
Py_DECREF(
cobj
);
Py_DECREF(
p
);
Py_DECREF(d);
Py_DECREF(d);
return 0;
return 0;
bad:
bad:
Py_XDECREF(
cobj
);
Py_XDECREF(
p
);
Py_XDECREF(d);
Py_XDECREF(d);
return -1;
return -1;
}
}
...
@@ -2159,12 +2158,12 @@ bad:
...
@@ -2159,12 +2158,12 @@ bad:
function_import_utility_code
=
UtilityCode
(
function_import_utility_code
=
UtilityCode
(
proto
=
"""
proto
=
"""
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void
(**f)(void)
, const char *sig); /*proto*/
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void
**f
, const char *sig); /*proto*/
"""
,
"""
,
impl
=
"""
impl
=
"""
#ifndef __PYX_HAVE_RT_ImportFunction
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void
(**f)(void)
, const char *sig) {
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void
**f
, const char *sig) {
#if PY_VERSION_HEX < 0x02050000
#if PY_VERSION_HEX < 0x02050000
char *api = (char *)"%(API)s";
char *api = (char *)"%(API)s";
#else
#else
...
@@ -2172,8 +2171,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
...
@@ -2172,8 +2171,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
#endif
#endif
PyObject *d = 0;
PyObject *d = 0;
PyObject *cobj = 0;
PyObject *cobj = 0;
void *p = 0;
char *desc;
const char *desc = 0;
d = PyObject_GetAttrString(module, api);
d = PyObject_GetAttrString(module, api);
if (!d)
if (!d)
...
@@ -2185,7 +2183,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
...
@@ -2185,7 +2183,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname);
PyModule_GetName(module), funcname);
goto bad;
goto bad;
}
}
desc = (c
onst c
har *)PyCObject_GetDesc(cobj);
desc = (char *)PyCObject_GetDesc(cobj);
if (!desc)
if (!desc)
goto bad;
goto bad;
if (strcmp(desc, sig) != 0) {
if (strcmp(desc, sig) != 0) {
...
@@ -2194,8 +2192,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
...
@@ -2194,8 +2192,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname, sig, desc);
PyModule_GetName(module), funcname, sig, desc);
goto bad;
goto bad;
}
}
p = PyCObject_AsVoidPtr(cobj);
*f = PyCObject_AsVoidPtr(cobj);
*f = *(void (**)(void))&p;
Py_DECREF(d);
Py_DECREF(d);
return 0;
return 0;
bad:
bad:
...
...
Cython/Compiler/PyrexTypes.py
View file @
4f8a75c1
...
@@ -303,14 +303,16 @@ class BuiltinObjectType(PyObjectType):
...
@@ -303,14 +303,16 @@ class BuiltinObjectType(PyObjectType):
def
type_test_code
(
self
,
arg
):
def
type_test_code
(
self
,
arg
):
type_name
=
self
.
name
type_name
=
self
.
name
if
type_name
==
'str'
:
if
type_name
==
'str'
:
type_name
=
'String
'
check
=
'PyString_CheckExact
'
elif
type_name
==
'set'
:
elif
type_name
==
'set'
:
type_name
=
'AnySe
t'
check
=
'PyAnySet_CheckExac
t'
elif
type_name
==
'frozenset'
:
elif
type_name
==
'frozenset'
:
type_name
=
'FrozenSet'
check
=
'PyFrozenSet_CheckExact'
elif
type_name
==
'bool'
:
check
=
'PyBool_Check'
else
:
else
:
type_name
=
type_name
.
capitalize
()
check
=
'Py%s_CheckExact'
%
type_name
.
capitalize
()
return
'likely(
Py%s_CheckExact(%s)) || (%s) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name), 0)'
%
(
type_name
,
arg
,
arg
,
self
.
name
,
arg
)
return
'likely(
%s(%s)) || (%s) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name), 0)'
%
(
check
,
arg
,
arg
,
self
.
name
,
arg
)
def
declaration_code
(
self
,
entity_code
,
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
...
...
tests/run/cdef_bool_T227.pyx
0 → 100644
View file @
4f8a75c1
__doc__
=
u"""
>>> foo(True)
True
>>> foo(False)
False
>>> foo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
>>> call_cfoo(True)
True
>>> call_cfoo(False)
False
>>> call_cfoo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
def
foo
(
bool
a
):
return
a
==
True
def
call_cfoo
(
a
):
return
cfoo
(
a
)
cdef
cfoo
(
bool
a
):
return
a
==
True
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