Skip to content

Commit 5cc39f3

Browse files
Enable capability to build with -Wpedantic.
1 parent a7e5455 commit 5cc39f3

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

rosidl_generator_py/resource/_idl_pkg_typesupport_entry_point.c.em

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ include_directives = set()
2121
register_functions = []
2222
}@
2323
#include <Python.h>
24+
#include <string.h>
25+
26+
// Convert a function pointer to void * via memcpy for use with PyCapsule_New().
27+
static inline void *
28+
_funcptr_to_capsule_ptr(void (* fn)(void))
29+
{
30+
_Static_assert(
31+
sizeof(void *) == sizeof(fn),
32+
"void * and function pointer must have the same size");
33+
void * ptr;
34+
memcpy(&ptr, &fn, sizeof(ptr));
35+
return ptr;
36+
}
2437

2538
static PyMethodDef @(package_name)__methods[] = {
2639
{NULL, NULL, 0, NULL} /* sentinel */

rosidl_generator_py/resource/_msg_pkg_typesupport_entry_point.c.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function_names = ['create_ros_message', 'destroy_ros_message', 'convert_from_py'
7474
PyObject * pyobject_@(function_name) = NULL;
7575
pyobject_@(function_name) = PyCapsule_New(
7676
@[ if function_name != 'type_support']@
77-
(void *)&@('__'.join(message.structure.namespaced_type.namespaces + [module_name]))__@(function_name),
77+
_funcptr_to_capsule_ptr((void (*)(void)) & @('__'.join(message.structure.namespaced_type.namespaces + [module_name]))__@(function_name)),
7878
@[ else]@
7979
(void *)ROSIDL_GET_MSG_TYPE_SUPPORT(@(', '.join(message.structure.namespaced_type.namespaced_name()))),
8080
@[ end if]@

0 commit comments

Comments
 (0)