X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fvariant.c;h=4f1e524ba608b4f0b3853ae7735fa0c2371f914f;hp=bb4faa17093a87ec0266f7f08349922037105e1b;hb=dd0365d91cfb990cf39c2c9ce50bb73423b6041e;hpb=01c76b246be85b5d9c8e99813950fb194c9f714f diff --git a/types/variant.c b/types/variant.c index bb4faa17..4f1e524b 100644 --- a/types/variant.c +++ b/types/variant.c @@ -16,10 +16,19 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include #include +#include #include static @@ -89,8 +98,9 @@ void _variant_declaration_free(struct declaration *declaration) struct declaration_variant *variant_declaration = container_of(declaration, struct declaration_variant, p); - _untagged_variant_declaration_free(&variant_declaration->untagged_variant->p); + declaration_unref(&variant_declaration->untagged_variant->p); g_array_free(variant_declaration->tag_name, TRUE); + g_free(variant_declaration); } struct declaration_variant * @@ -104,7 +114,7 @@ struct declaration_variant * variant_declaration->untagged_variant = untagged_variant; declaration_ref(&untagged_variant->p); variant_declaration->tag_name = g_array_new(FALSE, TRUE, sizeof(GQuark)); - append_scope_path(tag, variant_declaration->tag_name); + bt_append_scope_path(tag, variant_declaration->tag_name); declaration->id = CTF_TYPE_VARIANT; declaration->alignment = 1; declaration->declaration_free = _variant_declaration_free; @@ -243,6 +253,7 @@ void _variant_definition_free(struct definition *definition) definition_unref(variant->enum_tag); free_definition_scope(variant->p.scope); declaration_unref(variant->p.declaration); + g_ptr_array_free(variant->fields, TRUE); g_free(variant); } @@ -273,11 +284,18 @@ void untagged_variant_declaration_add_field(struct declaration_untagged_variant struct declaration_field * untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag) { - unsigned long index; + gpointer index; + gboolean found; - index = (unsigned long) g_hash_table_lookup(untagged_variant_declaration->fields_by_tag, - (gconstpointer) (unsigned long) tag); - return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, index); + found = g_hash_table_lookup_extended( + untagged_variant_declaration->fields_by_tag, + (gconstpointer) (unsigned long) tag, NULL, &index); + + if (!found) { + return NULL; + } + + return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, (unsigned long)index); } /*