X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstring.c;h=e76ac77ae7620def6537f415642ef8375bd9210d;hp=ab0ec72c30da53209355a229bf35aaefbd60867e;hb=c054553dac076f91196b372fa19efaf2adc4e4f9;hpb=8a4035bcbfe691490b031f08533676597f72a4ac diff --git a/types/string.c b/types/string.c index ab0ec72c..e76ac77a 100644 --- a/types/string.c +++ b/types/string.c @@ -3,7 +3,7 @@ * * BabelTrace - String Type Converter * - * Copyright 2010 - Mathieu Desnoyers + * Copyright 2010, 2011 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,12 +20,18 @@ #include #include +static +struct type_string *_string_type_new(struct type_class *type_class, + struct declaration_scope *parent_scope); +static +void _string_type_free(struct type *type); + void string_copy(struct stream_pos *dest, const struct format *fdest, struct stream_pos *src, const struct format *fsrc, - const struct type_class *type_class) + struct type *type) { - struct type_class_string *string_class = - container_of(type_class, struct type_class_string, p); + struct type_string *string = container_of(type, struct type_string, p); + struct type_class_string *string_class = string->_class; if (fsrc->string_copy == fdest->string_copy) { fsrc->string_copy(dest, src, string_class); @@ -38,19 +44,16 @@ void string_copy(struct stream_pos *dest, const struct format *fdest, } } -void string_type_free(struct type_class_string *string_class) -{ - g_free(string_class); -} - -static void _string_type_free(struct type_class *type_class) +static +void _string_type_class_free(struct type_class_string *string_class) { struct type_class_string *string_class = container_of(type_class, struct type_class_string, p); - string_type_free(string_class); + g_free(string_class); } -struct type_class_string *string_type_new(const char *name) +struct type_class_string * +string_type_class_new(const char *name) { struct type_class_string *string_class; int ret; @@ -59,7 +62,9 @@ struct type_class_string *string_type_new(const char *name) string_class->p.name = g_quark_from_string(name); string_class->p.alignment = CHAR_BIT; string_class->p.copy = string_copy; - string_class->p.free = _string_type_free; + string_class->p.class_free = _string_type_class_free; + string_class->p.type_new = _string_type_new; + string_class->p.type_free = _string_type_free; string_class->p.ref = 1; if (string_class->p.name) { ret = register_type(&string_class->p); @@ -70,3 +75,30 @@ struct type_class_string *string_type_new(const char *name) } return string_class; } + +static +struct type_string *_string_type_new(struct type_class *type_class, + struct declaration_scope *parent_scope) +{ + struct type_class_string *string_class = + container_of(type_class, struct type_class_string, p); + struct type_string *string; + + string = g_new(struct type_string, 1); + type_class_ref(&string_class->p); + string->p._class = string_class; + string->p.ref = 1; + string->value = NULL; + return &string->p; +} + +static +void _string_type_free(struct type *type) +{ + struct type_string *string = + container_of(type, struct type_string, p); + + type_class_unref(string->p._class); + g_free(string->value); + g_free(string); +}