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
77420aa2
Commit
77420aa2
authored
Aug 08, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
git+ssh://github.com/cython/cython
parents
c012ad6f
12ca46bf
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
3 deletions
+123
-3
Cython/Includes/libcpp/__init__.pxd
Cython/Includes/libcpp/__init__.pxd
+2
-0
Cython/Includes/libcpp/memory.pxd
Cython/Includes/libcpp/memory.pxd
+85
-0
docs/src/userguide/buffer.rst
docs/src/userguide/buffer.rst
+3
-3
tests/run/cpp_smart_ptr.pyx
tests/run/cpp_smart_ptr.pyx
+20
-0
tests/run/cpp_smart_ptr_helper.h
tests/run/cpp_smart_ptr_helper.h
+13
-0
No files found.
Cython/Includes/libcpp/__init__.pxd
View file @
77420aa2
cdef
extern
from
*
:
ctypedef
bint
bool
ctypedef
void
*
nullptr_t
nullptr_t
nullptr
Cython/Includes/libcpp/memory.pxd
0 → 100644
View file @
77420aa2
from
libcpp
cimport
bool
,
nullptr_t
,
nullptr
cdef
extern
from
"<memory>"
namespace
"std"
nogil
:
cdef
cppclass
unique_ptr
[
T
]:
unique_ptr
()
unique_ptr
(
nullptr_t
)
unique_ptr
(
T
*
)
unique_ptr
(
unique_ptr
[
T
]
&
)
# Modifiers
T
*
release
()
void
reset
()
void
reset
(
nullptr_t
)
void
reset
(
T
*
)
void
swap
(
unique_ptr
&
)
# Observers
T
*
get
()
T
&
operator
*
()
#T* operator->() # Not Supported
bool
operator
bool
()
# Not Supported
bool
operator
==
(
const
unique_ptr
&
)
bool
operator
!=
(
const
unique_ptr
&
)
bool
operator
<
(
const
unique_ptr
&
)
bool
operator
>
(
const
unique_ptr
&
)
bool
operator
<=
(
const
unique_ptr
&
)
bool
operator
>=
(
const
unique_ptr
&
)
bool
operator
==
(
nullptr_t
)
bool
operator
!=
(
nullptr_t
)
# Forward Declaration not working ("Compiler crash in AnalyseDeclarationsTransform")
#cdef cppclass weak_ptr[T]
cdef
cppclass
shared_ptr
[
T
]:
shared_ptr
()
shared_ptr
(
nullptr_t
)
shared_ptr
(
T
*
)
shared_ptr
(
shared_ptr
[
T
]
&
)
shared_ptr
(
shared_ptr
[
T
]
&
,
T
*
)
shared_ptr
(
unique_ptr
[
T
]
&
)
#shared_ptr(weak_ptr[T]&) # Not Supported
# Modifiers
void
reset
()
void
reset
(
T
*
)
void
swap
(
shared_ptr
&
)
# Observers
T
*
get
()
T
&
operator
*
()
#T* operator->() # Not Supported
long
use_count
()
bool
unique
()
bool
operator
bool
()
# Not Supported
#bool owner_before[Y](const weak_ptr[Y]&) # Not Supported
bool
owner_before
[
Y
](
const
shared_ptr
[
Y
]
&
)
bool
operator
==
(
const
shared_ptr
&
)
bool
operator
!=
(
const
shared_ptr
&
)
bool
operator
<
(
const
shared_ptr
&
)
bool
operator
>
(
const
shared_ptr
&
)
bool
operator
<=
(
const
shared_ptr
&
)
bool
operator
>=
(
const
shared_ptr
&
)
bool
operator
==
(
nullptr_t
)
bool
operator
!=
(
nullptr_t
)
cdef
cppclass
weak_ptr
[
T
]:
weak_ptr
()
weak_ptr
(
weak_ptr
[
T
]
&
)
weak_ptr
(
shared_ptr
[
T
]
&
)
# Modifiers
void
reset
()
void
swap
(
weak_ptr
&
)
# Observers
long
use_count
()
bool
expired
()
shared_ptr
[
T
]
lock
()
bool
owner_before
[
Y
](
const
weak_ptr
[
Y
]
&
)
bool
owner_before
[
Y
](
const
shared_ptr
[
Y
]
&
)
docs/src/userguide/buffer.rst
View file @
77420aa2
...
...
@@ -37,7 +37,7 @@ We could implement custom ``__getitem__``, ``__setitem__``, etc. for this,
but instead we'll use the buffer protocol to expose the matrix's data to Python
so we can use NumPy to do useful work.
Implementing the buffer protocol requires adding two me
mber
s,
Implementing the buffer protocol requires adding two me
thod
s,
``__getbuffer__`` and ``__releasebuffer__``,
which Cython handles specially.
...
...
@@ -62,7 +62,7 @@ which Cython handles specially.
def __getbuffer__(self, Py_buffer *buffer, int flags):
cdef Py_ssize_t itemsize = sizeof(self.v[0])
self.shape[0] = self.v.size()
self.shape[0] = self.v.size()
/ self.ncols
self.shape[1] = self.ncols
# Stride 1 is the distance, in bytes, between two items in a row;
...
...
@@ -165,7 +165,7 @@ The ``flags`` argument to ``__getbuffer__`` comes from ``np.asarray``
that describe the kind of array that is requested.
Strictly speaking, if the flags contain ``PyBUF_ND``, ``PyBUF_SIMPLE``,
or ``PyBUF_F_CONTIGUOUS``, ``__getbuffer__`` must raise a ``BufferError``.
These macros can be ``cimport``'d from
the pseudo-package ``cython
``.
These macros can be ``cimport``'d from
``cpython.buffer
``.
(The matrix-in-vector structure actually conforms to ``PyBUF_ND``,
but that would prohibit ``__getbuffer__`` from filling in the strides.
...
...
tests/run/cpp_smart_ptr.pyx
0 → 100644
View file @
77420aa2
# mode: run
# tag: cpp
from
libcpp.memory
cimport
unique_ptr
,
shared_ptr
cdef
extern
from
"cpp_smart_ptr_helper.h"
:
cdef
cppclass
CountAllocDealloc
:
CountAllocDealloc
(
int
*
,
int
*
)
def
test_unique_ptr
():
"""
>>> test_unique_ptr()
"""
cdef
int
alloc_count
=
0
,
dealloc_count
=
0
cdef
unique_ptr
[
CountAllocDealloc
]
x_ptr
x_ptr
.
reset
(
new
CountAllocDealloc
(
&
alloc_count
,
&
dealloc_count
))
assert
alloc_count
==
1
x_ptr
.
reset
()
assert
alloc_count
==
1
assert
dealloc_count
==
1
tests/run/cpp_smart_ptr_helper.h
0 → 100644
View file @
77420aa2
class
CountAllocDealloc
{
public:
CountAllocDealloc
(
int
*
alloc_count
,
int
*
dealloc_count
)
:
_alloc_count
(
alloc_count
),
_dealloc_count
(
dealloc_count
)
{
(
*
_alloc_count
)
++
;
}
~
CountAllocDealloc
()
{
(
*
_dealloc_count
)
++
;
}
private:
int
*
_alloc_count
;
int
*
_dealloc_count
;
};
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