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
9d374465
Commit
9d374465
authored
Feb 15, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove alignment check and track aligned pointer
parent
be851994
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
40 deletions
+34
-40
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+24
-1
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+10
-39
No files found.
Cython/Utility/MemoryView.pyx
View file @
9d374465
...
...
@@ -25,6 +25,7 @@ cdef extern from *:
void
__Pyx_ReleaseBuffer
(
Py_buffer
*
)
ctypedef
struct
PyObject
ctypedef
Py_ssize_t
Py_intptr_t
void
Py_INCREF
(
PyObject
*
)
void
Py_DECREF
(
PyObject
*
)
...
...
@@ -277,6 +278,21 @@ cdef indirect_contiguous = Enum("<contiguous and indirect>")
# 'follow' is implied when the first or last axis is ::1
@
cname
(
'__pyx_align_pointer'
)
cdef
void
*
align_pointer
(
void
*
memory
,
size_t
alignment
)
nogil
:
"Align pointer memory on a given boundary"
cdef
Py_intptr_t
aligned_p
=
<
Py_intptr_t
>
memory
cdef
size_t
offset
with
cython
.
cdivision
(
True
):
offset
=
aligned_p
%
alignment
if
offset
>
0
:
aligned_p
+=
alignment
-
offset
return
<
void
*>
aligned_p
@
cname
(
'__pyx_memoryview'
)
cdef
class
memoryview
(
object
):
...
...
@@ -284,7 +300,10 @@ cdef class memoryview(object):
cdef
object
_size
cdef
object
_array_interface
cdef
PyThread_type_lock
lock
cdef
__pyx_atomic_int
acquisition_count
# the following array will contain a single __pyx_atomic int with
# suitable alignment
cdef
__pyx_atomic_int
acquisition_count
[
2
]
cdef
__pyx_atomic_int
*
acquisition_count_aligned_p
cdef
Py_buffer
view
cdef
int
flags
cdef
bint
dtype_is_object
...
...
@@ -307,6 +326,10 @@ cdef class memoryview(object):
else
:
self
.
dtype_is_object
=
dtype_is_object
self
.
acquisition_count_aligned_p
=
<
__pyx_atomic_int
*>
align_pointer
(
<
void
*>
&
self
.
acquisition_count
[
0
],
sizeof
(
__pyx_atomic_int
))
def
__dealloc__
(
memoryview
self
):
if
self
.
obj
is
not
None
:
__Pyx_ReleaseBuffer
(
&
self
.
view
)
...
...
Cython/Utility/MemoryView_C.c
View file @
9d374465
...
...
@@ -61,46 +61,15 @@ typedef struct {
typedef
volatile
__pyx_atomic_int_type
__pyx_atomic_int
;
#if CYTHON_ATOMICS
static
CYTHON_INLINE
__pyx_atomic_int_type
__pyx_atomic_incr_maybealigned
(
__pyx_atomic_int
*
value
,
PyThread_type_lock
lock
);
static
CYTHON_INLINE
__pyx_atomic_int_type
__pyx_atomic_decr_maybealigned
(
__pyx_atomic_int
*
value
,
PyThread_type_lock
lock
);
#define __pyx_add_acquisition_count(memview) \
__pyx_atomic_incr_maybealigned(&memview->acquisition_count
, memview->lock)
__pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview)
, memview->lock)
#define __pyx_sub_acquisition_count(memview) \
__pyx_atomic_decr_
maybealigned(&memview->acquisition_count
, memview->lock)
__pyx_atomic_decr_
aligned(__pyx_get_slice_count_pointer(memview)
, memview->lock)
#else
#define __pyx_add_acquisition_count(memview) \
__pyx_add_acquisition_count_locked(
&memview->acquisition_count
, memview->lock)
__pyx_add_acquisition_count_locked(
__pyx_get_slice_count_pointer(memview)
, memview->lock)
#define __pyx_sub_acquisition_count(memview) \
__pyx_sub_acquisition_count_locked(&memview->acquisition_count, memview->lock)
#endif
////////// Atomics //////////
#if CYTHON_ATOMICS
#define __pyx_atomic_unaligned(pointer) \
(((Py_intptr_t) pointer) & (sizeof(pointer) - 1))
static
CYTHON_INLINE
__pyx_atomic_int_type
__pyx_atomic_incr_maybealigned
(
__pyx_atomic_int
*
value
,
PyThread_type_lock
lock
)
{
if
(
unlikely
(
__pyx_atomic_unaligned
(
value
)))
return
__pyx_add_acquisition_count_locked
(
value
,
lock
);
else
return
__pyx_atomic_incr_aligned
(
value
,
lock
);
}
static
CYTHON_INLINE
__pyx_atomic_int_type
__pyx_atomic_decr_maybealigned
(
__pyx_atomic_int
*
value
,
PyThread_type_lock
lock
)
{
if
(
unlikely
(
__pyx_atomic_unaligned
(
value
)))
return
__pyx_sub_acquisition_count_locked
(
value
,
lock
);
else
return
__pyx_atomic_decr_aligned
(
value
,
lock
);
}
__pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
#endif
/////////////// ObjectToMemviewSlice.proto ///////////////
...
...
@@ -133,6 +102,8 @@ static CYTHON_INLINE int __pyx_add_acquisition_count_locked(__pyx_atomic_int *ac
PyThread_type_lock
lock
);
static
CYTHON_INLINE
int
__pyx_sub_acquisition_count_locked
(
__pyx_atomic_int
*
acquisition_count
,
PyThread_type_lock
lock
);
#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p)
#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview))
#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__)
static
CYTHON_INLINE
void
__Pyx_INC_MEMVIEW
({{
memviewslice_name
}}
*
,
int
,
int
);
...
...
@@ -409,9 +380,9 @@ __Pyx_INC_MEMVIEW({{memviewslice_name}} *memslice, int have_gil, int lineno)
if
(
!
memview
||
(
PyObject
*
)
memview
==
Py_None
)
return
;
/* allow uninitialized memoryview assignment */
if
(
memview
->
acquisition_count
<
0
)
if
(
__pyx_get_slice_count
(
memview
)
<
0
)
__pyx_fatalerror
(
"Acquisition count is %d (line %d)"
,
memview
->
acquisition_count
,
lineno
);
__pyx_get_slice_count
(
memview
)
,
lineno
);
first_time
=
__pyx_add_acquisition_count
(
memview
)
==
0
;
...
...
@@ -438,9 +409,9 @@ static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *memslice,
return
;
}
if
(
memview
->
acquisition_count
<=
0
)
if
(
__pyx_get_slice_count
(
memview
)
<=
0
)
__pyx_fatalerror
(
"Acquisition count is %d (line %d)"
,
memview
->
acquisition_count
,
lineno
);
__pyx_get_slice_count
(
memview
)
,
lineno
);
last_time
=
__pyx_sub_acquisition_count
(
memview
)
==
1
;
memslice
->
data
=
NULL
;
...
...
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