63 lines
1.8 KiB
Diff
63 lines
1.8 KiB
Diff
--- upstart-0.6.3/nih/alloc.c.orig 2010-01-17 17:28:33.000000000 +0000
|
|
+++ upstart-0.6.3/nih/alloc.c 2010-01-17 17:28:38.000000000 +0000
|
|
@@ -54,6 +54,8 @@
|
|
NihDestructor destructor;
|
|
} NihAllocCtx;
|
|
|
|
+#define NIH_ALLOC_CTX_SIZE (sizeof(NihAllocCtx) + __alignof__(NihAllocCtx))
|
|
+
|
|
/**
|
|
* NihAllocRef:
|
|
* @children_entry: list head in parent's children list,
|
|
@@ -82,7 +84,7 @@
|
|
*
|
|
* Returns: pointer to NihAllocCtx structure.
|
|
**/
|
|
-#define NIH_ALLOC_CTX(ptr) ((NihAllocCtx *)(ptr) - 1)
|
|
+#define NIH_ALLOC_CTX(ptr) ((NihAllocCtx *)((void*)ptr - NIH_ALLOC_CTX_SIZE))
|
|
|
|
/**
|
|
* NIH_ALLOC_PTR:
|
|
@@ -93,7 +95,7 @@
|
|
*
|
|
* Returns: pointer to block of memory.
|
|
**/
|
|
-#define NIH_ALLOC_PTR(ctx) ((void *)((NihAllocCtx *)(ctx) + 1))
|
|
+#define NIH_ALLOC_PTR(ctx) ((void*)((void*)ctx + NIH_ALLOC_CTX_SIZE))
|
|
|
|
/**
|
|
* NIH_ALLOC_FINALISED:
|
|
@@ -145,7 +147,7 @@
|
|
{
|
|
NihAllocCtx *ctx;
|
|
|
|
- ctx = __nih_malloc (sizeof (NihAllocCtx) + size);
|
|
+ ctx = __nih_malloc (NIH_ALLOC_CTX_SIZE + size);
|
|
if (! ctx)
|
|
return NULL;
|
|
|
|
@@ -230,7 +232,7 @@
|
|
/* Now do the actual realloc(), if this fails then we can just
|
|
* return NULL since we've not actually changed anything.
|
|
*/
|
|
- ctx = __nih_realloc (ctx, sizeof (NihAllocCtx) + size);
|
|
+ ctx = __nih_realloc (ctx, NIH_ALLOC_CTX_SIZE + size);
|
|
if (! ctx)
|
|
return NULL;
|
|
|
|
@@ -562,7 +564,7 @@
|
|
nih_assert (child != NULL);
|
|
nih_assert (child->destructor != NIH_ALLOC_FINALISED);
|
|
|
|
- ref = NIH_MUST (malloc (sizeof (NihAllocRef)));
|
|
+ ref = NIH_MUST (malloc (NIH_ALLOC_CTX_SIZE));
|
|
|
|
nih_list_init (&ref->children_entry);
|
|
nih_list_init (&ref->parents_entry);
|
|
@@ -739,5 +741,5 @@
|
|
ctx = NIH_ALLOC_CTX (ptr);
|
|
nih_assert (ctx->destructor != NIH_ALLOC_FINALISED);
|
|
|
|
- return malloc_usable_size (ctx) - sizeof (NihAllocCtx);
|
|
+ return malloc_usable_size (ctx) - NIH_ALLOC_CTX_SIZE;
|
|
}
|