aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-01-28 11:46:28 +0200
committerMatti Picus <matti.picus@gmail.com>2021-01-28 11:46:28 +0200
commit58a882e1395524e470cf87c5a4c5acdaeac8e914 (patch)
tree0059ff644da3a5b163ae68d85e5a4494a4ab6067
parentre-apply backed out changes from rpython-never-allocate (diff)
parentunify 'hints' and '_hints' to '_hints' (diff)
downloadpypy-58a882e1395524e470cf87c5a4c5acdaeac8e914.tar.gz
pypy-58a882e1395524e470cf87c5a4c5acdaeac8e914.tar.bz2
pypy-58a882e1395524e470cf87c5a4c5acdaeac8e914.zip
remerge fixes from rpython-never-allocate
-rw-r--r--pypy/doc/whatsnew-head.rst6
-rw-r--r--rpython/rtyper/lltypesystem/ll2ctypes.py6
-rw-r--r--rpython/rtyper/lltypesystem/lltype.py2
-rw-r--r--rpython/translator/c/database.py14
-rw-r--r--rpython/translator/c/node.py2
5 files changed, 18 insertions, 12 deletions
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
index 436630784e..b47b83778a 100644
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -54,3 +54,9 @@ Backport fixes to winreg adding reflection and fix for passing None (bpo
Change parameter type of ``PyModule_New`` to ``const char*``, add
``PyModule_Check`` and ``PyModule_CheckExact``
+
+.. branch: rpython-never-allocate
+
+Introduce a ``@never_allocate`` class decorator, which ensure that a certain
+RPython class is never actually instantiated at runtime. Useful to ensure that
+e.g. it's always constant-folded away
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
index d9fdd322d7..efa6f11a2f 100644
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -374,9 +374,9 @@ def build_new_ctypes_type(T, delayed_builders):
elif isinstance(T, lltype.OpaqueType):
if T is lltype.RuntimeTypeInfo:
return ctypes.c_char * 2
- if T.hints.get('external', None) != 'C':
+ if T._hints.get('external', None) != 'C':
raise TypeError("%s is not external" % T)
- return ctypes.c_char * T.hints['getsize']()
+ return ctypes.c_char * T._hints['getsize']()
else:
_setup_ctypes_cache()
if T in _ctypes_cache:
@@ -934,7 +934,7 @@ def lltype2ctypes(llobj, normalize=True):
convert_array(container)
elif isinstance(T.TO, lltype.OpaqueType):
if T.TO != lltype.RuntimeTypeInfo:
- cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']())
+ cbuf = ctypes.create_string_buffer(T.TO._hints['getsize']())
else:
cbuf = ctypes.create_string_buffer("\x00")
cbuf = ctypes.cast(cbuf, ctypes.c_void_p)
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
index eaa51f1edc..c75fd90e7a 100644
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -584,7 +584,7 @@ class OpaqueType(ContainerType):
"""
self.tag = tag
self.__name__ = tag
- self.hints = frozendict(hints)
+ self._hints = frozendict(hints)
def __str__(self):
return "%s (opaque)" % self.tag
diff --git a/rpython/translator/c/database.py b/rpython/translator/c/database.py
index f21f661ba3..bf0ced6418 100644
--- a/rpython/translator/c/database.py
+++ b/rpython/translator/c/database.py
@@ -84,7 +84,7 @@ class LowLevelDatabase(object):
node = BareBoneArrayDefNode(self, T, varlength)
else:
node = ArrayDefNode(self, T, varlength)
- elif isinstance(T, OpaqueType) and T.hints.get("render_structure", False):
+ elif isinstance(T, OpaqueType) and T._hints.get("render_structure", False):
node = ExtTypeOpaqueDefNode(self, T)
elif T == WeakRef:
REALT = self.gcpolicy.get_real_weakref_type()
@@ -102,8 +102,8 @@ class LowLevelDatabase(object):
return '%s @' % T.c_name
elif isinstance(T, Ptr):
if (isinstance(T.TO, OpaqueType) and
- T.TO.hints.get('c_pointer_typedef') is not None):
- return '%s @' % T.TO.hints['c_pointer_typedef']
+ T.TO._hints.get('c_pointer_typedef') is not None):
+ return '%s @' % T.TO._hints['c_pointer_typedef']
try:
node = self.gettypedefnode(T.TO)
except NoCorrespondingNode:
@@ -134,13 +134,13 @@ class LowLevelDatabase(object):
elif isinstance(T, OpaqueType):
if T == RuntimeTypeInfo:
return self.gcpolicy.rtti_type()
- elif T.hints.get("render_structure", False):
+ elif T._hints.get("render_structure", False):
node = self.gettypedefnode(T, varlength=varlength)
if who_asks is not None:
who_asks.dependencies.add(node)
return 'struct %s @' % node.name
- elif T.hints.get('external', None) == 'C':
- return '%s @' % T.hints['c_name']
+ elif T._hints.get('external', None) == 'C':
+ return '%s @' % T._hints['c_name']
else:
#raise Exception("don't know about opaque type %r" % (T,))
return 'struct %s @' % (
@@ -182,7 +182,7 @@ class LowLevelDatabase(object):
return PrimitiveName[T](obj, self)
elif isinstance(T, Ptr):
if (isinstance(T.TO, OpaqueType) and
- T.TO.hints.get('c_pointer_typedef') is not None):
+ T.TO._hints.get('c_pointer_typedef') is not None):
if obj._obj is not None:
value = rffi.cast(rffi.SSIZE_T, obj)
return '((%s) %s)' % (cdecl(self.gettype(T), ''),
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
index 91458b643c..7898be2bdb 100644
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -947,7 +947,7 @@ class ExtType_OpaqueNode(ContainerNode):
def opaquenode_factory(db, T, obj):
if T == RuntimeTypeInfo:
return db.gcpolicy.rtti_node_factory()(db, T, obj)
- if T.hints.get("render_structure", False):
+ if T._hints.get("render_structure", False):
return ExtType_OpaqueNode(db, T, obj)
raise Exception("don't know about %r" % (T,))