1 #ifndef _ALLOCATORS_H_ 2 #define _ALLOCATORS_H_ 3 4 #include <glib.h> 5 6 G_BEGIN_DECLS 7 8 #define CORBA_sequence_set_release(s,r) (s)->_release = r 9 #define CORBA_sequence_get_release(s) (s)->_release 10 11 void CORBA_free (gpointer mem); 12 gpointer ORBit_alloc_tcval (CORBA_TypeCode tc, 13 guint nelements); 14 gpointer ORBit_realloc_tcval (gpointer old, 15 CORBA_TypeCode tc, 16 guint old_num_elements, 17 guint num_elements); 18 19 #ifdef ORBIT2_INTERNAL_API 20 21 #define PTR_TO_MEMINFO(x) (((ORBit_mem_info *)(x)) - 1) 22 #define MEMINFO_TO_PTR(x) ((gpointer)((x) + 1)) 23 24 /** 25 This function-type is used internally by the memory allocator 26 as a callback. When called, it must "free" anything contained 27 in {mem}. Normally, it does not free {mem} itself, only what is 28 inside {mem}. For example, if {mem} contains only integers, then 29 nothing happens. Alternatively, if {mem} contains object references, 30 then CORBA_Object_free (or ORBit_RootObject_release()) must be 31 invoked on it. 32 33 The callback func must return the "end" of {mem}. This is used 34 when iterating through sequences, arrays and structs. 35 36 Previously, older code supported the idea that the callback could 37 return FALSE (or NULL?), in which case that meant that the callback 38 itself had already free'd the memory. This convention is no longer 39 used. 40 41 Below, some magic values of the fnc ptr are defined. 42 **/ 43 typedef gpointer (*ORBit_Mem_free_fn) (gpointer mem, 44 gpointer func_data); 45 46 #define ORBIT_MEMHOW_HOW(how) ((how) & 0x3) 47 #define ORBIT_MEMHOW_ELEMENTS(how) ((how) >> 2) 48 #define ORBIT_MEMHOW_MAKE(how,elements) (((elements) << 2) | (how)) 49 50 typedef enum { 51 ORBIT_MEMHOW_NONE = 0, /* don't free */ 52 ORBIT_MEMHOW_SIMPLE = 1, /* plain g_free */ 53 ORBIT_MEMHOW_TYPECODE = 2, /* free via typecode */ 54 ORBIT_MEMHOW_FREEFNC = 3 /* free via a method */ 55 } ORBitMemHow; 56 57 typedef struct ORBit_Memprefix { 58 union { 59 CORBA_TypeCode tc; 60 ORBit_Mem_free_fn free_fn; 61 } u; 62 ORBitMemHow how; 63 } ORBit_MemPrefix; 64 65 void ORBit_free (gpointer mem); 66 void ORBit_free_T (gpointer mem); 67 68 CORBA_char *ORBit_alloc_string (size_t string_length); 69 gpointer ORBit_alloc_simple (size_t block_size); 70 gpointer ORBit_alloc_by_tc (CORBA_TypeCode tc); 71 gpointer ORBit_alloc_with_free_fn (size_t element_size, 72 guint num_elements, 73 ORBit_Mem_free_fn free_fn); 74 CORBA_TypeCode ORBit_alloc_get_tcval (gpointer mem); 75 76 gpointer CORBA_any__freekids (gpointer mem, gpointer dat); 77 gpointer ORBit_freekids_via_TypeCode (CORBA_TypeCode tc, gpointer mem); 78 79 #endif /* ORBIT2_INTERNAL_API */ 80 81 G_END_DECLS 82 83 #endif /* _ALLOCATORS_H_ */ 84 85