Philip Jenvey avatar Philip Jenvey committed c4d6a29 Merge

merge default

Comments (0)

Files changed (15)

lib-python/2.7/distutils/sysconfig_pypy.py

     optional C speedup components.
     """
     if compiler.compiler_type == "unix":
-        compiler.compiler_so.extend(['-fPIC', '-Wimplicit'])
+        compiler.compiler_so.extend(['-O2', '-fPIC', '-Wimplicit'])
         compiler.shared_lib_extension = get_config_var('SO')
         if "CFLAGS" in os.environ:
             cflags = os.environ["CFLAGS"].split()

pypy/interpreter/gateway.py

     args = inspect.getargs(func.func_code)
     if args.varargs or args.keywords:
         raise TypeError("Varargs and keywords not supported in unwrap_spec")
-    assert not func.func_defaults
     argspec = ', '.join([arg for arg in args.args[1:]])
     func_code = py.code.Source("""
     def f(w_obj, %(args)s):
     d = {}
     exec func_code.compile() in d
     f = d['f']
+    f.func_defaults = unbound_meth.func_defaults
+    f.func_doc = unbound_meth.func_doc
     f.__module__ = func.__module__
     # necessary for unique identifiers for pickling
     f.func_name = func.func_name
     if unwrap_spec is None:
-        unwrap_spec = {}
+        unwrap_spec = getattr(unbound_meth, 'unwrap_spec', {})
     else:
         assert isinstance(unwrap_spec, dict)
         unwrap_spec = unwrap_spec.copy()

pypy/interpreter/test/test_gateway.py

 
     def test_interpindirect2app(self):
         space = self.space
+
         class BaseA(W_Root):
             def method(self, space, x):
+                "This is a method"
+                pass
+
+            def method_with_default(self, space, x=5):
+                pass
+
+            @gateway.unwrap_spec(x=int)
+            def method_with_unwrap_spec(self, space, x):
                 pass
 
         class A(BaseA):
             def method(self, space, x):
                 return space.wrap(x + 2)
 
+            def method_with_default(self, space, x):
+                return space.wrap(x + 2)
+
+            def method_with_unwrap_spec(self, space, x):
+                return space.wrap(x + 2)
+
         class B(BaseA):
             def method(self, space, x):
                 return space.wrap(x + 1)
 
+            def method_with_default(self, space, x):
+                return space.wrap(x + 1)
+
+            def method_with_unwrap_spec(self, space, x):
+                return space.wrap(x + 1)
+
         class FakeTypeDef(object):
             rawdict = {}
             bases = {}
         assert space.int_w(space.call_function(w_c, w_a, space.wrap(1))) == 1 + 2
         assert space.int_w(space.call_function(w_c, w_b, space.wrap(-10))) == -10 + 1
 
+        doc = space.str_w(space.getattr(w_c, space.wrap('__doc__')))
+        assert doc == "This is a method"
+
+        meth_with_default = gateway.interpindirect2app(
+            BaseA.method_with_default, {'x': int})
+        w_d = space.wrap(meth_with_default)
+
+        assert space.int_w(space.call_function(w_d, w_a, space.wrap(4))) == 4 + 2
+        assert space.int_w(space.call_function(w_d, w_b, space.wrap(-10))) == -10 + 1
+        assert space.int_w(space.call_function(w_d, w_a)) == 5 + 2
+        assert space.int_w(space.call_function(w_d, w_b)) == 5 + 1
+
+        meth_with_unwrap_spec = gateway.interpindirect2app(
+            BaseA.method_with_unwrap_spec)
+        w_e = space.wrap(meth_with_unwrap_spec)
+        assert space.int_w(space.call_function(w_e, w_a, space.wrap(4))) == 4 + 2
+
     def test_interp2app_unwrap_spec(self):
         space = self.space
         w = space.wrap

pypy/module/cpyext/api.py

     def wrapper(*args):
         from pypy.module.cpyext.pyobject import make_ref, from_ref
         from pypy.module.cpyext.pyobject import Reference
-        # we hope that malloc removal removes the newtuple() that is
-        # inserted exactly here by the varargs specializer
-        rffi.stackcounter.stacks_counter += 1
-        llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
         retval = fatal_value
         boxed_args = ()
         try:
             else:
                 print str(e)
                 pypy_debug_catch_fatal_exception()
-        rffi.stackcounter.stacks_counter -= 1
         return retval
     callable._always_inline_ = 'try'
     wrapper.__name__ = "wrapper for %r" % (callable, )

pypy/module/micronumpy/compile.py

     w_str = "str"
     w_unicode = "unicode"
     w_complex = "complex"
-    
+    w_dict = "dict"
+
     def __init__(self):
         """NOT_RPYTHON"""
         self.fromcache = InternalSpaceCache(self).getorbuild
     def newcomplex(self, r, i):
         return ComplexObject(r, i)
 
