Issue #2 new

rbtree simple Segfault test

Anonymous created an issue

Hello bcsaller.

First of all, thanks for the python rbtree implementation!

But this simple test cause Segfault on my Ubuntu 10.10 {{{

!python

from rbtree import rbtree import datetime

def rbtest( n ): r = rbtree()

# Заполним случайными значениями
dt = datetime.datetime.now()
for i in xrange( 0, n ):
    r[i] = i

print 'rbtree Adding', n, 'elements', datetime.datetime.now() - dt


dt = datetime.datetime.now()
for i in xrange( 0, n ):
    k = r.min()
    v = r.pop()
    r[i] = i

print 'rbtree Remove -> add', n, 'elements', datetime.datetime.now() - dt
print 'last elem', r.pop()

rbtest( 100 ) rbtest( 1000 ) }}}

(vpython)r0@translator:~/d/tmp$ python ./deque.py rbtree Adding 100 elements 0:00:00.000249 rbtree Remove -> add 100 elements 0:00:00.002405 last elem 99 rbtree Adding 1000 elements 0:00:00.003311 Segmentation fault

Comments (2)

  1. Anonymous

    This segfault is because the code when updating references doesn't increases correctly the garbage counter. Here's the fix:

    diff -r b7365c1d45e7 src/rbtree_impl.c
    --- a/src/rbtree_impl.c	Tue Nov 16 06:42:07 2010 -0800
    +++ b/src/rbtree_impl.c	Mon Mar 05 21:37:27 2012 +0100
    @@ -288,15 +288,16 @@
     int
     __rb_insert (rbtree_t *T, PyObject *k, PyObject *v)
     {
    -    rbtree_node_t *x = __tree_insert(T, k, v);
    +    rbtree_node_t *x;
         rbtree_node_t *y;
     
    +    Py_INCREF(k);
    +    Py_INCREF(v);
    +    x = __tree_insert(T, k, v);
         if (x ==  NULL) {
             return 0;
         }
     
    -    Py_INCREF(k);
    -    Py_INCREF(v);
     
     
         if (x)
    
  2. Log in to comment