const struct callshapes *shapes =
(const struct callshapes *) keyword_value;
*/
- struct callshapes shapes;
- shapes.keyword = tp->string; /* XXX storage duration? */
- shapes.keyword_len = strlen (tp->string);
- shapes.nshapes = 1;
- shapes.shapes[0].argnum1 = 1;
- shapes.shapes[0].argnum2 = 0;
- shapes.shapes[0].argnumc = 0;
- shapes.shapes[0].argnum1_glib_context = false;
- shapes.shapes[0].argnum2_glib_context = false;
- shapes.shapes[0].argtotal = 0;
- string_list_init (&shapes.shapes[0].xcomments);
+ /* Allocating a 'struct callshapes' on the stack requires
+ a union. */
+ union
+ {
+ struct callshapes _main;
+ char room[FLEXSIZEOF (struct callshapes,
+ shapes, 1 * sizeof (struct callshape))];
+ } u;
+ #define simple_shapes u._main
+ simple_shapes.keyword = tp->string; /* XXX storage duration? */
+ simple_shapes.keyword_len = strlen (tp->string);
+ simple_shapes.nshapes = 1;
+ simple_shapes.shapes[0].argnum1 = 1;
+ simple_shapes.shapes[0].argnum2 = 0;
+ simple_shapes.shapes[0].argnumc = 0;
+ simple_shapes.shapes[0].argnum1_glib_context = false;
+ simple_shapes.shapes[0].argnum2_glib_context = false;
+ simple_shapes.shapes[0].argtotal = 0;
+ string_list_init (&simple_shapes.shapes[0].xcomments);
{
/* Extract a possible string from the key. Before proceeding
token_type_rbrace, true,
false, false, false,
null_context_region (), context_iter,
- 1, arglist_parser_alloc (xp->mlp, &shapes)))
+ 1, arglist_parser_alloc (xp->mlp, &simple_shapes)))
return;
}
}
+ #undef simple_shapes
}
else
{
if (hash_find_entry (table, keyword, keyword_len, &old_value))
{
/* Create a one-element 'struct callshapes'. */
- struct callshapes *shapes = XMALLOC (struct callshapes);
+ struct callshapes *shapes =
+ (struct callshapes *)
+ xmalloc (FLEXSIZEOF (struct callshapes, shapes,
+ 1 * sizeof (struct callshape)));
shapes->nshapes = 1;
shapes->shapes[0] = *shape;
keyword =
/* Replace the existing 'struct callshapes' with a new one. */
struct callshapes *shapes =
(struct callshapes *)
- xmalloc (xsum (sizeof (struct callshapes),
- xtimes (old_shapes->nshapes,
- sizeof (struct callshape))));
+ xmalloc (FLEXSIZEOF (struct callshapes, shapes,
+ xtimes (old_shapes->nshapes + 1,
+ sizeof (struct callshape))));
shapes->keyword = old_shapes->keyword;
shapes->keyword_len = old_shapes->keyword_len;
#include <stdbool.h>
#include <stddef.h>
+#include "flexmember.h"
#include "str-list.h"
#include "mem-hash-map.h"
const char *keyword; /* the keyword, not NUL terminated */
size_t keyword_len; /* the keyword's length */
size_t nshapes;
- struct callshape shapes[1]; /* actually nshapes elements */
+ struct callshape shapes[FLEXIBLE_ARRAY_MEMBER]; /* nshapes elements */
};
/* Insert a (keyword, callshape) pair into a hash table mapping keyword to