bt2: Adapt test_message_iterator.py and make it pass
[babeltrace.git] / bindings / python / bt2 / bt2 / native_bt_component_class.i
index 47a446dec93324157e5b14a092104eade4dd36c0..1dfa0110886fa05a225e1d018155d11b67829142 100644 (file)
@@ -719,12 +719,12 @@ bt_py3_exc_to_self_message_iterator_status(void)
        }
 
        if (PyErr_GivenExceptionMatches(exc, py_mod_bt2_exc_stop_type)) {
-               status = BT_MESSAGE_ITERATOR_STATUS_END;
+               status = BT_SELF_MESSAGE_ITERATOR_STATUS_END;
        } else if (PyErr_GivenExceptionMatches(exc, py_mod_bt2_exc_try_again_type)) {
-               status = BT_MESSAGE_ITERATOR_STATUS_AGAIN;
+               status = BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN;
        } else {
                bt2_py_loge_exception();
-               status = BT_MESSAGE_ITERATOR_STATUS_ERROR;
+               status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
        }
 
 end:
@@ -1276,7 +1276,7 @@ bt_py3_component_class_query(
         * (PyLong) containing the address of a BT value object (new
         * reference).
         */
-       *result = (void *) PyLong_AsUnsignedLongLong(py_results_addr);
+       *result = PyLong_AsVoidPtr(py_results_addr);
        BT_ASSERT(!PyErr_Occurred());
        BT_ASSERT(*result);
        goto end;
@@ -1336,10 +1336,11 @@ bt_py3_component_class_message_iterator_init(
                bt_self_component *self_component,
                bt_self_component_port_output *self_component_port_output)
 {
-       bt_self_message_iterator_status status = BT_MESSAGE_ITERATOR_STATUS_OK;
+       bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
        PyObject *py_comp_cls = NULL;
        PyObject *py_iter_cls = NULL;
        PyObject *py_iter_ptr = NULL;
+       PyObject *py_component_port_output_ptr = NULL;
        PyObject *py_init_method_result = NULL;
        PyObject *py_iter = NULL;
        PyObject *py_comp;
@@ -1384,14 +1385,23 @@ bt_py3_component_class_message_iterator_init(
        /*
         * Initialize object:
         *
-        *     py_iter.__init__()
+        *     py_iter.__init__(self_output_port)
+        *
+         * through the _init_for_native helper static method.
         *
         * At this point, py_iter._ptr is set, so this initialization
         * function has access to self._component (which gives it the
         * user Python component object from which the iterator was
         * created).
         */
-       py_init_method_result = PyObject_CallMethod(py_iter, "__init__", NULL);
+        py_component_port_output_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port_output),
+               SWIGTYPE_p_bt_self_component_port_output, 0);
+       if (!py_component_port_output_ptr) {
+               BT_LOGE_STR("Failed to create a SWIG pointer object.");
+               goto error;
+       }
+
+       py_init_method_result = PyObject_CallMethod(py_iter, "_init_from_native", "O", py_component_port_output_ptr);
        if (!py_init_method_result) {
                BT_LOGE_STR("User's __init__() method failed.");
                bt2_py_loge_exception();
@@ -1441,6 +1451,7 @@ end:
        Py_XDECREF(py_comp_cls);
        Py_XDECREF(py_iter_cls);
        Py_XDECREF(py_iter_ptr);
+       Py_XDECREF(py_component_port_output_ptr);
        Py_XDECREF(py_init_method_result);
        Py_XDECREF(py_iter);
        return status;
@@ -1501,7 +1512,7 @@ bt_py3_component_class_message_iterator_next(
                        bt_message_array_const msgs, uint64_t capacity,
                        uint64_t *count)
 {
-       bt_self_message_iterator_status status = BT_MESSAGE_ITERATOR_STATUS_OK;
+       bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
        PyObject *py_message_iter = bt_self_message_iterator_get_data(message_iterator);
        PyObject *py_method_result = NULL;
 
@@ -1519,9 +1530,7 @@ bt_py3_component_class_message_iterator_next(
         * (PyLong) containing the address of a native message
         * object (which is now ours).
         */
-       msgs[0] =
-               (const bt_message *) PyLong_AsUnsignedLongLong(
-                       py_method_result);
+       msgs[0] = PyLong_AsVoidPtr(py_method_result);
        *count = 1;
 
        /* Clear potential overflow error; should never happen */
This page took 0.024068 seconds and 4 git commands to generate.