Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
2cc9e465
Commit
2cc9e465
authored
Mar 09, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #361 from undingen/memoryview
Add bytearray and add a memoryview test
parents
e1ba120c
b27e16fd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
5 deletions
+77
-5
from_cpython/Objects/bytearrayobject.c
from_cpython/Objects/bytearrayobject.c
+3
-1
src/capi/abstract.cpp
src/capi/abstract.cpp
+49
-4
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+2
-0
test/tests/bytearray_test.py
test/tests/bytearray_test.py
+10
-0
test/tests/memoryview_test.py
test/tests/memoryview_test.py
+13
-0
No files found.
from_cpython/Objects/bytearrayobject.c
View file @
2cc9e465
...
...
@@ -30,7 +30,9 @@ _getbytevalue(PyObject* arg, int *value)
long
face_value
;
if
(
PyBytes_CheckExact
(
arg
))
{
if
(
Py_SIZE
(
arg
)
!=
1
)
{
// Pyston change: use correct size function
// if (Py_SIZE(arg) != 1) {
if
(
PyBytes_Size
(
arg
)
!=
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"string must be of size 1"
);
return
0
;
}
...
...
src/capi/abstract.cpp
View file @
2cc9e465
...
...
@@ -90,8 +90,56 @@ extern "C" int PyBuffer_IsContiguous(Py_buffer* view, char fort) noexcept {
return
0
;
}
/* view is not checked for consistency in either of these. It is
assumed that the size of the buffer is view->len in
view->len / view->itemsize elements.
*/
extern
"C"
int
PyBuffer_ToContiguous
(
void
*
buf
,
Py_buffer
*
view
,
Py_ssize_t
len
,
char
fort
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
int
k
;
void
(
*
addone
)(
int
,
Py_ssize_t
*
,
const
Py_ssize_t
*
);
Py_ssize_t
*
indices
,
elements
;
char
*
dest
,
*
ptr
;
if
(
len
>
view
->
len
)
{
len
=
view
->
len
;
}
if
(
PyBuffer_IsContiguous
(
view
,
fort
))
{
/* simplest copy is all that is needed */
memcpy
(
buf
,
view
->
buf
,
len
);
return
0
;
}
/* Otherwise a more elaborate scheme is needed */
/* XXX(nnorwitz): need to check for overflow! */
indices
=
(
Py_ssize_t
*
)
PyMem_Malloc
(
sizeof
(
Py_ssize_t
)
*
(
view
->
ndim
));
if
(
indices
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
}
for
(
k
=
0
;
k
<
view
->
ndim
;
k
++
)
{
indices
[
k
]
=
0
;
}
if
(
fort
==
'F'
)
{
addone
=
_Py_add_one_to_index_F
;
}
else
{
addone
=
_Py_add_one_to_index_C
;
}
dest
=
(
char
*
)
buf
;
/* XXX : This is not going to be the fastest code in the world
several optimizations are possible.
*/
elements
=
len
/
view
->
itemsize
;
while
(
elements
--
)
{
addone
(
view
->
ndim
,
indices
,
view
->
shape
);
ptr
=
(
char
*
)
PyBuffer_GetPointer
(
view
,
indices
);
memcpy
(
dest
,
ptr
,
view
->
itemsize
);
dest
+=
view
->
itemsize
;
}
PyMem_Free
(
indices
);
return
0
;
}
extern
"C"
int
PyBuffer_FillInfo
(
Py_buffer
*
view
,
PyObject
*
obj
,
void
*
buf
,
Py_ssize_t
len
,
int
readonly
,
...
...
@@ -135,9 +183,6 @@ extern "C" void PyBuffer_Release(Py_buffer* view) noexcept {
PyObject
*
obj
=
view
->
obj
;
if
(
obj
)
{
// This is a Pyston assert
assert
(
isSubclass
(
obj
->
cls
,
str_cls
));
if
(
obj
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
)
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
(
obj
,
view
);
Py_XDECREF
(
obj
);
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
2cc9e465
...
...
@@ -1178,6 +1178,8 @@ void setupBuiltins() {
Py_TYPE
(
&
PyMemoryView_Type
)
=
&
PyType_Type
;
PyType_Ready
(
&
PyMemoryView_Type
);
builtins_module
->
giveAttr
(
"memoryview"
,
memoryview_cls
);
PyType_Ready
(
&
PyByteArray_Type
);
builtins_module
->
giveAttr
(
"bytearray"
,
&
PyByteArray_Type
);
builtins_module
->
giveAttr
(
"eval"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
eval
,
UNKNOWN
,
1
,
0
,
false
,
false
),
"eval"
));
...
...
test/tests/bytearray_test.py
0 → 100644
View file @
2cc9e465
for
d
in
[
"teststring"
,
42
]:
b
=
bytearray
(
d
)
print
b
,
len
(
b
)
del
b
[
1
]
b
.
append
(
'!'
)
print
b
b
.
extend
(
'?.'
)
print
b
b
.
reverse
()
print
b
test/tests/memoryview_test.py
0 → 100644
View file @
2cc9e465
def
test
(
v
):
print
len
(
v
),
v
.
readonly
,
v
.
itemsize
,
v
.
tobytes
(),
v
.
tolist
()
for
d
in
[
"123456789"
,
bytearray
(
"123456789"
)]:
v
=
memoryview
(
d
)
test
(
v
)
s
=
v
[
1
:
len
(
v
)
-
1
]
test
(
s
)
if
not
s
.
readonly
:
s
[
1
:
4
]
=
"abc"
test
(
s
)
test
(
v
)
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