>>>>> "B" == Bill Tj <billtj / glue.umd.edu> writes:

B>     sval = ALLOC(type),\
B>     memset(sval, 0, sizeof(type)),\

[...]

B>     typedef struct
B>     {
B>         struct_A *data1;
B>         struct_B *data2;
B>     } struct_C;

[...]

B> out-of-memory.  The only way to solve the ALLOC problem is to do
B> "double-initialization":

B>     ....
B>     ptr = ALLOC (struct_C);
B>     ptr-> data1 = NULL;
B>     ptr-> data2 = NULL;    /* or just use one memset when it is proper

pigeon% cat aa.c
#include "ruby.h"

typedef struct
{
    int *x;
} struct_A;

typedef struct
{
    int *x;
} struct_B;

typedef struct
{
    struct_A *data1;
    struct_B *data2;
} struct_C;

void Init_aa() 
{
    struct_C *c;
    VALUE res = Data_Make_Struct(rb_cObject, struct_C, 0, free, c);
    if (c->data1 == NULL) {
        rb_warn("c->data1 is NULL");
    }
    if (c->data2 == NULL) {
        rb_warn("c->data2 is NULL");
    }
}
pigeon% 

pigeon% ruby -raa -e 1
warning: c->data1 is NULL
warning: c->data2 is NULL
pigeon% 


Guy Decoux