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
8d2a7185
Commit
8d2a7185
authored
Oct 30, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
2886c169
e85cb769
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
7 deletions
+103
-7
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+7
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+15
-3
Cython/Utility/arrayarray.h
Cython/Utility/arrayarray.h
+7
-4
tests/run/array_cimport.srctree
tests/run/array_cimport.srctree
+37
-0
tests/run/cpp_nested_classes.pyx
tests/run/cpp_nested_classes.pyx
+23
-0
tests/run/cpp_nested_classes_support.cpp
tests/run/cpp_nested_classes_support.cpp
+14
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
8d2a7185
...
...
@@ -481,6 +481,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
typecode
=
globalstate
[
'type_declarations'
]
typecode
.
putln
(
""
)
typecode
.
putln
(
"/*--- Type declarations ---*/"
)
# This is to work around the fact that array.h isn't part of the C-API,
# but we need to declare it earlier than utility code.
if
'cpython.array'
in
[
m
.
qualified_name
for
m
in
modules
]:
typecode
.
putln
(
'#ifndef _ARRAYARRAY_H'
)
typecode
.
putln
(
'struct arrayobject;'
)
typecode
.
putln
(
'typedef struct arrayobject arrayobject;'
)
typecode
.
putln
(
'#endif'
)
vtab_list
,
vtabslot_list
=
self
.
sort_type_hierarchy
(
modules
,
env
)
self
.
generate_type_definitions
(
env
,
modules
,
vtab_list
,
vtabslot_list
,
typecode
)
...
...
Cython/Compiler/Nodes.py
View file @
8d2a7185
...
...
@@ -838,6 +838,18 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
type
=
py_object_type
else
:
if
self
.
module_path
:
# Maybe it's a nested C++ class.
scope
=
env
for
item
in
self
.
module_path
:
entry
=
scope
.
lookup
(
item
)
if
entry
.
is_cpp_class
:
scope
=
entry
.
type
.
scope
else
:
scope
=
None
break
if
scope
is
None
:
# Maybe it's a cimport.
scope
=
env
.
find_imported_module
(
self
.
module_path
,
self
.
pos
)
if
scope
:
scope
.
fused_to_specific
=
env
.
fused_to_specific
...
...
Cython/Utility/arrayarray.h
View file @
8d2a7185
...
...
@@ -13,7 +13,11 @@
#ifndef _ARRAYARRAY_H
#define _ARRAYARRAY_H
struct
arrayobject
;
/* Forward */
// These two forward declarations are explicitly handled in the type
// declaration code, as including them here is too late for cython-defined
// types to use them.
// struct arrayobject;
// typedef struct arrayobject arrayobject;
// All possible arraydescr values are defined in the vector "descriptors"
// below. That's defined later because the appropriate get and set
...
...
@@ -29,7 +33,7 @@ typedef struct arraydescr {
}
arraydescr
;
typedef
struct
arrayobject
{
struct
arrayobject
{
PyObject_HEAD
Py_ssize_t
ob_size
;
union
{
...
...
@@ -54,8 +58,7 @@ typedef struct arrayobject {
#if PY_VERSION_HEX >= 0x03000000
int
ob_exports
;
/* Number of exported buffers */
#endif
}
arrayobject
;
};
#ifndef NO_NEWARRAY_INLINE
// fast creation of a new array
...
...
tests/run/array_cimport.srctree
0 → 100644
View file @
8d2a7185
PYTHON setup.py build_ext --inplace
PYTHON -c "import ttt"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("*.pyx"),
)
######## tt.pxd ########
from cpython.array cimport array
cdef class Foo:
cdef array obj
######## tt.pyx ########
cdef class Foo:
def __init__(self, data):
self.obj = data
######## ttt.pyx ########
from array import array
from cpython.array cimport array
from tt cimport Foo
cdef array a = array('i', [1,2,3])
cdef Foo x
print a.data.as_ints[0]
x = Foo(a)
print x.obj.data.as_ints[0]
tests/run/cpp_nested_classes.pyx
0 → 100644
View file @
8d2a7185
# tag: cpp
cdef
extern
from
"cpp_nested_classes_support.cpp"
:
cdef
cppclass
A
:
cppclass
B
:
int
square
(
int
)
cppclass
C
:
int
cube
(
int
)
B
*
createB
()
def
test
():
"""
>>> test()
"""
cdef
A
a
cdef
A
.
B
b
assert
b
.
square
(
3
)
==
9
cdef
A
.
B
.
C
c
assert
c
.
cube
(
3
)
==
27
cdef
A
.
B
*
b_ptr
=
a
.
createB
()
assert
b_ptr
.
square
(
4
)
==
16
del
b_ptr
tests/run/cpp_nested_classes_support.cpp
0 → 100644
View file @
8d2a7185
class
A
{
public:
class
B
{
public:
int
square
(
int
x
)
{
return
x
*
x
;
}
class
C
{
public:
int
cube
(
int
x
)
{
return
x
*
x
*
x
;
}
};
};
B
*
createB
()
{
return
new
B
();
}
};
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