+ Data_Get_Notmuch_Object ((obj), ¬much_rb_tags_type, (ptr))
+
+typedef struct {
+ void *nm_object;
+} notmuch_rb_object_t;
+
+static inline void *
+notmuch_rb_object_create (void *nm_object, const char *name)
+{
+ notmuch_rb_object_t *rb_wrapper = talloc_named_const (NULL, sizeof (*rb_wrapper), name);
+
+ if (RB_UNLIKELY (!rb_wrapper))
+ return NULL;
+
+ rb_wrapper->nm_object = nm_object;
+ talloc_steal (rb_wrapper, nm_object);
+ return rb_wrapper;
+}
+
+static inline void
+notmuch_rb_object_free (void *rb_wrapper)
+{
+ talloc_free (rb_wrapper);
+}
+
+static inline void
+notmuch_rb_object_destroy (VALUE rb_object, const rb_data_type_t *type)
+{
+ notmuch_rb_object_t *rb_wrapper;
+
+ Data_Get_Notmuch_Rb_Object (rb_object, type, rb_wrapper);
+
+ /* Call the corresponding notmuch_*_destroy function */
+ ((void (*)(void *)) type->data) (rb_wrapper->nm_object);
+ notmuch_rb_object_free (rb_wrapper);
+ DATA_PTR (rb_object) = NULL;
+}