Skip to content

Commit

Permalink
Reuse destroy functions
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
  • Loading branch information
ivanpauno committed Feb 14, 2020
1 parent 034da37 commit 3aee070
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ _rclpy_destroy_guard_condition(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_guard_condition failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_guard_condition got NULL pointer");
return;
}

Expand Down Expand Up @@ -183,9 +183,7 @@ rclpy_create_guard_condition(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * gc_handle = _rclpy_create_handle(gc, _rclpy_destroy_guard_condition);
if (!gc_handle) {
ret = rcl_guard_condition_fini(gc);
(void)ret;
PyMem_Free(gc);
_rclpy_destroy_guard_condition(gc);
return NULL;
}
_rclpy_handle_add_dependency(gc_handle, context_handle);
Expand Down Expand Up @@ -639,7 +637,7 @@ _rclpy_destroy_node(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_node failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_node got a NULL pointer");
return;
}

Expand Down Expand Up @@ -757,9 +755,7 @@ rclpy_create_node(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * node_handle = _rclpy_create_handle(node, _rclpy_destroy_node);
if (!node_handle) {
rcl_ret_t ret = rcl_node_fini(node);
(void)ret;
PyMem_Free(node);
_rclpy_destroy_node(node);
return NULL;
}
_rclpy_handle_add_dependency(node_handle, context_handle);
Expand Down Expand Up @@ -1321,7 +1317,7 @@ _rclpy_destroy_publisher(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_publisher failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_publisher got NULL pointer");
return;
}

Expand Down Expand Up @@ -1426,9 +1422,7 @@ rclpy_create_publisher(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * pub_handle = _rclpy_create_handle(pub, _rclpy_destroy_publisher);
if (!pub_handle) {
rcl_ret_t ret = rcl_publisher_fini(&(pub->publisher), pub->node);
(void)ret;
PyMem_Free(pub);
_rclpy_destroy_publisher(pub);
return NULL;
}
_rclpy_handle_add_dependency(pub_handle, node_handle);
Expand Down Expand Up @@ -1527,7 +1521,7 @@ _rclpy_destroy_timer(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_timer failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_timer got NULL pointer");
return;
}

Expand Down Expand Up @@ -1607,9 +1601,7 @@ rclpy_create_timer(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * timer_handle = _rclpy_create_handle(timer, _rclpy_destroy_timer);
if (!timer_handle) {
ret = rcl_timer_fini(timer);
(void)ret;
PyMem_Free(timer);
_rclpy_destroy_timer(timer);
return NULL;
}
_rclpy_handle_add_dependency(timer_handle, context_handle);
Expand Down Expand Up @@ -1941,7 +1933,7 @@ _rclpy_destroy_subscription(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_subscrition failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_subscrition got NULL pointer");
return;
}

Expand Down Expand Up @@ -2050,9 +2042,7 @@ rclpy_create_subscription(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * sub_handle = _rclpy_create_handle(sub, _rclpy_destroy_subscription);
if (!sub_handle) {
ret = rcl_subscription_fini(&(sub->subscription), node);
(void)ret;
PyMem_Free(sub);
_rclpy_destroy_subscription(sub);
return NULL;
}
_rclpy_handle_add_dependency(sub_handle, node_handle);
Expand All @@ -2079,7 +2069,7 @@ _rclpy_destroy_client(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_client failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_client got NULL pointer");
return;
}

Expand Down Expand Up @@ -2185,9 +2175,7 @@ rclpy_create_client(PyObject * Py_UNUSED(self), PyObject * args)
rclpy_handle_t * client_handle = _rclpy_create_handle(
client, _rclpy_destroy_client);
if (!client_handle) {
ret = rcl_client_fini(&(client->client), node);
(void)ret;
PyMem_Free(client);
_rclpy_destroy_client(client);
return NULL;
}
_rclpy_handle_add_dependency(client_handle, node_handle);
Expand Down Expand Up @@ -2254,7 +2242,7 @@ _rclpy_destroy_service(void * p)
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_service failed to get pointer");
PyExc_RuntimeWarning, stack_level, "_rclpy_destroy_service got NULL pointer");
return;
}

Expand Down Expand Up @@ -2361,9 +2349,7 @@ rclpy_create_service(PyObject * Py_UNUSED(self), PyObject * args)

rclpy_handle_t * service_handle = _rclpy_create_handle(srv, _rclpy_destroy_service);
if (!service_handle) {
ret = rcl_service_fini(&(srv->service), node);
(void)ret;
PyMem_Free(srv);
_rclpy_destroy_service(srv);
return NULL;
}
_rclpy_handle_add_dependency(service_handle, node_handle);
Expand Down

0 comments on commit 3aee070

Please sign in to comment.