Skip to content

Commit

Permalink
wip test
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Aug 26, 2024
1 parent 70de9df commit d2b0b27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void s_on_stream_complete(struct aws_http_stream *native_stream, int erro
}

/* DECREF python self, we don't need to force it to stay alive any longer. */
Py_DECREF(PyWeakref_GetObject(stream->self_proxy));
Py_XDECREF(stream->self_proxy);

PyGILState_Release(state);
/*************** GIL RELEASE ***************/
Expand Down
27 changes: 20 additions & 7 deletions source/mqtt_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ static void s_on_connection_success(
return; /* Python has shut down. Nothing matters anymore, but don't crash */
}

PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = Py_None;
#if PY_VERSION_HEX >= 0x030D0000 // Check if Python version is 3.13 or higher
if (PyWeakref_GetRef(py_connection->self_proxy, &self) < 0) { /* strong reference */
PyErr_WriteUnraisable(PyErr_Occurred());
goto on_done;
}
#else
/* PyWeakref_GetObject is deprecated since python 3.13 */
PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
#endif

if (self != Py_None) {
PyObject *success_result =
PyObject_CallMethod(self, "_on_connection_success", "(iN)", return_code, PyBool_FromLong(session_present));
Expand All @@ -150,7 +160,10 @@ static void s_on_connection_success(
PyErr_WriteUnraisable(PyErr_Occurred());
}
}

#if PY_VERSION_HEX >= 0x030D0000
Py_DECREF(self);
#endif
on_done:
PyGILState_Release(state);
}

Expand All @@ -167,7 +180,7 @@ static void s_on_connection_failure(struct aws_mqtt_client_connection *connectio
return; /* Python has shut down. Nothing matters anymore, but don't crash */
}

PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = Py_None; // PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
if (self != Py_None) {
PyObject *success_result = PyObject_CallMethod(self, "_on_connection_failure", "(i)", error_code);
if (success_result) {
Expand All @@ -194,7 +207,7 @@ static void s_on_connection_interrupted(struct aws_mqtt_client_connection *conne
}

/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = Py_None; // PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
if (self != Py_None) {
PyObject *result = PyObject_CallMethod(self, "_on_connection_interrupted", "(i)", error_code);
if (result) {
Expand Down Expand Up @@ -227,7 +240,7 @@ static void s_on_connection_resumed(
}

/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = Py_None; // PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
if (self != Py_None) {
PyObject *result =
PyObject_CallMethod(self, "_on_connection_resumed", "(iN)", return_code, PyBool_FromLong(session_present));
Expand Down Expand Up @@ -258,7 +271,7 @@ static void s_on_connection_closed(

struct mqtt_connection_binding *py_connection = userdata;
/* Ensure that python class is still alive */
PyObject *self = PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
PyObject *self = Py_None; // PyWeakref_GetObject(py_connection->self_proxy); /* borrowed reference */
if (self != Py_None) {
PyObject *result = PyObject_CallMethod(self, "_on_connection_closed", "()");
if (result) {
Expand Down Expand Up @@ -535,7 +548,7 @@ static void s_ws_handshake_transform(
}

/* Ensure python mqtt connection object is still alive */
PyObject *connection_py = PyWeakref_GetObject(connection_binding->self_proxy); /* borrowed reference */
PyObject *connection_py = Py_None; // PyWeakref_GetObject(connection_binding->self_proxy); /* borrowed reference */
if (connection_py == Py_None) {
aws_raise_error(AWS_ERROR_INVALID_STATE);
goto done;
Expand Down

0 comments on commit d2b0b27

Please sign in to comment.