mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
Added g_alloca, g_new_a, g_new0_a macros.
This commit is contained in:
parent
ab114d33f7
commit
81224ac5ac
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 2 19:52:45 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
|
* glib.h, testglib.c:
|
||||||
|
Added g_alloca, g_new_a, g_new0_a macros.
|
||||||
|
|
||||||
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
Sat Jan 2 16:45:44 EST 1999 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
|
||||||
* testglib.c: Added g_strdup_printf check.
|
* testglib.c: Added g_strdup_printf check.
|
||||||
|
10
glib.h
10
glib.h
@ -301,6 +301,16 @@ extern "C" {
|
|||||||
((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
|
((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
|
||||||
#endif /* __DMALLOC_H__ */
|
#endif /* __DMALLOC_H__ */
|
||||||
|
|
||||||
|
/* alloca-based counterparts of the above routines */
|
||||||
|
#if G_HAVE_ALLOCA
|
||||||
|
# define g_alloca alloca
|
||||||
|
# define g_new_a(type, count) \
|
||||||
|
((type *) alloca ((unsigned) sizeof (type) * (count)))
|
||||||
|
# define g_new0_a(type, count) \
|
||||||
|
((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \
|
||||||
|
((unsigned) sizeof (type) * (count))))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
||||||
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
||||||
sizeof (type), \
|
sizeof (type), \
|
||||||
|
10
glib/glib.h
10
glib/glib.h
@ -301,6 +301,16 @@ extern "C" {
|
|||||||
((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
|
((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
|
||||||
#endif /* __DMALLOC_H__ */
|
#endif /* __DMALLOC_H__ */
|
||||||
|
|
||||||
|
/* alloca-based counterparts of the above routines */
|
||||||
|
#if G_HAVE_ALLOCA
|
||||||
|
# define g_alloca alloca
|
||||||
|
# define g_new_a(type, count) \
|
||||||
|
((type *) alloca ((unsigned) sizeof (type) * (count)))
|
||||||
|
# define g_new0_a(type, count) \
|
||||||
|
((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \
|
||||||
|
((unsigned) sizeof (type) * (count))))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
||||||
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
||||||
sizeof (type), \
|
sizeof (type), \
|
||||||
|
34
testglib.c
34
testglib.c
@ -42,6 +42,11 @@ else \
|
|||||||
#define GLIB_TEST_STRING "el dorado "
|
#define GLIB_TEST_STRING "el dorado "
|
||||||
#define GLIB_TEST_STRING_5 "el do"
|
#define GLIB_TEST_STRING_5 "el do"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
guint age;
|
||||||
|
gchar name[40];
|
||||||
|
} GlibTestInfo;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
node_build_string (GNode *node,
|
node_build_string (GNode *node,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -294,6 +299,7 @@ main (int argc,
|
|||||||
GRelation *relation;
|
GRelation *relation;
|
||||||
GTuples *tuples;
|
GTuples *tuples;
|
||||||
gint data [1024];
|
gint data [1024];
|
||||||
|
GlibTestInfo *gti;
|
||||||
struct {
|
struct {
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
gchar *dirname;
|
gchar *dirname;
|
||||||
@ -905,6 +911,34 @@ main (int argc,
|
|||||||
g_print ("ok\n");
|
g_print ("ok\n");
|
||||||
|
|
||||||
#ifdef G_HAVE_ALLOCA
|
#ifdef G_HAVE_ALLOCA
|
||||||
|
g_print ("checking alloca()-based allocation routines...");
|
||||||
|
|
||||||
|
string = g_alloca(80);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
for (i = 0; i < 80; i++)
|
||||||
|
string[i] = 'x';
|
||||||
|
string[79] = 0;
|
||||||
|
g_assert(strlen(string) == 79);
|
||||||
|
|
||||||
|
gti = g_new_a(GlibTestInfo, 2);
|
||||||
|
string = g_alloca(2);
|
||||||
|
strcpy(string, "x");
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
for (j = 0; j < 40; j++)
|
||||||
|
gti[i].name[j] = 'x';
|
||||||
|
gti[i].name[39] = 0;
|
||||||
|
g_assert(strlen(gti[i].name) == 39);
|
||||||
|
gti[i].age = 42;
|
||||||
|
}
|
||||||
|
g_assert(strcmp(string, "x") == 0);
|
||||||
|
|
||||||
|
string = g_new0_a(char, 40);
|
||||||
|
for (i = 0; i < 39; i++)
|
||||||
|
string[i] = 'x';
|
||||||
|
g_assert(strlen(string) == 39);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
g_print ("checking alloca()-based string duplication routines...");
|
g_print ("checking alloca()-based string duplication routines...");
|
||||||
|
|
||||||
g_strdup_a(string, GLIB_TEST_STRING);
|
g_strdup_a(string, GLIB_TEST_STRING);
|
||||||
|
@ -42,6 +42,11 @@ else \
|
|||||||
#define GLIB_TEST_STRING "el dorado "
|
#define GLIB_TEST_STRING "el dorado "
|
||||||
#define GLIB_TEST_STRING_5 "el do"
|
#define GLIB_TEST_STRING_5 "el do"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
guint age;
|
||||||
|
gchar name[40];
|
||||||
|
} GlibTestInfo;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
node_build_string (GNode *node,
|
node_build_string (GNode *node,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -294,6 +299,7 @@ main (int argc,
|
|||||||
GRelation *relation;
|
GRelation *relation;
|
||||||
GTuples *tuples;
|
GTuples *tuples;
|
||||||
gint data [1024];
|
gint data [1024];
|
||||||
|
GlibTestInfo *gti;
|
||||||
struct {
|
struct {
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
gchar *dirname;
|
gchar *dirname;
|
||||||
@ -905,6 +911,34 @@ main (int argc,
|
|||||||
g_print ("ok\n");
|
g_print ("ok\n");
|
||||||
|
|
||||||
#ifdef G_HAVE_ALLOCA
|
#ifdef G_HAVE_ALLOCA
|
||||||
|
g_print ("checking alloca()-based allocation routines...");
|
||||||
|
|
||||||
|
string = g_alloca(80);
|
||||||
|
g_assert(string != NULL);
|
||||||
|
for (i = 0; i < 80; i++)
|
||||||
|
string[i] = 'x';
|
||||||
|
string[79] = 0;
|
||||||
|
g_assert(strlen(string) == 79);
|
||||||
|
|
||||||
|
gti = g_new_a(GlibTestInfo, 2);
|
||||||
|
string = g_alloca(2);
|
||||||
|
strcpy(string, "x");
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
for (j = 0; j < 40; j++)
|
||||||
|
gti[i].name[j] = 'x';
|
||||||
|
gti[i].name[39] = 0;
|
||||||
|
g_assert(strlen(gti[i].name) == 39);
|
||||||
|
gti[i].age = 42;
|
||||||
|
}
|
||||||
|
g_assert(strcmp(string, "x") == 0);
|
||||||
|
|
||||||
|
string = g_new0_a(char, 40);
|
||||||
|
for (i = 0; i < 39; i++)
|
||||||
|
string[i] = 'x';
|
||||||
|
g_assert(strlen(string) == 39);
|
||||||
|
|
||||||
|
g_print ("ok\n");
|
||||||
|
|
||||||
g_print ("checking alloca()-based string duplication routines...");
|
g_print ("checking alloca()-based string duplication routines...");
|
||||||
|
|
||||||
g_strdup_a(string, GLIB_TEST_STRING);
|
g_strdup_a(string, GLIB_TEST_STRING);
|
||||||
|
Loading…
Reference in New Issue
Block a user