%rename("%(strip:[bt_])s", %$isvariable) "";
%rename("%(strip:[BT_])s", %$isenumitem) "";
-/* Output argument typemap for string output (always appends) */
-%typemap(in, numinputs=0) (const char **OUT) (char *temp_value) {
+/*
+ * Output argument typemap for string output (always appends)
+ *
+ * We initialize the output parameter `temp_value` to an invalid but non-zero
+ * pointer value. This is to make sure we don't rely on its initial value in
+ * the epilogue (where we call SWIG_Python_str_FromChar). When they fail,
+ * functions on which we apply this typemap don't guarantee that the value of
+ * `temp_value` will be unchanged or valid.
+ */
+%typemap(in, numinputs=0) (const char **OUT) (char *temp_value = (void *) 1) {
$1 = &temp_value;
}
extern void bt_plugin_set_get_ref(const bt_plugin_set *plugin_set);
extern void bt_plugin_set_put_ref(const bt_plugin_set *plugin_set);
+
+/* Helpers */
+
+bt_property_availability bt_plugin_get_version_wrapper(
+ const bt_plugin *plugin, unsigned int *OUT,
+ unsigned int *OUT, unsigned int *OUT, const char **OUT);
+
+%{
+
+/*
+ * This wrapper ensures that when the API function fails, the `*extra` output
+ * parameter is set to NULL. This is necessary because the epilogue of the
+ * "char **OUT" typemap will use that value to make a Python str object. We
+ * can't rely on the initial value of `*extra`, it could point to unreadable
+ * memory.
+ */
+
+bt_property_availability bt_plugin_get_version_wrapper(
+ const bt_plugin *plugin, unsigned int *major,
+ unsigned int *minor, unsigned int *patch, const char **extra)
+{
+ bt_property_availability ret;
+
+ ret = bt_plugin_get_version(plugin, major, minor, patch, extra);
+
+ if (ret == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
+ *extra = NULL;
+ }
+
+ return ret;
+}
+
+%}
@property
def version(self):
- status, major, minor, patch, extra = native_bt.plugin_get_version(self._ptr)
+ status, major, minor, patch, extra = native_bt.plugin_get_version_wrapper(self._ptr)
if status == native_bt.PROPERTY_AVAILABILITY_NOT_AVAILABLE:
return