[pypy-commit] pypy kill-someobject: Progress towards killing PyObject support

alex_gaynor noreply at buildbot.pypy.org
Sun Oct 7 18:08:52 CEST 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: kill-someobject
Changeset: r57825:c7d5af174015
Date: 2012-10-07 18:08 +0200
http://bitbucket.org/pypy/pypy/changeset/c7d5af174015/

Log:	Progress towards killing PyObject support

diff --git a/pypy/rlib/rstring.py b/pypy/rlib/rstring.py
--- a/pypy/rlib/rstring.py
+++ b/pypy/rlib/rstring.py
@@ -199,25 +199,25 @@
 class __extend__(pairtype(SomeStringBuilder, SomePBC)):
     def union((sb, p)):
         assert p.const is None
-        return SomeStringBuilder(can_be_None=True)
+        return SomeStringBuilder()
 
 
 class __extend__(pairtype(SomePBC, SomeStringBuilder)):
     def union((p, sb)):
         assert p.const is None
-        return SomeStringBuilder(can_be_None=True)
+        return SomeStringBuilder()
 
 
 class __extend__(pairtype(SomeUnicodeBuilder, SomePBC)):
     def union((sb, p)):
         assert p.const is None
-        return SomeUnicodeBuilder(can_be_None=True)
+        return SomeUnicodeBuilder()
 
 
 class __extend__(pairtype(SomePBC, SomeUnicodeBuilder)):
     def union((p, sb)):
         assert p.const is None
-        return SomeUnicodeBuilder(can_be_None=True)
+        return SomeUnicodeBuilder()
 
 #___________________________________________________________________
 # Support functions for SomeString.no_nul
diff --git a/pypy/translator/c/database.py b/pypy/translator/c/database.py
--- a/pypy/translator/c/database.py
+++ b/pypy/translator/c/database.py
@@ -1,7 +1,7 @@
 
-from pypy.rpython.lltypesystem.lltype import (
-    Primitive, Ptr, typeOf, RuntimeTypeInfo, Struct, Array, FuncType, PyObject,
-    Void, ContainerType, OpaqueType, FixedSizeArray, _uninitialized, Typedef)
+from pypy.rpython.lltypesystem.lltype import (Primitive, Ptr, typeOf,
+    RuntimeTypeInfo, Struct, Array, FuncType, Void, ContainerType, OpaqueType,
+    FixedSizeArray, Typedef)
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rpython.lltypesystem.llmemory import WeakRef, _WeakRefType, GCREF
 from pypy.rpython.lltypesystem.rffi import CConstant
@@ -14,7 +14,6 @@
 from pypy.translator.c.support import cdecl, CNameManager
 from pypy.translator.c.support import log, barebonearray
 from pypy.translator.c.extfunc import do_the_getting
-from pypy import conftest
 from pypy.translator.c import gc
 from pypy.tool.identity_dict import identity_dict
 
@@ -120,8 +119,6 @@
             if who_asks is not None:
                 who_asks.dependencies[node] = True
             return node.gettype()
-        elif T == PyObject:
-            return 'PyObject @'
         elif isinstance(T, FuncType):
             resulttype = self.gettype(T.RESULT)
             argtypes = []
@@ -363,11 +360,8 @@
                 yield node
 
     def get_lltype_of_exception_value(self):
-        if self.translator is not None and self.translator.rtyper is not None:
-            exceptiondata = self.translator.rtyper.getexceptiondata()
-            return exceptiondata.lltype_of_exception_value
-        else:
-            return Ptr(PyObject)
+        exceptiondata = self.translator.rtyper.getexceptiondata()
+        return exceptiondata.lltype_of_exception_value
 
     def getstructdeflist(self):
         # return the StructDefNodes sorted according to dependencies
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -3,14 +3,11 @@
 from pypy.translator.c.support import cdecl
 from pypy.translator.c.support import llvalue_from_constant, gen_assignments
 from pypy.translator.c.support import c_string_constant, barebonearray
-from pypy.objspace.flow.model import Variable, Constant, Block
+from pypy.objspace.flow.model import Variable, Constant
 from pypy.objspace.flow.model import c_last_exception, copygraph
