[Vala] Simple Memory Management Issue
- From: Joseph Montanez <jmontanez gorilla3d com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Simple Memory Management Issue
- Date: Tue, 16 Aug 2011 06:53:34 -0700
I've been trying to get this to work but it keeps crashing :\. I don't
think I understand the memory model here.. "PlugPlug* plugin" is
suppose to allow me full control of the object. When I call "var
plugin = plugins[choice];" its not null... So after that I'm calling
"plugin.run" and it crashes. I've looked at the C code and saw when
its assigned to the hashmap it uses "PLUG_PLUG (plugin)" but when its
retrieved its not. Maybe that's my issue? but how would I even fix
that?
var items = new Gee.ArrayList<ItemInfo> ();
var plugins = new Gee.HashMap<string, PlugPlug?> ();
var choice = "plugin";
var has_plugin = plugins.has_key (choice);
if (!has_plugin) {
var registrar = new PluginRegistrar<PlugPlug> (choice);
var loaded = registrar.load ();
if (loaded) {
PlugPlug* plugin = registrar.new_object ();
plugins[choice] = plugin;
has_plugin = true;
// This will run
//plugin.run (items);
}
}
if (has_plugin) {
var plugin = plugins[choice];
if (plugin != null) {
// This will crash
plugin.run (items);
}
}
C Code:
void plug_plug_run (PlugPlug* self, GeeArrayList* items);
gboolean _tmp4_;
gboolean has_plugin;
_tmp4_ = gee_abstract_map_has_key (GEE_ABSTRACT_MAP (plugins), choice);
has_plugin = _tmp4_;
if (!has_plugin) {
PluginRegistrar* _tmp5_ = NULL;
PluginRegistrar* registrar;
gboolean _tmp6_;
gboolean loaded;
_tmp5_ = plugin_registrar_new (TYPE_PLUG_PLUG, (GBoxedCopyFunc)
g_object_ref, g_object_unref, choice);
registrar = _tmp5_;
_tmp6_ = plugin_registrar_load (registrar);
loaded = _tmp6_;
if (loaded) {
gpointer _tmp7_ = NULL;
PlugPlug* plugin;
_tmp7_ = plugin_registrar_new_object (registrar);
plugin = (PlugPlug*) _tmp7_;
gee_abstract_map_set (GEE_ABSTRACT_MAP (plugins), choice, PLUG_PLUG (plugin));
has_plugin = TRUE;
}
_g_object_unref0 (registrar);
}
if (has_plugin) {
gpointer _tmp8_ = NULL;
PlugPlug* plugin;
_tmp8_ = gee_abstract_map_get (GEE_ABSTRACT_MAP (plugins), choice);
plugin = (PlugPlug*) _tmp8_;
if (plugin != NULL) {
plug_plug_run (plugin, items);
}
_g_object_unref0 (plugin);
}
--
Joseph Montanez
Web Developer
Gorilla3D
Design, Develop, Deploy
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]