[pypy-svn] r53995 - in pypy/branch/io-improvements/pypy: rlib rpython/lltypesystem rpython/lltypesystem/test rpython/module
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 22 11:32:12 CEST 2008
Author: arigo
Date: Tue Apr 22 11:32:09 2008
New Revision: 53995
Modified:
pypy/branch/io-improvements/pypy/rlib/rzlib.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/rffi.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
pypy/branch/io-improvements/pypy/rpython/module/ll_os.py
Log:
Use the simpler try:finally: style where we allocate
on the line before the try:, instead of initializing
the variable with NULL.
Modified: pypy/branch/io-improvements/pypy/rlib/rzlib.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rzlib.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/rzlib.py Tue Apr 22 11:32:09 2008
@@ -154,8 +154,8 @@
Compute the CRC32 checksum of the string, possibly with the given
start value, and return it as a unsigned 32 bit integer.
"""
+ bytes = rffi.get_nonmovingbuffer(string)
try:
- bytes = rffi.get_nonmovingbuffer(string)
checksum = _crc32(start, rffi.cast(Bytefp, bytes), len(string))
finally:
rffi.free_nonmovingbuffer(string, bytes)
@@ -169,8 +169,8 @@
Compute the Adler-32 checksum of the string, possibly with the given
start value, and return it as a unsigned 32 bit integer.
"""
+ bytes = rffi.get_nonmovingbuffer(string)
try:
- bytes = rffi.get_nonmovingbuffer(string)
checksum = _adler32(start, rffi.cast(Bytefp, bytes), len(string))
finally:
rffi.free_nonmovingbuffer(string, bytes)
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 Tue Apr 22 11:32:09 2008
@@ -533,9 +533,8 @@
str_chars_offset = offsetof(STR, 'chars') + itemoffsetof(STR.chars, 0)
if gc_buf:
if allocated_size != needed_size:
- new_buf = lltype.nullptr(STR)
+ new_buf = lltype.malloc(STR, needed_size)
try:
- new_buf = lltype.malloc(STR, needed_size)
dest = cast_ptr_to_adr(new_buf) + str_chars_offset
## FIXME: This is bad, because dest could potentially move
## if there are threads involved.
@@ -545,9 +544,8 @@
keepalive_until_here(new_buf)
return hlstr(gc_buf)
else:
- new_buf = lltype.nullptr(STR)
+ new_buf = lltype.malloc(STR, needed_size)
try:
- new_buf = lltype.malloc(STR, needed_size)
dest = cast_ptr_to_adr(new_buf) + str_chars_offset
## FIXME: see above
raw_memcopy(cast_ptr_to_adr(raw_buf), dest, sizeof(lltype.Char) * needed_size)
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py Tue Apr 22 11:32:09 2008
@@ -434,10 +434,8 @@
def test_nonmoving(self):
d = 'non-moving data stuff'
def f():
- gc_buf = lltype.nullptr(STR)
- raw_buf = lltype.nullptr(CCHARP.TO)
+ raw_buf, gc_buf = alloc_buffer(len(d))
try:
- raw_buf, gc_buf = alloc_buffer(len(d))
for i in range(len(d)):
raw_buf[i] = d[i]
return str_from_buffer(raw_buf, gc_buf, len(d), len(d)-1)
@@ -450,9 +448,8 @@
def test_nonmovingbuffer(self):
d = 'some cool data that should not move'
def f():
- buf = lltype.nullptr(CCHARP.TO)
+ buf = get_nonmovingbuffer(d)
try:
- buf = get_nonmovingbuffer(d)
counter = 0
for i in range(len(d)):
if buf[i] == d[i]:
@@ -466,9 +463,8 @@
def test_nonmovingbuffer_semispace(self):
d = 'some cool data that should not move'
def f():
- buf = lltype.nullptr(CCHARP.TO)
+ buf = get_nonmovingbuffer(d)
try:
- buf = get_nonmovingbuffer(d)
counter = 0
for i in range(len(d)):
if buf[i] == d[i]:
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 Tue Apr 22 11:32:09 2008
@@ -487,10 +487,8 @@
def os_read_llimpl(fd, count):
if count < 0:
raise OSError(errno.EINVAL, None)
- raw_buf = lltype.nullptr(rffi.CCHARP.TO)
- gc_buf = lltype.nullptr(STR)
+ raw_buf, gc_buf = rffi.alloc_buffer(count)
try:
- raw_buf, gc_buf = rffi.alloc_buffer(count)
void_buf = rffi.cast(rffi.VOIDP, raw_buf)
got = rffi.cast(lltype.Signed, os_read(fd, void_buf, count))
if got < 0:
@@ -512,10 +510,9 @@
rffi.SIZE_T)
def os_write_llimpl(fd, data):
- buf = lltype.nullptr(rffi.CCHARP.TO)
+ count = len(data)
+ buf = rffi.get_nonmovingbuffer(data)
try:
- count = len(data)
- buf = rffi.get_nonmovingbuffer(data)
written = rffi.cast(lltype.Signed, os_write(
rffi.cast(rffi.INT, fd),
buf, rffi.cast(rffi.SIZE_T, count)))
More information about the Pypy-commit
mailing list