X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fnative_bt_component.i;fp=bindings%2Fpython%2Fbt2%2Fbt2%2Fnative_bt_component.i;h=f484263ecccad70bd6ff0411fa8a60bc3b237904;hp=6612ad9c2d5e6c1de63c4aa3237d76f533921acc;hb=2e00bc76cf37af167c45253cfc8f8d197222d6b8;hpb=c5f330cd909f5dfbdb519546e875b4427434ba4f diff --git a/bindings/python/bt2/bt2/native_bt_component.i b/bindings/python/bt2/bt2/native_bt_component.i index 6612ad9c..f484263e 100644 --- a/bindings/python/bt2/bt2/native_bt_component.i +++ b/bindings/python/bt2/bt2/native_bt_component.i @@ -62,6 +62,26 @@ } } +/* Typemaps used for user data attached to self component ports. */ + +/* + * The user data Python object is kept as the user data of the port, we pass + * the PyObject pointer directly to the port creation function. + */ +%typemap(in) void *PY_SELF_PORT_USER_DATA { + $1 = $input; +} + +/* + * The port, if created successfully, now owns a reference to the Python object, + * we reflect that here. + */ +%typemap(argout) void *PY_SELF_PORT_USER_DATA { + if (PyLong_AsLong($result) == BT_SELF_COMPONENT_STATUS_OK) { + Py_INCREF($1); + } +} + /* From component-const.h */ extern const char *bt_component_get_name(const bt_component *component); @@ -216,7 +236,7 @@ bt_self_component_source_borrow_output_port_by_index( extern bt_self_component_status bt_self_component_source_add_output_port( bt_self_component_source *self_component, - const char *name, void *user_data, + const char *name, void *PY_SELF_PORT_USER_DATA, bt_self_component_port_output **OUT); /* From self-component-filter.h */ @@ -241,7 +261,7 @@ bt_self_component_filter_borrow_output_port_by_index( extern bt_self_component_status bt_self_component_filter_add_output_port( bt_self_component_filter *self_component, - const char *name, void *data, + const char *name, void *PY_SELF_PORT_USER_DATA, bt_self_component_port_output **OUT); extern bt_self_component_port_input * @@ -257,7 +277,7 @@ bt_self_component_filter_borrow_input_port_by_index( extern bt_self_component_status bt_self_component_filter_add_input_port( bt_self_component_filter *self_component, - const char *name, void *data, + const char *name, void *PY_SELF_PORT_USER_DATA, bt_self_component_port_input **OUT); /* From self-component-sink.h */ @@ -281,5 +301,5 @@ bt_self_component_sink_borrow_input_port_by_index( extern bt_self_component_status bt_self_component_sink_add_input_port( bt_self_component_sink *self_component, - const char *name, void *user_data, + const char *name, void *PY_SELF_PORT_USER_DATA, bt_self_component_port_input **OUT);