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