]> git.sesse.net Git - vlc/blob - test/native/gc.c
Dynamic array with log allocation
[vlc] / test / native / gc.c
1 #include "../pyunit.h"
2 #include <vlc/vlc.h>
3
4 struct mygc
5 {
6     VLC_GC_MEMBERS;
7     int i;
8 };
9
10 typedef struct mygc mygc;
11
12 static void mygc_destructor( gc_object_t *p_gc )
13 {
14     free( p_gc );
15     p_gc = NULL;
16 };
17
18 static PyObject *gc_test( PyObject *self, PyObject *args )
19 {
20      mygc *gc = (mygc *)malloc( sizeof( mygc ) );
21
22      vlc_gc_init( gc, mygc_destructor, NULL );
23      ASSERT( gc->i_gc_refcount == 0, "Refcount should be 0" );
24      vlc_gc_incref( gc );
25      ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
26      vlc_gc_incref( gc );
27      ASSERT( gc->i_gc_refcount == 2, "Refcount should be 2" );
28      gc->i++;
29      vlc_gc_decref( gc );
30      ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
31      vlc_gc_decref( gc );
32
33      Py_INCREF( Py_None );
34      return Py_None;
35 };
36
37 static PyMethodDef native_gc_test_methods[] = {
38    DEF_METHOD( gc_test, "Test GC" )
39    { NULL, NULL, 0, NULL }
40 };
41
42 asserts = 0;
43
44 DECLARE_MODULE( native_gc_test )