[pypy-commit] pypy cpyext-ext: first implementation of PyByteArray_AsString, returns NULL for now
mattip
pypy.commits at gmail.com
Wed Jun 1 15:21:25 EDT 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: cpyext-ext
Changeset: r84868:54ced1ce3f6e
Date: 2016-06-01 22:11 +0300
http://bitbucket.org/pypy/pypy/changeset/54ced1ce3f6e/
Log: first implementation of PyByteArray_AsString, returns NULL for now
diff --git a/pypy/module/cpyext/bytearrayobject.py b/pypy/module/cpyext/bytearrayobject.py
--- a/pypy/module/cpyext/bytearrayobject.py
+++ b/pypy/module/cpyext/bytearrayobject.py
@@ -111,7 +111,11 @@
def PyByteArray_AsString(space, w_obj):
"""Return the contents of bytearray as a char array after checking for a
NULL pointer."""
- raise NotImplementedError
+ if space.isinstance_w(w_obj, space.w_bytearray):
+ return w_obj.nonmovable_carray(space)
+ else:
+ raise oefmt(space.w_TypeError,
+ "expected bytearray object, %T found", w_obj)
@cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
def PyByteArray_Resize(space, bytearray, len):
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -5,6 +5,7 @@
from rpython.rlib.buffer import Buffer
from rpython.rlib.rstring import StringBuilder, ByteListBuilder
from rpython.rlib.debug import check_list_of_chars
+from rpython.rtyper.lltypesystem import rffi
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
@@ -42,6 +43,9 @@
def charbuf_w(self, space):
return ''.join(self.data)
+ def nonmovable_carray(self, space):
+ return rffi.cast(rffi.CCHARP, 0)
+
def _new(self, value):
if value is self.data:
value = value[:]
More information about the pypy-commit
mailing list