-from pypy.rpython.lltypesystem.lltype import Ptr, PyObject, Void, Bool, Signed
-from pypy.rpython.lltypesystem.lltype import Unsigned, SignedLongLong, Float
-from pypy.rpython.lltypesystem.lltype import UnsignedLongLong, Char, UniChar
-from pypy.rpython.lltypesystem.lltype import pyobjectptr, ContainerType
-from pypy.rpython.lltypesystem.lltype import Struct, Array, FixedSizeArray
-from pypy.rpython.lltypesystem.lltype import ForwardReference, FuncType
+from pypy.rpython.lltypesystem.lltype import (Ptr, Void, Bool, Signed, Unsigned,
+    SignedLongLong, Float, UnsignedLongLong, Char, UniChar, ContainerType,
+    Array, FixedSizeArray, ForwardReference, FuncType)
 from pypy.rpython.lltypesystem.rffi import INT
 from pypy.rpython.lltypesystem.llmemory import Address
 from pypy.translator.backendopt.ssa import SSI_to_SSA
@@ -18,7 +15,6 @@
 from pypy.tool.identity_dict import identity_dict
 
 
-PyObjPtr = Ptr(PyObject)
 LOCALVAR = 'l_%s'
 
 KEEP_INLINED_GRAPHS = False
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -2,9 +2,8 @@
 import py
 import sys, os
 from pypy.rlib import exports
-from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.typesystem import getfunctionptr
-from pypy.tool import isolate, runsubprocess
+from pypy.tool import runsubprocess
 from pypy.tool.nullpath import NullPyPathLocal
 from pypy.tool.udir import udir
 from pypy.translator.c import gc
@@ -12,7 +11,6 @@
 from pypy.translator.c.extfunc import pre_include_code_lines
 from pypy.translator.c.support import log
 from pypy.translator.gensupp import uniquemodulename, NameManager
-from pypy.translator.llsupport.wrapper import new_wrapper
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 
 _CYGWIN = sys.platform == 'cygwin'
@@ -317,118 +315,6 @@
             pass
 
 
-class CExtModuleBuilder(CBuilder):
-    standalone = False
-    cpython_extension = True
-    _module = None
-    _wrapper = None
-
-    def get_eci(self):
-        from distutils import sysconfig
-        python_inc = sysconfig.get_python_inc()
-        eci = ExternalCompilationInfo(
-            include_dirs=[python_inc],
-            includes=["Python.h",
-                      ],
-            )
-        return eci.merge(CBuilder.get_eci(self))
-
-    def getentrypointptr(self): # xxx
-        if self._wrapper is None:
-            self._wrapper = new_wrapper(self.entrypoint, self.translator)
-        return self._wrapper
-
-    def compile(self):
-        assert self.c_source_filename 
-        assert not self._compiled
-        export_symbols = [self.db.get(self.getentrypointptr()),
-                          'RPython_StartupCode',
-                          ]
-        if self.config.translation.countmallocs:
-            export_symbols.append('malloc_counters')
-        extsymeci = ExternalCompilationInfo(export_symbols=export_symbols)
-        self.eci = self.eci.merge(extsymeci)
-
-        if sys.platform == 'win32':
-            self.eci = self.eci.merge(ExternalCompilationInfo(
-                library_dirs = [py.path.local(sys.exec_prefix).join('LIBs'),
-                                py.path.local(sys.executable).dirpath(),
-                                ],
-                ))
-
-
-        files = [self.c_source_filename] + self.extrafiles
-        self.translator.platform.compile(files, self.eci, standalone=False)
-        self._compiled = True
-
-    def _make_wrapper_module(self):
-        fname = 'wrap_' + self.c_source_filename.purebasename
-        modfile = self.c_source_filename.new(purebasename=fname, ext=".py")
-
-        entrypoint_ptr = self.getentrypointptr()
-        wrapped_entrypoint_c_name = self.db.get(entrypoint_ptr)
-        
-        CODE = """
-import ctypes
-
-_lib = ctypes.PyDLL(r"%(so_name)s")
-
-_entry_point = getattr(_lib, "%(c_entrypoint_name)s")
-_entry_point.restype = ctypes.py_object
-_entry_point.argtypes = %(nargs)d*(ctypes.py_object,)
-
-def entrypoint(*args):
-    return _entry_point(*args)
-
-try:
-    _malloc_counters = _lib.malloc_counters
-except AttributeError:
-    pass
-else:
-    _malloc_counters.restype = ctypes.py_object
-    _malloc_counters.argtypes = 2*(ctypes.py_object,)
-
-    def malloc_counters():
-        return _malloc_counters(None, None)
-
-_rpython_startup = _lib.RPython_StartupCode
-_rpython_startup()
-""" % {'so_name': self.c_source_filename.new(ext=self.translator.platform.so_ext),
-       'c_entrypoint_name': wrapped_entrypoint_c_name,
-       'nargs': len(lltype.typeOf(entrypoint_ptr).TO.ARGS)}
-        modfile.write(CODE)
-        self._module_path = modfile
-       
-    def _import_module(self, isolated=False):
-        if self._module is not None:
-            return self._module
-        assert self._compiled
-        assert not self._module
-        self._make_wrapper_module()
-        if not isolated:
-            mod = ModuleWithCleanup(self._module_path.pyimport())
-        else:
-            mod = isolate.Isolate((str(self._module_path.dirpath()),
-                                   self._module_path.purebasename))
-        self._module = mod
-        return mod
-        
-    def get_entry_point(self, isolated=False):
-        self._import_module(isolated=isolated)
-        return getattr(self._module, "entrypoint")
-
-    def get_malloc_counters(self, isolated=False):
-        self._import_module(isolated=isolated)
-        return self._module.malloc_counters
-                       
-    def cleanup(self):
-        #assert self._module
-        if isinstance(self._module, isolate.Isolate):
-            isolate.close_isolate(self._module)
-
-    def gen_makefile(self, targetdir, exe_name=None):
-        pass
-
 class CStandaloneBuilder(CBuilder):
     standalone = True
     split = True
