Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r64024:c4d6a29c134f
Date: 2013-05-12 17:00 -0700
http://bitbucket.org/pypy/pypy/changeset/c4d6a29c134f/
Log: merge default
diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py
b/lib-python/2.7/distutils/sysconfig_pypy.py
--- a/lib-python/2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/2.7/distutils/sysconfig_pypy.py
@@ -119,7 +119,7 @@
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()
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -821,7 +821,6 @@
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):
@@ -830,11 +829,13 @@
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()
diff --git a/pypy/interpreter/test/test_gateway.py
b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -136,18 +136,39 @@
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 = {}
@@ -164,6 +185,23 @@
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
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -553,10 +553,6 @@
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:
@@ -625,7 +621,6 @@
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, )
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -58,7 +58,8 @@
w_str = "str"
w_unicode = "unicode"
w_complex = "complex"
-
+ w_dict = "dict"
+
def __init__(self):
"""NOT_RPYTHON"""
self.fromcache = InternalSpaceCache(self).getorbuild
@@ -115,9 +116,13 @@
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):
@@ -480,7 +485,7 @@
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":
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -1005,6 +1005,19 @@
"""
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]
diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -332,6 +332,9 @@
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)
diff --git a/rpython/rlib/entrypoint.py b/rpython/rlib/entrypoint.py
--- a/rpython/rlib/entrypoint.py
+++ b/rpython/rlib/entrypoint.py
@@ -1,5 +1,11 @@
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.
@@ -10,14 +16,41 @@
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
@@ -25,8 +58,6 @@
# 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')
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -1314,7 +1314,8 @@
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
@@ -1327,7 +1328,8 @@
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
diff --git a/rpython/rtyper/lltypesystem/lltype.py
b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -317,7 +317,7 @@
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)])
@@ -425,7 +425,7 @@
_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]
@@ -669,7 +669,7 @@
def normalized(self):
return build_number(None, normalizedinttype(self._type))
-
+
_numbertypes = {int: Number("Signed", int, intmask)}
_numbertypes[r_int] = _numbertypes[int]
@@ -766,7 +766,7 @@
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):
@@ -911,7 +911,7 @@
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"
@@ -1120,7 +1120,7 @@
# _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
@@ -1131,7 +1131,7 @@
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:
@@ -1307,7 +1307,7 @@
return result
class _ptr(_abstract_ptr):
- __slots__ = ('_TYPE',
+ __slots__ = ('_TYPE',
'_weak', '_solid',
'_obj0', '__weakref__')
@@ -1462,9 +1462,9 @@
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):
@@ -1581,7 +1581,7 @@
__slots__ = flds
cache[tag] = _struct1
return _struct1
-
+
#for pickling support:
def _get_empty_instance_of_struct_variety(flds):
cls = _struct_variety(flds)
@@ -1644,7 +1644,7 @@
return r
# for FixedSizeArray kind of structs:
-
+
def getlength(self):
assert isinstance(self._TYPE, FixedSizeArray)
return self._TYPE.length
@@ -1891,6 +1891,8 @@
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,)
@@ -1959,7 +1961,7 @@
# 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):
@@ -2082,7 +2084,7 @@
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)
diff --git a/rpython/rtyper/lltypesystem/rffi.py
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -329,8 +329,9 @@
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_()
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -427,7 +427,10 @@
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")
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -492,7 +492,7 @@
class ContainerNode(Node):
if USESLOTS: # keep the number of slots down!
- __slots__ = """db obj
+ __slots__ = """db obj
typename implementationtypename
name
_funccodegen_owner
diff --git a/rpython/translator/c/src/entrypoint.c
b/rpython/translator/c/src/entrypoint.c
--- a/rpython/translator/c/src/entrypoint.c
+++ b/rpython/translator/c/src/entrypoint.c
@@ -20,12 +20,20 @@
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();
diff --git a/rpython/translator/c/test/test_standalone.py
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1,10 +1,13 @@
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
@@ -18,9 +21,16 @@
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:
@@ -29,7 +39,11 @@
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:
@@ -89,7 +103,7 @@
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
@@ -277,7 +291,7 @@
def test_debug_print_start_stop(self):
from rpython.rtyper.lltypesystem import rffi
-
+
def entry_point(argv):
x = "got:"
debug_start ("mycat")
@@ -409,7 +423,6 @@
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
@@ -823,7 +836,6 @@
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
@@ -1164,3 +1176,26 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit