Re: g_value_new Macro?



On Thu, 2004-26-08 at 15:59 +0800, James Henstridge wrote:
> On 26/08/04 14:22, Ryan McDougall wrote:

> 
> Also, your macro looks like it might break sometimes.  The 
> g_value_init() function expects the GValue to be zeroed out (the type 
> field at a minimum), and g_new() doesn't guarantee this.  replacing it 
> with g_new0() would fix this problem.

I spotted where the docs say it must be zero init'd, but I can't see in
the source *why* thats needed. I guess so you don't call init on a value
that has already been init'd without calling reset first.

Perhaps its my ignorance of GValue, why is memory allocation GValue's
problem, thus necessitating an unset function. Shouldn't I dealloc my
own pointers?

> 
> If you are doing this for your tutorial, it would probably be better to 
> document the common usage of GValues rather than using a non standard 
> g_value_new() macro.

For some internal code, I prefer to pass a heap allocated GValue pointer
to some unnecessary copies of stack alloc'd GValues, so I use it outside
of the tutorial (which can be changed). Basically I don't see any reason
*not* to add it once the g_new0 bug is fixed.

> 
> James.
> 

Thanks James!

Cheers,
Ryan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]