[pypy-commit] pypy default: make struct pack helper func
bdkearns
noreply at buildbot.pypy.org
Thu May 8 23:08:27 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r71417:e09a947e8997
Date: 2014-05-06 12:05 -0400
http://bitbucket.org/pypy/pypy/changeset/e09a947e8997/
Log: make struct pack helper func
diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -21,11 +21,6 @@
return space.fromcache(Cache).error
- at unwrap_spec(format=str)
-def calcsize(space, format):
- return space.wrap(_calcsize(space, format))
-
-
def _calcsize(space, format):
fmtiter = CalcSizeFormatIterator()
try:
@@ -38,7 +33,11 @@
@unwrap_spec(format=str)
-def pack(space, format, args_w):
+def calcsize(space, format):
+ return space.wrap(_calcsize(space, format))
+
+
+def _pack(space, format, args_w):
if jit.isconstant(format):
size = _calcsize(space, format)
else:
@@ -50,13 +49,18 @@
raise OperationError(space.w_OverflowError, space.wrap(e.msg))
except StructError, e:
raise OperationError(get_error(space), space.wrap(e.msg))
- return space.wrap(fmtiter.result.build())
+ return fmtiter.result.build()
+
+
+ at unwrap_spec(format=str)
+def pack(space, format, args_w):
+ return space.wrap(_pack(space, format, args_w))
# XXX inefficient
@unwrap_spec(format=str, offset=int)
def pack_into(space, format, w_buffer, offset, args_w):
- res = pack(space, format, args_w).str_w(space)
+ res = _pack(space, format, args_w)
buf = space.writebuf_w(w_buffer)
if offset < 0:
offset += buf.getlength()
More information about the pypy-commit
mailing list