second patch for gerror.
- From: Mathieu Lacage <mathieu eazel com>
- To: gtk-devel-list gnome org
- Subject: second patch for gerror.
- Date: 07 Dec 2000 16:01:49 -0800
As Darin pointed out, here are fixes.
Index: gerror.c
===================================================================
RCS file: /cvs/gnome/glib/gerror.c,v
retrieving revision 1.18
diff -u -r1.18 gerror.c
--- gerror.c 2000/11/05 17:02:35 1.18
+++ gerror.c 2000/12/07 20:56:29
@@ -29,6 +29,8 @@
static GError*
g_error_new_valist(GQuark domain,
gint code,
+ gpointer data,
+ GDestroyNotify destroy_notify,
const gchar *format,
va_list args)
{
@@ -39,6 +41,8 @@
error->domain = domain;
error->code = code;
error->message = g_strdup_vprintf (format, args);
+ error->data = data;
+ error->destroy_notify = destroy_notify;
return error;
}
@@ -68,13 +72,51 @@
g_return_val_if_fail (domain != 0, NULL);
va_start (args, format);
- error = g_error_new_valist (domain, code, format, args);
+ error = g_error_new_valist (domain, code, NULL, NULL, format, args);
va_end (args);
return error;
}
/**
+ * g_error_new_with_data:
+ * @domain: error domain
+ * @code: error code
+ * @data: error data
+ * @destroy_notify: data destruction handler.
+ * @format: printf()-style format for error message
+ * @Varargs: parameters for message format
+ *
+ * Creates a new #GError with the given @domain, @code,
+ * @data and a message formatted with @format.
+ * @destroy_notify can be NULL if you do not want to destroy
+ * the data.
+ *
+ * Return value: a new #GError
+ **/
+GError*
+g_error_new_with_data (GQuark domain,
+ gint code,
+ gpointer data,
+ GDestroyNotify destroy_notify,
+ const gchar *format,
+ ...)
+{
+ GError* error;
+ va_list args;
+
+ g_return_val_if_fail (format != NULL, NULL);
+ g_return_val_if_fail (domain != 0, NULL);
+ g_return_val_if_fail (data != NULL, NULL);
+
+ va_start (args, format);
+ error = g_error_new_valist (domain, code, data, destroy_notify, format, args);
+ va_end (args);
+
+ return error;
+}
+
+/**
* g_error_new_literal:
* @domain: error domain
* @code: error code
@@ -92,18 +134,20 @@
gint code,
const gchar *message)
{
- GError* err;
+ GError* error;
g_return_val_if_fail (message != NULL, NULL);
g_return_val_if_fail (domain != 0, NULL);
- err = g_new (GError, 1);
+ error = g_new (GError, 1);
- err->domain = domain;
- err->code = code;
- err->message = g_strdup (message);
+ error->domain = domain;
+ error->code = code;
+ error->message = g_strdup (message);
+ error->data = NULL;
+ error->destroy_notify = NULL;
- return err;
+ return error;
}
/**
@@ -119,6 +163,9 @@
g_return_if_fail (error != NULL);
g_free (error->message);
+ if (error->destroy_notify != NULL) {
+ (* error->destroy_notify) (error->data);
+ }
g_free (error);
}
@@ -137,6 +184,7 @@
GError *copy;
g_return_val_if_fail (error != NULL, NULL);
+ g_return_val_if_fail (error->data != NULL, NULL);
copy = g_new (GError, 1);
@@ -198,11 +246,46 @@
g_warning (ERROR_OVERWRITTEN_WARNING);
va_start (args, format);
- *err = g_error_new_valist (domain, code, format, args);
+ *err = g_error_new_valist (domain, code, NULL, NULL, format, args);
va_end (args);
}
/**
+ * g_set_data_error:
+ * @err: a return location for a #GError, or NULL
+ * @domain: error domain
+ * @code: error code
+ * @data: error data
+ * @destroy_notify: destroy callback
+ * @format: printf()-style format
+ * @Varargs: args for @format
+ *
+ * Does nothing if @err is NULL; if @err is non-NULL, then * err must
+ * be NULL. A new #GError is created and assigned to * err
+ **/
+void
+g_set_data_error (GError **err,
+ GQuark domain,
+ gint code,
+ gpointer data,
+ GDestroyNotify destroy_notify,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+
+ if (err == NULL)
+ return;
+
+ if (*err != NULL)
+ g_warning (ERROR_OVERWRITTEN_WARNING);
+
+ va_start (args, format);
+ *err = g_error_new_valist (domain, code, data, destroy_notify, format, args);
+ va_end (args);
+}
+
+/**
* g_propagate_error:
* @dest: error return location
* @src: error to move into the return location
@@ -247,3 +330,8 @@
*err = NULL;
}
}
+
+
+
+
+
Index: gerror.h
===================================================================
RCS file: /cvs/gnome/glib/gerror.h,v
retrieving revision 1.4
diff -u -r1.4 gerror.h
--- gerror.h 2000/10/12 11:52:07 1.4
+++ gerror.h 2000/12/07 20:56:29
@@ -29,9 +29,11 @@
struct _GError
{
- GQuark domain;
- gint code;
- gchar *message;
+ GQuark domain;
+ gint code;
+ gchar *message;
+ gpointer data;
+ GDestroyNotify destroy_notify;
};
GError* g_error_new (GQuark domain,
@@ -39,6 +41,14 @@
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
+GError* g_error_new_with_data (GQuark domain,
+ gint code,
+ gpointer data,
+ GDestroyNotify destroy_notify,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (5, 6);
+
+
GError* g_error_new_literal (GQuark domain,
gint code,
const gchar *message);
@@ -58,6 +68,15 @@
gint code,
const gchar *format,
...) G_GNUC_PRINTF (4, 5);
+
+void g_set_data_error (GError **err,
+ GQuark domain,
+ gint code,
+ gpointer data,
+ GDestroyNotify destroy_notify,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (6, 7);
+
/* if (dest) *dest = src; also has some sanity checks.
*/
--
Mathieu Lacage <mathieu eazel com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]