Author: wenzhuman <[email protected]>
Branch: gc-pinning
Changeset: r71802:1f4aa19a1f22
Date: 2014-06-01 03:25 -0400
http://bitbucket.org/pypy/pypy/changeset/1f4aa19a1f22/
Log: merge default
diff --git a/lib-python/2.7/imputil.py b/lib-python/2.7/imputil.py
--- a/lib-python/2.7/imputil.py
+++ b/lib-python/2.7/imputil.py
@@ -422,7 +422,8 @@
saved back to the filesystem for future imports. The source file's
modification timestamp must be provided as a Long value.
"""
- codestring = open(pathname, 'rU').read()
+ with open(pathname, 'rU') as fp:
+ codestring = fp.read()
if codestring and codestring[-1] != '\n':
codestring = codestring + '\n'
code = __builtin__.compile(codestring, pathname, 'exec')
@@ -603,8 +604,8 @@
self.desc = desc
def import_file(self, filename, finfo, fqname):
- fp = open(filename, self.desc[1])
- module = imp.load_module(fqname, fp, filename, self.desc)
+ with open(filename, self.desc[1]) as fp:
+ module = imp.load_module(fqname, fp, filename, self.desc)
module.__file__ = filename
return 0, module, { }
diff --git a/lib-python/2.7/modulefinder.py b/lib-python/2.7/modulefinder.py
--- a/lib-python/2.7/modulefinder.py
+++ b/lib-python/2.7/modulefinder.py
@@ -109,16 +109,16 @@
def run_script(self, pathname):
self.msg(2, "run_script", pathname)
- fp = open(pathname, READ_MODE)
- stuff = ("", "r", imp.PY_SOURCE)
- self.load_module('__main__', fp, pathname, stuff)
+ with open(pathname, READ_MODE) as fp:
+ stuff = ("", "r", imp.PY_SOURCE)
+ self.load_module('__main__', fp, pathname, stuff)
def load_file(self, pathname):
dir, name = os.path.split(pathname)
name, ext = os.path.splitext(name)
- fp = open(pathname, READ_MODE)
- stuff = (ext, "r", imp.PY_SOURCE)
- self.load_module(name, fp, pathname, stuff)
+ with open(pathname, READ_MODE) as fp:
+ stuff = (ext, "r", imp.PY_SOURCE)
+ self.load_module(name, fp, pathname, stuff)
def import_hook(self, name, caller=None, fromlist=None, level=-1):
self.msg(3, "import_hook", name, caller, fromlist, level)
@@ -461,6 +461,8 @@
fp, buf, stuff = self.find_module("__init__", m.__path__)
self.load_module(fqname, fp, buf, stuff)
self.msgout(2, "load_package ->", m)
+ if fp:
+ fp.close()
return m
def add_module(self, fqname):
diff --git a/lib-python/2.7/test/test_argparse.py
b/lib-python/2.7/test/test_argparse.py
--- a/lib-python/2.7/test/test_argparse.py
+++ b/lib-python/2.7/test/test_argparse.py
@@ -48,6 +48,9 @@
def tearDown(self):
os.chdir(self.old_dir)
+ import gc
+ # Force a collection which should close FileType() options
+ gc.collect()
for root, dirs, files in os.walk(self.temp_dir, topdown=False):
for name in files:
os.chmod(os.path.join(self.temp_dir, name), stat.S_IWRITE)
diff --git a/rpython/rtyper/lltypesystem/rclass.py
b/rpython/rtyper/lltypesystem/rclass.py
--- a/rpython/rtyper/lltypesystem/rclass.py
+++ b/rpython/rtyper/lltypesystem/rclass.py
@@ -585,7 +585,11 @@
if not i:
return rstr.null_str
instance = cast_pointer(OBJECTPTR, i)
- uid = r_uint(cast_ptr_to_int(i))
+ # Two choices: the first gives a fast answer but it can change
+ # (typically only once) during the life of the object.
+ #uid = r_uint(cast_ptr_to_int(i))
+ uid = llop.gc_id(lltype.Signed, i)
+ #
nameLen = len(instance.typeptr.name)
nameString = rstr.mallocstr(nameLen-1)
i = 0
diff --git a/rpython/rtyper/lltypesystem/rpbc.py
b/rpython/rtyper/lltypesystem/rpbc.py
--- a/rpython/rtyper/lltypesystem/rpbc.py
+++ b/rpython/rtyper/lltypesystem/rpbc.py
@@ -1,6 +1,6 @@
import types
-from rpython.annotator import description, model as annmodel
+from rpython.annotator import description
from rpython.rlib.debug import ll_assert
from rpython.rlib.unroll import unrolling_iterable
from rpython.rtyper import callparse
@@ -8,8 +8,8 @@
from rpython.rtyper.lltypesystem.lltype import (typeOf, Void, ForwardReference,
Struct, Bool, Char, Ptr, malloc, nullptr, Array, Signed)
from rpython.rtyper.rmodel import Repr, inputconst
-from rpython.rtyper.rpbc import (AbstractClassesPBCRepr,
AbstractMethodsPBCRepr,
- OverriddenFunctionPBCRepr, AbstractMultipleFrozenPBCRepr,
+from rpython.rtyper.rpbc import (
+ AbstractClassesPBCRepr, AbstractMultipleFrozenPBCRepr,
AbstractFunctionsPBCRepr, AbstractMultipleUnrelatedFrozenPBCRepr,
SingleFrozenPBCRepr, get_concrete_calltable)
from rpython.rtyper.typesystem import getfunctionptr
@@ -302,47 +302,8 @@
else:
return v
-
-class MethodsPBCRepr(AbstractMethodsPBCRepr):
- """Representation selected for a PBC of the form {func: classdef...}.
- It assumes that all the methods come from the same name in a base
- classdef."""
-
- def rtype_simple_call(self, hop):
- return self.redispatch_call(hop, call_args=False)
-
- def rtype_call_args(self, hop):
- return self.redispatch_call(hop, call_args=True)
-
- def redispatch_call(self, hop, call_args):
- r_class = self.r_im_self.rclass
- mangled_name, r_func = r_class.clsfields[self.methodname]
- assert isinstance(r_func, (FunctionsPBCRepr,
- OverriddenFunctionPBCRepr,
- SmallFunctionSetPBCRepr))
- # s_func = r_func.s_pbc -- not precise enough, see
- # test_precise_method_call_1. Build a more precise one...
- funcdescs = [desc.funcdesc for desc in hop.args_s[0].descriptions]
- s_func = annmodel.SomePBC(funcdescs, subset_of=r_func.s_pbc)
- v_im_self = hop.inputarg(self, arg=0)
- v_cls = self.r_im_self.getfield(v_im_self, '__class__', hop.llops)
- v_func = r_class.getclsfield(v_cls, self.methodname, hop.llops)
-
- hop2 = self.add_instance_arg_to_hop(hop, call_args)
- hop2.v_s_insertfirstarg(v_func, s_func) # insert 'function'
-
- if type(hop2.args_r[0]) is SmallFunctionSetPBCRepr and type(r_func) is
FunctionsPBCRepr:
- hop2.args_r[0] = FunctionsPBCRepr(self.rtyper, s_func)
- else:
- hop2.args_v[0] = hop2.llops.convertvar(hop2.args_v[0], r_func,
hop2.args_r[0])
-
- # now hop2 looks like simple_call(function, self, args...)
- return hop2.dispatch()
-
-
# ____________________________________________________________
-
class ClassesPBCRepr(AbstractClassesPBCRepr):
"""Representation selected for a PBC of class(es)."""
@@ -359,10 +320,10 @@
# "my_instantiate = typeptr.instantiate"
c_name = hop.inputconst(Void, 'instantiate')
v_instantiate = hop.genop('getfield', [vtypeptr, c_name],
- resulttype = rclass.OBJECT_VTABLE.instantiate)
+ resulttype=rclass.OBJECT_VTABLE.instantiate)
# "my_instantiate()"
v_inst = hop.genop('indirect_call', [v_instantiate, c_graphs],
- resulttype = rclass.OBJECTPTR)
+ resulttype=rclass.OBJECTPTR)
return hop.genop('cast_pointer', [v_inst], resulttype=r_instance)
def getlowleveltype(self):
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -345,17 +345,6 @@
# ____________________________________________________________
-def inputdesc(reqtype, desc):
- """Return a Constant for the given desc, of the requested type,
- which can only be a Repr.
- """
- assert isinstance(reqtype, Repr)
- value = reqtype.convert_desc(desc)
- lltype = reqtype.lowleveltype
- c = Constant(value)
- c.concretetype = lltype
- return c
-
def inputconst(reqtype, value):
"""Return a Constant with the given value, of the requested type,
which can be a Repr instance or a low-level type.
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -7,7 +7,7 @@
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem.lltype import typeOf, Void
from rpython.rtyper.rmodel import (Repr, inputconst, CanBeNull, mangle,
- inputdesc, warning, impossible_repr)
+ warning, impossible_repr)
from rpython.tool.pairtype import pair, pairtype
@@ -21,8 +21,8 @@
class __extend__(annmodel.SomePBC):
def rtyper_makerepr(self, rtyper):
- from rpython.rtyper.lltypesystem.rpbc import (FunctionsPBCRepr,
- SmallFunctionSetPBCRepr, ClassesPBCRepr, MethodsPBCRepr)
+ from rpython.rtyper.lltypesystem.rpbc import (
+ FunctionsPBCRepr, SmallFunctionSetPBCRepr, ClassesPBCRepr)
kind = self.getKind()
if issubclass(kind, description.FunctionDesc):
sample = self.any_description()
@@ -495,7 +495,9 @@
frozendesc1 = r_pbc1.frozendesc
access = frozendesc1.queryattrfamily()
if access is r_pbc2.access_set:
- return inputdesc(r_pbc2, frozendesc1)
+ value = r_pbc2.convert_desc(frozendesc1)
+ lltype = r_pbc2.lowleveltype
+ return Constant(value, lltype)
return NotImplemented
class __extend__(pairtype(AbstractMultipleUnrelatedFrozenPBCRepr,
@@ -746,7 +748,7 @@
s_shape = hop2.rtyper.annotator.bookkeeper.immutablevalue(new_shape)
hop2.v_s_insertfirstarg(c_shape, s_shape) # reinsert adjusted shape
-class AbstractMethodsPBCRepr(Repr):
+class MethodsPBCRepr(Repr):
"""Representation selected for a PBC of MethodDescs.
It assumes that all the methods come from the same name and have
been read from instances with a common base."""
@@ -806,6 +808,42 @@
_, s_shape = hop2.r_s_popfirstarg()
adjust_shape(hop2, s_shape)
return hop2
+
+ def rtype_simple_call(self, hop):
+ return self.redispatch_call(hop, call_args=False)
+
+ def rtype_call_args(self, hop):
+ return self.redispatch_call(hop, call_args=True)
+
+ def redispatch_call(self, hop, call_args):
+ from rpython.rtyper.lltypesystem.rpbc import (
+ FunctionsPBCRepr, SmallFunctionSetPBCRepr)
+ r_class = self.r_im_self.rclass
+ mangled_name, r_func = r_class.clsfields[self.methodname]
+ assert isinstance(r_func, (FunctionsPBCRepr,
+ OverriddenFunctionPBCRepr,
+ SmallFunctionSetPBCRepr))
+ # s_func = r_func.s_pbc -- not precise enough, see
+ # test_precise_method_call_1. Build a more precise one...
+ funcdescs = [desc.funcdesc for desc in hop.args_s[0].descriptions]
+ s_func = annmodel.SomePBC(funcdescs, subset_of=r_func.s_pbc)
+ v_im_self = hop.inputarg(self, arg=0)
+ v_cls = self.r_im_self.getfield(v_im_self, '__class__', hop.llops)
+ v_func = r_class.getclsfield(v_cls, self.methodname, hop.llops)
+
+ hop2 = self.add_instance_arg_to_hop(hop, call_args)
+ hop2.v_s_insertfirstarg(v_func, s_func) # insert 'function'
+
+ if (type(hop2.args_r[0]) is SmallFunctionSetPBCRepr and
+ type(r_func) is FunctionsPBCRepr):
+ hop2.args_r[0] = FunctionsPBCRepr(self.rtyper, s_func)
+ else:
+ hop2.args_v[0] = hop2.llops.convertvar(
+ hop2.args_v[0], r_func, hop2.args_r[0])
+
+ # now hop2 looks like simple_call(function, self, args...)
+ return hop2.dispatch()
+
# ____________________________________________________________
def samesig(funcs):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit