libgimp: gimp_pdb_get_data() and gimp_pdb_set_data() are made internal.

These are not usable by plug-ins anymore which should store their data between
runs as arguments or aux arguments (in case of values which should be stored
from one run to another but are not really usable for non-interactive scripts).
These are per-plug-in (not polluting the whole process space with just random
strings as identifiers which could be used by other plug-ins) and even survive
restarts of GIMP.

I still keep these functions, but only internally, as they are used to store
settings of GimpAspectPreview, GimpDrawablePreview and GimpZoomPreview across
plug-in runs. Still I changed their API to set and return a GBytes directly
(mimicking the private PDB functions' API).
Also I remove gimp_pdb_get_data_size() which is useless when exchanging GBytes
directly.

Note that the 2 functions are still exported in the library, and only not
advertized through headers (so they are not really internal, just hidden), on
purpose, because we need to call them in libgimpui. So it is still relatively
easy for a plug-in to use them. Nevertheless I made clear in the function
documentation that these must not be considered public and could end up deleted
at any time. Any plug-in still trying to call these takes the risk of having
their code relying on unreliable API.
This commit is contained in:
Jehan 2023-10-26 21:48:07 +02:00
parent 0b0adfc627
commit 7a03b3ea09
8 changed files with 54 additions and 67 deletions

View File

@ -696,7 +696,6 @@ EXPORTS
gimp_patterns_set_popup
gimp_pdb_dump_to_file
gimp_pdb_get_data
gimp_pdb_get_data_size
gimp_pdb_get_last_error
gimp_pdb_get_last_status
gimp_pdb_get_type

View File

@ -82,11 +82,6 @@
G_BEGIN_DECLS
#define gimp_get_data gimp_pdb_get_data
#define gimp_get_data_size gimp_pdb_get_data_size
#define gimp_set_data gimp_pdb_set_data
/**
* GIMP_MAIN:
* @plug_in_type: The #GType of the plug-in's #GimpPlugIn subclass

View File

@ -28,6 +28,7 @@
#include "gimpuitypes.h"
#include "gimp.h"
#include "gimppdb-private.h"
#include "libgimp-intl.h"
@ -154,6 +155,7 @@ gimp_aspect_preview_constructed (GObject *object)
{
gchar *data_name;
PreviewSettings settings;
GBytes *settings_bytes = NULL;
G_OBJECT_CLASS (parent_class)->constructed (object);
@ -161,10 +163,13 @@ gimp_aspect_preview_constructed (GObject *object)
g_get_prgname (),
gimp_aspect_preview_counter++);
if (gimp_get_data (data_name, &settings))
if (gimp_pdb_get_data (data_name, &settings_bytes) &&
g_bytes_get_size (settings_bytes) == sizeof (PreviewSettings))
{
settings = *((PreviewSettings *) g_bytes_get_data (settings_bytes, NULL));
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
}
g_bytes_unref (settings_bytes);
g_object_set_data_full (object, "gimp-aspect-preview-data-name",
data_name, (GDestroyNotify) g_free);
@ -181,11 +186,14 @@ gimp_aspect_preview_dispose (GObject *object)
if (data_name)
{
GimpPreview *preview = GIMP_PREVIEW (object);
GBytes *bytes;
PreviewSettings settings;
settings.update = gimp_preview_get_update (preview);
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
bytes = g_bytes_new_static (&settings, sizeof (PreviewSettings));
gimp_pdb_set_data (data_name, bytes);
g_bytes_unref (bytes);
}
g_clear_object (&priv->drawable);

View File

@ -28,6 +28,7 @@
#include "gimpuitypes.h"
#include "gimp.h"
#include "gimppdb-private.h"
#include "gimpdrawablepreview.h"
@ -152,6 +153,7 @@ gimp_drawable_preview_constructed (GObject *object)
{
gchar *data_name;
PreviewSettings settings;
GBytes *settings_bytes = NULL;
G_OBJECT_CLASS (parent_class)->constructed (object);
@ -159,12 +161,15 @@ gimp_drawable_preview_constructed (GObject *object)
g_get_prgname (),
++gimp_drawable_preview_counter);
if (gimp_get_data (data_name, &settings))
if (gimp_pdb_get_data (data_name, &settings_bytes) &&
g_bytes_get_size (settings_bytes) == sizeof (PreviewSettings))
{
settings = *((PreviewSettings *) g_bytes_get_data (settings_bytes, NULL));
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
gimp_scrolled_preview_set_position (GIMP_SCROLLED_PREVIEW (object),
settings.x, settings.y);
}
g_bytes_unref (settings_bytes);
g_object_set_data_full (object, "gimp-drawable-preview-data-name",
data_name, (GDestroyNotify) g_free);
@ -181,12 +186,15 @@ gimp_drawable_preview_dispose (GObject *object)
if (data_name)
{
GimpPreview *preview = GIMP_PREVIEW (object);
GBytes *bytes;
PreviewSettings settings;
gimp_preview_get_position (preview, &settings.x, &settings.y);
settings.update = gimp_preview_get_update (preview);
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
bytes = g_bytes_new_static (&settings, sizeof (PreviewSettings));
gimp_pdb_set_data (data_name, bytes);
g_bytes_unref (bytes);
}
g_clear_object (&priv->drawable);

View File

@ -41,10 +41,14 @@ typedef enum
GQuark _gimp_pdb_error_quark (void) G_GNUC_CONST;
GimpPDB * _gimp_pdb_new (GimpPlugIn *plug_in);
GimpPDB * _gimp_pdb_new (GimpPlugIn *plug_in);
GimpPlugIn * _gimp_pdb_get_plug_in (GimpPDB *pdb);
GimpPlugIn * _gimp_pdb_get_plug_in (GimpPDB *pdb);
gboolean gimp_pdb_get_data (const gchar *identifier,
GBytes **data);
gboolean gimp_pdb_set_data (const gchar *identifier,
GBytes *data);
G_END_DECLS

View File

@ -383,43 +383,19 @@ gimp_pdb_get_last_status (GimpPDB *pdb)
* the specified identifier. The data is copied into the given memory
* location.
*
* WARNING: this function is exported in the library so that it can be used by
* libgimpwidgets. Nevertheless it is considered internal, and is not declared
* in any public header on purpose. It should not be considered part of the API
* and therefore should not be used in plug-ins. It may disappear at any time.
*
* Returns: TRUE on success, FALSE if no data has been associated with
* the identifier
*/
gboolean
gimp_pdb_get_data (const gchar *identifier,
gpointer data)
gimp_pdb_get_data (const gchar *identifier,
GBytes **data)
{
GBytes *hack = NULL;
gboolean success;
success = _gimp_pdb_get_data (identifier, &hack);
if (hack)
{
memcpy (data, g_bytes_get_data (hack, NULL), g_bytes_get_size (hack));
g_free (hack);
}
return success;
}
/**
* gimp_pdb_get_data_size:
* @identifier: The identifier associated with data.
*
* Returns size of data associated with the specified identifier.
*
* This procedure returns the size of any data which may have been
* associated with the specified identifier. If no data has been
* associated with the identifier, an error is returned.
*
* Returns: The number of bytes in the data.
**/
gint
gimp_pdb_get_data_size (const gchar *identifier)
{
return _gimp_pdb_get_data_size (identifier);
return _gimp_pdb_get_data (identifier, data);
}
/**
@ -432,23 +408,21 @@ gimp_pdb_get_data_size (const gchar *identifier)
*
* This procedure associates the supplied data with the provided
* identifier. The data may be subsequently retrieved by a call to
* 'procedural-db-get-data'.
* 'procedural-db-get-data'. This storage is global within the session, even
* shareable between plug-ins, though it won't survive a restart of GIMP.
*
* WARNING: this function is exported in the library so that it can be used by
* libgimpwidgets. Nevertheless it is considered internal, and is not declared
* in any public header on purpose. It should not be considered part of the API
* and therefore should not be used in plug-ins. It may disappear at any time.
* Returns: TRUE on success.
*/
gboolean
gimp_pdb_set_data (const gchar *identifier,
gconstpointer data,
guint32 data_len)
gimp_pdb_set_data (const gchar *identifier,
GBytes *data)
{
GBytes *bytes;
gboolean ret;
bytes = g_bytes_new_static (data, data_len);
ret = _gimp_pdb_set_data (identifier, bytes);
g_bytes_unref (bytes);
return ret;
return _gimp_pdb_set_data (identifier, data);
}
/**

View File

@ -91,15 +91,6 @@ const gchar * gimp_pdb_get_last_error (GimpPDB *pdb);
GimpPDBStatusType gimp_pdb_get_last_status (GimpPDB *pdb);
/* Cruft API */
gboolean gimp_pdb_get_data (const gchar *identifier,
gpointer data);
gint gimp_pdb_get_data_size (const gchar *identifier);
gboolean gimp_pdb_set_data (const gchar *identifier,
gconstpointer data,
guint32 data_len);
/* Internal use */
G_GNUC_INTERNAL GimpValueArray * _gimp_pdb_run_procedure_array (GimpPDB *pdb,

View File

@ -29,6 +29,7 @@
#include "gimpuitypes.h"
#include "gimp.h"
#include "gimppdb-private.h"
#include "gimpdrawablepreview.h"
#include "gimpzoompreview.h"
@ -212,6 +213,7 @@ gimp_zoom_preview_constructed (GObject *object)
GimpZoomPreviewPrivate *priv = GET_PRIVATE (object);
gchar *data_name;
PreviewSettings settings;
GBytes *settings_bytes = NULL;
G_OBJECT_CLASS (parent_class)->constructed (object);
@ -219,10 +221,13 @@ gimp_zoom_preview_constructed (GObject *object)
g_get_prgname (),
gimp_zoom_preview_counter++);
if (gimp_get_data (data_name, &settings))
if (gimp_pdb_get_data (data_name, &settings_bytes) &&
g_bytes_get_size (settings_bytes) == sizeof (PreviewSettings))
{
settings = *((PreviewSettings *) g_bytes_get_data (settings_bytes, NULL));
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
}
g_bytes_unref (settings_bytes);
g_object_set_data_full (object, "gimp-zoom-preview-data-name",
data_name, (GDestroyNotify) g_free);
@ -260,11 +265,14 @@ gimp_zoom_preview_dispose (GObject *object)
if (data_name)
{
GimpPreview *preview = GIMP_PREVIEW (object);
GBytes *bytes;
PreviewSettings settings;
settings.update = gimp_preview_get_update (preview);
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
bytes = g_bytes_new_static (&settings, sizeof (PreviewSettings));
gimp_pdb_set_data (data_name, bytes);
g_bytes_unref (bytes);
}
G_OBJECT_CLASS (parent_class)->dispose (object);