diff --git a/pypy/translator/c/node.py b/pypy/translator/c/node.py
--- a/pypy/translator/c/node.py
+++ b/pypy/translator/c/node.py
@@ -1,8 +1,7 @@
-from pypy.rpython.lltypesystem.lltype import \
-     Struct, Array, FixedSizeArray, FuncType, PyObjectType, typeOf, \
-     GcStruct, GcArray, RttiStruct, ContainerType, \
-     parentlink, Ptr, PyObject, Void, OpaqueType, Float, \
-     RuntimeTypeInfo, getRuntimeTypeInfo, Char, _subarray
+from pypy.rpython.lltypesystem.lltype import (Struct, Array, FixedSizeArray,
+    FuncType, typeOf, GcStruct, GcArray, RttiStruct, ContainerType, parentlink,
+    Ptr, Void, OpaqueType, Float, RuntimeTypeInfo, getRuntimeTypeInfo, Char,
+    _subarray)
 from pypy.rpython.lltypesystem import llmemory, llgroup
 from pypy.translator.c.funcgen import FunctionCodeGenerator
 from pypy.translator.c.external import CExternalFunctionCodeGenerator
@@ -790,12 +789,7 @@
         return lines
     else:
         comma = ','
-        if typeOf(value) == Ptr(PyObject) and value:
-            # cannot just write 'gxxx' as a constant in a structure :-(
-            node = db.getcontainernode(value._obj)
-            expr = 'NULL /*%s*/' % node.name
-            node.where_to_copy_me.append('&%s' % access_expr)
-        elif typeOf(value) == Float and not isfinite(value):
+        if typeOf(value) == Float and not isfinite(value):
             db.late_initializations.append(('%s' % access_expr, db.get(value)))
             expr = '0.0 /* patched later by %sinfinity */' % (
                 '-+'[value > 0])
@@ -1005,54 +999,6 @@
     raise Exception("don't know about %r" % (T,))
 
 
-class PyObjectNode(ContainerNode):
-    nodekind = 'pyobj'
-    globalcontainer = True
-    typename = 'PyObject @'
-    implementationtypename = 'PyObject *@'
-    _funccodegen_owner = None
-
-    def __init__(self, db, T, obj):
-        # obj is a _pyobject here; obj.value is the underlying CPython object
-        self.db = db
-        self.T = T
-        self.obj = obj
-        value = obj.value
-        self.name = self._python_c_name(value)
-        self.exported_name = self.name
-        # a list of expressions giving places where this constant PyObject
-        # must be copied.  Normally just in the global variable of the same
-        # name, but see also StructNode.initializationexpr()  :-(
-        self.where_to_copy_me = []
-
-    def getptrname(self):
-        return self.name
-
-    def _python_c_name(self, value):
-        # just some minimal cases: None and builtin exceptions
-        if value is None:
-            return 'Py_None'
-        import types, py
-        if isinstance(value, (type, types.ClassType)):
-            if (issubclass(value, BaseException) and
-                value.__module__ == 'exceptions'):
-                return 'PyExc_' + value.__name__
-            if issubclass(value, AssertionError):
-                return 'PyExc_AssertionError'
-            if value is _StackOverflow:
-                return 'PyExc_RuntimeError'
-        raise Exception("don't know how to simply render py object: %r" %
-                        (value, ))
-    
-    def forward_declaration(self):
-        return []
-
-    def enum_dependencies(self):
-        return []
-
-    def implementation(self):
-        return []
-
 def weakrefnode_factory(db, T, obj):
     assert isinstance(obj, llmemory._wref)
     ptarget = obj._dereference()
