Navigation Menu

Skip to content

Commit

Permalink
[glibutil] Added gutil_slice_free() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Oct 16, 2020
1 parent bb2817d commit b54311d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
12 changes: 7 additions & 5 deletions include/gutil_macros.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014-2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2014-2020 Jolla Ltd.
* Copyright (C) 2014-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Jolla Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand Down Expand Up @@ -48,6 +48,8 @@
# define G_PACKED
#endif

#define gutil_slice_free(x) g_slice_free1(sizeof(*(x)), x) /* Since 1.0.49 */

#endif /* GUTIL_MACROS_H */

/*
Expand Down
11 changes: 6 additions & 5 deletions src/gutil_idlepool.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2016-2018 Jolla Ltd.
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2016-2020 Jolla Ltd.
* Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -31,6 +31,7 @@
*/

#include <gutil_idlepool.h>
#include <gutil_macros.h>
#include <gutil_log.h>

#include <glib-object.h>
Expand Down Expand Up @@ -103,7 +104,7 @@ gutil_idle_pool_unref(
/* Clear pointer to the shared instance */
if (self->shared) *(self->shared) = NULL;
gutil_idle_pool_drain(self);
g_slice_free(GUtilIdlePool, self);
gutil_slice_free(self);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/gutil_idlequeue.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2017-2020 Jolla Ltd.
* Copyright (C) 2017-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -31,6 +31,7 @@
*/

#include "gutil_idlequeue.h"
#include "gutil_macros.h"
#include "gutil_log.h"

typedef struct gutil_idle_queue_item GUtilIdleQueueItem;
Expand Down Expand Up @@ -60,7 +61,7 @@ gutil_idle_queue_item_destroy(
if (item->destroy) {
item->destroy(item->data);
}
g_slice_free(GUtilIdleQueueItem, item);
gutil_slice_free(item);
}

static
Expand Down Expand Up @@ -151,7 +152,7 @@ gutil_idle_queue_unref(
GASSERT(q->ref_count > 0);
if (g_atomic_int_dec_and_test(&q->ref_count)) {
gutil_idle_queue_cancel_all(q);
g_slice_free(GUtilIdleQueue, q);
gutil_slice_free(q);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/gutil_ints.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2017-2020 Jolla Ltd.
* Copyright (C) 2017-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -32,6 +32,7 @@

#include "gutil_intarray.h"
#include "gutil_ints.h"
#include "gutil_macros.h"

struct gutil_ints {
const int* data;
Expand Down Expand Up @@ -134,7 +135,7 @@ gutil_ints_unref(
if (ints->free_func) {
ints->free_func(ints->user_data);
}
g_slice_free(GUtilInts, ints);
gutil_slice_free(ints);
}
}
}
Expand All @@ -157,7 +158,7 @@ gutil_ints_unref_to_data(
result = g_memdup(ints->data, ints->count * sizeof(int));
ints->free_func(ints->user_data);
}
g_slice_free(GUtilInts, ints);
gutil_slice_free(ints);
} else {
result = g_memdup(ints->data, ints->count * sizeof(int));
}
Expand Down
13 changes: 7 additions & 6 deletions src/gutil_ring.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2016-2020 Jolla Ltd.
* Copyright (C) 2016-2020 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Jolla Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -31,6 +31,7 @@
*/

#include "gutil_ring.h"
#include "gutil_macros.h"
#include "gutil_log.h"

struct gutil_ring {
Expand Down Expand Up @@ -101,7 +102,7 @@ gutil_ring_unref(
}
}
g_free(r->data);
g_slice_free(GUtilRing, r);
gutil_slice_free(r);
}
}
}
Expand Down

0 comments on commit b54311d

Please sign in to comment.