1 /* A toy re-implementation of CPython's object model. */
6 #include "analyzer-decls.h"
8 typedef struct base_obj
10 struct type_obj
*ob_type
;
14 typedef struct type_obj
17 void (*tp_dealloc
) (base_obj
*);
20 typedef struct boxed_int_obj
26 extern void int_del (base_obj
*);
28 type_obj type_type
= {
32 type_obj boxed_int_type
= {
37 base_obj
*alloc_obj (type_obj
*ob_type
, size_t sz
)
39 base_obj
*obj
= (base_obj
*)malloc (sz
);
42 obj
->ob_type
= ob_type
;
47 base_obj
*new_int_obj (int val
)
49 boxed_int_obj
*int_obj
50 = (boxed_int_obj
*)alloc_obj (&boxed_int_type
, sizeof (boxed_int_obj
));
53 int_obj
->int_val
= val
;
54 return (base_obj
*)int_obj
;
57 void unref (base_obj
*obj
)
59 if (--obj
->ob_refcnt
== 0)
60 obj
->ob_type
->tp_dealloc (obj
);
63 void test_1 (const char *str
)
65 base_obj
*obj
= new_int_obj (42);
68 __analyzer_eval (((boxed_int_obj
*)obj
)->int_val
== 42); /* { dg-warning "TRUE" } */
69 __analyzer_eval (obj
->ob_refcnt
== 1); /* { dg-warning "TRUE" } */
71 } /* { dg-bogus "leak" "" } */