libpurple/memorypool.c

changeset 35759
cf4d3e9df570
parent 35733
60a5d065ca81
child 39364
54439db24429
equal deleted inserted replaced
35758:87c51487e197 35759:cf4d3e9df570
31 (gpointer)((guintptr)(pointer) + (value)) 31 (gpointer)((guintptr)(pointer) + (value))
32 #define PURPLE_MEMORY_PADDED(pointer, padding) \ 32 #define PURPLE_MEMORY_PADDED(pointer, padding) \
33 (gpointer)((((guintptr)(pointer) - 1) / (padding) + 1) * padding) 33 (gpointer)((((guintptr)(pointer) - 1) / (padding) + 1) * padding)
34 34
35 #define PURPLE_MEMORY_POOL_DEFAULT_BLOCK_SIZE 1024 35 #define PURPLE_MEMORY_POOL_DEFAULT_BLOCK_SIZE 1024
36 #define PURPLE_MEMORY_POOL_DISABLED FALSE
36 37
37 typedef struct _PurpleMemoryPoolBlock PurpleMemoryPoolBlock; 38 typedef struct _PurpleMemoryPoolBlock PurpleMemoryPoolBlock;
38 39
39 typedef struct 40 typedef struct
40 { 41 {
42 gboolean disabled;
41 gulong block_size; 43 gulong block_size;
42 44
43 PurpleMemoryPoolBlock *first_block; 45 PurpleMemoryPoolBlock *first_block;
44 PurpleMemoryPoolBlock *last_block; 46 PurpleMemoryPoolBlock *last_block;
45 } PurpleMemoryPoolPrivate; 47 } PurpleMemoryPoolPrivate;
101 PurpleMemoryPoolPrivate *priv = PURPLE_MEMORY_POOL_GET_PRIVATE(pool); 103 PurpleMemoryPoolPrivate *priv = PURPLE_MEMORY_POOL_GET_PRIVATE(pool);
102 PurpleMemoryPoolBlock *blk; 104 PurpleMemoryPoolBlock *blk;
103 gpointer mem = NULL; 105 gpointer mem = NULL;
104 106
105 g_return_val_if_fail(priv != NULL, NULL); 107 g_return_val_if_fail(priv != NULL, NULL);
108
109 if (priv->disabled) {
110 /* XXX: this may cause some leaks */
111 return g_try_malloc(size);
112 }
106 113
107 g_return_val_if_fail(alignment <= PURPLE_MEMORY_POOL_BLOCK_PADDING, NULL); 114 g_return_val_if_fail(alignment <= PURPLE_MEMORY_POOL_BLOCK_PADDING, NULL);
108 g_warn_if_fail(alignment >= 1); 115 g_warn_if_fail(alignment >= 1);
109 if (alignment < 1) 116 if (alignment < 1)
110 alignment = 1; 117 alignment = 1;
260 { 267 {
261 return g_object_new(PURPLE_TYPE_MEMORY_POOL, NULL); 268 return g_object_new(PURPLE_TYPE_MEMORY_POOL, NULL);
262 } 269 }
263 270
264 static void 271 static void
272 purple_memory_pool_init(GTypeInstance *instance, gpointer klass)
273 {
274 PurpleMemoryPool *pool = PURPLE_MEMORY_POOL(instance);
275 PurpleMemoryPoolPrivate *priv = PURPLE_MEMORY_POOL_GET_PRIVATE(pool);
276
277 priv->disabled = PURPLE_MEMORY_POOL_DISABLED;
278 }
279
280 static void
265 purple_memory_pool_finalize(GObject *obj) 281 purple_memory_pool_finalize(GObject *obj)
266 { 282 {
267 purple_memory_pool_cleanup(PURPLE_MEMORY_POOL(obj)); 283 purple_memory_pool_cleanup(PURPLE_MEMORY_POOL(obj));
268 284
269 G_OBJECT_CLASS(parent_class)->finalize(obj); 285 G_OBJECT_CLASS(parent_class)->finalize(obj);
333 if (G_UNLIKELY(type == 0)) { 349 if (G_UNLIKELY(type == 0)) {
334 static const GTypeInfo info = { 350 static const GTypeInfo info = {
335 .class_size = sizeof(PurpleMemoryPoolClass), 351 .class_size = sizeof(PurpleMemoryPoolClass),
336 .class_init = (GClassInitFunc)purple_memory_pool_class_init, 352 .class_init = (GClassInitFunc)purple_memory_pool_class_init,
337 .instance_size = sizeof(PurpleMemoryPool), 353 .instance_size = sizeof(PurpleMemoryPool),
354 .instance_init = (GInstanceInitFunc)purple_memory_pool_init
338 }; 355 };
339 356
340 type = g_type_register_static(G_TYPE_OBJECT, 357 type = g_type_register_static(G_TYPE_OBJECT,
341 "PurpleMemoryPool", &info, 0); 358 "PurpleMemoryPool", &info, 0);
342 } 359 }

mercurial