Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r68800:4da44a7d1989
Date: 2014-01-21 11:21 +0100
http://bitbucket.org/pypy/pypy/changeset/4da44a7d1989/

Log:    merge heads

diff --git a/pypy/doc/_ref.txt b/pypy/doc/_ref.txt
--- a/pypy/doc/_ref.txt
+++ b/pypy/doc/_ref.txt
@@ -109,6 +109,4 @@
 .. _`rpython/translator/c/`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
 .. _`rpython/translator/c/src/stacklet/`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
 .. _`rpython/translator/c/src/stacklet/stacklet.h`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
 .. _`rpython/translator/tool/`: 
https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -167,7 +167,7 @@
     def run(self):
         """Start this frame's execution."""
         if self.getcode().co_flags & pycode.CO_GENERATOR:
-            if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
+            if 1:# self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
                 from pypy.interpreter.generator import GeneratorIteratorWithDel
                 return self.space.wrap(GeneratorIteratorWithDel(self))
             else:
diff --git a/pypy/module/_rawffi/test/test__rawffi.py 
b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -1,6 +1,5 @@
 from rpython.translator.platform import platform
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.conftest import option
 from pypy.module._rawffi.interp_rawffi import TYPEMAP, TYPEMAP_FLOAT_LETTERS
 from pypy.module._rawffi.tracker import Tracker
 
