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
4da4a98a
Commit
4da4a98a
authored
Aug 14, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'char-buffers'
parents
7bcc15a6
0f6ddce0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
24 deletions
+43
-24
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+5
-2
Cython/Utility/Buffer.c
Cython/Utility/Buffer.c
+23
-7
tests/buffers/bufaccess.pyx
tests/buffers/bufaccess.pyx
+1
-1
tests/buffers/buffmt.pyx
tests/buffers/buffmt.pyx
+9
-9
tests/buffers/mockbuffers.pxi
tests/buffers/mockbuffers.pxi
+1
-1
tests/memoryview/memoryview.pyx
tests/memoryview/memoryview.pyx
+1
-1
tests/memoryview/memoryviewattrs.pyx
tests/memoryview/memoryviewattrs.pyx
+2
-2
tests/memoryview/memslice.pyx
tests/memoryview/memslice.pyx
+1
-1
No files found.
Cython/Compiler/Buffer.py
View file @
4da4a98a
...
...
@@ -681,7 +681,10 @@ def get_type_information_cname(code, dtype, maxdepth=None):
flags
=
"0"
is_unsigned
=
"0"
if
dtype
.
is_int
:
if
dtype
is
PyrexTypes
.
c_char_type
:
is_unsigned
=
"IS_UNSIGNED(%s)"
%
declcode
typegroup
=
"'H'"
elif
dtype
.
is_int
:
is_unsigned
=
"IS_UNSIGNED(%s)"
%
declcode
typegroup
=
"%s ? 'U' : 'I'"
%
is_unsigned
elif
complex_possible
or
dtype
.
is_complex
:
...
...
@@ -695,7 +698,7 @@ def get_type_information_cname(code, dtype, maxdepth=None):
elif
dtype
.
is_pyobject
:
typegroup
=
"'O'"
else
:
assert
False
assert
False
,
dtype
typeinfo
=
(
'static __Pyx_TypeInfo %s = '
'{ "%s", %s, sizeof(%s), { %s }, %s, %s, %s, %s };'
)
...
...
Cython/Utility/Buffer.c
View file @
4da4a98a
...
...
@@ -66,7 +66,7 @@ typedef struct {
size_t
size
;
/* sizeof(type) */
size_t
arraysize
[
8
];
/* length of array in each dimension */
int
ndim
;
char
typegroup
;
/* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */
char
typegroup
;
/* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject
, c_H_ar
*/
char
is_unsigned
;
int
flags
;
}
__Pyx_TypeInfo
;
...
...
@@ -290,7 +290,8 @@ static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
static
const
char
*
__Pyx_BufFmt_DescribeTypeChar
(
char
ch
,
int
is_complex
)
{
switch
(
ch
)
{
case
'b'
:
return
"'char'"
;
case
'c'
:
return
"'char'"
;
case
'b'
:
return
"'signed char'"
;
case
'B'
:
return
"'unsigned char'"
;
case
'h'
:
return
"'short'"
;
case
'H'
:
return
"'unsigned short'"
;
...
...
@@ -417,7 +418,9 @@ static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_compl
static
char
__Pyx_BufFmt_TypeCharToGroup
(
char
ch
,
int
is_complex
)
{
switch
(
ch
)
{
case
'c'
:
case
'b'
:
case
'h'
:
case
'i'
:
case
'c'
:
return
'H'
;
case
'b'
:
case
'h'
:
case
'i'
:
case
'l'
:
case
'q'
:
case
's'
:
case
'p'
:
return
'I'
;
case
'B'
:
case
'H'
:
case
'I'
:
case
'L'
:
case
'Q'
:
...
...
@@ -530,8 +533,12 @@ static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
continue
;
}
__Pyx_BufFmt_RaiseExpected
(
ctx
);
return
-
1
;
if
((
type
->
typegroup
==
'H'
||
group
==
'H'
)
&&
type
->
size
==
size
)
{
/* special case -- chars don't care about sign */
}
else
{
__Pyx_BufFmt_RaiseExpected
(
ctx
);
return
-
1
;
}
}
offset
=
ctx
->
head
->
parent_offset
+
field
->
offset
;
...
...
@@ -837,8 +844,14 @@ __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b)
return
1
;
if
(
a
->
size
!=
b
->
size
||
a
->
typegroup
!=
b
->
typegroup
||
a
->
is_unsigned
!=
b
->
is_unsigned
||
a
->
ndim
!=
b
->
ndim
)
return
0
;
a
->
is_unsigned
!=
b
->
is_unsigned
||
a
->
ndim
!=
b
->
ndim
)
{
if
(
a
->
typegroup
==
'H'
||
b
->
typegroup
==
'H'
)
{
/* Special case for chars */
return
a
->
size
==
b
->
size
;
}
else
{
return
0
;
}
}
if
(
a
->
ndim
)
{
/* Verify multidimensional C arrays */
...
...
@@ -893,6 +906,9 @@ static struct __pyx_typeinfo_string __Pyx_TypeInfoToFormat(__Pyx_TypeInfo *type)
size_t
size
=
type
->
size
;
switch
(
type
->
typegroup
)
{
case
'H'
:
*
buf
=
'c'
;
break
;
case
'I'
:
case
'U'
:
if
(
size
==
1
)
...
...
tests/buffers/bufaccess.pyx
View file @
4da4a98a
...
...
@@ -1034,7 +1034,7 @@ def basic_struct(object[MyStruct] buf):
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
bb
qii"))
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
cc
qii"))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
c
,
buf
[
0
].
d
,
buf
[
0
].
e
...
...
tests/buffers/buffmt.pyx
View file @
4da4a98a
...
...
@@ -63,7 +63,7 @@ def _int(fmt):
>>> _int("b")
Traceback (most recent call last):
...
ValueError: Buffer dtype mismatch, expected 'int' but got 'char'
ValueError: Buffer dtype mismatch, expected 'int' but got '
signed
char'
>>> _int("if")
Traceback (most recent call last):
...
...
@@ -184,13 +184,13 @@ def char3int(fmt):
def
unpacked_struct
(
fmt
):
"""
Native formats:
>>> unpacked_struct("
biZffb
iii")
>>> unpacked_struct("@
bi3fb
3i")
>>> unpacked_struct("@
biZffb
i2i")
>>> unpacked_struct("
biZffT{b
iii}")
>>> unpacked_struct("
bT{ifffb
2i}i")
>>> unpacked_struct("
biZffb
3T{i}")
>>> unpacked_struct("T{
b}T{T{iZffT{b
i}}}2T{T{i}}")
>>> unpacked_struct("
ciZffc
iii")
>>> unpacked_struct("@
ci3fc
3i")
>>> unpacked_struct("@
ciZffc
i2i")
>>> unpacked_struct("
ciZffT{c
iii}")
>>> unpacked_struct("
cT{ifffc
2i}i")
>>> unpacked_struct("
ciZffc
3T{i}")
>>> unpacked_struct("T{
c}T{T{iZffT{c
i}}}2T{T{i}}")
"""
assert
(
sizeof
(
UnpackedStruct1
)
==
sizeof
(
UnpackedStruct2
)
...
...
@@ -303,7 +303,7 @@ def packed_struct(fmt):
Assuming int is four bytes:
>>> packed_struct("^cici")
>>> packed_struct("=ci
b
i")
>>> packed_struct("=ci
c
i")
However aligned access won't work:
...
...
tests/buffers/mockbuffers.pxi
View file @
4da4a98a
...
...
@@ -280,7 +280,7 @@ cdef class MyStructMockBuffer(MockBuffer):
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
MyStruct
)
cdef
get_default_format
(
self
):
return
b"2
b
q2i"
cdef
get_default_format
(
self
):
return
b"2
c
q2i"
cdef
class
NestedStructMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
...
...
tests/memoryview/memoryview.pyx
View file @
4da4a98a
...
...
@@ -237,7 +237,7 @@ def basic_struct(MyStruct[:] mslice):
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
bb
qii"))
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
cc
qii"))
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
"""
buf
=
mslice
...
...
tests/memoryview/memoryviewattrs.pyx
View file @
4da4a98a
...
...
@@ -30,13 +30,13 @@ def test_shape_stride_suboffset():
77 11 1
-1 -1 -1
'''
cdef
char
[:,:,:]
larr
=
array
((
5
,
7
,
11
),
1
,
'
b
'
)
cdef
char
[:,:,:]
larr
=
array
((
5
,
7
,
11
),
1
,
'
c
'
)
print
larr
.
shape
[
0
],
larr
.
shape
[
1
],
larr
.
shape
[
2
]
print
larr
.
strides
[
0
],
larr
.
strides
[
1
],
larr
.
strides
[
2
]
print
larr
.
suboffsets
[
0
],
larr
.
suboffsets
[
1
],
larr
.
suboffsets
[
2
]
print
larr
=
array
((
5
,
7
,
11
),
1
,
'
b
'
,
mode
=
'fortran'
)
larr
=
array
((
5
,
7
,
11
),
1
,
'
c
'
,
mode
=
'fortran'
)
print
larr
.
shape
[
0
],
larr
.
shape
[
1
],
larr
.
shape
[
2
]
print
larr
.
strides
[
0
],
larr
.
strides
[
1
],
larr
.
strides
[
2
]
print
larr
.
suboffsets
[
0
],
larr
.
suboffsets
[
1
],
larr
.
suboffsets
[
2
]
...
...
tests/memoryview/memslice.pyx
View file @
4da4a98a
...
...
@@ -1008,7 +1008,7 @@ def basic_struct(MyStruct[:] buf):
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
bb
qii"))
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="
cc
qii"))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
c
,
buf
[
0
].
d
,
buf
[
0
].
e
...
...
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