ir: support optional parameters in bt_ctf_field_type_structure_get_field
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 13 May 2015 18:05:53 +0000 (14:05 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 13 May 2015 18:05:53 +0000 (14:05 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c
tests/lib/test_ctf_writer.c

index 78d0fa0daa6b4b6b14fd8a9445a7126445f94bf3..c03f0b7758f578b81e3c300118f94a9c7c96b34f 100644 (file)
@@ -1207,8 +1207,7 @@ int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *type,
        struct structure_field *field;
        int ret = 0;
 
-       if (!type || index < 0 || !field_name || !field_type ||
-               (type->declaration->id != CTF_TYPE_STRUCT)) {
+       if (!type || index < 0 || (type->declaration->id != CTF_TYPE_STRUCT)) {
                ret = -1;
                goto end;
        }
@@ -1221,9 +1220,13 @@ int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *type,
        }
 
        field = g_ptr_array_index(structure->fields, index);
-       *field_type = field->type;
-       bt_ctf_field_type_get(field->type);
-       *field_name = g_quark_to_string(field->name);
+       if (field_type) {
+               *field_type = field->type;
+               bt_ctf_field_type_get(field->type);
+       }
+       if (field_name) {
+               *field_name = g_quark_to_string(field->name);
+       }
 end:
        return ret;
 }
index 60a51132f209a5727ae164cc7281b6ce427de48a..47096354821fb410730ed8d2c0dfac00d455c41c 100644 (file)
@@ -1072,10 +1072,11 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class,
                &ret_field_type, 0) < 0,
                "bt_ctf_event_class_get_field handles a NULL event class correctly");
        ok(bt_ctf_event_class_get_field(event_class, NULL,
-               &ret_field_type, 0) < 0,
+               &ret_field_type, 0) == 0,
                "bt_ctf_event_class_get_field handles a NULL field name correctly");
+       bt_ctf_field_type_put(ret_field_type);
        ok(bt_ctf_event_class_get_field(event_class, &ret_string,
-               NULL, 0) < 0,
+               NULL, 0) == 0,
                "bt_ctf_event_class_get_field handles a NULL field type correctly");
        ok(bt_ctf_event_class_get_field(event_class, &ret_string,
                &ret_field_type, 42) < 0,
@@ -1980,10 +1981,11 @@ void type_field_tests()
                &ret_string, &returned_type, 1) < 0,
                "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
-               NULL, &returned_type, 1) < 0,
+               NULL, &returned_type, 1) == 0,
                "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
+       bt_ctf_field_type_put(returned_type);
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
-               &ret_string, NULL, 1) < 0,
+               &ret_string, NULL, 1) == 0,
                "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
                &ret_string, &returned_type, 10) < 0,
This page took 0.027485 seconds and 4 git commands to generate.