aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Cross <hodgestar@gmail.com>2020-12-03 23:29:18 +0200
committerSimon Cross <hodgestar@gmail.com>2020-12-03 23:29:18 +0200
commitf8837c782df58fcc4e0abdc194d5d91a5bdb20b0 (patch)
tree79554a382c4b009bb00764b3971616b36ec323cc /rpython
parentMerge the rpython-error_value branch. (diff)
downloadpypy-f8837c782df58fcc4e0abdc194d5d91a5bdb20b0.tar.gz
pypy-f8837c782df58fcc4e0abdc194d5d91a5bdb20b0.tar.bz2
pypy-f8837c782df58fcc4e0abdc194d5d91a5bdb20b0.zip
Implement constcharpsize2str in rffi.
Diffstat (limited to 'rpython')
-rw-r--r--rpython/rtyper/lltypesystem/rffi.py10
-rw-r--r--rpython/rtyper/lltypesystem/test/test_rffi.py17
2 files changed, 27 insertions, 0 deletions
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
index 87e424522d..8c50b8b3b6 100644
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -1038,6 +1038,16 @@ def constcharp2str(cp):
return charp2str(cp)
constcharp2str._annenforceargs_ = [lltype.SomePtr(CONST_CCHARP)]
+
+def constcharpsize2str(cp, size):
+ """
+ Like charpsize2str, but takes a CONST_CCHARP instead
+ """
+ cp = cast(CCHARP, cp)
+ return charpsize2str(cp, size)
+constcharpsize2str._annenforceargs_ = [lltype.SomePtr(CONST_CCHARP), int]
+
+
@not_rpython
def _deprecated_get_nonmovingbuffer(*args):
raise Exception(
diff --git a/rpython/rtyper/lltypesystem/test/test_rffi.py b/rpython/rtyper/lltypesystem/test/test_rffi.py
index ed894ddc46..9218448182 100644
--- a/rpython/rtyper/lltypesystem/test/test_rffi.py
+++ b/rpython/rtyper/lltypesystem/test/test_rffi.py
@@ -169,6 +169,23 @@ class BaseTestRffi:
xf = self.compile(f, [], backendopt=False)
assert xf() == 3
+ def test_constcharpsize2str(self):
+ def f():
+ l_buf = lltype.malloc(CCHARP.TO, 5, flavor='raw')
+ l_buf[0] = 'A'
+ l_buf[1] = 'B'
+ l_buf[2] = 'C'
+ l_buf[3] = '\x00'
+ l_buf[4] = 'E'
+ l_constbuf = cast(CONST_CCHARP, l_buf)
+ res = constcharpsize2str(l_constbuf, 5)
+ lltype.free(l_buf, flavor='raw')
+ return res
+
+ assert f() == "ABC\x00E"
+ xf = self.compile(f, [], backendopt=False)
+ assert xf() == "ABC\x00E"
+
def test_stringstar(self):
c_source = """
#include <string.h>