@@ -1133,15 +1132,6 @@
     def setup_class(cls):
         cls.w_sizes_and_alignments = cls.space.wrap(dict(
             [(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()]))
-        #
-        # detect if we're running on PyPy with DO_TRACING not compiled in
-        if option.runappdirect:
-            try:
-                import _rawffi
-                _rawffi._num_of_allocated_objects()
-            except (ImportError, RuntimeError), e:
-                py.test.skip(str(e))
-        #
         Tracker.DO_TRACING = True
 
     def test_structure_autofree(self):
diff --git a/pypy/module/struct/__init__.py b/pypy/module/struct/__init__.py
--- a/pypy/module/struct/__init__.py
+++ b/pypy/module/struct/__init__.py
@@ -49,11 +49,12 @@
         'calcsize': 'interp_struct.calcsize',
         'pack': 'interp_struct.pack',
         'unpack': 'interp_struct.unpack',
-        }
+
+        'Struct': 'interp_struct.W_Struct',
+    }
 
     appleveldefs = {
         'error': 'app_struct.error',
         'pack_into': 'app_struct.pack_into',
         'unpack_from': 'app_struct.unpack_from',
-        'Struct': 'app_struct.Struct',
-        }
+    }
diff --git a/pypy/module/struct/app_struct.py b/pypy/module/struct/app_struct.py
--- a/pypy/module/struct/app_struct.py
+++ b/pypy/module/struct/app_struct.py
@@ -4,6 +4,7 @@
 """
 import struct
 
+
 class error(Exception):
     """Exception raised on various occasions; argument is a string
     describing what is wrong."""
@@ -21,21 +22,3 @@
         raise error("unpack_from requires a buffer of at least %d bytes"
                     % (size,))
     return struct.unpack(fmt, data)
-
-# XXX inefficient
-class Struct(object):
-    def __init__(self, format):
-        self.format = format
-        self.size = struct.calcsize(format)
-
-    def pack(self, *args):
-        return struct.pack(self.format, *args)
-
-    def unpack(self, s):
-        return struct.unpack(self.format, s)
-
-    def pack_into(self, buffer, offset, *args):
-        return pack_into(self.format, buffer, offset, *args)
-
-    def unpack_from(self, buffer, offset=0):
-        return unpack_from(self.format, buffer, offset)
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
@@ -1,15 +1,22 @@
-from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import OperationError
-from pypy.module.struct.formatiterator import PackFormatIterator, 
UnpackFormatIterator
 from rpython.rlib import jit
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.rstruct.formatiterator import CalcSizeFormatIterator
+from rpython.tool.sourcetools import func_with_new_name
+
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+from pypy.module.struct.formatiterator import (
+    PackFormatIterator, UnpackFormatIterator
+)
 
 
 @unwrap_spec(format=str)
 def calcsize(space, format):
     return space.wrap(_calcsize(space, format))
 
+
 def _calcsize(space, format):
     fmtiter = CalcSizeFormatIterator()
     try:
@@ -52,3 +59,44 @@
         w_error = space.getattr(w_module, space.wrap('error'))
         raise OperationError(w_error, space.wrap(e.msg))
     return space.newtuple(fmtiter.result_w[:])
+
+
+class W_Struct(W_Root):
+    _immutable_fields_ = ["format", "size"]
+
+    def __init__(self, space, format):
+        self.format = format
+        self.size = _calcsize(space, format)
+
+    @unwrap_spec(format=str)
+    def descr__new__(space, w_subtype, format):
+        self = space.allocate_instance(W_Struct, w_subtype)
+        W_Struct.__init__(self, space, format)
+        return self
+
+    def wrap_struct_method(name):
+        def impl(self, space, __args__):
+            w_module = space.getbuiltinmodule('struct')
+            w_method = space.getattr(w_module, space.wrap(name))
+            return space.call_obj_args(
+                w_method, space.wrap(self.format), __args__
+            )
+
+        return func_with_new_name(impl, 'descr_' + name)
+
+    descr_pack = wrap_struct_method("pack")
+    descr_unpack = wrap_struct_method("unpack")
+    descr_pack_into = wrap_struct_method("pack_into")
+    descr_unpack_from = wrap_struct_method("unpack_from")
+
+
+W_Struct.typedef = TypeDef("Struct",
+    __new__=interp2app(W_Struct.descr__new__.im_func),
+    format=interp_attrproperty("format", cls=W_Struct),
+    size=interp_attrproperty("size", cls=W_Struct),
+
+    pack=interp2app(W_Struct.descr_pack),
+    unpack=interp2app(W_Struct.descr_unpack),
+    pack_into=interp2app(W_Struct.descr_pack_into),
+    unpack_from=interp2app(W_Struct.descr_unpack_from),
+)
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -167,7 +167,7 @@
 #
 # This list corresponds to the operations implemented by the LLInterpreter.
 # Note that many exception-raising operations can be replaced by calls
-# to helper functions in rpython.rtyper.raisingops.raisingops.
+# to helper functions in rpython.rtyper.raisingops.
 # ***** Run test_lloperation after changes. *****
 
 LL_OPERATIONS = {
diff --git a/rpython/rtyper/raisingops/raisingops.py 
b/rpython/rtyper/raisingops.py
rename from rpython/rtyper/raisingops/raisingops.py
rename to rpython/rtyper/raisingops.py
diff --git a/rpython/rtyper/raisingops/__init__.py 
b/rpython/rtyper/raisingops/__init__.py
deleted file mode 100644
diff --git a/rpython/translator/backendopt/raisingop2direct_call.py 
b/rpython/translator/backendopt/raisingop2direct_call.py
--- a/rpython/translator/backendopt/raisingop2direct_call.py
+++ b/rpython/translator/backendopt/raisingop2direct_call.py
@@ -1,5 +1,5 @@
 from rpython.translator.backendopt.support import log, all_operations, annotate
-import rpython.rtyper.raisingops.raisingops
+import rpython.rtyper.raisingops
 
 
 log = log.raisingop2directcall
@@ -15,7 +15,7 @@
 
 def raisingop2direct_call(translator, graphs=None):
     """search for operations that could raise an exception and change that
-    operation into a direct_call to a function from the raisingops directory.
+    operation into a direct_call to a function from the raisingops module.
     This function also needs to be annotated and specialized.
 
     note: this could be extended to allow for any operation to be changed into
@@ -30,7 +30,7 @@
     for op in all_operations(graphs):
         if not is_raisingop(op):
             continue
-        func = getattr(rpython.rtyper.raisingops.raisingops, op.opname, None)
+        func = getattr(rpython.rtyper.raisingops, op.opname, None)
         if not func:
             log.warning("%s not found" % op.opname)
             continue
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to