[pypy-svn] r34184 - in pypy/dist/pypy/rpython/rctypes: . test
ac at codespeak.net
ac at codespeak.net
Sat Nov 4 16:34:43 CET 2006
Author: ac
Date: Sat Nov 4 16:34:42 2006
New Revision: 34184
Modified:
pypy/dist/pypy/rpython/rctypes/astringbuf.py
pypy/dist/pypy/rpython/rctypes/test/test_rstringbuf.py
Log:
Support r_uint arguments to create_string_buffer.
Modified: pypy/dist/pypy/rpython/rctypes/astringbuf.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/astringbuf.py (original)
+++ pypy/dist/pypy/rpython/rctypes/astringbuf.py Sat Nov 4 16:34:42 2006
@@ -1,7 +1,7 @@
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.rctypes.implementation import CTypesObjEntry
from pypy.annotation.model import SomeCTypesObject, SomeString, SomeInteger
-
+from pypy.rlib.rarithmetic import r_uint
from ctypes import create_string_buffer, c_char, sizeof
######################################################################
@@ -25,7 +25,7 @@
_about_ = create_string_buffer
def compute_result_annotation(self, s_length):
- if s_length.knowntype != int:
+ if s_length.knowntype not in (int, r_uint):
raise Exception("only supports create_string_buffer(length)")
return SomeCTypesObject(StringBufferType, ownsmemory=True)
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rstringbuf.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rstringbuf.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rstringbuf.py Sat Nov 4 16:34:42 2006
@@ -15,6 +15,7 @@
from ctypes import create_string_buffer, cast, POINTER, c_void_p, c_char
from ctypes import c_char_p, c_long, pointer, sizeof, c_int
from pypy.rpython.rctypes.astringbuf import StringBufferType
+from pypy.rlib.rarithmetic import r_uint
class Test_annotation:
@@ -29,6 +30,14 @@
if conftest.option.view:
a.translator.view()
+ a = RPythonAnnotator()
+ s = a.build_types(func, [r_uint])
+ assert s.knowntype == StringBufferType
+
+ if conftest.option.view:
+ a.translator.view()
+
+
def test_annotate_access(self):
def func(n):
buf = create_string_buffer(n)
@@ -94,6 +103,13 @@
assert len(c_data) == 17
py.test.raises(IndexError, "c_data[17]")
+ res = interpret(func, [r_uint(17)])
+ c_data = res.c_data
+ assert c_data[0] == '\x00'
+ assert c_data[16] == '\x00'
+ assert len(c_data) == 17
+ py.test.raises(IndexError, "c_data[17]")
+
def test_specialize_access(self):
def func(n):
buf = create_string_buffer(n)
More information about the Pypy-commit
mailing list