Author: Richard Plangger <[email protected]>
Branch: strbuf-as-buffer
Changeset: r88987:d9a749dfce80
Date: 2016-12-09 14:14 +0100
http://bitbucket.org/pypy/pypy/changeset/d9a749dfce80/
Log: fixed some more tests
diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py
--- a/rpython/rlib/buffer.py
+++ b/rpython/rlib/buffer.py
@@ -83,7 +83,7 @@
def __init__(self, value):
self.value = value
- self.readonly = True
+ self.readonly = 1
def getlength(self):
return len(self.value)
diff --git a/rpython/rtyper/lltypesystem/rffi.py
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -755,49 +755,6 @@
SIGNEDP = lltype.Ptr(lltype.Array(SIGNED, hints={'nolength': True}))
-class RawBytes(object):
- # literal copy of _cffi_backend/func.py
- def __init__(self, string):
- self.ptr = str2charp(string, track_allocation=False)
- def __del__(self):
- free_charp(self.ptr, track_allocation=False)
-
-from rpython.rlib import rweakref
-from rpython.rlib.buffer import Buffer
-_STR_WDICT = rweakref.RWeakKeyDictionary(Buffer, RawBytes)
-
[email protected]_look_inside
-def get_raw_address_of_string(key, string):
- """Returns a 'char *' that is valid as long as the key object is alive.
- Two calls to to this function are guaranteed to return the same pointer.
-
- The extra parameter key is necessary to create a weak reference.
- The buffer of the returned pointer (if object is young) lives as long
- as key is alive. If key goes out of scope, the buffer will eventually
- be freed. `string` cannot go out of scope until the RawBytes object
- referencing it goes out of scope.
- """
- from rpython.rtyper.annlowlevel import llstr
- from rpython.rtyper.lltypesystem.rstr import STR
- from rpython.rtyper.lltypesystem import llmemory
- from rpython.rlib import rgc
-
- global _STR_WDICT
- rawbytes = _STR_WDICT.get(key)
- if rawbytes is None:
- if we_are_translated() and not rgc.can_move(string):
- lldata = llstr(string)
- data_start = (llmemory.cast_ptr_to_adr(lldata) +
- offsetof(STR, 'chars') +
- llmemory.itemoffsetof(STR.chars, 0))
- data_start = cast(CCHARP, data_start)
- data_start[len(string)] = '\x00' # write the final extra null
- return data_start
- rawbytes = RawBytes(string)
- _STR_WDICT.set(key, rawbytes)
-
- return rawbytes.ptr
-
# various type mapping
# conversions between str and char*
@@ -1355,3 +1312,47 @@
releasegil=False,
calling_conv='c',
)
+
+class RawBytes(object):
+ # literal copy of _cffi_backend/func.py
+ def __init__(self, string):
+ self.ptr = str2charp(string, track_allocation=False)
+ def __del__(self):
+ free_charp(self.ptr, track_allocation=False)
+
+from rpython.rlib import rweakref
+from rpython.rlib.buffer import Buffer
+_STR_WDICT = rweakref.RWeakKeyDictionary(Buffer, RawBytes)
+
[email protected]_look_inside
+def get_raw_address_of_string(key, string):
+ """Returns a 'char *' that is valid as long as the key object is alive.
+ Two calls to to this function are guaranteed to return the same pointer.
+
+ The extra parameter key is necessary to create a weak reference.
+ The buffer of the returned pointer (if object is young) lives as long
+ as key is alive. If key goes out of scope, the buffer will eventually
+ be freed. `string` cannot go out of scope until the RawBytes object
+ referencing it goes out of scope.
+ """
+ from rpython.rtyper.annlowlevel import llstr
+ from rpython.rtyper.lltypesystem.rstr import STR
+ from rpython.rtyper.lltypesystem import llmemory
+ from rpython.rlib import rgc
+
+ global _STR_WDICT
+ rawbytes = _STR_WDICT.get(key)
+ if rawbytes is None:
+ if we_are_translated() and not rgc.can_move(string):
+ lldata = llstr(string)
+ data_start = (llmemory.cast_ptr_to_adr(lldata) +
+ offsetof(STR, 'chars') +
+ llmemory.itemoffsetof(STR.chars, 0))
+ data_start = cast(CCHARP, data_start)
+ data_start[len(string)] = '\x00' # write the final extra null
+ return data_start
+ rawbytes = RawBytes(string)
+ _STR_WDICT.set(key, rawbytes)
+
+ return rawbytes.ptr
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit