Commit 036085fd authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/base/temp-buf.c app/base/tile-manager.c accept NULL in all

2007-11-16  Michael Natterer  <mitch@gimp.org>

	* app/base/temp-buf.c
	* app/base/tile-manager.c
	* app/core/gimpobject.c: accept NULL in all get_memsize() functions.

	* app/core/gimp-utils.[ch]: ditto. Added gimp_string_get_memsize().

	* app/core/gimp.c
	* app/core/gimpbrush.c
	* app/core/gimpbuffer.c
	* app/core/gimpcontainer.c
	* app/core/gimpcontext.c
	* app/core/gimpdata.c
	* app/core/gimpdrawable.c
	* app/core/gimpdrawablemodundo.c
	* app/core/gimpdrawableundo.c
	* app/core/gimpimage.c
	* app/core/gimpitempropundo.c
	* app/core/gimplayer.c
	* app/core/gimpmaskundo.c
	* app/core/gimppalette.c
	* app/core/gimpparasitelist.c
	* app/core/gimppattern.c
	* app/core/gimppreviewcache.c
	* app/core/gimpundo.c
	* app/core/gimpundostack.c
	* app/core/gimpviewable.c
	* app/pdb/gimpprocedure.c
	* app/plug-in/gimpplugindef.c
	* app/plug-in/gimppluginmanager.c
	* app/plug-in/gimppluginprocedure.c
	* app/text/gimptext.c
	* app/text/gimptextlayer.c
	* app/text/gimptextundo.c
	* app/vectors/gimpvectorsmodundo.c: simplify
	GimpObject::get_memsize() implementations accordingly.

	* app/core/gimpimageundo.c: ditto. Always keep around colormaps in
	chunks of GIMP_IMAGE_COLORMAP_SIZE to be coonsistent with the
	other colormap handling code.


