summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-05-28 19:51:13 +0000
committermental <mental@users.sourceforge.net>2006-05-28 19:51:13 +0000
commit2d08a9d98d19a0581eeae687bb0322dc98806d40 (patch)
tree3adec19e80f170b623e41454aae370cb7c75dade /src/libnr
parentokay, that looked better in the icon preview than it did in practice; putting... (diff)
downloadinkscape-2d08a9d98d19a0581eeae687bb0322dc98806d40.tar.gz
inkscape-2d08a9d98d19a0581eeae687bb0322dc98806d40.zip
replace nr_new() with g_new(), and try to converge on using the glib allocator a little more instead of the others (aside from libgc)
(bzr r1044)
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/nr-macros.h4
-rw-r--r--src/libnr/nr-object.cpp11
-rw-r--r--src/libnr/nr-path.cpp3
-rw-r--r--src/libnr/nr-pixblock-pattern.cpp3
-rw-r--r--src/libnr/nr-pixblock.cpp35
-rw-r--r--src/libnr/nr-svp-render.cpp5
-rw-r--r--src/libnr/nr-svp.cpp11
7 files changed, 37 insertions, 35 deletions
diff --git a/src/libnr/nr-macros.h b/src/libnr/nr-macros.h
index 74a627ae7..616504c6f 100644
--- a/src/libnr/nr-macros.h
+++ b/src/libnr/nr-macros.h
@@ -17,10 +17,6 @@
#endif
#include <assert.h>
-#define nr_new(t,n) ((t *) malloc ((n) * sizeof (t)))
-#define nr_free free
-#define nr_renew(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
-
#ifndef TRUE
#define TRUE (!0)
#endif
diff --git a/src/libnr/nr-object.cpp b/src/libnr/nr-object.cpp
index feffbd884..12f57bd81 100644
--- a/src/libnr/nr-object.cpp
+++ b/src/libnr/nr-object.cpp
@@ -15,6 +15,7 @@
#include <typeinfo>
+#include <glib/gmem.h>
#include <libnr/nr-macros.h>
#include "nr-object.h"
@@ -77,7 +78,7 @@ NRType nr_object_register_type(NRType parent,
{
if (classes_len >= classes_size) {
classes_size += 32;
- classes = nr_renew (classes, NRObjectClass *, classes_size);
+ classes = g_renew (NRObjectClass *, classes, classes_size);
if (classes_len == 0) {
classes[0] = NULL;
classes_len = 1;
@@ -251,7 +252,7 @@ static void nr_active_object_finalize(NRObject *object)
listener->vector->dispose(object, listener->data);
}
}
- free (aobject->callbacks);
+ g_free (aobject->callbacks);
}
((NRObjectClass *) (parent_class))->finalize(object);
@@ -263,7 +264,7 @@ void nr_active_object_add_listener(NRActiveObject *object,
void *data)
{
if (!object->callbacks) {
- object->callbacks = (NRObjectCallbackBlock*) malloc(sizeof(NRObjectCallbackBlock));
+ object->callbacks = (NRObjectCallbackBlock*)g_malloc(sizeof(NRObjectCallbackBlock));
object->callbacks->size = 1;
object->callbacks->length = 0;
}
@@ -271,7 +272,7 @@ void nr_active_object_add_listener(NRActiveObject *object,
if (object->callbacks->length >= object->callbacks->size) {
int newsize = object->callbacks->size << 1;
object->callbacks = (NRObjectCallbackBlock *)
- realloc(object->callbacks, sizeof(NRObjectCallbackBlock) + (newsize - 1) * sizeof (NRObjectListener));
+ g_realloc(object->callbacks, sizeof(NRObjectCallbackBlock) + (newsize - 1) * sizeof (NRObjectListener));
object->callbacks->size = newsize;
}
@@ -293,7 +294,7 @@ void nr_active_object_remove_listener_by_data(NRActiveObject *object, void *data
if ( listener->data == data ) {
object->callbacks->length -= 1;
if ( object->callbacks->length < 1 ) {
- free(object->callbacks);
+ g_free(object->callbacks);
object->callbacks = NULL;
} else if ( object->callbacks->length != i ) {
*listener = object->callbacks->listeners[object->callbacks->length];
diff --git a/src/libnr/nr-path.cpp b/src/libnr/nr-path.cpp
index 6ce2f5f99..99adcb3e1 100644
--- a/src/libnr/nr-path.cpp
+++ b/src/libnr/nr-path.cpp
@@ -9,6 +9,7 @@
* This code is in public domain
*/
+#include <glib/gmem.h>
#include "n-art-bpath.h"
#include "nr-rect.h"
#include "nr-path.h"
@@ -31,7 +32,7 @@ NRBPath *nr_path_duplicate_transform(NRBPath *d, NRBPath *s, NRMatrix const *tra
i = 0;
while (s->path[i].code != NR_END) i += 1;
- d->path = nr_new (NArtBpath, i + 1);
+ d->path = g_new (NArtBpath, i + 1);
i = 0;
while (s->path[i].code != NR_END) {
diff --git a/src/libnr/nr-pixblock-pattern.cpp b/src/libnr/nr-pixblock-pattern.cpp
index 03bd688ba..b4e25638f 100644
--- a/src/libnr/nr-pixblock-pattern.cpp
+++ b/src/libnr/nr-pixblock-pattern.cpp
@@ -10,6 +10,7 @@
*/
+#include <glib/gmem.h>
#include "nr-pixops.h"
#include "nr-pixblock-pattern.h"
@@ -34,7 +35,7 @@ nr_pixblock_render_gray_noise (NRPixBlock *pb, NRPixBlock *mask)
if (!noise) {
int i;
- noise = nr_new (unsigned char, NR_NOISE_SIZE);
+ noise = g_new (unsigned char, NR_NOISE_SIZE);
for (i = 0; i < NR_NOISE_SIZE; i++) noise[i] = (rand () / (RAND_MAX >> 8)) & 0xff;
}
diff --git a/src/libnr/nr-pixblock.cpp b/src/libnr/nr-pixblock.cpp
index 59e64b558..079bca6ca 100644
--- a/src/libnr/nr-pixblock.cpp
+++ b/src/libnr/nr-pixblock.cpp
@@ -9,6 +9,7 @@
* This code is in the Public Domain
*/
+#include <glib/gmem.h>
#include "nr-pixblock.h"
/// Size of buffer that needs no allocation (default 4).
@@ -58,7 +59,7 @@ nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, i
pb->data.px = nr_pixelstore_1M_new (clear, 0x0);
} else {
pb->size = NR_PIXBLOCK_SIZE_BIG;
- pb->data.px = nr_new (unsigned char, size);
+ pb->data.px = g_new (unsigned char, size);
if (clear) memset (pb->data.px, 0x0, size);
}
@@ -72,7 +73,7 @@ nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, i
}
/**
- * Pixbuf initialisation using nr_new.
+ * Pixbuf initialisation using g_new.
*
* After allocating memory, the buffer is cleared if the clear flag is set.
* \param pb Pointer to the pixbuf struct.
@@ -97,7 +98,7 @@ nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1
if (clear) memset (pb->data.p, 0x0, size);
} else {
pb->size = NR_PIXBLOCK_SIZE_BIG;
- pb->data.px = nr_new (unsigned char, size);
+ pb->data.px = g_new (unsigned char, size);
if (clear) memset (pb->data.px, 0x0, size);
}
@@ -183,7 +184,7 @@ nr_pixblock_release (NRPixBlock *pb)
nr_pixelstore_1M_free (pb->data.px);
break;
case NR_PIXBLOCK_SIZE_BIG:
- nr_free (pb->data.px);
+ g_free (pb->data.px);
break;
case NR_PIXBLOCK_SIZE_STATIC:
break;
@@ -196,14 +197,14 @@ nr_pixblock_release (NRPixBlock *pb)
* Allocates NRPixBlock and sets it up.
*
* \return Pointer to fresh pixblock.
- * Calls nr_new() and nr_pixblock_setup().
+ * Calls g_new() and nr_pixblock_setup().
*/
NRPixBlock *
nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear)
{
NRPixBlock *pb;
- pb = nr_new (NRPixBlock, 1);
+ pb = g_new (NRPixBlock, 1);
nr_pixblock_setup (pb, mode, x0, y0, x1, y1, clear);
@@ -220,7 +221,7 @@ nr_pixblock_free (NRPixBlock *pb)
{
nr_pixblock_release (pb);
- nr_free (pb);
+ g_free (pb);
return NULL;
}
@@ -241,7 +242,7 @@ nr_pixelstore_4K_new (bool clear, unsigned char val)
nr_4K_len -= 1;
px = nr_4K_px[nr_4K_len];
} else {
- px = nr_new (unsigned char, 4096);
+ px = g_new (unsigned char, 4096);
}
if (clear) memset (px, val, 4096);
@@ -254,7 +255,7 @@ nr_pixelstore_4K_free (unsigned char *px)
{
if (nr_4K_len == nr_4K_size) {
nr_4K_size += NR_4K_BLOCK;
- nr_4K_px = nr_renew (nr_4K_px, unsigned char *, nr_4K_size);
+ nr_4K_px = g_renew (unsigned char *, nr_4K_px, nr_4K_size);
}
nr_4K_px[nr_4K_len] = px;
@@ -275,7 +276,7 @@ nr_pixelstore_16K_new (bool clear, unsigned char val)
nr_16K_len -= 1;
px = nr_16K_px[nr_16K_len];
} else {
- px = nr_new (unsigned char, 16384);
+ px = g_new (unsigned char, 16384);
}
if (clear) memset (px, val, 16384);
@@ -288,7 +289,7 @@ nr_pixelstore_16K_free (unsigned char *px)
{
if (nr_16K_len == nr_16K_size) {
nr_16K_size += NR_16K_BLOCK;
- nr_16K_px = nr_renew (nr_16K_px, unsigned char *, nr_16K_size);
+ nr_16K_px = g_renew (unsigned char *, nr_16K_px, nr_16K_size);
}
nr_16K_px[nr_16K_len] = px;
@@ -309,7 +310,7 @@ nr_pixelstore_64K_new (bool clear, unsigned char val)
nr_64K_len -= 1;
px = nr_64K_px[nr_64K_len];
} else {
- px = nr_new (unsigned char, 65536);
+ px = g_new (unsigned char, 65536);
}
if (clear) memset (px, val, 65536);
@@ -322,7 +323,7 @@ nr_pixelstore_64K_free (unsigned char *px)
{
if (nr_64K_len == nr_64K_size) {
nr_64K_size += NR_64K_BLOCK;
- nr_64K_px = nr_renew (nr_64K_px, unsigned char *, nr_64K_size);
+ nr_64K_px = g_renew (unsigned char *, nr_64K_px, nr_64K_size);
}
nr_64K_px[nr_64K_len] = px;
@@ -344,7 +345,7 @@ nr_pixelstore_256K_new (bool clear, unsigned char val)
nr_256K_len -= 1;
px = nr_256K_px[nr_256K_len];
} else {
- px = nr_new (unsigned char, NR_256K);
+ px = g_new (unsigned char, NR_256K);
}
if (clear) memset (px, val, NR_256K);
@@ -357,7 +358,7 @@ nr_pixelstore_256K_free (unsigned char *px)
{
if (nr_256K_len == nr_256K_size) {
nr_256K_size += NR_256K_BLOCK;
- nr_256K_px = nr_renew (nr_256K_px, unsigned char *, nr_256K_size);
+ nr_256K_px = g_renew (unsigned char *, nr_256K_px, nr_256K_size);
}
nr_256K_px[nr_256K_len] = px;
@@ -379,7 +380,7 @@ nr_pixelstore_1M_new (bool clear, unsigned char val)
nr_1M_len -= 1;
px = nr_1M_px[nr_1M_len];
} else {
- px = nr_new (unsigned char, NR_1M);
+ px = g_new (unsigned char, NR_1M);
}
if (clear) memset (px, val, NR_1M);
@@ -392,7 +393,7 @@ nr_pixelstore_1M_free (unsigned char *px)
{
if (nr_1M_len == nr_1M_size) {
nr_1M_size += NR_1M_BLOCK;
- nr_1M_px = nr_renew (nr_1M_px, unsigned char *, nr_1M_size);
+ nr_1M_px = g_renew (unsigned char *, nr_1M_px, nr_1M_size);
}
nr_1M_px[nr_1M_len] = px;
diff --git a/src/libnr/nr-svp-render.cpp b/src/libnr/nr-svp-render.cpp
index 0c3b391d5..0ca73bc0e 100644
--- a/src/libnr/nr-svp-render.cpp
+++ b/src/libnr/nr-svp-render.cpp
@@ -14,6 +14,7 @@
#define noNR_VERBOSE
+#include <glib/gmem.h>
#include "nr-svp-render.h"
static void nr_svp_render (NRSVP *svp, unsigned char *px, unsigned int bpp, unsigned int rs, int x0, int y0, int x1, int y1,
@@ -371,7 +372,7 @@ nr_slice_new (int wind, NRPoint *points, unsigned int length, NR::Coord y)
if (s == NULL) {
int i;
- s = nr_new (NRSlice, NR_SLICE_ALLOC_SIZE);
+ s = g_new (NRSlice, NR_SLICE_ALLOC_SIZE);
for (i = 1; i < (NR_SLICE_ALLOC_SIZE - 1); i++) s[i].next = &s[i + 1];
s[NR_SLICE_ALLOC_SIZE - 1].next = NULL;
ffslice = s + 1;
@@ -521,7 +522,7 @@ nr_run_new (NR::Coord x0, NR::Coord y0, NR::Coord x1, NR::Coord y1, int wind)
if (r == NULL) {
int i;
- r = nr_new (NRRun, NR_RUN_ALLOC_SIZE);
+ r = g_new (NRRun, NR_RUN_ALLOC_SIZE);
for (i = 1; i < (NR_RUN_ALLOC_SIZE - 1); i++) (r + i)->next = (r + i + 1);
(r + NR_RUN_ALLOC_SIZE - 1)->next = NULL;
ffrun = r + 1;
diff --git a/src/libnr/nr-svp.cpp b/src/libnr/nr-svp.cpp
index a1484397a..7fa2cfd36 100644
--- a/src/libnr/nr-svp.cpp
+++ b/src/libnr/nr-svp.cpp
@@ -21,6 +21,7 @@
# include <ieeefp.h>
#endif
+#include <glib/gmem.h>
#include "nr-rect.h"
#include "nr-svp-private.h"
@@ -29,7 +30,7 @@
void
nr_svp_free (NRSVP *svp)
{
- if (svp->points) nr_free (svp->points);
+ if (svp->points) g_free (svp->points);
free (svp);
}
@@ -83,7 +84,7 @@ nr_vertex_new (void)
if (v == NULL) {
int i;
- v = nr_new (NRVertex, NR_VERTEX_ALLOC_SIZE);
+ v = g_new (NRVertex, NR_VERTEX_ALLOC_SIZE);
for (i = 1; i < (NR_VERTEX_ALLOC_SIZE - 1); i++) v[i].next = &v[i + 1];
v[NR_VERTEX_ALLOC_SIZE - 1].next = NULL;
ffvertex = v + 1;
@@ -91,7 +92,7 @@ nr_vertex_new (void)
ffvertex = v->next;
}
#else
- v = nr_new (NRVertex, 1);
+ v = g_new (NRVertex, 1);
#endif
v->next = NULL;
@@ -127,7 +128,7 @@ nr_vertex_free_one (NRVertex * v)
v->next = ffvertex;
ffvertex = v;
#else
- nr_free (v);
+ g_free (v);
#endif
}
@@ -144,7 +145,7 @@ nr_vertex_free_list (NRVertex * v)
l = v;
while (l) {
n = l->next;
- nr_free (l);
+ g_free (l);
l = n;
}
#endif