Author: Brian Kearns <bdkea...@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 -@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() + + +@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() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit