Is it possible to initialise a ptr to NULL from the python side when dealing with SWIG module?
For example, say I have wrapped a struct track_t in a swig module m (_m.so), I can create a pointer to the struct from python as follows:
import m
track = m.track_t()
this will just malloc a track_t for me in the appropriate wrapper function.
I would however like to be able to achieve the following:
track_t *track = NULL;
But in python rather than C, e.g. initialise a pointer to NULL from the python side
I need to do this as it is a requirement of the hash table C implementation I am using that new hash tables start with a NULL pointer
I could write a helper function, say, track_t* create_null_track()
that returns a NULL pointer but thought there may be a simpler way?
EDIT:
I can confirm that the helper function works but I would expect there to be a built in way of doing this as requiring a NULL pointer would seem a common requirement
helper function is as simple as:
track_t* create_null_track(void)
{
return NULL;
}
not sure that the return type information specified in the function is necessary so a more generic approach could be:
void* get_null(void)
{
return NULL;
}
perhaps?
Just use None
from python to represent a null value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With