-    def listview(self, obj):
+    def listview(self, obj, number=-1):
         assert isinstance(obj, ListObject)
+        if number != -1:
+            assert number == 2
+            return [obj.items[0], obj.items[1]]
         return obj.items
+
     fixedview = listview
 
     def float(self, w_obj):
                 w_res = neg.call(interp.space, [arr])
             elif self.name == "cos":
                 cos = interp_ufuncs.get(interp.space).cos
-                w_res = cos.call(interp.space, [arr])                
+                w_res = cos.call(interp.space, [arr])
             elif self.name == "flat":
                 w_res = arr.descr_get_flatiter(interp.space)
             elif self.name == "argsort":

rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py

         """
         self.optimize_loop(ops, expected)
 
+    def test_virtual_array_of_struct_len(self):
+        ops = """
+        []
+        p0 = new_array(2, descr=complexarraydescr)
+        i0 = arraylen_gc(p0)
+        finish(i0)
+        """
+        expected = """
+        []
+        finish(2)
+        """
+        self.optimize_loop(ops, expected)
+
     def test_nonvirtual_1(self):
         ops = """
         [i]

rpython/jit/metainterp/optimizeopt/virtualize.py

         self.arraydescr = arraydescr
         self._items = [{} for _ in xrange(size)]
 
+    def getlength(self):
+        return len(self._items)
+
     def getinteriorfield(self, index, ofs, default):
         return self._items[index].get(ofs, default)
 

rpython/rlib/entrypoint.py

 secondary_entrypoints = {}
 
