We basically steal all the objects from their notmuch parents, therefore
they are completely under Ruby's gc control.
The order at which these objects are freed does not matter any more,
because destroying the database does not destroy all the children
objects, since they belong to Ruby now.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
ret = notmuch_database_open (path, mode, &database);
notmuch_rb_status_raise (ret);
ret = notmuch_database_open (path, mode, &database);
notmuch_rb_status_raise (ret);
- DATA_PTR (self) = notmuch_rb_object_create (database);
+ DATA_PTR (self) = notmuch_rb_object_create (database, "notmuch_rb_database");
#include <notmuch.h>
#include <ruby.h>
#include <notmuch.h>
#include <ruby.h>
extern VALUE notmuch_rb_cDatabase;
extern VALUE notmuch_rb_cDirectory;
extern VALUE notmuch_rb_cDatabase;
extern VALUE notmuch_rb_cDirectory;
} while (0)
#define Data_Wrap_Notmuch_Object(klass, type, ptr) \
} while (0)
#define Data_Wrap_Notmuch_Object(klass, type, ptr) \
- TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr)))
+ TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr), "notmuch_rb_object: " __location__))
#define Data_Get_Notmuch_Database(obj, ptr) \
Data_Get_Notmuch_Object ((obj), ¬much_rb_database_type, (ptr))
#define Data_Get_Notmuch_Database(obj, ptr) \
Data_Get_Notmuch_Object ((obj), ¬much_rb_database_type, (ptr))
} notmuch_rb_object_t;
static inline void *
} notmuch_rb_object_t;
static inline void *
-notmuch_rb_object_create (void *nm_object)
+notmuch_rb_object_create (void *nm_object, const char *name)
- notmuch_rb_object_t *rb_wrapper = malloc (sizeof (*rb_wrapper));
+ 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;
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)
{
return rb_wrapper;
}
static inline void
notmuch_rb_object_free (void *rb_wrapper)
{
+ talloc_free (rb_wrapper);
}
static inline notmuch_status_t
}
static inline notmuch_status_t
end
$LOCAL_LIBS += ENV['LIBNOTMUCH']
end
$LOCAL_LIBS += ENV['LIBNOTMUCH']
# Create Makefile
dir_config('notmuch')
# Create Makefile
dir_config('notmuch')