@@ -1131,7 +1077,6 @@
     FixedSizeArray: FixedSizeArrayNode,
     FuncType:     FuncNode,
     OpaqueType:   opaquenode_factory,
-    PyObjectType: PyObjectNode,
     llmemory._WeakRefType: weakrefnode_factory,
     llgroup.GroupType: GroupNode,
-    }
+}
diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py
--- a/pypy/translator/driver.py
+++ b/pypy/translator/driver.py
@@ -172,19 +172,14 @@
     def _maybe_skip(self):
         maybe_skip = []
         if self._disabled:
-             for goal in  self.backend_select_goals(self._disabled):
+             for goal in self.backend_select_goals(self._disabled):
                  maybe_skip.extend(self._depending_on_closure(goal))
         return dict.fromkeys(maybe_skip).keys()
 
-
     def setup(self, entry_point, inputtypes, policy=None, extra={}, empty_translator=None):
-        standalone = inputtypes is None
-        self.standalone = standalone
-
-        if standalone:
-            # the 'argv' parameter
-            inputtypes = [s_list_of_strings]
-        self.inputtypes = inputtypes
+        assert inputtypes is None
+        # the 'argv' parameter
+        self.inputtypes = [s_list_of_strings]
 
         if policy is None:
             policy = annpolicy.AnnotatorPolicy()
@@ -322,7 +317,7 @@
             s = None
 
         self.sanity_check_annotation()
-        if self.entry_point and self.standalone and s.knowntype != int:
+        if self.entry_point and s.knowntype != int:
             raise Exception("stand-alone program entry point must return an "
                             "int (and not, e.g., None or always raise an "
                             "exception).")
@@ -469,15 +464,10 @@
 
         if self.libdef is not None:
             cbuilder = self.libdef.getcbuilder(self.translator, self.config)
-            self.standalone = False
             standalone = False
         else:
-            standalone = self.standalone
-
-            if standalone:
-                from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
-            else:
-                from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
+            from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
+            standalone = True
             cbuilder = CBuilder(self.translator, self.entry_point,
                                 config=self.config,
                                 secondary_entrypoints=self.secondary_entrypoints)
@@ -551,17 +541,13 @@
         """
         cbuilder = self.cbuilder
         kwds = {}
-        if self.standalone and self.exe_name is not None:
+        if self.exe_name is not None:
             kwds['exe_name'] = self.compute_exe_name().basename
         cbuilder.compile(**kwds)
 
-        if self.standalone:
-            self.c_entryp = cbuilder.executable_name
-            self.create_exe()
-        else:
-            isolated = self._backend_extra_options.get('c_isolated', False)
-            self.c_entryp = cbuilder.get_entry_point(isolated=isolated)
-    #
+        self.c_entryp = cbuilder.executable_name
+        self.create_exe()
+
     task_compile_c = taskdef(task_compile_c, ['source_c'], "Compiling c source")
 
     def task_llinterpret_lltype(self):
@@ -611,7 +597,7 @@
             unpatch_os(self.old_cli_defs)
         
         self.log.info("Compiled %s" % filename)
-        if self.standalone and self.exe_name:
+        if self.exe_name:
             self.copy_cli_exe()
     task_compile_cli = taskdef(task_compile_cli, ['source_cli'],
                               'Compiling CLI source')
@@ -678,8 +664,7 @@
         from pypy.translator.jvm.node import EntryPoint
 
         entry_point_graph = self.translator.graphs[0]
-        is_func = not self.standalone
-        entry_point = EntryPoint(entry_point_graph, is_func, is_func)
+        entry_point = EntryPoint(entry_point_graph, False, False)
         self.gen = GenJvm(udir, self.translator, entry_point)
         self.jvmsource = self.gen.generate_source()
         self.log.info("Wrote JVM code")
@@ -695,7 +680,7 @@
         if hasattr(self, 'old_cli_defs'):
             unpatch_os(self.old_cli_defs)
         self.log.info("Compiled JVM source")
-        if self.standalone and self.exe_name:
+        if self.exe_name:
             self.copy_jvm_jar()
     task_compile_jvm = taskdef(task_compile_jvm, ['source_jvm'],
                               'Compiling JVM source')


More information about the pypy-commit mailing list