Author: Armin Rigo <[email protected]>
Branch: cffi-handle-lifetime
Changeset: r80124:75e8da1995d8
Date: 2015-10-12 11:28 +0200
http://bitbucket.org/pypy/pypy/changeset/75e8da1995d8/
Log: Simplify again the code by moving the special logic into its own
function
diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -172,6 +172,9 @@
def can_move(self, addr):
return False
+ def malloc_fixedsize_nonmovable(self, typeid):
+ raise MemoryError
+
def pin(self, addr):
return False
diff --git a/rpython/memory/gc/generation.py b/rpython/memory/gc/generation.py
--- a/rpython/memory/gc/generation.py
+++ b/rpython/memory/gc/generation.py
@@ -170,10 +170,7 @@
def malloc_fixedsize_clear(self, typeid, size,
has_finalizer=False,
is_finalizer_light=False,
- contains_weakptr=False,
- nonmovable=False):
- if nonmovable:
- raise MemoryError
+ contains_weakptr=False):
if (has_finalizer or
(raw_malloc_usage(size) > self.lb_young_fixedsize and
raw_malloc_usage(size) > self.largest_young_fixedsize)):
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -587,8 +587,7 @@
def malloc_fixedsize(self, typeid, size,
needs_finalizer=False,
is_finalizer_light=False,
- contains_weakptr=False,
- nonmovable=False):
+ contains_weakptr=False):
size_gc_header = self.gcheaderbuilder.size_gc_header
totalsize = size_gc_header + size
rawtotalsize = raw_malloc_usage(totalsize)
@@ -604,7 +603,7 @@
# If totalsize is greater than nonlarge_max (which should never be
# the case in practice), ask for a rawmalloc. The following check
# should be constant-folded.
- elif rawtotalsize > self.nonlarge_max or nonmovable:
+ elif rawtotalsize > self.nonlarge_max:
ll_assert(not contains_weakptr,
"'contains_weakptr' specified for a large object")
obj = self.external_malloc(typeid, 0, alloc_young=True)
@@ -693,6 +692,11 @@
return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
+ def malloc_fixedsize_nonmovable(self, typeid):
+ obj = self.external_malloc(typeid, 0, alloc_young=True)
+ return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
+
+
def collect(self, gen=2):
"""Do a minor (gen=0), start a major (gen=1), or do a full
major (gen>=2) collection."""
diff --git a/rpython/memory/gc/minimark.py b/rpython/memory/gc/minimark.py
--- a/rpython/memory/gc/minimark.py
+++ b/rpython/memory/gc/minimark.py
@@ -509,8 +509,7 @@
def malloc_fixedsize_clear(self, typeid, size,
needs_finalizer=False,
is_finalizer_light=False,
- contains_weakptr=False,
- nonmovable=False):
+ contains_weakptr=False):
size_gc_header = self.gcheaderbuilder.size_gc_header
totalsize = size_gc_header + size
rawtotalsize = raw_malloc_usage(totalsize)
@@ -526,7 +525,7 @@
# If totalsize is greater than nonlarge_max (which should never be
# the case in practice), ask for a rawmalloc. The following check
# should be constant-folded.
- elif rawtotalsize > self.nonlarge_max or nonmovable:
+ elif rawtotalsize > self.nonlarge_max:
ll_assert(not contains_weakptr,
"'contains_weakptr' specified for a large object")
obj = self.external_malloc(typeid, 0, alloc_young=True)
@@ -615,6 +614,11 @@
return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
+ def malloc_fixedsize_nonmovable(self, typeid):
+ obj = self.external_malloc(typeid, 0, alloc_young=True)
+ return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
+
+
def collect(self, gen=1):
"""Do a minor (gen=0) or major (gen>0) collection."""
self.minor_collection()
diff --git a/rpython/memory/gc/semispace.py b/rpython/memory/gc/semispace.py
--- a/rpython/memory/gc/semispace.py
+++ b/rpython/memory/gc/semispace.py
@@ -98,10 +98,7 @@
def malloc_fixedsize_clear(self, typeid16, size,
has_finalizer=False,
is_finalizer_light=False,
- contains_weakptr=False,
- nonmovable=False):
- if nonmovable:
- raise MemoryError
+ contains_weakptr=False):
size_gc_header = self.gcheaderbuilder.size_gc_header
totalsize = size_gc_header + size
result = self.free
diff --git a/rpython/memory/gctransform/framework.py
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -305,7 +305,6 @@
annmodel.SomeInteger(nonneg=True),
annmodel.SomeBool(),
annmodel.SomeBool(),
- annmodel.SomeBool(),
annmodel.SomeBool()], s_gcref,
inline = False)
self.malloc_varsize_ptr = getfn(
@@ -321,7 +320,6 @@
annmodel.SomeInteger(nonneg=True),
annmodel.SomeBool(),
annmodel.SomeBool(),
- annmodel.SomeBool(),
annmodel.SomeBool()], s_gcref,
inline = False)
self.malloc_varsize_ptr = getfn(
@@ -365,7 +363,7 @@
raise NotImplementedError("GC needs write barrier, but does not
provide writebarrier_before_copy functionality")
# in some GCs we can inline the common case of
- # malloc_fixedsize(typeid, size, False, False, False, False)
+ # malloc_fixedsize(typeid, size, False, False, False)
if getattr(GCClass, 'inline_simple_malloc', False):
# make a copy of this function so that it gets annotated
# independently and the constants are folded inside
@@ -384,7 +382,7 @@
malloc_fast,
[s_gc, s_typeid16,
annmodel.SomeInteger(nonneg=True),
- s_False, s_False, s_False, s_False], s_gcref,
+ s_False, s_False, s_False], s_gcref,
inline = True)
else:
self.malloc_fast_ptr = None
@@ -533,6 +531,9 @@
getfn(func,
[SomeAddress()],
annmodel.s_None)
+ self.malloc_nonmovable_ptr = getfn(GCClass.malloc_fixedsize_nonmovable,
+ [s_gc, s_typeid16],
+ s_gcref)
def create_custom_trace_funcs(self, gc, rtyper):
custom_trace_funcs = tuple(rtyper.custom_trace_funcs)
@@ -759,21 +760,22 @@
c_has_light_finalizer = rmodel.inputconst(lltype.Bool,
has_light_finalizer)
- if not op.opname.endswith('_varsize') and not flags.get('varsize'):
+ if flags.get('nonmovable'):
+ assert op.opname == 'malloc'
+ assert not flags.get('varsize')
+ malloc_ptr = self.malloc_nonmovable_ptr
+ args = [self.c_const_gc, c_type_id]
+ elif not op.opname.endswith('_varsize') and not flags.get('varsize'):
zero = flags.get('zero', False)
- c_nonmovable = rmodel.inputconst(lltype.Bool,
- flags.get('nonmovable', False))
if (self.malloc_fast_ptr is not None and
not c_has_finalizer.value and
- not c_nonmovable.value and
(self.malloc_fast_is_clearing or not zero)):
malloc_ptr = self.malloc_fast_ptr
else:
malloc_ptr = self.malloc_fixedsize_ptr
args = [self.c_const_gc, c_type_id, c_size,
c_has_finalizer, c_has_light_finalizer,
- rmodel.inputconst(lltype.Bool, False),
- c_nonmovable]
+ rmodel.inputconst(lltype.Bool, False)]
else:
assert not c_has_finalizer.value
info_varsize = self.layoutbuilder.get_info_varsize(type_id)
@@ -914,12 +916,11 @@
[v_typeid, v_size,
v_has_finalizer, v_has_light_finalizer, v_contains_weakptr] = op.args
livevars = self.push_roots(hop)
- c_nonmovable = rmodel.inputconst(lltype.Bool, False)
hop.genop("direct_call",
[self.malloc_fixedsize_ptr, self.c_const_gc,
v_typeid, v_size,
v_has_finalizer, v_has_light_finalizer,
- v_contains_weakptr, c_nonmovable],
+ v_contains_weakptr],
resultvar=op.result)
self.pop_roots(hop, livevars)
@@ -1025,9 +1026,8 @@
malloc_ptr = self.malloc_fixedsize_ptr
c_false = rmodel.inputconst(lltype.Bool, False)
c_has_weakptr = rmodel.inputconst(lltype.Bool, True)
- c_nonmovable = rmodel.inputconst(lltype.Bool, False)
args = [self.c_const_gc, c_type_id, c_size,
- c_false, c_false, c_has_weakptr, c_nonmovable]
+ c_false, c_false, c_has_weakptr]
# push and pop the current live variables *including* the argument
# to the weakref_create operation, which must be kept alive and
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit