You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently rclpy creates PyCapsule with NULL names. This means if a function is given a PyCapsule containing rcl_client_t * but it expects rcl_node_t * the C code will still attempt to use it as such. If the capsules were given a name at creation then the methods could use the name as a type check when getting the pointer.
PyCapsule_GetPointer accepts a const char *name argument, and it sets a python exception and returns NULL if the name does not match (it uses strcmp() ).
rcl_node_t*node= (rcl_node_t*)PyCapsule_GetPointer(pynode, "rcl_node_t *");
if (!node)
{
// GetPointer already set an exceptionreturnNULL;
}
If the default exception isn't appropriate, PyCapsule_GetPointer is guaranteed to succeed if PyCapsule_IsValid returns true. This can be checked first with custom handling code to run if it returns False.
// PyObject * pynode;if (!PyCapsule_IsValid(pynode, "rcl_node_t *"))
{
// Do something about it
}
The text was updated successfully, but these errors were encountered:
Feature request
Feature description
Currently rclpy creates
PyCapsule
with NULL names. This means if a function is given aPyCapsule
containingrcl_client_t *
but it expectsrcl_node_t *
the C code will still attempt to use it as such. If the capsules were given a name at creation then the methods could use the name as a type check when getting the pointer.Implementation considerations
https://docs.python.org/3/c-api/capsule.html
PyCapsule_New
accepts aconst char *name
argument. It could be given a string like"rcl_node_t *"
.PyCapsule_GetPointer
accepts aconst char *name
argument, and it sets a python exception and returnsNULL
if the name does not match (it usesstrcmp()
).If the default exception isn't appropriate,
PyCapsule_GetPointer
is guaranteed to succeed ifPyCapsule_IsValid
returns true. This can be checked first with custom handling code to run if it returns False.The text was updated successfully, but these errors were encountered: