[pypy-commit] pypy default: If no maxlength is provided to _rawffi.charp2string, don't pass sys.maxint to rffi.str2charpn, which will try to allocate a buffer of that size.
alex_gaynor
noreply at buildbot.pypy.org
Sat Jun 18 01:20:31 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r44990:18946db08957
Date: 2011-06-17 16:23 -0700
http://bitbucket.org/pypy/pypy/changeset/18946db08957/
Log: If no maxlength is provided to _rawffi.charp2string, don't pass
sys.maxint to rffi.str2charpn, which will try to allocate a buffer
of that size.
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -176,7 +176,7 @@
except KeyError:
raise operationerrfmt(space.w_AttributeError,
"No symbol %s found in library %s", name, self.name)
-
+
elif (_MS_WINDOWS and
space.is_true(space.isinstance(w_name, space.w_int))):
ordinal = space.int_w(w_name)
@@ -261,7 +261,7 @@
def descr_size_alignment(self, space, n=1):
return space.newtuple([space.wrap(self.size * n),
space.wrap(self.alignment)])
-
+
class W_DataInstance(Wrappable):
def __init__(self, space, size, address=r_uint(0)):
@@ -427,7 +427,7 @@
if not (argletter in TYPEMAP_PTR_LETTERS and
letter in TYPEMAP_PTR_LETTERS):
msg = "Argument %d should be typecode %s, got %s"
- raise operationerrfmt(space.w_TypeError, msg,
+ raise operationerrfmt(space.w_TypeError, msg,
i+1, argletter, letter)
args_ll.append(arg.ll_buffer)
# XXX we could avoid the intermediate list args_ll
@@ -480,17 +480,25 @@
alignment = _create_new_accessor('alignment', 'c_alignment')
@unwrap_spec(address=r_uint, maxlength=int)
-def charp2string(space, address, maxlength=sys.maxint):
+def charp2string(space, address, maxlength=-1):
if address == 0:
return space.w_None
- s = rffi.charp2strn(rffi.cast(rffi.CCHARP, address), maxlength)
+ charp_addr = rffi.cast(rffi.CCHARP, address)
+ if maxlength == -1:
+ s = rffi.charp2str(charp_addr)
+ else:
+ s = rffi.charp2strn(charp_addr, maxlength)
return space.wrap(s)
@unwrap_spec(address=r_uint, maxlength=int)
-def wcharp2unicode(space, address, maxlength=sys.maxint):
+def wcharp2unicode(space, address, maxlength=-1):
if address == 0:
return space.w_None
- s = rffi.wcharp2unicoden(rffi.cast(rffi.CWCHARP, address), maxlength)
+ wcharp_addr = rffi.cast(rffi.CWCHARP, address)
+ if maxlength == -1:
+ s = rffi.wcharp2unicode(wcharp_addr)
+ else:
+ s = rffi.wcharp2unicoden(wcharp_addr, maxlength)
return space.wrap(s)
@unwrap_spec(address=r_uint, maxlength=int)
More information about the pypy-commit
mailing list