+import py
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib.objectmodel import we_are_translated
+
+pypy_debug_catch_fatal_exception = rffi.llexternal('pypy_debug_catch_fatal_exception', [], lltype.Void)
 
 def entrypoint(key, argtypes, c_name=None, relax=False):
     """ Note: entrypoint should call llop.gc_stack_bottom on it's own.
     from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
     def deco(func):
-        secondary_entrypoints.setdefault(key, []).append((func, argtypes))
+        source = py.code.Source("""
+        def wrapper(%(args)s):
+            # the tuple has to be killed, but it's fine because this is
+            # called from C
+            rffi.stackcounter.stacks_counter += 1
+            llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
+            # this should not raise
+            try:
+                res = func(%(args)s)
+            except Exception, e:
+                if not we_are_translated():
+                    import traceback
+                    traceback.print_exc()
+                else:
+                    print str(e)
+                    pypy_debug_catch_fatal_exception()
+                    llop.debug_fatalerror(lltype.Void, "error in c callback")
+                    assert 0 # dead code
+            rffi.stackcounter.stacks_counter -= 1
+            return res
+        """ % {'args': ', '.join(['arg%d' % i for i in range(len(argtypes))])})
+        d = {'rffi': rffi, 'lltype': lltype,
+         'pypy_debug_catch_fatal_exception': pypy_debug_catch_fatal_exception,
+         'llop': llop, 'func': func, 'we_are_translated': we_are_translated}
+        exec source.compile() in d
+        wrapper = d['wrapper']
+        secondary_entrypoints.setdefault(key, []).append((wrapper, argtypes))
+        wrapper.func_name = func.func_name
         if c_name is not None:
-            func.c_name = c_name
+            wrapper.c_name = c_name
         if relax:
-            func.relax_sig_check = True
-        func._compilation_info = ExternalCompilationInfo(
+            wrapper.relax_sig_check = True
+        wrapper._compilation_info = ExternalCompilationInfo(
             export_symbols=[c_name or func.func_name])
-        return func
+        return wrapper
     return deco
 
 # the point of dance below is so the call to rpython_startup_code actually
 # This thing is imported by any target which has any API, so it'll get
 # registered
 
-from rpython.rtyper.lltypesystem import lltype, rffi
-
 RPython_StartupCode = rffi.llexternal('RPython_StartupCode', [], lltype.Void)
 
 @entrypoint('main', [], c_name='rpython_startup_code')

rpython/rlib/rbigint.py

 
     assert t1.sign >= 0
     assert 2*shift + t1.numdigits() <= ret.numdigits()
-    ret._digits[2*shift : 2*shift + t1.numdigits()] = t1._digits
+    for i in range(t1.numdigits()):
+        ret._digits[2*shift + i] = t1._digits[i]
 
     # Zero-out the digits higher than the ah*bh copy. */
     ## ignored, assuming that we initialize to zero
     t2 = al.mul(bl)
     assert t2.sign >= 0
     assert t2.numdigits() <= 2*shift # no overlap with high digits
-    ret._digits[:t2.numdigits()] = t2._digits
+    for i in range(t2.numdigits()):
+        ret._digits[i] = t2._digits[i]
 
     # Zero out remaining digits.
     ## ignored, assuming that we initialize to zero

rpython/rtyper/lltypesystem/lltype.py

     def _names_without_voids(self):
         names_without_voids = [name for name in self._names if self._flds[name] is not Void]
         return names_without_voids
-    
+
     def _str_fields_without_voids(self):
         return ', '.join(['%s: %s' % (name, self._flds[name])
                           for name in self._names_without_voids(False)])
     _gckind = 'raw'
     __name__ = 'array'
     _anonym_struct = False
-    
+
     def __init__(self, *fields, **kwds):
         if len(fields) == 1 and isinstance(fields[0], LowLevelType):
             self.OF = fields[0]
 
     def normalized(self):
         return build_number(None, normalizedinttype(self._type))
-        
+
 
 _numbertypes = {int: Number("Signed", int, intmask)}
 _numbertypes[r_int] = _numbertypes[int]
                          adtmeths=TO._adtmeths)
         else:
             R = GcStruct("Interior", ('ptr', self), ('index', Signed),
-                         hints={'interior_ptr_type':True})            
+                         hints={'interior_ptr_type':True})
         return R
 
 class InteriorPtr(LowLevelType):
             return dwn
         OUTSIDE = getattr(OUTSIDE, first)
     return -1
- 
+
 def castable(PTRTYPE, CURTYPE):
     if CURTYPE.TO._gckind != PTRTYPE.TO._gckind:
         raise TypeError("cast_pointer() cannot change the gc status: %s to %s"
 
     # _setobj, _getobj and _obj0 are really _internal_ implementations details of _ptr,
     # use _obj if necessary instead !
-    def _setobj(self, pointing_to, solid=False):        
+    def _setobj(self, pointing_to, solid=False):
         if pointing_to is None:
             obj0 = None
         elif (solid or self._T._gckind != 'raw' or
             obj0 = weakref.ref(pointing_to)
         self._set_solid(solid)
         self._set_obj0(obj0)
-        
+
     def _getobj(self, check=True):
         obj = self._obj0
         if obj is not None:
             return result
 
 class _ptr(_abstract_ptr):
-    __slots__ = ('_TYPE', 
+    __slots__ = ('_TYPE',
                  '_weak', '_solid',
                  '_obj0', '__weakref__')
 
             assert T._gckind == 'raw'
             val = _interior_ptr(T, self._parent, self._offsets + [offset])
         return val
-    
-    
-        
+
+
+
 assert not '__dict__' in dir(_interior_ptr)
 
 class _container(object):
             __slots__ = flds
         cache[tag] = _struct1
         return _struct1
- 
+
 #for pickling support:
 def _get_empty_instance_of_struct_variety(flds):
     cls = _struct_variety(flds)
         return r
 
     # for FixedSizeArray kind of structs:
-    
+
     def getlength(self):
         assert isinstance(self._TYPE, FixedSizeArray)
         return self._TYPE.length
         attrs.setdefault('_name', '?')
         attrs.setdefault('_callable', None)
         self.__dict__.update(attrs)
+        if '_callable' in attrs and hasattr(attrs['_callable'], '_compilation_info'):
+            self.__dict__['compilation_info'] = attrs['_callable']._compilation_info
 
     def __repr__(self):
         return '<%s>' % (self,)
         # if we are an opaque containing a normal Struct/GcStruct,
         # unwrap it
         if hasattr(self, 'container'):
-            # an integer, cast to a ptr, cast to an opaque    
+            # an integer, cast to a ptr, cast to an opaque
             if type(self.container) is int:
                 return self.container
             if getattr(self.container, '_carry_around_for_tests', False):
     if not isinstance(GCSTRUCT, RttiStruct):
         raise TypeError, "expected a RttiStruct: %s" % GCSTRUCT
     if GCSTRUCT._runtime_type_info is None:
-        raise ValueError, ("no attached runtime type info for GcStruct %s" % 
+        raise ValueError, ("no attached runtime type info for GcStruct %s" %
                            GCSTRUCT._name)
     return _ptr(Ptr(RuntimeTypeInfo), GCSTRUCT._runtime_type_info)
 

rpython/rtyper/lltypesystem/rffi.py

 
 class StackCounter:
     def _cleanup_(self):
-        self.stacks_counter = 1     # number of "stack pieces": callbacks
+        self.stacks_counter = 0     # number of "stack pieces": callbacks
                                     # and threads increase it by one
+
 stackcounter = StackCounter()
 stackcounter._cleanup_()
 

rpython/translator/c/genc.py

             if sys.platform == 'win32':
                 mk.definition('DEBUGFLAGS', '/MD /Zi')
             else:
-                mk.definition('DEBUGFLAGS', '-O2 -fomit-frame-pointer -g')
+                if self.config.translation.shared:
+                    mk.definition('DEBUGFLAGS', '-O2 -fomit-frame-pointer -g -fPIC')
+                else:
+                    mk.definition('DEBUGFLAGS', '-O2 -fomit-frame-pointer -g')
 
             if self.config.translation.shared:
                 mk.definition('PYPY_MAIN_FUNCTION', "pypy_main_startup")

rpython/translator/c/node.py

 
 class ContainerNode(Node):
     if USESLOTS:      # keep the number of slots down!
-        __slots__ = """db obj 
+        __slots__ = """db obj
                        typename implementationtypename
                         name
                         _funccodegen_owner

rpython/translator/c/src/entrypoint.c

 int pypy_main_function(int argc, char *argv[]) __attribute__((__noinline__));
 #endif
 
+# ifdef PYPY_USE_ASMGCC
+#  include "structdef.h"
+#  include "forwarddecl.h"
+# endif
+
 int pypy_main_function(int argc, char *argv[])
 {
     char *errmsg;
     int i, exitcode;
     RPyListOfString *list;
 
+#ifdef PYPY_USE_ASMGCC
+    pypy_g_rpython_rtyper_lltypesystem_rffi_StackCounter.sc_inst_stacks_counter++;
+#endif
     pypy_asm_stack_bottom();
 #ifdef PYPY_X86_CHECK_SSE2_DEFINED
     pypy_x86_check_sse2();

rpython/translator/c/test/test_standalone.py

 import py
 import sys, os, re
 
+from rpython.config.translationoption import get_combined_translation_config
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import r_longlong
 from rpython.rlib.debug import ll_assert, have_debug_prints, debug_flush
 from rpython.rlib.debug import debug_print, debug_start, debug_stop, debug_offset
+from rpython.rlib.entrypoint import entrypoint, secondary_entrypoints
+from rpython.rtyper.lltypesystem import lltype
 from rpython.translator.translator import TranslationContext
 from rpython.translator.backendopt import all
 from rpython.translator.c.genc import CStandaloneBuilder, ExternalCompilationInfo
     config = None
 
     def compile(self, entry_point, debug=True, shared=False,
-                stackcheck=False):
+                stackcheck=False, entrypoints=None):
         t = TranslationContext(self.config)
-        t.buildannotator().build_types(entry_point, [s_list_of_strings])
+        ann = t.buildannotator()
+        ann.build_types(entry_point, [s_list_of_strings])
+        if entrypoints is not None:
+            anns = {}
+            for func, annotation in secondary_entrypoints['test']:
+                anns[func] = annotation
+            for item in entrypoints:
+                ann.build_types(item, anns[item])
         t.buildrtyper().specialize()
 
         if stackcheck:
 
         t.config.translation.shared = shared
 
-        cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+        if entrypoints is not None:
+            kwds = {'secondary_entrypoints': [(i, None) for i in entrypoints]}
+        else:
+            kwds = {}
+        cbuilder = CStandaloneBuilder(t, entry_point, t.config, **kwds)
         if debug:
             cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
         else:
             llop.instrument_count(lltype.Void, 'test', 1)
             llop.instrument_count(lltype.Void, 'test', 1)
             llop.instrument_count(lltype.Void, 'test', 2)
-            llop.instrument_count(lltype.Void, 'test', 1)        
+            llop.instrument_count(lltype.Void, 'test', 1)
             return 0
         t = TranslationContext(self.config)
         t.config.translation.instrument = True
 
     def test_debug_print_start_stop(self):
         from rpython.rtyper.lltypesystem import rffi
-        
+
         def entry_point(argv):
             x = "got:"
             debug_start  ("mycat")
         assert 'bok' in data
         #
         # finally, check compiling with logging disabled
-        from rpython.config.translationoption import get_combined_translation_config
         config = get_combined_translation_config(translating=True)
         config.translation.log = False
         self.config = config
         py.test.skip("TestMaemo: tests skipped for now")
         from rpython.translator.platform.maemo import check_scratchbox
         check_scratchbox()
-        from rpython.config.translationoption import get_combined_translation_config
         config = get_combined_translation_config(translating=True)
         config.translation.platform = 'maemo'
         cls.config = config
                 and result.count('c') == result.count('p') == 5
                 and result.count('a') == 1
                 and result.count('d') == 6)
+
+
+class TestShared(StandaloneTests):
+
+    def test_entrypoint(self):
+        import ctypes
+
+        config = get_combined_translation_config(translating=True)
+        self.config = config
+
+        @entrypoint('test', [lltype.Signed], relax=True, c_name='foo')
+        def f(a):
+            return a + 3
+
+        def entry_point(argv):
+            return 0
+
+        t, cbuilder = self.compile(entry_point, shared=True,
+                                   entrypoints=[f])
+        libname = cbuilder.executable_name.join('..', 'lib' +
+                                                cbuilder.modulename + '.so')
+        lib = ctypes.CDLL(str(libname))
+        assert lib.foo(13) == 16
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.