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
Gwenaël Samain
cython
Commits
111f3d42
Commit
111f3d42
authored
Sep 04, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffers: Format string parsing change (ticket 66)
parent
509b419f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
31 deletions
+41
-31
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+9
-28
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+32
-3
No files found.
Cython/Compiler/Buffer.py
View file @
111f3d42
...
...
@@ -534,12 +534,11 @@ def get_getbuffer_code(dtype, code):
}
ts = buf->format;
ts = __Pyx_ConsumeWhitespace(ts);
ts = __Pyx_BufferTypestringCheckEndian(ts);
if (!ts) goto fail;
ts = __Pyx_ConsumeWhitespace(ts);
ts = %(itemchecker)s(ts);
if (!ts) goto fail;
ts = __Pyx_ConsumeWhitespace(ts);
if (!ts) goto fail;
if (*ts != 0) {
PyErr_Format(PyExc_ValueError,
"Expected non-struct buffer data type (expected end, got '%%s')", ts);
...
...
@@ -667,7 +666,6 @@ acquire_utility_code = ["""\
static INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf); /*proto*/
static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts); /*proto*/
static INLINE const char* __Pyx_BufferTypestringCheckEndian(const char* ts); /*proto*/
static void __Pyx_BufferNdimError(Py_buffer* buffer, int expected_ndim); /*proto*/
"""
,
"""
static INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
...
...
@@ -687,41 +685,24 @@ static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts) {
while (1) {
switch (*ts) {
case '@':
case 10:
case 13:
case ' ':
++ts;
break;
case '=':
case '<':
case '>':
case '!':
PyErr_SetString(PyExc_ValueError, "Buffer acquisition error: Only native byte order, size and alignment supported.");
return NULL;
default:
return ts;
}
}
}
static INLINE const char* __Pyx_BufferTypestringCheckEndian(const char* ts) {
int num = 1;
int little_endian = ((char*)&num)[0];
int ok = 1;
switch (*ts) {
case '@':
case '=':
++ts; break;
case '<':
if (little_endian) ++ts;
else ok = 0;
break;
case '>':
case '!':
if (!little_endian) ++ts;
else ok = 0;
break;
}
if (!ok) {
PyErr_Format(PyExc_ValueError, "Buffer has wrong endianness (rejecting on '%s')", ts);
return NULL;
}
return ts;
}
static void __Pyx_BufferNdimError(Py_buffer* buffer, int expected_ndim) {
PyErr_Format(PyExc_ValueError,
"Buffer has wrong number of dimensions (expected %d, got %d)",
...
...
tests/run/bufaccess.pyx
View file @
111f3d42
...
...
@@ -329,6 +329,35 @@ def explicitly_release_buffer():
x
=
None
print
"After release"
#
# Format strings
#
@
testcase
def
alignment_string
(
object
[
int
]
buf
):
"""
>>> alignment_string(IntMockBuffer(None, [1,2], format="@i"))
2
>>> alignment_string(IntMockBuffer(None, [1,2], format="@i@@"))
2
>>> alignment_string(IntMockBuffer(None, [1,2], format=">i"))
Traceback (most recent call last):
...
ValueError: Buffer acquisition error: Only native byte order, size and alignment supported.
>>> alignment_string(IntMockBuffer(None, [1,2], format="<i"))
Traceback (most recent call last):
...
ValueError: Buffer acquisition error: Only native byte order, size and alignment supported.
>>> alignment_string(IntMockBuffer(None, [1,2], format="=i"))
Traceback (most recent call last):
...
ValueError: Buffer acquisition error: Only native byte order, size and alignment supported.
>>> alignment_string(IntMockBuffer(None, [1,2], format="!i"))
Traceback (most recent call last):
...
ValueError: Buffer acquisition error: Only native byte order, size and alignment supported.
"""
print
buf
[
1
]
#
# Getting items and index bounds checking
#
...
...
@@ -997,7 +1026,7 @@ cdef class IntMockBuffer(MockBuffer):
(
<
int
*>
buf
)[
0
]
=
<
int
>
value
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
int
)
cdef
get_default_format
(
self
):
return
b"
=
i"
cdef
get_default_format
(
self
):
return
b"
@
i"
cdef
class
ShortMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
...
...
@@ -1011,7 +1040,7 @@ cdef class UnsignedShortMockBuffer(MockBuffer):
(
<
unsigned
short
*>
buf
)[
0
]
=
<
unsigned
short
>
value
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
unsigned
short
)
cdef
get_default_format
(
self
):
return
b"
=
1H"
# Try with repeat count
cdef
get_default_format
(
self
):
return
b"
@
1H"
# Try with repeat count
cdef
class
FloatMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
...
...
@@ -1037,7 +1066,7 @@ cdef class ObjectMockBuffer(MockBuffer):
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
void
*
)
cdef
get_default_format
(
self
):
return
b"
=
O"
cdef
get_default_format
(
self
):
return
b"
@
O"
cdef
class
IntStridedMockBuffer
(
IntMockBuffer
):
...
...
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