*/
#include "python-complements.h"
+#include <babeltrace/ctf-writer/event-types-internal.h>
+#include <babeltrace/ctf-writer/event-fields-internal.h>
+#include <babeltrace/iterator.h>
+#include <glib.h>
/* FILE functions
----------------------------------------------------
/* ctf-field-list */
struct bt_definition **_bt_python_field_listcaller(
const struct bt_ctf_event *ctf_event,
- const struct bt_definition *scope)
+ const struct bt_definition *scope,
+ unsigned int *len)
{
struct bt_definition **list;
- unsigned int count;
int ret;
ret = bt_ctf_get_field_list(ctf_event, scope,
- (const struct bt_definition * const **)&list, &count);
+ (const struct bt_definition * const **)&list, len);
if (ret < 0) /* For python to know an error occured */
list = NULL;
- else /* For python to know the end is reached */
- list[count] = NULL;
return list;
}
/* event_decl_list */
struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
- int handle_id, struct bt_context *ctx)
+ int handle_id,
+ struct bt_context *ctx,
+ unsigned int *len)
{
struct bt_ctf_event_decl **list;
- unsigned int count;
int ret;
ret = bt_ctf_get_event_decl_list(handle_id, ctx,
- (struct bt_ctf_event_decl * const **)&list, &count);
+ (struct bt_ctf_event_decl * const **)&list, len);
if (ret < 0) /* For python to know an error occured */
list = NULL;
- else /* For python to know the end is reached */
- list[count] = NULL;
return list;
}
/* decl_fields */
struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
struct bt_ctf_event_decl *event_decl,
- enum bt_ctf_scope scope)
+ enum bt_ctf_scope scope,
+ unsigned int *len)
{
struct bt_ctf_field_decl **list;
- unsigned int count;
int ret;
ret = bt_ctf_get_decl_fields(event_decl, scope,
- (const struct bt_ctf_field_decl * const **)&list, &count);
+ (const struct bt_ctf_field_decl * const **)&list, len);
if (ret < 0) /* For python to know an error occured */
list = NULL;
- else /* For python to know the end is reached */
- list[count] = NULL;
return list;
}
return array;
}
+struct bt_declaration *_bt_python_get_array_element_declaration(
+ struct bt_declaration *field)
+{
+ struct declaration_array *array_decl;
+ struct bt_declaration *ret = NULL;
+
+ if (!field) {
+ goto end;
+ }
+
+ array_decl = container_of(field, struct declaration_array, p);
+ ret = array_decl->elem;
+end:
+ return ret;
+}
+
+struct bt_declaration *_bt_python_get_sequence_element_declaration(
+ struct bt_declaration *field)
+{
+ struct declaration_sequence *sequence_decl;
+ struct bt_declaration *ret = NULL;
+
+ if (!field) {
+ goto end;
+ }
+
+ sequence_decl = container_of(field, struct declaration_sequence, p);
+ ret = sequence_decl->elem;
+end:
+ return ret;
+}
+
+const char *_bt_python_get_array_string(struct bt_definition *field)
+{
+ struct definition_array *array;
+ const char *ret = NULL;
+
+ if (!field) {
+ goto end;
+ }
+
+ array = container_of(field, struct definition_array, p);
+ ret = array->string->str;
+end:
+ return ret;
+}
+
+const char *_bt_python_get_sequence_string(struct bt_definition *field)
+{
+ struct definition_sequence *sequence;
+ const char *ret = NULL;
+
+ if (!field) {
+ goto end;
+ }
+
+ sequence = container_of(field, struct definition_sequence, p);
+ ret = sequence->string->str;
+end:
+ return ret;
+}
+
struct definition_sequence *_bt_python_get_sequence_from_def(
struct bt_definition *field)
{
return NULL;
}
+
+int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field)
+{
+ int ret;
+
+ if (!field || field->type->declaration->id != CTF_TYPE_INTEGER) {
+ ret = -1;
+ goto end;
+ }
+
+ const struct bt_ctf_field_type_integer *type = container_of(field->type,
+ const struct bt_ctf_field_type_integer, parent);
+ ret = type->declaration.signedness;
+end:
+ return ret;
+}
+
+enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field)
+{
+ enum ctf_type_id type_id = CTF_TYPE_UNKNOWN;
+
+ if (!field) {
+ goto end;
+ }
+
+ type_id = field->type->declaration->id;
+end:
+ return type_id;
+}
+
+/*
+ * Python 3.5 changes the StopIteration exception clearing behaviour which
+ * erroneously marks swig clean-up function as having failed. This explicit
+ * allocation function is intended as a work-around so SWIG doesn't manage
+ * the lifetime of a "temporary" object by itself.
+ */
+struct bt_iter_pos *_bt_python_create_iter_pos(void)
+{
+ return g_new0(struct bt_iter_pos, 1);
+}