[pypy-commit] pypy missing-tp_new: merge default into branch
mattip
pypy.commits at gmail.com
Thu Nov 24 04:28:03 EST 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: missing-tp_new
Changeset: r88609:adafff615169
Date: 2016-11-24 11:27 +0200
http://bitbucket.org/pypy/pypy/changeset/adafff615169/
Log: merge default into branch
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
@@ -67,6 +67,7 @@
g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
g['CC'] = "gcc -pthread" # -pthread might not be valid on OS/X, check
g['OPT'] = ""
+ g['VERSION'] = get_python_version()
global _config_vars
_config_vars = g
diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -120,8 +120,8 @@
raise OperationError(AttributeError, name)
return method(*args)
- def lookup_in_type_where(self, cls, name):
- return 'hopefully not needed', getattr(cls, name)
+ def lookup_in_type(self, cls, name):
+ return getattr(cls, name)
def get_and_call_function(self, w_descr, w_obj, *args):
return w_descr.__get__(w_obj)(*args)
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -1,7 +1,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import cpython_api, cpython_struct, \
METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, CONST_STRING
-from pypy.module.cpyext.pyobject import PyObject
+from pypy.module.cpyext.pyobject import PyObject, as_pyobj
from pypy.interpreter.module import Module
from pypy.module.cpyext.methodobject import (
W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod,
@@ -124,11 +124,17 @@
else:
PyErr_BadInternalCall(space)
- at cpython_api([PyObject], rffi.CCHARP, error=0)
-def PyModule_GetName(space, module):
+ at cpython_api([PyObject], rffi.CCHARP)
+def PyModule_GetName(space, w_mod):
"""
Return module's __name__ value. If the module does not provide one,
- or if it is not a string, SystemError is raised and NULL is returned."""
- raise NotImplementedError
-
-
+ or if it is not a string, SystemError is raised and NULL is returned.
+ """
+ # NOTE: this version of the code works only because w_mod.w_name is
+ # a wrapped string object attached to w_mod; so it makes a
+ # PyStringObject that will live as long as the module itself,
+ # and returns a "char *" inside this PyStringObject.
+ if not isinstance(w_mod, Module):
+ raise oefmt(space.w_SystemError, "PyModule_GetName(): not a module")
+ from pypy.module.cpyext.bytesobject import PyString_AsString
+ return PyString_AsString(space, as_pyobj(space, w_mod.w_name))
diff --git a/pypy/module/cpyext/test/test_module.py b/pypy/module/cpyext/test/test_module.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/test_module.py
@@ -0,0 +1,12 @@
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from rpython.rtyper.lltypesystem import rffi
+
+
+class TestModuleObject(BaseApiTest):
+ def test_module_getname(self, space, api):
+ w_sys = space.wrap(space.sys)
+ p = api.PyModule_GetName(w_sys)
+ assert rffi.charp2str(p) == 'sys'
+ p2 = api.PyModule_GetName(w_sys)
+ assert p2 == p
+ self.raises(space, api, SystemError, api.PyModule_GetName, space.w_True)
diff --git a/pypy/module/faulthandler/test/test_ztranslation.py b/pypy/module/faulthandler/test/test_ztranslation.py
--- a/pypy/module/faulthandler/test/test_ztranslation.py
+++ b/pypy/module/faulthandler/test/test_ztranslation.py
@@ -1,4 +1,5 @@
from pypy.objspace.fake.checkmodule import checkmodule
def test_faulthandler_translates():
+ import pypy.module._vmprof.interp_vmprof # register_code_object_class()
checkmodule('faulthandler')
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -12,72 +12,52 @@
@specialize.memo()
def object_getattribute(space):
"Utility that returns the app-level descriptor object.__getattribute__."
- w_src, w_getattribute = space.lookup_in_type_where(space.w_object,
- '__getattribute__')
- return w_getattribute
+ return space.lookup_in_type(space.w_object, '__getattribute__')
@specialize.memo()
def object_setattr(space):
"Utility that returns the app-level descriptor object.__setattr__."
- w_src, w_setattr = space.lookup_in_type_where(space.w_object,
- '__setattr__')
- return w_setattr
+ return space.lookup_in_type(space.w_object, '__setattr__')
@specialize.memo()
def object_delattr(space):
"Utility that returns the app-level descriptor object.__delattr__."
- w_src, w_delattr = space.lookup_in_type_where(space.w_object,
- '__delattr__')
- return w_delattr
+ return space.lookup_in_type(space.w_object, '__delattr__')
@specialize.memo()
def object_hash(space):
"Utility that returns the app-level descriptor object.__hash__."
- w_src, w_hash = space.lookup_in_type_where(space.w_object,
- '__hash__')
- return w_hash
+ return space.lookup_in_type(space.w_object, '__hash__')
@specialize.memo()
def type_eq(space):
"Utility that returns the app-level descriptor type.__eq__."
- w_src, w_eq = space.lookup_in_type_where(space.w_type,
- '__eq__')
- return w_eq
+ return space.lookup_in_type(space.w_type, '__eq__')
@specialize.memo()
def list_iter(space):
"Utility that returns the app-level descriptor list.__iter__."
- w_src, w_iter = space.lookup_in_type_where(space.w_list,
- '__iter__')
- return w_iter
+ return space.lookup_in_type(space.w_list, '__iter__')
@specialize.memo()
def tuple_iter(space):
"Utility that returns the app-level descriptor tuple.__iter__."
- w_src, w_iter = space.lookup_in_type_where(space.w_tuple,
- '__iter__')
- return w_iter
+ return space.lookup_in_type(space.w_tuple, '__iter__')
@specialize.memo()
def str_getitem(space):
"Utility that returns the app-level descriptor str.__getitem__."
- w_src, w_getitem = space.lookup_in_type_where(space.w_str,
- '__getitem__')
- return w_getitem
+ return space.lookup_in_type(space.w_str, '__getitem__')
@specialize.memo()
def unicode_getitem(space):
"Utility that returns the app-level descriptor unicode.__getitem__."
- w_src, w_getitem = space.lookup_in_type_where(space.w_unicode,
- '__getitem__')
- return w_getitem
+ return space.lookup_in_type(space.w_unicode, '__getitem__')
@specialize.memo()
def dict_getitem(space):
"Utility that returns the app-level descriptor dict.__getitem__."
- w_src, w_getitem = space.lookup_in_type_where(space.w_dict,
- '__getitem__')
- return w_getitem
+ return space.lookup_in_type(space.w_dict, '__getitem__')
def raiseattrerror(space, w_obj, name, w_descr=None):
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -339,6 +339,9 @@
def is_generator(self, w_obj):
return NonConstant(False)
+ def lookup_in_type(self, w_type, name):
+ return w_some_obj()
+
# ----------
def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds):
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -339,6 +339,10 @@
return w_type.lookup(name)
lookup._annspecialcase_ = 'specialize:lookup'
+ def lookup_in_type(self, w_type, name):
+ w_src, w_descr = self.lookup_in_type_where(w_type, name)
+ return w_descr
+
def lookup_in_type_where(self, w_type, name):
return w_type.lookup_where(name)
lookup_in_type_where._annspecialcase_ = 'specialize:lookup_in_type_where'
@@ -659,4 +663,4 @@
@specialize.arg(2, 3)
def is_overloaded(self, w_obj, tp, method):
return (self.lookup(w_obj, method) is not
- self.lookup_in_type_where(tp, method)[1])
+ self.lookup_in_type(tp, method))
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -22,7 +22,8 @@
"""Block annotator for RPython.
See description in doc/translation.txt."""
- def __init__(self, translator=None, policy=None, bookkeeper=None):
+ def __init__(self, translator=None, policy=None, bookkeeper=None,
+ keepgoing=False):
import rpython.rtyper.extfuncregistry # has side effects
if translator is None:
@@ -50,6 +51,9 @@
if bookkeeper is None:
bookkeeper = Bookkeeper(self)
self.bookkeeper = bookkeeper
+ self.keepgoing = keepgoing
+ self.failed_blocks = set()
+ self.errors = []
def __getstate__(self):
attrs = """translator pendingblocks annotated links_followed
@@ -202,6 +206,12 @@
else:
newgraphs = self.translator.graphs #all of them
got_blocked_blocks = False in self.annotated.values()
+ if self.failed_blocks:
+ text = ('Annotation failed, %s errors were recorded:' %
+ len(self.errors))
+ text += '\n-----'.join(str(e) for e in self.errors)
+ raise annmodel.AnnotatorError(text)
+
if got_blocked_blocks:
for graph in self.blocked_graphs.values():
self.blocked_graphs[graph] = True
@@ -348,6 +358,8 @@
#print '* processblock', block, cells
self.annotated[block] = graph
+ if block in self.failed_blocks:
+ return
if block in self.blocked_blocks:
del self.blocked_blocks[block]
try:
@@ -392,6 +404,10 @@
except annmodel.UnionError as e:
# Add source code to the UnionError
e.source = '\n'.join(source_lines(graph, block, None, long=True))
+ if self.keepgoing:
+ self.errors.append(e)
+ self.failed_blocks.add(block)
+ return
raise
# if the merged cells changed, we must redo the analysis
if unions != oldcells:
@@ -482,6 +498,10 @@
except annmodel.AnnotatorError as e: # note that UnionError is a subclass
e.source = gather_error(self, graph, block, i)
+ if self.keepgoing:
+ self.errors.append(e)
+ self.failed_blocks.add(block)
+ return
raise
else:
diff --git a/rpython/config/translationoption.py b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -188,6 +188,10 @@
"When true, enable the use of tagged pointers. "
"If false, use normal boxing",
default=False),
+ BoolOption("keepgoing",
+ "Continue annotating when errors are encountered, and report "
+ "them all at the end of the annotation phase",
+ default=False, cmdline="--keepgoing"),
BoolOption("lldebug",
"If true, makes an lldebug build", default=False,
cmdline="--lldebug"),
diff --git a/rpython/translator/translator.py b/rpython/translator/translator.py
--- a/rpython/translator/translator.py
+++ b/rpython/translator/translator.py
@@ -67,7 +67,8 @@
if self.annotator is not None:
raise ValueError("we already have an annotator")
from rpython.annotator.annrpython import RPythonAnnotator
- self.annotator = RPythonAnnotator(self, policy=policy)
+ self.annotator = RPythonAnnotator(
+ self, policy=policy, keepgoing=self.config.translation.keepgoing)
return self.annotator
def buildrtyper(self):
More information about the pypy-commit
mailing list