Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rosidl_generator_py/resource/_idl_pkg_typesupport_entry_point.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ include_directives = set()
register_functions = []
}@
#include <Python.h>
#include <string.h>

// Convert a function pointer to void * via memcpy for use with PyCapsule_New().
static inline void *
_funcptr_to_capsule_ptr(void (* fn)(void))
{
_Static_assert(
sizeof(void *) == sizeof(fn),
"void * and function pointer must have the same size");
void * ptr;
memcpy(&ptr, &fn, sizeof(ptr));
return ptr;
}

static PyMethodDef @(package_name)__methods[] = {
{NULL, NULL, 0, NULL} /* sentinel */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function_names = ['create_ros_message', 'destroy_ros_message', 'convert_from_py'
PyObject * pyobject_@(function_name) = NULL;
pyobject_@(function_name) = PyCapsule_New(
@[ if function_name != 'type_support']@
(void *)&@('__'.join(message.structure.namespaced_type.namespaces + [module_name]))__@(function_name),
_funcptr_to_capsule_ptr((void (*)(void)) & @('__'.join(message.structure.namespaced_type.namespaces + [module_name]))__@(function_name)),
@[ else]@
(void *)ROSIDL_GET_MSG_TYPE_SUPPORT(@(', '.join(message.structure.namespaced_type.namespaced_name()))),
@[ end if]@
Expand Down