Commit 451d392a authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Some PDB cleanup:

2002-09-10  Michael Natterer  <mitch@gimp.org>

	Some PDB cleanup:

	* tools/pdbgen/pdb/procedural_db.pdb: removed the get_data() and
	set_data() implementations and the global "data_list" variable.
	Cleaned up the dump() stuff (pass the FILE pointer around instead
	of having a global variable for it). Fixed output_string() so it
	does not crash on NULL strings.

	* app/core/gimp.[ch]: added gimp->procedural_db_data_list.

	* app/pdb/procedural_db.[ch]: added procedural_db_[set|get]_data().
	Don't leak data identifiers when overwriting an already existing
	entry. Added g_return_if_fail() stuff to all public functions.

	* tools/pdbgen/pdb/channel.pdb
	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/layer.pdb
	* tools/pdbgen/pdb/parasite.pdb: tweaked some helper functions to
	take parameters which make them aware of the real type of the
	objects they handle (e.g. the PDB function gimp_layer_set_name()
	matches the core function gimp_object_get_name()).

	* app/pdb/pdb_glue.h: removed ugly CPP-level workarounds for the
	issue mentioned above.

	* app/pdb/channel_cmds.c
	* app/pdb/drawable_cmds.c
	* app/pdb/layer_cmds.c
	* app/pdb/parasite_cmds.c
	* app/pdb/procedural_db_cmds.c: regenerated.
