[pypy-commit] stmgc default: Generalize the tuple's stmcb_size()

arigo noreply at buildbot.pypy.org
Tue Jun 25 17:12:44 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r282:d1f22e7b8690
Date: 2013-06-25 17:12 +0200
http://bitbucket.org/pypy/stmgc/changeset/d1f22e7b8690/

Log:	Generalize the tuple's stmcb_size()

diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -23,6 +23,7 @@
 
 
 typedef void(*trace_fn)(DuObject *, void visit(gcptr *));
+typedef size_t(*bytesize_fn)(DuObject *);
 typedef void(*print_fn)(DuObject *);
 typedef DuObject *(*eval_fn)(DuObject *, DuObject *);
 typedef int(*len_fn)(DuObject *);
@@ -36,6 +37,7 @@
     eval_fn dt_eval;
     len_fn dt_is_true;
     len_fn dt_length;
+    bytesize_fn dt_bytesize;
 } DuType;
 
 /* keep this list in sync with object.c's Du_Types[] */
@@ -98,7 +100,6 @@
 DuObject *DuList_GetItem(DuObject *list, int index);
 void DuList_SetItem(DuObject *list, int index, DuObject *newobj);
 DuObject *DuList_Pop(DuObject *list, int index);
-size_t _DuTuple_ByteSize(DuObject *tuple);
 
 DuObject *DuContainer_New(DuObject *obj);
 DuObject *DuContainer_GetRef(DuObject *container);
diff --git a/duhton/frame.c b/duhton/frame.c
--- a/duhton/frame.c
+++ b/duhton/frame.c
@@ -28,6 +28,12 @@
     }
 }
 
+size_t framenode_bytesize(DuFrameNodeObject *ob)
+{
+    return (sizeof(DuFrameNodeObject) +
+            (ob->ob_count - 1) * sizeof(struct dictentry));
+}
+
 
 typedef struct {
     DuOBJECT_HEAD
@@ -100,6 +106,13 @@
     struct dictentry *entries = ob->ob_items;
     revision_t search_id = stm_id(symbol);
 
+#ifdef _GC_DEBUG
+    int j;
+    for (j = 0; j < right; j++) {
+        dprintf(("\t%p\n", (gcptr)entries[j].symbol_id));
+    }
+#endif
+
     while (right > left) {
         int middle = (left + right) / 2;
         revision_t found_id = entries[middle].symbol_id;
@@ -137,6 +150,7 @@
             newentries[i] = entries[i];
 
         DuSymbol_Ensure("find_entry", symbol);
+        dprintf(("NEW ENTRY ADDED WITH search_id = %p\n", (gcptr)search_id));
         newentries[left].symbol_id = search_id;
         newentries[left].symbol = symbol;
         newentries[left].value = NULL;
@@ -305,8 +319,13 @@
 DuType DuFrameNode_Type = {    /* internal type */
     "framenode",
     DUTYPE_FRAMENODE,
-    sizeof(DuFrameNodeObject),
+    0,    /* dt_size */
     (trace_fn)framenode_trace,
+    (print_fn)NULL,
+    (eval_fn)NULL,
+    (len_fn)NULL,
+    (len_fn)NULL,
+    (bytesize_fn)framenode_bytesize,
 };
 
 DuType DuFrame_Type = {
diff --git a/duhton/listobject.c b/duhton/listobject.c
--- a/duhton/listobject.c
+++ b/duhton/listobject.c
@@ -25,6 +25,11 @@
     }
 }
 
+size_t tuple_bytesize(DuTupleObject *ob)
+{
+    return sizeof(DuTupleObject) + (ob->ob_count - 1) * sizeof(DuObject *);
+}
+
 void list_trace(DuListObject *ob, void visit(gcptr *))
 {
     visit((gcptr *)&ob->ob_tuple);
@@ -155,12 +160,6 @@
     return _list_pop((DuListObject *)list, index);
 }
 
-size_t _DuTuple_ByteSize(DuObject *tuple)
-{
-    DuTupleObject *t = (DuTupleObject *)tuple;
-    return sizeof(DuTupleObject) + (t->ob_count - 1) * sizeof(DuObject *);
-}
-
 DuType DuTuple_Type = {    /* "tuple" is mostly an internal type here */
     "tuple",
     DUTYPE_TUPLE,
@@ -170,6 +169,7 @@
     (eval_fn)NULL,
     (len_fn)NULL,
     (len_fn)NULL,
+    (bytesize_fn)tuple_bytesize,
 };
 
 DuType DuList_Type = {
diff --git a/duhton/object.c b/duhton/object.c
--- a/duhton/object.c
+++ b/duhton/object.c
@@ -19,10 +19,11 @@
 /* callback: get the size of an object */
 size_t stmcb_size(gcptr obj)
 {
-    if (_DuObject_TypeNum(obj) == DUTYPE_TUPLE)
-        return _DuTuple_ByteSize(obj);
-    else
-        return Du_TYPE(obj)->dt_size;
+    DuType *tp = Du_TYPE(obj);
+    size_t result = tp->dt_size;
+    if (result == 0)
+        result = tp->dt_bytesize(obj);
+    return result;
 }
 
 /* callback: trace the content of an object */


More information about the pypy-commit mailing list