Author: Armin Rigo <ar...@tunes.org> Branch: stmgc-c8-hashtable Changeset: r76356:8dead8bff1d7 Date: 2015-03-12 17:49 +0100 http://bitbucket.org/pypy/pypy/changeset/8dead8bff1d7/
Log: Re-introduce this part from stmgc-c7 diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py --- a/rpython/rlib/rstm.py +++ b/rpython/rlib/rstm.py @@ -256,8 +256,7 @@ 'freelist': _ll_hashtable_freelist, 'lookup': _ll_hashtable_lookup, 'writeobj': _ll_hashtable_writeobj}) -# NULL_HASHTABLE = lltype.nullptr(_HASHTABLE_OBJ) -NULL_HASHTABLE = None +NULL_HASHTABLE = lltype.nullptr(_HASHTABLE_OBJ) def _ll_hashtable_trace(gc, obj, callback, arg): from rpython.memory.gctransform.stmframework import get_visit_function @@ -277,67 +276,23 @@ def create_hashtable(): if not we_are_translated(): return HashtableForTest() # for tests - return HashtableEmulation() - # rgc.register_custom_light_finalizer(_HASHTABLE_OBJ, lambda_hashtable_finlz) - # rgc.register_custom_trace_hook(_HASHTABLE_OBJ, lambda_hashtable_trace) - # # Pass a null pointer to _STM_HASHTABLE_ENTRY to stm_hashtable_create(). - # # Make sure we see a malloc() of it, so that its typeid is correctly - # # initialized. It can be done in a NonConstant(False) path so that - # # the C compiler will actually drop it. - # if _false: - # p = lltype.malloc(_STM_HASHTABLE_ENTRY) - # else: - # p = lltype.nullptr(_STM_HASHTABLE_ENTRY) - # h = lltype.malloc(_HASHTABLE_OBJ) - # h.ll_raw_hashtable = lltype.nullptr(_STM_HASHTABLE_P.TO) - # h.ll_raw_hashtable = llop.stm_hashtable_create(_STM_HASHTABLE_P, p) - # return h + rgc.register_custom_light_finalizer(_HASHTABLE_OBJ, lambda_hashtable_finlz) + rgc.register_custom_trace_hook(_HASHTABLE_OBJ, lambda_hashtable_trace) + # Pass a null pointer to _STM_HASHTABLE_ENTRY to stm_hashtable_create(). + # Make sure we see a malloc() of it, so that its typeid is correctly + # initialized. It can be done in a NonConstant(False) path so that + # the C compiler will actually drop it. + if _false: + p = lltype.malloc(_STM_HASHTABLE_ENTRY) + else: + p = lltype.nullptr(_STM_HASHTABLE_ENTRY) + h = lltype.malloc(_HASHTABLE_OBJ) + h.ll_raw_hashtable = lltype.nullptr(_STM_HASHTABLE_P.TO) + h.ll_raw_hashtable = llop.stm_hashtable_create(_STM_HASHTABLE_P, p) + return h NULL_GCREF = lltype.nullptr(llmemory.GCREF.TO) -class HashtableEmulation(object): - def __init__(self): - self._content = {} # dict {integer: GCREF} - - def get(self, key): - return self._content.get(key, NULL_GCREF) - - def set(self, key, value): - if value: - self._content[key] = value - else: - try: - del self._content[key] - except KeyError: - pass - - def len(self): - return len(self._content) - - def list(self): - items = [] - for key in self._content.keys(): - items.append(self.lookup(key)) - count = len(items) - return items, count - - def freelist(self, array): - pass - - def lookup(self, key): - return EntryObjectEmulation(self, key) - - def writeobj(self, entry, nvalue): - self.set(entry.key, nvalue) - -class EntryObjectEmulation(object): - def __init__(self, hashtable, key): - self.hashtable = hashtable - self.key = key - self.index = r_uint(key) - self.object = hashtable.get(key) - - class HashtableForTest(object): def __init__(self): self._content = {} # dict {integer: GCREF} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit