Skip to content

Commit 297d89b

Browse files
authored
Ref (#175)
* Updates crt native code against new ref-counting APIs
1 parent 5d19b1f commit 297d89b

File tree

9 files changed

+34
-26
lines changed

9 files changed

+34
-26
lines changed

aws-common-runtime/aws-c-common

Submodule aws-c-common updated 181 files

source/io.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PyObject *aws_py_is_alpn_available(PyObject *self, PyObject *args) {
8686
******************************************************************************/
8787

8888
struct event_loop_group_binding {
89-
struct aws_event_loop_group native;
89+
struct aws_event_loop_group *native;
9090

9191
/* Dependencies that must outlive this */
9292
PyObject *shutdown_complete;
@@ -122,7 +122,7 @@ static void s_elg_capsule_destructor(PyObject *elg_capsule) {
122122

123123
/* Must use async cleanup.
124124
* We could deadlock if we ran the synchronous cleanup from an event-loop thread. */
125-
aws_event_loop_group_clean_up_async(&elg_binding->native, s_elg_native_cleanup_complete, elg_binding);
125+
aws_event_loop_group_release(elg_binding->native);
126126
}
127127

128128
PyObject *aws_py_event_loop_group_new(PyObject *self, PyObject *args) {
@@ -141,7 +141,13 @@ PyObject *aws_py_event_loop_group_new(PyObject *self, PyObject *args) {
141141
return PyErr_AwsLastError();
142142
}
143143

144-
if (aws_event_loop_group_default_init(&binding->native, allocator, num_threads)) {
144+
struct aws_shutdown_callback_options shutdown_options = {
145+
.shutdown_callback_fn = s_elg_native_cleanup_complete,
146+
.shutdown_callback_user_data = binding,
147+
};
148+
149+
binding->native = aws_event_loop_group_new_default(allocator, num_threads, &shutdown_options);
150+
if (binding->native == NULL) {
145151
PyErr_SetAwsLastError();
146152
goto elg_init_failed;
147153
}
@@ -158,23 +164,22 @@ PyObject *aws_py_event_loop_group_new(PyObject *self, PyObject *args) {
158164
return capsule;
159165

160166
capsule_new_failed:
161-
aws_event_loop_group_clean_up(&binding->native);
167+
aws_event_loop_group_release(binding->native);
162168
elg_init_failed:
163169
aws_mem_release(allocator, binding);
164170
return NULL;
165171
}
166172

167173
struct aws_event_loop_group *aws_py_get_event_loop_group(PyObject *event_loop_group) {
168-
AWS_PY_RETURN_NATIVE_REF_FROM_BINDING(
169-
event_loop_group, s_capsule_name_elg, "EventLoopGroup", event_loop_group_binding);
174+
AWS_PY_RETURN_NATIVE_FROM_BINDING(event_loop_group, s_capsule_name_elg, "EventLoopGroup", event_loop_group_binding);
170175
}
171176

172177
/*******************************************************************************
173178
* AWS_HOST_RESOLVER
174179
******************************************************************************/
175180

176181
struct host_resolver_binding {
177-
struct aws_host_resolver native;
182+
struct aws_host_resolver *native;
178183

179184
/* Dependencies that must outlive this */
180185
PyObject *event_loop_group;
@@ -184,7 +189,7 @@ static void s_host_resolver_destructor(PyObject *host_resolver_capsule) {
184189
struct host_resolver_binding *host_resolver =
185190
PyCapsule_GetPointer(host_resolver_capsule, s_capsule_name_host_resolver);
186191
assert(host_resolver);
187-
aws_host_resolver_clean_up(&host_resolver->native);
192+
aws_host_resolver_release(host_resolver->native);
188193
Py_DECREF(host_resolver->event_loop_group);
189194
aws_mem_release(aws_py_get_allocator(), host_resolver);
190195
}
@@ -218,7 +223,8 @@ PyObject *aws_py_host_resolver_new_default(PyObject *self, PyObject *args) {
218223

219224
/* From hereon, we need to clean up if errors occur */
220225

221-
if (aws_host_resolver_init_default(&host_resolver->native, allocator, max_hosts, elg)) {
226+
host_resolver->native = aws_host_resolver_new_default(allocator, max_hosts, elg, NULL);
227+
if (host_resolver->native == NULL) {
222228
PyErr_SetAwsLastError();
223229
goto resolver_init_failed;
224230
}
@@ -235,14 +241,14 @@ PyObject *aws_py_host_resolver_new_default(PyObject *self, PyObject *args) {
235241
return capsule;
236242

237243
capsule_new_failed:
238-
aws_host_resolver_clean_up(&host_resolver->native);
244+
aws_host_resolver_release(host_resolver->native);
239245
resolver_init_failed:
240246
aws_mem_release(allocator, host_resolver);
241247
return NULL;
242248
}
243249

244250
struct aws_host_resolver *aws_py_get_host_resolver(PyObject *host_resolver) {
245-
AWS_PY_RETURN_NATIVE_REF_FROM_BINDING(
251+
AWS_PY_RETURN_NATIVE_FROM_BINDING(
246252
host_resolver, s_capsule_name_host_resolver, "HostResolverBase", host_resolver_binding);
247253
}
248254

@@ -375,7 +381,7 @@ static void s_tls_ctx_destructor(PyObject *tls_ctx_capsule) {
375381
struct aws_tls_ctx *tls_ctx = PyCapsule_GetPointer(tls_ctx_capsule, s_capsule_name_tls_ctx);
376382
assert(tls_ctx);
377383

378-
aws_tls_ctx_destroy(tls_ctx);
384+
aws_tls_ctx_release(tls_ctx);
379385
}
380386

381387
PyObject *aws_py_client_tls_ctx_new(PyObject *self, PyObject *args) {
@@ -480,6 +486,8 @@ PyObject *aws_py_client_tls_ctx_new(PyObject *self, PyObject *args) {
480486
return capsule;
481487

482488
capsule_new_failure:
489+
aws_tls_ctx_release(tls_ctx);
490+
483491
ctx_options_failure:
484492
aws_tls_ctx_options_clean_up(&ctx_options);
485493
return NULL;

source/mqtt_client.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
static const char *s_capsule_name_mqtt_client = "aws_mqtt_client";
1010

1111
struct mqtt_client_binding {
12-
struct aws_mqtt_client native;
12+
struct aws_mqtt_client *native;
1313

1414
/* Dependencies that must outlive this */
1515
PyObject *bootstrap;
@@ -21,7 +21,7 @@ static void s_mqtt_python_client_destructor(PyObject *client_capsule) {
2121
struct mqtt_client_binding *client = PyCapsule_GetPointer(client_capsule, s_capsule_name_mqtt_client);
2222
assert(client);
2323

24-
aws_mqtt_client_clean_up(&client->native);
24+
aws_mqtt_client_release(client->native);
2525
Py_DECREF(client->bootstrap);
2626
Py_DECREF(client->tls_ctx);
2727
aws_mem_release(aws_py_get_allocator(), client);
@@ -50,8 +50,8 @@ PyObject *aws_py_mqtt_client_new(PyObject *self, PyObject *args) {
5050
}
5151

5252
/* From hereon, we need to clean up if errors occur */
53-
54-
if (aws_mqtt_client_init(&client->native, allocator, bootstrap)) {
53+
client->native = aws_mqtt_client_new(allocator, bootstrap);
54+
if (client->native == NULL) {
5555
PyErr_SetAwsLastError();
5656
goto client_init_failed;
5757
}
@@ -70,12 +70,12 @@ PyObject *aws_py_mqtt_client_new(PyObject *self, PyObject *args) {
7070
return capsule;
7171

7272
capsule_new_failed:
73-
aws_mqtt_client_clean_up(&client->native);
73+
aws_mqtt_client_release(client->native);
7474
client_init_failed:
7575
aws_mem_release(allocator, client);
7676
return NULL;
7777
}
7878

7979
struct aws_mqtt_client *aws_py_get_mqtt_client(PyObject *mqtt_client) {
80-
AWS_PY_RETURN_NATIVE_REF_FROM_BINDING(mqtt_client, s_capsule_name_mqtt_client, "Client", mqtt_client_binding);
80+
AWS_PY_RETURN_NATIVE_FROM_BINDING(mqtt_client, s_capsule_name_mqtt_client, "Client", mqtt_client_binding);
8181
}

source/mqtt_client_connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct mqtt_connection_binding {
5555
};
5656

5757
static void s_mqtt_python_connection_finish_destruction(struct mqtt_connection_binding *py_connection) {
58-
aws_mqtt_client_connection_destroy(py_connection->native);
58+
aws_mqtt_client_connection_release(py_connection->native);
5959

6060
Py_DECREF(py_connection->self_proxy);
6161
Py_DECREF(py_connection->client);
@@ -230,7 +230,7 @@ PyObject *aws_py_mqtt_client_connection_new(PyObject *self, PyObject *args) {
230230
proxy_new_failed:
231231
use_websockets_failed:
232232
set_interruption_failed:
233-
aws_mqtt_client_connection_destroy(py_connection->native);
233+
aws_mqtt_client_connection_release(py_connection->native);
234234
connection_new_failed:
235235
aws_mem_release(allocator, py_connection);
236236
return NULL;

0 commit comments

Comments
 (0)