svn path=/trunk/; revision=24174
parent b9973273
2007-11-16 Michael Natterer <mitch@gimp.org>
* app/base/temp-buf.c
* app/base/tile-manager.c
* app/core/gimpobject.c: accept NULL in all get_memsize() functions.
* app/core/gimp-utils.[ch]: ditto. Added gimp_string_get_memsize().
* app/core/gimp.c
* app/core/gimpbrush.c
* app/core/gimpbuffer.c
* app/core/gimpcontainer.c
* app/core/gimpcontext.c
* app/core/gimpdata.c
* app/core/gimpdrawable.c
* app/core/gimpdrawablemodundo.c
* app/core/gimpdrawableundo.c
* app/core/gimpimage.c
* app/core/gimpitempropundo.c
* app/core/gimplayer.c
* app/core/gimpmaskundo.c
* app/core/gimppalette.c
* app/core/gimpparasitelist.c
* app/core/gimppattern.c
* app/core/gimppreviewcache.c
* app/core/gimpundo.c
* app/core/gimpundostack.c
* app/core/gimpviewable.c
* app/pdb/gimpprocedure.c
* app/plug-in/gimpplugindef.c
* app/plug-in/gimppluginmanager.c
* app/plug-in/gimppluginprocedure.c
* app/text/gimptext.c
* app/text/gimptextlayer.c
* app/text/gimptextundo.c
* app/vectors/gimpvectorsmodundo.c: simplify
GimpObject::get_memsize() implementations accordingly.
* app/core/gimpimageundo.c: ditto. Always keep around colormaps in
chunks of GIMP_IMAGE_COLORMAP_SIZE to be coonsistent with the
other colormap handling code.
2007-11-16 Sven Neumann <sven@gimp.org>
* app/base/lut-funcs.c (equalize_lut_setup): make sure we don't
......
......@@ -373,14 +373,11 @@ temp_buf_data_clear (TempBuf *temp_buf)
gsize
temp_buf_get_memsize (TempBuf *temp_buf)
{
gsize memsize = 0;
if (temp_buf)
return (sizeof (TempBuf) +
(gsize) temp_buf->bytes * temp_buf->width * temp_buf->height);
g_return_val_if_fail (temp_buf != NULL, 0);
memsize += (sizeof (TempBuf)
+ (gsize) temp_buf->bytes * temp_buf->width * temp_buf->height);
return memsize;
return 0;
}
......
......@@ -569,7 +569,8 @@ tile_manager_get_memsize (const TileManager *tm,
/* the tile manager itself */
gint64 memsize = sizeof (TileManager);
g_return_val_if_fail (tm != NULL, 0);
if (! tm)
return 0;
/* the array of tiles */
memsize += (gint64) tm->ntile_rows * tm->ntile_cols * (sizeof (Tile) +
......
......@@ -60,37 +60,37 @@
gint64
gimp_g_type_instance_get_memsize (GTypeInstance *instance)
{
GTypeQuery type_query;
gint64 memsize = 0;
g_return_val_if_fail (instance != NULL, 0);
if (instance)
{
GTypeQuery type_query;
g_type_query (G_TYPE_FROM_INSTANCE (instance), &type_query);
g_type_query (G_TYPE_FROM_INSTANCE (instance), &type_query);
memsize += type_query.instance_size;
return type_query.instance_size;
}
return memsize;
return 0;
}
gint64
gimp_g_object_get_memsize (GObject *object)
{
gint64 memsize = 0;
g_return_val_if_fail (G_IS_OBJECT (object), 0);
if (object)
return gimp_g_type_instance_get_memsize ((GTypeInstance *) object);
return memsize + gimp_g_type_instance_get_memsize ((GTypeInstance *) object);
return 0;
}
gint64
gimp_g_hash_table_get_memsize (GHashTable *hash,
gint64 data_size)
{
g_return_val_if_fail (hash != NULL, 0);
if (hash)
return (2 * sizeof (gint) +
5 * sizeof (gpointer) +
g_hash_table_size (hash) * (3 * sizeof (gpointer) + data_size));
return (2 * sizeof (gint) +
5 * sizeof (gpointer) +
g_hash_table_size (hash) * (3 * sizeof (gpointer) + data_size));
return 0;
}
typedef struct
......@@ -118,9 +118,11 @@ gimp_g_hash_table_get_memsize_foreach (GHashTable *hash,
{
HashMemsize memsize;
g_return_val_if_fail (hash != NULL, 0);
g_return_val_if_fail (func != NULL, 0);
if (! hash)
return 0;
memsize.func = func;
memsize.memsize = 0;
memsize.gui_size = 0;
......@@ -182,14 +184,14 @@ gimp_g_list_get_memsize_foreach (GList *list,
gint64
gimp_g_value_get_memsize (GValue *value)
{
gint64 memsize = sizeof (GValue);
gint64 memsize = 0;
if (! value)
return 0;
if (G_VALUE_HOLDS_STRING (value))
{
const gchar *str = g_value_get_string (value);
if (str)
memsize += strlen (str) + 1;
memsize += gimp_string_get_memsize (g_value_get_string (value));
}
else if (G_VALUE_HOLDS_BOXED (value))
{
......@@ -203,11 +205,8 @@ gimp_g_value_get_memsize (GValue *value)
}
else if (GIMP_VALUE_HOLDS_PARASITE (value))
{
GimpParasite *parasite = g_value_get_boxed (value);
if (parasite)
memsize += (sizeof (GimpParasite) + parasite->size +
parasite->name ? (strlen (parasite->name) + 1) : 0);
memsize += gimp_parasite_get_memsize (g_value_get_boxed (value),
NULL);
}
else if (GIMP_VALUE_HOLDS_ARRAY (value) ||
GIMP_VALUE_HOLDS_INT8_ARRAY (value) ||
......@@ -237,7 +236,7 @@ gimp_g_value_get_memsize (GValue *value)
memsize += array->length * sizeof (gchar *);
for (i = 0; i < array->length; i++)
memsize += strlen (tmp[i]) + 1;
memsize += gimp_string_get_memsize (tmp[i]);
}
}
}
......@@ -253,51 +252,48 @@ gimp_g_value_get_memsize (GValue *value)
G_STRFUNC, G_VALUE_TYPE_NAME (value));
}
return memsize;
return memsize + sizeof (GValue);
}
gint64
gimp_g_param_spec_get_memsize (GParamSpec *pspec)
{
const gchar *str;
gint64 memsize = 0;
gint64 memsize = 0;
if (! pspec)
return 0;
if (! (pspec->flags & G_PARAM_STATIC_NAME))
{
str = g_param_spec_get_name (pspec);
if (str)
memsize += strlen (str) + 1;
}
memsize += gimp_string_get_memsize (g_param_spec_get_name (pspec));
if (! (pspec->flags & G_PARAM_STATIC_NICK))
{
str = g_param_spec_get_nick (pspec);
if (str)
memsize += strlen (str) + 1;
}
memsize += gimp_string_get_memsize (g_param_spec_get_nick (pspec));
if (! (pspec->flags & G_PARAM_STATIC_BLURB))
{
str = g_param_spec_get_blurb (pspec);
if (str)
memsize += strlen (str) + 1;
}
memsize += gimp_string_get_memsize (g_param_spec_get_blurb (pspec));
return memsize + gimp_g_type_instance_get_memsize ((GTypeInstance *) pspec);
}
gint64
gimp_string_get_memsize (const gchar *string)
{
if (string)
return strlen (string) + 1;
return 0;
}
gint64
gimp_parasite_get_memsize (GimpParasite *parasite,
gint64 *gui_size)
{
gint64 memsize = 0;
if (parasite)
memsize += (sizeof (GimpParasite) +
strlen (parasite->name) + 1 +
parasite->size);
return (sizeof (GimpParasite) +
gimp_string_get_memsize (parasite->name) +
parasite->size);
return memsize;
return 0;
}
......
......@@ -40,6 +40,7 @@ gint64 gimp_g_list_get_memsize_foreach (GList *slist,
gint64 gimp_g_value_get_memsize (GValue *value);
gint64 gimp_g_param_spec_get_memsize (GParamSpec *pspec);
gint64 gimp_string_get_memsize (const gchar *string);
gint64 gimp_parasite_get_memsize (GimpParasite *parasite,
gint64 *gui_size);
......
......@@ -438,49 +438,49 @@ gimp_get_memsize (GimpObject *object,
gui_size);
memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->module_db));
memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->plug_in_manager));
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->plug_in_manager),
gui_size);
memsize += gimp_g_hash_table_get_memsize (gimp->image_table, 0);
memsize += gimp_g_hash_table_get_memsize (gimp->item_table, 0);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size);
if (gimp->global_buffer)
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->global_buffer),
gui_size);
memsize += (gimp_object_get_memsize (GIMP_OBJECT (gimp->named_buffers),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->fonts),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->brush_factory),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->pattern_factory),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->gradient_factory),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->palette_factory),
gui_size));
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->global_buffer),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->named_buffers),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->fonts),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->brush_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->pattern_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->gradient_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->palette_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->pdb), gui_size);
memsize += (gimp_object_get_memsize (GIMP_OBJECT (gimp->tool_info_list),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->standard_tool_info),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->documents),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->templates),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->image_new_last_template),
gui_size));
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->tool_info_list),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->standard_tool_info),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->documents),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->templates),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->image_new_last_template),
gui_size);
memsize += gimp_g_list_get_memsize (gimp->context_list, 0);
memsize += (gimp_object_get_memsize (GIMP_OBJECT (gimp->default_context),
gui_size) +
gimp_object_get_memsize (GIMP_OBJECT (gimp->user_context),
gui_size));
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->default_context),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->user_context),
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -211,11 +211,8 @@ gimp_brush_get_memsize (GimpObject *object,
GimpBrush *brush = GIMP_BRUSH (object);
gint64 memsize = 0;
if (brush->mask)
memsize += temp_buf_get_memsize (brush->mask);
if (brush->pixmap)
memsize += temp_buf_get_memsize (brush->pixmap);
memsize += temp_buf_get_memsize (brush->mask);
memsize += temp_buf_get_memsize (brush->pixmap);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -113,8 +113,7 @@ gimp_buffer_get_memsize (GimpObject *object,
GimpBuffer *buffer = GIMP_BUFFER (object);
gint64 memsize = 0;
if (buffer->tiles)
memsize += tile_manager_get_memsize (buffer->tiles, FALSE);
memsize += tile_manager_get_memsize (buffer->tiles, FALSE);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -21,8 +21,6 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpconfig/gimpconfig.h"
......@@ -30,6 +28,7 @@
#include "core-types.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpcontainer.h"
#include "gimpmarshal.h"
......@@ -298,7 +297,7 @@ gimp_container_get_memsize (GimpObject *object,
memsize += (sizeof (GList) +
sizeof (GimpContainerHandler) +
strlen (handler->signame) + 1);
gimp_string_get_memsize (handler->signame));
}
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
......
......@@ -21,8 +21,6 @@
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
......@@ -34,6 +32,7 @@
#include "config/gimpcoreconfig.h"
#include "gimp.h"
#include "gimp-utils.h"
#include "gimpbrush.h"
#include "gimpbuffer.h"
#include "gimpcontainer.h"
......@@ -1090,32 +1089,15 @@ gimp_context_get_memsize (GimpObject *object,
GimpContext *context = GIMP_CONTEXT (object);
gint64 memsize = 0;
if (context->tool_name)
memsize += strlen (context->tool_name) + 1;
if (context->paint_name)
memsize += strlen (context->paint_name) + 1;
if (context->brush_name)
memsize += strlen (context->brush_name) + 1;
if (context->pattern_name)
memsize += strlen (context->pattern_name) + 1;
if (context->palette_name)
memsize += strlen (context->palette_name) + 1;
if (context->font_name)
memsize += strlen (context->font_name) + 1;
if (context->buffer_name)
memsize += strlen (context->buffer_name) + 1;
if (context->imagefile_name)
memsize += strlen (context->imagefile_name) + 1;
if (context->template_name)
memsize += strlen (context->template_name) + 1;
memsize += gimp_string_get_memsize (context->tool_name);
memsize += gimp_string_get_memsize (context->paint_name);
memsize += gimp_string_get_memsize (context->brush_name);
memsize += gimp_string_get_memsize (context->pattern_name);
memsize += gimp_string_get_memsize (context->palette_name);
memsize += gimp_string_get_memsize (context->font_name);
memsize += gimp_string_get_memsize (context->buffer_name);
memsize += gimp_string_get_memsize (context->imagefile_name);
memsize += gimp_string_get_memsize (context->template_name);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -39,6 +39,7 @@
#include "core-types.h"
#include "gimp-utils.h"
#include "gimpdata.h"
#include "gimpmarshal.h"
......@@ -297,8 +298,7 @@ gimp_data_get_memsize (GimpObject *object,
GimpData *data = GIMP_DATA (object);
gint64 memsize = 0;
if (data->filename)
memsize += strlen (data->filename) + 1;
memsize += gimp_string_get_memsize (data->filename);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -262,11 +262,9 @@ gimp_drawable_get_memsize (GimpObject *object,
GimpDrawable *drawable = GIMP_DRAWABLE (object);
gint64 memsize = 0;
if (drawable->tiles)
memsize += tile_manager_get_memsize (drawable->tiles, FALSE);
memsize += tile_manager_get_memsize (drawable->tiles, FALSE);
if (drawable->preview_cache)
*gui_size += gimp_preview_cache_get_memsize (drawable->preview_cache);
*gui_size += gimp_preview_cache_get_memsize (drawable->preview_cache);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -100,8 +100,7 @@ gimp_drawable_mod_undo_get_memsize (GimpObject *object,
GimpDrawableModUndo *drawable_mod_undo = GIMP_DRAWABLE_MOD_UNDO (object);
gint64 memsize = 0;
if (drawable_mod_undo->tiles)
memsize += tile_manager_get_memsize (drawable_mod_undo->tiles, FALSE);
memsize += tile_manager_get_memsize (drawable_mod_undo->tiles, FALSE);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -222,9 +222,8 @@ gimp_drawable_undo_get_memsize (GimpObject *object,
GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (object);
gint64 memsize = 0;
if (drawable_undo->tiles)
memsize += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
memsize += tile_manager_get_memsize (drawable_undo->tiles,
drawable_undo->sparse);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -986,17 +986,14 @@ gimp_image_get_memsize (GimpObject *object,
if (image->cmap)
memsize += GIMP_IMAGE_COLORMAP_SIZE;
if (image->shadow)
memsize += tile_manager_get_memsize (image->shadow, FALSE);
memsize += tile_manager_get_memsize (image->shadow, FALSE);
if (image->projection)
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->projection),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->projection),
gui_size);
memsize += gimp_g_list_get_memsize (image->guides, sizeof (GimpGuide));
if (image->grid)
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->grid), gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->grid), gui_size);
memsize += gimp_g_list_get_memsize (image->sample_points,
sizeof (GimpSamplePoint));
......@@ -1010,9 +1007,8 @@ gimp_image_get_memsize (GimpObject *object,
memsize += gimp_g_slist_get_memsize (image->layer_stack, 0);
if (image->selection_mask)
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->selection_mask),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->selection_mask),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->parasites),
gui_size);
......@@ -1022,8 +1018,7 @@ gimp_image_get_memsize (GimpObject *object,
memsize += gimp_object_get_memsize (GIMP_OBJECT (image->redo_stack),
gui_size);
if (image->preview)
*gui_size += temp_buf_get_memsize (image->preview);
*gui_size += temp_buf_get_memsize (image->preview);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
......@@ -28,6 +28,7 @@
#include "core-types.h"
#include "gimp-utils.h"
#include "gimpdrawable.h"
#include "gimpgrid.h"
#include "gimpimage.h"
......@@ -146,7 +147,7 @@ gimp_image_undo_constructor (GType type,
case GIMP_UNDO_IMAGE_COLORMAP:
image_undo->num_colors = gimp_image_get_colormap_size (image);
image_undo->colormap = g_memdup (gimp_image_get_colormap (image),
image_undo->num_colors * 3);
GIMP_IMAGE_COLORMAP_SIZE);
break;
case GIMP_UNDO_PARASITE_ATTACH:
......@@ -223,19 +224,12 @@ gimp_image_undo_get_memsize (GimpObject *object,
gint64 memsize = 0;
if (image_undo->colormap)
memsize += image_undo->num_colors * 3;
memsize += GIMP_IMAGE_COLORMAP_SIZE;
if (image_undo->grid)
memsize += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
gui_size);
if (image_undo->parasite_name)
memsize += strlen (image_undo->parasite_name) + 1;
if (image_undo->parasite)
memsize += (sizeof (GimpParasite) +
strlen (image_undo->parasite->name) + 1 +
image_undo->parasite->size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
gui_size);
memsize += gimp_string_get_memsize (image_undo->parasite_name);
memsize += gimp_parasite_get_memsize (image_undo->parasite, gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......@@ -344,7 +338,7 @@ gimp_image_undo_pop (GimpUndo *undo,
num_colors = gimp_image_get_colormap_size (image);
colormap = g_memdup (gimp_image_get_colormap (image),
num_colors * 3);
GIMP_IMAGE_COLORMAP_SIZE);
gimp_image_set_colormap (image,
image_undo->colormap, image_undo->num_colors,
......