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
Boxiang Sun
cython
Commits
6853d59e
Commit
6853d59e
authored
May 22, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
ff08e584
7c6f0728
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
381 additions
and
99 deletions
+381
-99
.gitignore
.gitignore
+1
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+8
-28
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+105
-22
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-9
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+97
-32
tests/build/module_api.srctree
tests/build/module_api.srctree
+121
-0
tests/compile/publicapi_cimport.pyx
tests/compile/publicapi_cimport.pyx
+16
-0
tests/compile/publicapi_pxd_mix.pxd
tests/compile/publicapi_pxd_mix.pxd
+4
-3
tests/compile/publicapi_pxd_mix.pyx
tests/compile/publicapi_pxd_mix.pyx
+5
-0
tests/errors/cdef_in_pyclass.pyx
tests/errors/cdef_in_pyclass.pyx
+3
-1
tests/errors/cfunc_directive_in_pyclass.pyx
tests/errors/cfunc_directive_in_pyclass.pyx
+2
-1
tests/run/capiimpl.pyx
tests/run/capiimpl.pyx
+11
-2
No files found.
.gitignore
View file @
6853d59e
...
...
@@ -8,6 +8,7 @@ Cython/Runtime/refnanny.c
BUILD/
build/
!tests/build/
dist/
.gitrev
.coverage
...
...
Cython/Compiler/Code.py
View file @
6853d59e
...
...
@@ -1166,39 +1166,19 @@ class CCodeWriter(object):
self
.
funcstate
.
use_label
(
lbl
)
self
.
putln
(
"goto %s;"
%
lbl
)
def
put_var_declarations
(
self
,
entries
,
static
=
0
,
dll_linkage
=
None
,
definition
=
True
):
for
entry
in
entries
:
if
not
entry
.
in_cinclude
:
self
.
put_var_declaration
(
entry
,
static
,
dll_linkage
,
definition
)
def
put_var_declaration
(
self
,
entry
,
static
=
0
,
dll_linkage
=
None
,
definition
=
True
):
def
put_var_declaration
(
self
,
entry
,
storage_class
=
""
,
dll_linkage
=
None
,
definition
=
True
):
#print "Code.put_var_declaration:", entry.name, "definition =", definition ###
if
entry
.
in_closure
:
return
visibility
=
entry
.
visibility
if
visibility
==
'private'
and
not
definition
:
#print "...private and not definition, skipping" ###
if
entry
.
visibility
==
'private'
and
not
(
definition
or
entry
.
defined_in_pxd
):
#print "...private and not definition, skipping", entry.cname ###
return
if
not
entry
.
used
and
visibility
==
"private"
:
#print "
not used and private
, skipping", entry.cname ###
if
entry
.
visibility
==
"private"
and
not
entry
.
used
:
#print "
...private and not used
, skipping", entry.cname ###
return
storage_class
=
""
if
visibility
==
'extern'
:
storage_class
=
Naming
.
extern_c_macro
elif
visibility
==
'public'
:
if
not
definition
:
storage_class
=
Naming
.
extern_c_macro
elif
visibility
==
'private'
:
if
static
:
storage_class
=
"static"
if
storage_class
:
self
.
put
(
"%s "
%
storage_class
)
if
visibility
!=
'public'
:
dll_linkage
=
None
self
.
put
(
entry
.
type
.
declaration_code
(
entry
.
cname
,
dll_linkage
=
dll_linkage
))
self
.
put
(
entry
.
type
.
declaration_code
(
entry
.
cname
,
dll_linkage
=
dll_linkage
))
if
entry
.
init
is
not
None
:
self
.
put_safe
(
" = %s"
%
entry
.
type
.
literal_code
(
entry
.
init
))
self
.
putln
(
";"
)
...
...
Cython/Compiler/ExprNodes.py
View file @
6853d59e
...
...
@@ -7507,7 +7507,7 @@ class NoneCheckNode(CoercionNode):
def
generate_result_code
(
self
,
code
):
code
.
putln
(
"if (unlikely(%s == Py_None)) {"
%
self
.
arg
.
result
())
"if (unlikely(%s == Py_None)) {"
%
self
.
arg
.
py_
result
())
code
.
putln
(
'PyErr_SetString(%s, "%s"); %s '
%
(
self
.
exception_type_cname
,
StringEncoding
.
escape_byte_string
(
...
...
Cython/Compiler/ModuleNode.py
View file @
6853d59e
This diff is collapsed.
Click to expand it.
Cython/Compiler/Naming.py
View file @
6853d59e
...
...
@@ -36,6 +36,7 @@ prop_set_prefix = pyrex_prefix + "setprop_"
type_prefix
=
pyrex_prefix
+
"t_"
typeobj_prefix
=
pyrex_prefix
+
"type_"
var_prefix
=
pyrex_prefix
+
"v_"
varptr_prefix
=
pyrex_prefix
+
"vp_"
wrapperbase_prefix
=
pyrex_prefix
+
"wrapperbase_"
bufstruct_prefix
=
pyrex_prefix
+
"bstruct_"
bufstride_prefix
=
pyrex_prefix
+
"bstride_"
...
...
Cython/Compiler/Nodes.py
View file @
6853d59e
...
...
@@ -969,18 +969,16 @@ class CVarDefNode(StatNode):
return
if
type
.
is_cfunction
:
entry
=
dest_scope
.
declare_cfunction
(
name
,
type
,
declarator
.
pos
,
cname
=
cname
,
visibility
=
self
.
visibility
,
in_pxd
=
self
.
in_pxd
,
api
=
self
.
api
)
cname
=
cname
,
visibility
=
self
.
visibility
,
in_pxd
=
self
.
in_pxd
,
api
=
self
.
api
)
if
entry
is
not
None
:
entry
.
directive_locals
=
copy
.
copy
(
self
.
directive_locals
)
else
:
if
self
.
directive_locals
:
error
(
self
.
pos
,
"Decorators can only be followed by functions"
)
if
self
.
in_pxd
and
self
.
visibility
!=
'extern'
:
error
(
self
.
pos
,
"Only 'extern' C variable declaration allowed in .pxd file"
)
entry
=
dest_scope
.
declare_var
(
name
,
type
,
declarator
.
pos
,
cname
=
cname
,
visibility
=
visibility
,
api
=
self
.
api
,
is_cdef
=
1
)
cname
=
cname
,
visibility
=
visibility
,
in_pxd
=
self
.
in_pxd
,
api
=
self
.
api
,
is_cdef
=
1
)
class
CStructOrUnionDefNode
(
StatNode
):
...
...
@@ -1700,9 +1698,8 @@ class CFuncDefNode(FuncDefNode):
cname
=
name_declarator
.
cname
self
.
entry
=
env
.
declare_cfunction
(
name
,
type
,
self
.
pos
,
cname
=
cname
,
visibility
=
self
.
visibility
,
defining
=
self
.
body
is
not
None
,
api
=
self
.
api
,
modifiers
=
self
.
modifiers
)
cname
=
cname
,
visibility
=
self
.
visibility
,
api
=
self
.
api
,
defining
=
self
.
body
is
not
None
,
modifiers
=
self
.
modifiers
)
self
.
entry
.
inline_func_in_pxd
=
self
.
inline_in_pxd
self
.
return_type
=
type
.
return_type
if
self
.
return_type
.
is_array
and
visibility
!=
'extern'
:
...
...
Cython/Compiler/Symtab.py
View file @
6853d59e
This diff is collapsed.
Click to expand it.
tests/build/module_api.srctree
0 → 100644
View file @
6853d59e
PYTHON setup.py build_ext --inplace
PYTHON test.py
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
exts = cythonize("*.pyx")
for e in exts:
if e.name == "d":
e.sources.append("a.c")
setup(
ext_modules = exts,
)
######## a.pxd ########
ctypedef api float flt
cdef int int0
cdef float flt0
cdef api int int1
cdef api float flt1
cdef public api int int2
cdef public api flt flt2
######## a.pyx ########
cdef int int0 = 1, int1 = 1, int2 = 1
cdef float flt0 = 1, flt1 = 1, flt2 = 1
cdef api int int3 = 1
cdef api flt flt3 = 1
cdef public int int4 = 1
cdef public flt flt4 = 1
def get_int():
return (int0, int1, int2, int3, int4)
def get_flt():
return (flt0, flt1, flt2, flt3, flt4)
######## b.pyx ########
from a cimport *
int0 = int1 = int2 = 7
flt0 = flt1 = flt2 = 7
######## c.pyx ########
# distutils: language = c++
cdef extern from "a_api.h":
int import_a() except -1
ctypedef float flt
int int1, int2, int3
flt flt1, flt2, flt3
import_a()
int1 = int2 = int3 = 5
flt1 = flt2 = flt3 = 5
######## inita.h ########
#if PY_MAJOR_VERSION >= 3
void inita(void)
{
PyObject *sys_modules = NULL;
PyObject *mod = NULL;
sys_modules = PyImport_GetModuleDict();
if (!sys_modules) return;
mod = PyInit_a();
if (!mod) return;
PyDict_SetItemString(sys_modules, (char*)"a", mod);
}
#endif
######## d.pyx ########
cdef extern from "a.h":
pass
cdef extern from "inita.h":
pass
cdef extern from "a.h":
void inita() except *
ctypedef float flt
int int2, int4
flt flt2, flt4
inita()
int2 = int4 = 3
flt2 = flt4 = 3
######## test.py ########
import a
assert a.get_int() == (1,1,1,1,1)
assert a.get_flt() == (1,1,1,1,1)
import b
assert a.get_int() == (7,7,7,1,1)
assert a.get_flt() == (7,7,7,1,1)
import c
assert a.get_int() == (7,5,5,5,1)
assert a.get_flt() == (7,5,5,5,1)
import d
import a
assert a.get_int() == (1,1,3,1,3)
assert a.get_flt() == (1,1,3,1,3)
tests/compile/publicapi_cimport.pyx
View file @
6853d59e
# mode: compile
from
publicapi_pxd_mix
cimport
*
bar0
()
bar1
()
bar2
()
bar3
()
spam0
(
None
)
spam1
(
None
)
spam2
(
None
)
spam3
(
None
)
i0
=
0
i1
=
1
i2
=
2
i3
=
3
tests/compile/publicapi_pxd_mix.pxd
View file @
6853d59e
...
...
@@ -66,8 +66,9 @@ cdef public api void* spam3(object o) except NULL with gil
# --
#cdef public int i1
#cdef api int i2
#cdef public api int i3
cdef
int
i0
=
0
# XXX implement initialization!!!
cdef
public
int
i1
cdef
api
int
i2
cdef
public
api
int
i3
# --
tests/compile/publicapi_pxd_mix.pyx
View file @
6853d59e
...
...
@@ -17,3 +17,8 @@ cdef void* spam0(object o) except NULL: return NULL
cdef
public
void
*
spam1
(
object
o
)
except
NULL
:
return
NULL
cdef
api
void
*
spam2
(
object
o
)
nogil
except
NULL
:
return
NULL
cdef
public
api
void
*
spam3
(
object
o
)
except
NULL
with
gil
:
return
NULL
cdef
int
i0
=
0
# XXX This should not be required!
cdef
public
int
i1
=
1
cdef
api
int
i2
=
2
cdef
public
api
int
i3
=
3
tests/errors/cdef_in_pyclass.pyx
View file @
6853d59e
# mode: error
class
Pyclass
(
object
):
cdef
bad
(
self
):
pass
_ERRORS
=
"""
2
:9: cdef statement not allowed here
4
:9: cdef statement not allowed here
"""
tests/errors/cfunc_directive_in_pyclass.pyx
View file @
6853d59e
# mode: error
import
cython
class
Pyclass
(
object
):
...
...
@@ -6,5 +7,5 @@ class Pyclass(object):
pass
_ERRORS
=
"""
5
:4: cfunc directive is not allowed here
6
:4: cfunc directive is not allowed here
"""
tests/run/capiimpl.pyx
View file @
6853d59e
...
...
@@ -2,6 +2,10 @@ __doc__ = u"""
>>> import sys
>>> sys.getrefcount(Foo.__pyx_vtable__)
2
>>> sys.getrefcount(__pyx_capi__['bar'])
2
>>> sys.getrefcount(__pyx_capi__['spam'])
2
>>> sys.getrefcount(__pyx_capi__['ten'])
2
>>> sys.getrefcount(__pyx_capi__['pi'])
...
...
@@ -10,6 +14,8 @@ __doc__ = u"""
2
>>> sys.getrefcount(__pyx_capi__['dct'])
2
>>> sys.getrefcount(__pyx_capi__['tpl'])
2
>>> sys.getrefcount(__pyx_capi__['one'])
2
>>> sys.getrefcount(__pyx_capi__['two'])
...
...
@@ -22,6 +28,8 @@ cdef public api class Foo [type FooType, object FooObject]:
cdef
void
bar
(
self
):
pass
cdef
public
api
void
bar
():
pass
cdef
api
void
spam
():
pass
...
...
@@ -30,6 +38,7 @@ cdef api double pi = 3.14
cdef
api
object
obj
=
object
()
cdef
api
dict
dct
=
{}
cdef
public
api
int
one
=
1
cdef
public
int
two
=
2
cdef
public
api
tuple
tpl
=
()
cdef
public
api
float
one
=
1
cdef
public
float
two
=
2
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