Python 3.5 changes the StopIteration exception clearing behaviour when
a generator finishes its iteration. This causes the interpreter to
errounously consider SWIG clean-up functions as having "set an error".
This hack explicitly allocates and cleans up struct bt_iter_pos
instead of relying on SWIG auto-generated code which manages
the lifetime of temporary objects.
An investigation of the cause of this change is under way, but at
least this makes the bindings usable on Python 3.5 which is
being rolled-out in some distros.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
const char *_bt_python_get_sequence_string(struct bt_definition *field);
int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
const char *_bt_python_get_sequence_string(struct bt_definition *field);
int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
+struct bt_iter_pos *_bt_python_create_iter_pos(void);
/* =================================================================
CONTEXT.H, CONTEXT-INTERNAL.H
/* =================================================================
CONTEXT.H, CONTEXT-INTERNAL.H
event after the the generator has gone out of scope may result in a
crash or data corruption.
"""
event after the the generator has gone out of scope may result in a
crash or data corruption.
"""
- begin_pos_ptr = _bt_iter_pos()
- end_pos_ptr = _bt_iter_pos()
+ begin_pos_ptr = _bt_python_create_iter_pos()
+ end_pos_ptr = _bt_python_create_iter_pos()
begin_pos_ptr.type = SEEK_BEGIN
end_pos_ptr.type = SEEK_LAST
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
begin_pos_ptr.type = SEEK_BEGIN
end_pos_ptr.type = SEEK_LAST
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
+ _bt_iter_free_pos(begin_pos_ptr)
+ _bt_iter_free_pos(end_pos_ptr)
+
def events_timestamps(self, timestamp_begin, timestamp_end):
"""
Generator function to iterate over the events of open in the current
TraceCollection from timestamp_begin to timestamp_end.
"""
def events_timestamps(self, timestamp_begin, timestamp_end):
"""
Generator function to iterate over the events of open in the current
TraceCollection from timestamp_begin to timestamp_end.
"""
- begin_pos_ptr = _bt_iter_pos()
- end_pos_ptr = _bt_iter_pos()
+ begin_pos_ptr = _bt_python_create_iter_pos()
+ end_pos_ptr = _bt_python_create_iter_pos()
begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
begin_pos_ptr.u.seek_time = timestamp_begin
end_pos_ptr.u.seek_time = timestamp_end
begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
begin_pos_ptr.u.seek_time = timestamp_begin
end_pos_ptr.u.seek_time = timestamp_end
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
+ _bt_iter_free_pos(begin_pos_ptr)
+ _bt_iter_free_pos(end_pos_ptr)
+
@property
def timestamp_begin(self):
pos_ptr = _bt_iter_pos()
@property
def timestamp_begin(self):
pos_ptr = _bt_iter_pos()
#include "python-complements.h"
#include <babeltrace/ctf-writer/event-types-internal.h>
#include <babeltrace/ctf-writer/event-fields-internal.h>
#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
----------------------------------------------------
/* FILE functions
----------------------------------------------------
+
+/*
+ * 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);
+}
/* ctf writer */
int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
/* ctf writer */
int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
+
+/* iterator */
+struct bt_iter_pos *_bt_python_create_iter_pos(void);