parent 734a7861
2002-09-10 Michael Natterer <mitch@gimp.org>
Some PDB cleanup:
* tools/pdbgen/pdb/procedural_db.pdb: removed the get_data() and
set_data() implementations and the global "data_list" variable.
Cleaned up the dump() stuff (pass the FILE pointer around instead
of having a global variable for it). Fixed output_string() so it
does not crash on NULL strings.
* app/core/gimp.[ch]: added gimp->procedural_db_data_list.
* app/pdb/procedural_db.[ch]: added procedural_db_[set|get]_data().
Don't leak data identifiers when overwriting an already existing
entry. Added g_return_if_fail() stuff to all public functions.
* tools/pdbgen/pdb/channel.pdb
* tools/pdbgen/pdb/drawable.pdb
* tools/pdbgen/pdb/layer.pdb
* tools/pdbgen/pdb/parasite.pdb: tweaked some helper functions to
take parameters which make them aware of the real type of the
objects they handle (e.g. the PDB function gimp_layer_set_name()
matches the core function gimp_object_get_name()).
* app/pdb/pdb_glue.h: removed ugly CPP-level workarounds for the
issue mentioned above.
* app/pdb/channel_cmds.c
* app/pdb/drawable_cmds.c
* app/pdb/layer_cmds.c
* app/pdb/parasite_cmds.c
* app/pdb/procedural_db_cmds.c: regenerated.
2002-09-10 Dave Neary <bolsh@gimp.org>
* plug-ins/common/png.c: Handle INDEXA images if the
......
......@@ -377,6 +377,9 @@ gimp_get_memsize (GimpObject *object)
memsize += (g_hash_table_size (gimp->procedural_ht) *
3 * sizeof (gpointer)); /* FIXME */
memsize += (g_list_length (gimp->procedural_db_data_list) *
sizeof (GList)); /* FIXME */
memsize += g_slist_length (gimp->load_procs) * sizeof (GSList); /* FIXME */
memsize += g_slist_length (gimp->save_procs) * sizeof (GSList); /* FIXME */
......
......@@ -96,6 +96,7 @@ struct _Gimp
GimpDataFactory *palette_factory;
GHashTable *procedural_ht;
GList *procedural_db_data_list;
GSList *load_procs;
GSList *save_procs;
......
......@@ -31,7 +31,6 @@
#include "core/core-enums.h"
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "pdb_glue.h"
#include "libgimpcolor/gimpcolor.h"
......@@ -387,7 +386,7 @@ channel_get_name_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&channel_get_name_proc, success);
if (success)
return_args[1].value.pdb_pointer = g_strdup (gimp_channel_get_name (channel));
return_args[1].value.pdb_pointer = g_strdup (gimp_object_get_name (GIMP_OBJECT (channel)));
return return_args;
}
......@@ -443,7 +442,7 @@ channel_set_name_invoker (Gimp *gimp,
success = FALSE;
if (success)
gimp_channel_set_name (channel, name);
gimp_object_set_name (GIMP_OBJECT (channel), name);
return procedural_db_return_args (&channel_set_name_proc, success);
}
......@@ -493,7 +492,7 @@ channel_get_visible_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&channel_get_visible_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_channel_get_visible (channel);
return_args[1].value.pdb_int = gimp_drawable_get_visible (GIMP_DRAWABLE (channel));
return return_args;
}
......@@ -547,7 +546,7 @@ channel_set_visible_invoker (Gimp *gimp,
visible = args[1].value.pdb_int ? TRUE : FALSE;
if (success)
gimp_channel_set_visible (channel, visible);
gimp_drawable_set_visible (GIMP_DRAWABLE (channel), visible);
return procedural_db_return_args (&channel_set_visible_proc, success);
}
......@@ -922,7 +921,7 @@ channel_get_tattoo_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&channel_get_tattoo_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_channel_get_tattoo (channel);
return_args[1].value.pdb_int = gimp_item_get_tattoo (GIMP_ITEM (channel));
return return_args;
}
......@@ -978,7 +977,7 @@ channel_set_tattoo_invoker (Gimp *gimp,
success = FALSE;
if (success)
gimp_channel_set_tattoo (channel, tattoo);
gimp_item_set_tattoo (GIMP_ITEM (channel), tattoo);
return procedural_db_return_args (&channel_set_tattoo_proc, success);
}
......
......@@ -40,7 +40,6 @@
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
#include "pdb_glue.h"
static ProcRecord drawable_merge_shadow_proc;
static ProcRecord drawable_fill_proc;
......@@ -984,7 +983,7 @@ drawable_is_layer_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&drawable_is_layer_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_drawable_layer (drawable) ? TRUE : FALSE;
return_args[1].value.pdb_int = GIMP_IS_LAYER (drawable) ? TRUE : FALSE;
return return_args;
}
......@@ -1038,7 +1037,7 @@ drawable_is_layer_mask_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&drawable_is_layer_mask_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_drawable_layer_mask (drawable) ? TRUE : FALSE;
return_args[1].value.pdb_int = GIMP_IS_LAYER_MASK (drawable) ? TRUE : FALSE;
return return_args;
}
......@@ -1092,7 +1091,7 @@ drawable_is_channel_invoker (Gimp *gimp,
return_args = procedural_db_return_args (&drawable_is_channel_proc, success);
if (success)
return_args[1].value.pdb_int = gimp_drawable_channel (drawable) ? TRUE : FALSE;
return_args[1].value.pdb_int = GIMP_IS_CHANNEL (drawable) ? TRUE : FALSE;
return return_args;
}
......
......@@ -37,13 +37,23 @@
#include "libgimp/gimpintl.h"
typedef struct _PDBData PDBData;
struct _PDBData
{
gchar *identifier;
gint32 bytes;
guint8 *data;
};
void
procedural_db_init (Gimp *gimp)
{
g_return_if_fail (gimp != NULL);
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->procedural_ht = g_hash_table_new (g_str_hash, g_str_equal);
gimp->procedural_ht = g_hash_table_new (g_str_hash, g_str_equal);
gimp->procedural_db_data_list = NULL;
}
static void
......@@ -58,6 +68,8 @@ procedural_db_free_entry (gpointer key,
void
procedural_db_free (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->procedural_ht)
{
g_hash_table_foreach (gimp->procedural_ht,
......@@ -66,6 +78,24 @@ procedural_db_free (Gimp *gimp)
gimp->procedural_ht = NULL;
}
if (gimp->procedural_db_data_list)
{
PDBData *data;
GList *list;
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
data = (PDBData *) list->data;
g_free (data->identifier);
g_free (data->data);
g_free (data);
}
g_list_free (gimp->procedural_db_data_list);
gimp->procedural_db_data_list = NULL;
}
}
void
......@@ -74,6 +104,9 @@ procedural_db_register (Gimp *gimp,
{
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (procedure != NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) procedure->name);
list = g_list_prepend (list, (gpointer) procedure);
......@@ -88,6 +121,9 @@ procedural_db_unregister (Gimp *gimp,
{
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (name != NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
if (list)
......@@ -110,6 +146,9 @@ procedural_db_lookup (Gimp *gimp,
{
GList *list;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
if (list)
......@@ -128,6 +167,9 @@ procedural_db_execute (Gimp *gimp,
GList *list;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
return_args = NULL;
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
......@@ -225,6 +267,9 @@ procedural_db_run_proc (Gimp *gimp,
va_list args;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
if ((proc = procedural_db_lookup (gimp, name)) == NULL)
{
return_vals = g_new (Argument, 1);
......@@ -323,6 +368,8 @@ procedural_db_return_args (ProcRecord *procedure,
Argument *return_args;
gint i;
g_return_val_if_fail (procedure != NULL, NULL);
return_args = g_new (Argument, procedure->num_values + 1);
if (success)
......@@ -410,3 +457,71 @@ procedural_db_destroy_args (Argument *args,
g_free (args);
}
void
procedural_db_set_data (Gimp *gimp,
const gchar *identifier,
gint32 bytes,
const guint8 *data)
{
GList *list;
PDBData *pdb_data;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (identifier != NULL);
g_return_if_fail (bytes > 0);
g_return_if_fail (data != NULL);
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
pdb_data = (PDBData *) list->data;
if (! strcmp (pdb_data->identifier, identifier))
break;
}
/* If there isn't already data with the specified identifier, create one */
if (list == NULL)
{
pdb_data = g_new0 (PDBData, 1);
pdb_data->identifier = g_strdup (identifier);
gimp->procedural_db_data_list =
g_list_prepend (gimp->procedural_db_data_list, pdb_data);
}
else
{
g_free (pdb_data->data);
}
pdb_data->bytes = bytes;
pdb_data->data = g_memdup (data, bytes);
}
const guint8 *
procedural_db_get_data (Gimp *gimp,
const gchar *identifier,
gint32 *bytes)
{
GList *list;
PDBData *pdb_data;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (identifier != NULL, NULL);
g_return_val_if_fail (bytes != NULL, NULL);
*bytes = 0;
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
pdb_data = (PDBData *) list->data;
if (! strcmp (pdb_data->identifier, identifier))
{
*bytes = pdb_data->bytes;
return pdb_data->data;
}
}
return NULL;
}
......@@ -119,29 +119,43 @@ struct _ProcRecord
/* Functions */
void procedural_db_init (Gimp *gimp);
void procedural_db_free (Gimp *gimp);
void procedural_db_register (Gimp *gimp,
ProcRecord *procedure);
void procedural_db_unregister (Gimp *gimp,
const gchar *name);
ProcRecord * procedural_db_lookup (Gimp *gimp,
const gchar *name);
Argument * procedural_db_execute (Gimp *gimp,
const gchar *name,
Argument *args);
Argument * procedural_db_run_proc (Gimp *gimp,
const gchar *name,
gint *nreturn_vals,
...);
Argument * procedural_db_return_args (ProcRecord *procedure,
gboolean success);
void procedural_db_destroy_args (Argument *args,
gint nargs);
void procedural_db_init (Gimp *gimp);
void procedural_db_free (Gimp *gimp);
void procedural_db_register (Gimp *gimp,
ProcRecord *procedure);
void procedural_db_unregister (Gimp *gimp,
const gchar *name);
ProcRecord * procedural_db_lookup (Gimp *gimp,
const gchar *name);
Argument * procedural_db_execute (Gimp *gimp,
const gchar *name,
Argument *args);
Argument * procedural_db_run_proc (Gimp *gimp,
const gchar *name,
gint *nreturn_vals,
...);
Argument * procedural_db_return_args (ProcRecord *procedure,
gboolean success);
void procedural_db_destroy_args (Argument *args,
gint nargs);
void procedural_db_set_data (Gimp *gimp,
const gchar *identifier,
gint32 bytes,
const guint8 *data);
const guint8 * procedural_db_get_data (Gimp *gimp,
const gchar *identifier,
gint32 *bytes);
/* "type" should really be a GimpPDBArgType, but we can cope with
* out-of-range values.
*/
const gchar * pdb_type_name (gint type); /* really exists in _cmds.c file */
const gchar * pdb_type_name (gint type); /* really exists in _cmds.c file */
#endif /* __PROCEDURAL_DB_H__ */
......@@ -37,13 +37,23 @@
#include "libgimp/gimpintl.h"
typedef struct _PDBData PDBData;
struct _PDBData
{
gchar *identifier;
gint32 bytes;
guint8 *data;
};
void
procedural_db_init (Gimp *gimp)
{
g_return_if_fail (gimp != NULL);
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->procedural_ht = g_hash_table_new (g_str_hash, g_str_equal);
gimp->procedural_ht = g_hash_table_new (g_str_hash, g_str_equal);
gimp->procedural_db_data_list = NULL;
}
static void
......@@ -58,6 +68,8 @@ procedural_db_free_entry (gpointer key,
void
procedural_db_free (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->procedural_ht)
{
g_hash_table_foreach (gimp->procedural_ht,
......@@ -66,6 +78,24 @@ procedural_db_free (Gimp *gimp)
gimp->procedural_ht = NULL;
}
if (gimp->procedural_db_data_list)
{
PDBData *data;
GList *list;
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
data = (PDBData *) list->data;
g_free (data->identifier);
g_free (data->data);
g_free (data);
}
g_list_free (gimp->procedural_db_data_list);
gimp->procedural_db_data_list = NULL;
}
}
void
......@@ -74,6 +104,9 @@ procedural_db_register (Gimp *gimp,
{
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (procedure != NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) procedure->name);
list = g_list_prepend (list, (gpointer) procedure);
......@@ -88,6 +121,9 @@ procedural_db_unregister (Gimp *gimp,
{
GList *list;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (name != NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
if (list)
......@@ -110,6 +146,9 @@ procedural_db_lookup (Gimp *gimp,
{
GList *list;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
if (list)
......@@ -128,6 +167,9 @@ procedural_db_execute (Gimp *gimp,
GList *list;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
return_args = NULL;
list = g_hash_table_lookup (gimp->procedural_ht, (gpointer) name);
......@@ -225,6 +267,9 @@ procedural_db_run_proc (Gimp *gimp,
va_list args;
gint i;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
if ((proc = procedural_db_lookup (gimp, name)) == NULL)
{
return_vals = g_new (Argument, 1);
......@@ -323,6 +368,8 @@ procedural_db_return_args (ProcRecord *procedure,
Argument *return_args;
gint i;
g_return_val_if_fail (procedure != NULL, NULL);
return_args = g_new (Argument, procedure->num_values + 1);
if (success)
......@@ -410,3 +457,71 @@ procedural_db_destroy_args (Argument *args,
g_free (args);
}
void
procedural_db_set_data (Gimp *gimp,
const gchar *identifier,
gint32 bytes,
const guint8 *data)
{
GList *list;
PDBData *pdb_data;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (identifier != NULL);
g_return_if_fail (bytes > 0);
g_return_if_fail (data != NULL);
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
pdb_data = (PDBData *) list->data;
if (! strcmp (pdb_data->identifier, identifier))
break;
}
/* If there isn't already data with the specified identifier, create one */
if (list == NULL)
{
pdb_data = g_new0 (PDBData, 1);
pdb_data->identifier = g_strdup (identifier);
gimp->procedural_db_data_list =
g_list_prepend (gimp->procedural_db_data_list, pdb_data);
}
else
{
g_free (pdb_data->data);
}
pdb_data->bytes = bytes;
pdb_data->data = g_memdup (data, bytes);
}
const guint8 *
procedural_db_get_data (Gimp *gimp,
const gchar *identifier,
gint32 *bytes)
{
GList *list;
PDBData *pdb_data;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (identifier != NULL, NULL);
g_return_val_if_fail (bytes != NULL, NULL);
*bytes = 0;
for (list = gimp->procedural_db_data_list; list; list = g_list_next (list))
{
pdb_data = (PDBData *) list->data;
if (! strcmp (pdb_data->identifier, identifier))
{
*bytes = pdb_data->bytes;
return pdb_data->data;
}
}
return NULL;
}
......@@ -119,29 +119,43 @@ struct _ProcRecord
/* Functions */
void procedural_db_init (Gimp *gimp);
void procedural_db_free (Gimp *gimp);
void procedural_db_register (Gimp *gimp,
ProcRecord *procedure);
void procedural_db_unregister (Gimp *gimp,
const gchar *name);
ProcRecord * procedural_db_lookup (Gimp *gimp,
const gchar *name);
Argument * procedural_db_execute (Gimp *gimp,
const gchar *name,
Argument *args);
Argument * procedural_db_run_proc (Gimp *gimp,
const gchar *name,
gint *nreturn_vals,
...);
Argument * procedural_db_return_args (ProcRecord *procedure,
gboolean success);
void procedural_db_destroy_args (Argument *args,
gint nargs);
void procedural_db_init (Gimp *gimp);
void procedural_db_free (Gimp *gimp);
void procedural_db_register (Gimp *gimp,
ProcRecord *procedure);
void procedural_db_unregister (Gimp *gimp,
const gchar *name);
ProcRecord * procedural_db_lookup (Gimp *gimp,
const gchar *name);
Argument * procedural_db_execute (Gimp *gimp,
const gchar *name,
Argument *args);
Argument * procedural_db_run_proc (Gimp *gimp,
const gchar *name,
gint *nreturn_vals,