[pypy-svn] r53813 - in pypy/branch/io-improvements/pypy/rpython: lltypesystem module
docgok at codespeak.net
docgok at codespeak.net
Wed Apr 16 01:59:23 CEST 2008
Author: docgok
Date: Wed Apr 16 01:59:23 2008
New Revision: 53813
Modified:
pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py
pypy/branch/io-improvements/pypy/rpython/module/ll_os.py
Log:
Cleaner API, plus it works now.
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py Wed Apr 16 01:59:23 2008
@@ -508,25 +508,24 @@
offset = offsetof(STR, 'chars') + itemoffsetof(STR.chars, 0)
realbuf = cast_ptr_to_adr(buf) + offset
c_buf = cast(VOIDP, realbuf)
- return c_buf, buf, True
+ return c_buf, buf
else:
raw_buf = lltype.malloc(CCHARP.TO, count, flavor='raw')
- return raw_buf, lltype.nullptr(STR), False
+ return raw_buf, lltype.nullptr(STR)
-def hlstr_from_buffer(buf, is_collected, allocated_size, needed_size):
+def hlstr_from_buffer(buf, allocated_size, needed_size):
from pypy.rpython.lltypesystem.rstr import STR, mallocstr
offset = offsetof(STR, 'chars') + itemoffsetof(STR.chars, 0)
- if is_collected:
+ if buf:
if allocated_size != needed_size:
new_buf = lltype.nullptr(STR)
try:
new_buf = mallocstr(needed_size)
dest = cast_ptr_to_adr(new_buf) + offset
- source = cast_ptr_to_adr(buf) + \
- itemoffsetof(lltype.typeOf(buf).TO, 0)
+ realbuf = cast_ptr_to_adr(buf) + offset
## FIXME: This is bad, because dest could potentially move
## if there are threads involved.
- raw_memcopy(source, dest, sizeof(lltype.Char) * needed_size)
+ raw_memcopy(realbuf, dest, sizeof(lltype.Char) * needed_size)
return hlstr(new_buf)
finally:
keepalive_until_here(new_buf)
@@ -536,7 +535,7 @@
try:
new_buf = mallocstr(needed_size)
source = cast_ptr_to_adr(buf) + \
- itemoffsetof(lltype.typeOf(buf).TO, 0)
+ itemoffsetof(CCHARP.TO, 0)
dest = cast_ptr_to_adr(new_buf) + offset
## FIXME: see above
raw_memcopy(source, dest, sizeof(lltype.Char) * needed_size)
@@ -544,8 +543,8 @@
finally:
keepalive_until_here(new_buf)
-def keep_buffer_for_hlstr_alive_until_here(buf, is_collected):
- if is_collected:
+def keep_buffer_for_hlstr_alive_until_here(buf):
+ if buf:
keepalive_until_here(buf)
else:
lltype.free(buf, flavor='raw')
Modified: pypy/branch/io-improvements/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/module/ll_os.py Wed Apr 16 01:59:23 2008
@@ -488,15 +488,14 @@
if count < 0:
raise OSError(errno.EINVAL, None)
buf = lltype.nullptr(STR)
- is_collected = False
try:
- c_buf, buf, is_collected = rffi.alloc_buffer_for_hlstr(count)
+ c_buf, buf = rffi.alloc_buffer_for_hlstr(count)
got = rffi.cast(lltype.Signed, os_read(fd, c_buf, count))
if got < 0:
raise OSError(rposix.get_errno(), "os_read failed")
- return rffi.hlstr_from_buffer(buf, is_collected, count, got)
+ return rffi.hlstr_from_buffer(buf, count, got)
finally:
- rffi.keep_buffer_for_hlstr_alive_until_here(buf, is_collected)
+ rffi.keep_buffer_for_hlstr_alive_until_here(buf)
def os_read_oofakeimpl(fd, count):
return OOSupport.to_rstr(os.read(fd, count))
More information about the Pypy-commit
mailing list