libsysprof-capture: Use sysprof_{steal,clear}_pointer() instead of GLib

They work exactly the same way as the GLib functions.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-01 17:41:03 +01:00
parent e96e35b6f1
commit 1d865c5c8e
8 changed files with 30 additions and 14 deletions

View File

@ -30,6 +30,7 @@
#include <unistd.h>
#include "sysprof-capture-util-private.h"
#include "sysprof-macros-internal.h"
#include "sysprof-platform.h"
#include "mapped-ring-buffer.h"
@ -214,7 +215,7 @@ mapped_ring_buffer_new_reader (size_t buffer_size)
self->map = map;
self->page_size = page_size;
return g_steal_pointer (&self);
return sysprof_steal_pointer (&self);
}
MappedRingBuffer *
@ -319,7 +320,7 @@ mapped_ring_buffer_new_writer (int fd)
self->map = map;
self->page_size = page_size;
return g_steal_pointer (&self);
return sysprof_steal_pointer (&self);
}
static void

View File

@ -221,7 +221,7 @@ sysprof_capture_condition_init (void)
self->ref_count = 1;
return g_steal_pointer (&self);
return sysprof_steal_pointer (&self);
}
/* Returns NULL on allocation failure. */

View File

@ -64,6 +64,7 @@
#include "sysprof-capture-cursor.h"
#include "sysprof-capture-reader.h"
#include "sysprof-capture-util-private.h"
#include "sysprof-macros-internal.h"
#define READ_DELEGATE(f) ((ReadDelegate)(f))
@ -80,8 +81,8 @@ struct _SysprofCaptureCursor
static void
sysprof_capture_cursor_finalize (SysprofCaptureCursor *self)
{
g_clear_pointer (&self->conditions, g_ptr_array_unref);
g_clear_pointer (&self->reader, sysprof_capture_reader_unref);
sysprof_clear_pointer (&self->conditions, g_ptr_array_unref);
sysprof_clear_pointer (&self->reader, sysprof_capture_reader_unref);
free (self);
}
@ -97,7 +98,7 @@ sysprof_capture_cursor_init (void)
self->conditions = g_ptr_array_new_with_free_func ((GDestroyNotify) sysprof_capture_condition_unref);
self->ref_count = 1;
return g_steal_pointer (&self);
return sysprof_steal_pointer (&self);
}
/**

View File

@ -820,7 +820,7 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
self->pos += jitmap->frame.len;
return g_steal_pointer (&ret);
return sysprof_steal_pointer (&ret);
}
const SysprofCaptureSample *
@ -1309,7 +1309,7 @@ sysprof_capture_reader_list_files (SysprofCaptureReader *self)
g_ptr_array_add (ar, g_strdup (key));
g_ptr_array_add (ar, NULL);
return (char **)g_ptr_array_free (g_steal_pointer (&ar), FALSE);
return (char **)g_ptr_array_free (sysprof_steal_pointer (&ar), FALSE);
}
bool

View File

@ -65,6 +65,8 @@
#include <sysprof-capture.h>
#include <unistd.h>
#include "sysprof-macros-internal.h"
typedef struct
{
uint64_t src;
@ -81,7 +83,7 @@ static void
translate_table_clear (GArray **tables,
unsigned int table)
{
g_clear_pointer (&tables[table], g_array_unref);
sysprof_clear_pointer (&tables[table], g_array_unref);
}
static int

View File

@ -171,7 +171,7 @@ sysprof_capture_writer_finalize (SysprofCaptureWriter *self)
{
if (self != NULL)
{
g_clear_pointer (&self->periodic_flush, g_source_destroy);
sysprof_clear_pointer (&self->periodic_flush, g_source_destroy);
sysprof_capture_writer_flush (self);
@ -1154,7 +1154,7 @@ sysprof_capture_writer_create_reader (SysprofCaptureWriter *self,
if ((ret = sysprof_capture_reader_new_from_fd (copy, error)))
sysprof_capture_reader_set_stat (ret, &self->stat);
return g_steal_pointer (&ret);
return sysprof_steal_pointer (&ret);
}
/**
@ -1516,7 +1516,7 @@ sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self,
g_return_if_fail (self != NULL);
g_clear_pointer (&self->periodic_flush, g_source_destroy);
sysprof_clear_pointer (&self->periodic_flush, g_source_destroy);
if (timeout_seconds == 0)
return;

View File

@ -77,6 +77,7 @@
#include "sysprof-capture-util-private.h"
#include "sysprof-collector.h"
#include "sysprof-macros-internal.h"
#define MAX_UNWIND_DEPTH 128
#define CREATRING "CreatRing\0"
@ -179,7 +180,7 @@ request_writer (void)
}
}
return g_steal_pointer (&buffer);
return sysprof_steal_pointer (&buffer);
}
static void
@ -207,7 +208,7 @@ sysprof_collector_free (void *data)
if (collector != NULL && collector != COLLECTOR_INVALID)
{
MappedRingBuffer *buffer = g_steal_pointer (&collector->buffer);
MappedRingBuffer *buffer = sysprof_steal_pointer (&collector->buffer);
if (buffer != NULL)
{

View File

@ -60,3 +60,14 @@
#pragma once
#define sysprof_assert_not_reached() assert (false)
#define sysprof_steal_pointer(pp) __extension__ ({__typeof(*(pp)) _p = *(pp); *(pp) = NULL; _p;})
#define sysprof_clear_pointer(pp, destroy) \
do { \
__typeof((pp)) _pp = (pp); \
__typeof(*(pp)) _p = *_pp; \
*_pp = NULL; \
if (_p != NULL) \
(destroy) (_p); \
} while (0)