[gimp/goat-invasion: 563/608] app: get rid of base-utils.[ch] and move its functions to gimp-utils.[ch]



commit 55556093c223fb48a0cc7177f2b2780d7cc2112f
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 23 21:13:57 2012 +0200

    app: get rid of base-utils.[ch] and move its functions to gimp-utils.[ch]

 app/base/Makefile.am            |    2 -
 app/base/base-utils.c           |  140 ------------------------------------
 app/base/base-utils.h           |   28 -------
 app/base/tile-swap.c            |    9 ++-
 app/config/Makefile.am          |    2 +-
 app/config/gimpbaseconfig.c     |    9 ++-
 app/core/gimp-utils.c           |  150 ++++++++++++++++++++++++++++++---------
 app/core/gimp-utils.h           |    7 +-
 app/core/gimp.c                 |   31 ++++++++
 app/core/gimp.h                 |    3 +
 app/pdb/gimp-cmds.c             |    4 +-
 app/widgets/gimpselectiondata.c |   19 +++---
 tools/pdbgen/pdb/gimp.pdb       |    4 +-
 13 files changed, 179 insertions(+), 229 deletions(-)
---
diff --git a/app/base/Makefile.am b/app/base/Makefile.am
index 8d1b293..b1da187 100644
--- a/app/base/Makefile.am
+++ b/app/base/Makefile.am
@@ -21,8 +21,6 @@ libappbase_a_SOURCES = \
 	base.h			\
 	base-enums.h		\
 	base-types.h		\
-	base-utils.c		\
-	base-utils.h		\
 	pixel-processor.c	\
 	pixel-processor.h	\
 	pixel-region.c		\
diff --git a/app/base/tile-swap.c b/app/base/tile-swap.c
index b65526e..06afcae 100644
--- a/app/base/tile-swap.c
+++ b/app/base/tile-swap.c
@@ -25,7 +25,7 @@
 #include <unistd.h>
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #include "libgimpbase/gimpbase.h"
@@ -36,7 +36,7 @@
 #include "libgimpbase/gimpwin32-io.h"
 #endif
 
-#include "base-types.h"
+#include "core/core-types.h" /* screw it */
 
 #ifndef _O_BINARY
 #define _O_BINARY 0
@@ -45,13 +45,14 @@
 #define _O_TEMPORARY 0
 #endif
 
-#include "base-utils.h"
 #include "tile.h"
 #include "tile-rowhints.h"
 #include "tile-swap.h"
 #include "tile-private.h"
 #include "tile-cache.h"
 
+#include "core/gimp-utils.h"
+
 #include "gimp-intl.h"
 
 typedef enum
@@ -200,7 +201,7 @@ tile_swap_init (const gchar *path)
   g_return_if_fail (path != NULL);
 
   dirname  = gimp_config_path_expand (path, TRUE, NULL);
-  basename = g_strdup_printf ("gimpswap.%lu", (unsigned long) get_pid ());
+  basename = g_strdup_printf ("gimpswap.%lu", (unsigned long) gimp_get_pid ());
 
   /*  create the swap directory if it doesn't exist */
   if (! g_file_test (dirname, G_FILE_TEST_EXISTS))
diff --git a/app/config/Makefile.am b/app/config/Makefile.am
index 3b40d07..dd49d18 100644
--- a/app/config/Makefile.am
+++ b/app/config/Makefile.am
@@ -16,7 +16,7 @@ INCLUDES = \
 	-I$(top_srcdir)		\
 	-I$(top_builddir)/app	\
 	-I$(top_srcdir)/app	\
-	$(BABL_CFLAGS)		\
+	$(GEGL_CFLAGS)		\
 	$(CAIRO_CFLAGS)		\
 	$(GDK_PIXBUF_CFLAGS)	\
 	-I$(includedir)
diff --git a/app/config/gimpbaseconfig.c b/app/config/gimpbaseconfig.c
index cac2823..972a5c2 100644
--- a/app/config/gimpbaseconfig.c
+++ b/app/config/gimpbaseconfig.c
@@ -24,19 +24,20 @@
 #include <unistd.h>
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
 
-#include "config-types.h"
+#include "core/core-types.h" /* eek */
 
-#include "base/base-utils.h"
 #include "base/pixel-processor.h"
 
 #include "gimprc-blurbs.h"
 #include "gimpbaseconfig.h"
 
+#include "core/gimp-utils.h"
+
 #include "gimp-debug.h"
 
 #include "gimp-intl.h"
@@ -125,7 +126,7 @@ gimp_base_config_class_init (GimpBaseConfigClass *klass)
                                  GIMP_PARAM_STATIC_STRINGS |
                                  GIMP_CONFIG_PARAM_RESTART);
 
-  num_processors = get_number_of_processors ();
+  num_processors = gimp_get_number_of_processors ();
 
 #ifdef GIMP_UNSTABLE
   num_processors = num_processors * 2;
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 21e690e..23c20ed 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -26,6 +26,25 @@
 #include <langinfo.h>
 #endif
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#include <process.h>
+#endif
+
+#ifdef G_OS_UNIX
+/* For get_backtrace() */
+#include <stdlib.h>
+#include <string.h>
+#include <execinfo.h>
+#endif
+
 #include <cairo.h>
 #include <gegl.h>
 #include <gobject/gvaluecollector.h>
@@ -37,8 +56,6 @@
 
 #include "core-types.h"
 
-#include "base/base-utils.h"
-
 #include "config/gimpbaseconfig.h"
 
 #include "gimp.h"
@@ -48,6 +65,10 @@
 #include "gimpparamspecs.h"
 
 
+#define NUM_PROCESSORS_DEFAULT 1
+#define MAX_FUNC               100
+
+
 gint64
 gimp_g_type_instance_get_memsize (GTypeInstance *instance)
 {
@@ -304,6 +325,100 @@ gimp_parasite_get_memsize (GimpParasite *parasite,
 }
 
 
+gint
+gimp_get_pid (void)
+{
+  return (gint) getpid ();
+}
+
+gint
+gimp_get_number_of_processors (void)
+{
+  gint retval = NUM_PROCESSORS_DEFAULT;
+
+#ifdef G_OS_UNIX
+#if defined(HAVE_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
+  retval = sysconf (_SC_NPROCESSORS_ONLN);
+#endif
+#endif
+#ifdef G_OS_WIN32
+  SYSTEM_INFO system_info;
+
+  GetSystemInfo (&system_info);
+
+  retval = system_info.dwNumberOfProcessors;
+#endif
+
+  return retval;
+}
+
+guint64
+gimp_get_physical_memory_size (void)
+{
+#ifdef G_OS_UNIX
+#if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE)
+  return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE);
+#endif
+#endif
+
+#ifdef G_OS_WIN32
+# if defined(_MSC_VER) && (_MSC_VER <= 1200)
+  MEMORYSTATUS memory_status;
+  memory_status.dwLength = sizeof (memory_status);
+
+  GlobalMemoryStatus (&memory_status);
+  return memory_status.dwTotalPhys;
+# else
+  /* requires w2k and newer SDK than provided with msvc6 */
+  MEMORYSTATUSEX memory_status;
+
+  memory_status.dwLength = sizeof (memory_status);
+
+  if (GlobalMemoryStatusEx (&memory_status))
+    return memory_status.ullTotalPhys;
+# endif
+#endif
+
+  return 0;
+}
+
+/**
+ * gimp_get_backtrace:
+ *
+ * Returns: The current stack trace. Free with g_free(). Mainly meant
+ * for debugging, for example storing the allocation stack traces for
+ * objects to hunt down leaks.
+ **/
+gchar *
+gimp_get_backtrace (void)
+{
+#ifdef G_OS_UNIX
+  void     *functions[MAX_FUNC];
+  char    **function_names;
+  int       n_functions;
+  int       i;
+  GString  *result;
+
+  /* Get symbols */
+  n_functions    = backtrace (functions, MAX_FUNC);
+  function_names = backtrace_symbols (functions, n_functions);
+
+  /* Construct stack trace */
+  result = g_string_new ("");
+  for (i = 0; i < n_functions; i++)
+    g_string_append_printf (result, "%s\n", function_names[i]);
+
+  /* We must not free the function names themselves, we only need to
+   * free the array that points to them
+   */
+  free (function_names);
+
+  return g_string_free (result, FALSE/*free_segment*/);
+#else
+  return g_strdup ("backtrace() only available with GNU libc\n");
+#endif
+}
+
 /*
  *  basically copied from gtk_get_default_language()
  */
@@ -485,37 +600,6 @@ gimp_value_array_truncate (GValueArray  *args,
     g_value_array_remove (args, i - 1);
 }
 
-gchar *
-gimp_get_temp_filename (Gimp        *gimp,
-                        const gchar *extension)
-{
-  static gint  id = 0;
-  static gint  pid;
-  gchar       *filename;
-  gchar       *basename;
-  gchar       *path;
-
-  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
-
-  if (id == 0)
-    pid = get_pid ();
-
-  if (extension)
-    basename = g_strdup_printf ("gimp-temp-%d%d.%s", pid, id++, extension);
-  else
-    basename = g_strdup_printf ("gimp-temp-%d%d", pid, id++);
-
-  path = gimp_config_path_expand (GIMP_BASE_CONFIG (gimp->config)->temp_path,
-                                  TRUE, NULL);
-
-  filename = g_build_filename (path, basename, NULL);
-
-  g_free (path);
-  g_free (basename);
-
-  return filename;
-}
-
 /*  markup unescape code stolen and adapted from gmarkup.c
  */
 static gchar *
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index a07f656..dc8cdc4 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -58,6 +58,10 @@ gint64       gimp_string_get_memsize               (const gchar     *string);
 gint64       gimp_parasite_get_memsize             (GimpParasite    *parasite,
                                                     gint64          *gui_size);
 
+gint         gimp_get_pid                          (void);
+gint         gimp_get_number_of_processors         (void);
+guint64      gimp_get_physical_memory_size         (void);
+gchar      * gimp_get_backtrace                    (void);
 gchar      * gimp_get_default_language             (const gchar     *category);
 GimpUnit     gimp_get_default_unit                 (void);
 
@@ -75,9 +79,6 @@ void         gimp_parameters_free                  (GParameter      *params,
 void         gimp_value_array_truncate             (GValueArray     *args,
                                                     gint             n_values);
 
-gchar      * gimp_get_temp_filename                (Gimp            *gimp,
-                                                    const gchar     *extension);
-
 gchar      * gimp_markup_extract_text              (const gchar     *markup);
 
 const gchar* gimp_enum_get_value_name              (GType            enum_type,
diff --git a/app/core/gimp.c b/app/core/gimp.c
index bd97262..1543afc 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -1294,6 +1294,37 @@ gimp_image_opened (Gimp        *gimp,
   g_signal_emit (gimp, gimp_signals[IMAGE_OPENED], 0, uri);
 }
 
+gchar *
+gimp_get_temp_filename (Gimp        *gimp,
+                        const gchar *extension)
+{
+  static gint  id = 0;
+  static gint  pid;
+  gchar       *filename;
+  gchar       *basename;
+  gchar       *path;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+
+  if (id == 0)
+    pid = gimp_get_pid ();
+
+  if (extension)
+    basename = g_strdup_printf ("gimp-temp-%d%d.%s", pid, id++, extension);
+  else
+    basename = g_strdup_printf ("gimp-temp-%d%d", pid, id++);
+
+  path = gimp_config_path_expand (GIMP_BASE_CONFIG (gimp->config)->temp_path,
+                                  TRUE, NULL);
+
+  filename = g_build_filename (path, basename, NULL);
+
+  g_free (path);
+  g_free (basename);
+
+  return filename;
+}
+
 gboolean
 gimp_use_gegl (Gimp *gimp)
 {
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 2d9e8bf..e6b3a56 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -213,6 +213,9 @@ void           gimp_message_literal      (Gimp                *gimp,
 void           gimp_image_opened         (Gimp                *gimp,
                                           const gchar         *uri);
 
+gchar        * gimp_get_temp_filename    (Gimp                *gimp,
+                                          const gchar         *extension);
+
 gboolean       gimp_use_gegl             (Gimp                *gimp);
 
 
diff --git a/app/pdb/gimp-cmds.c b/app/pdb/gimp-cmds.c
index 8dda7d7..a702516 100644
--- a/app/pdb/gimp-cmds.c
+++ b/app/pdb/gimp-cmds.c
@@ -25,8 +25,8 @@
 
 #include "pdb-types.h"
 
-#include "base/base-utils.h"
 #include "core/gimp-parasites.h"
+#include "core/gimp-utils.h"
 #include "core/gimp.h"
 #include "core/gimpparamspecs.h"
 
@@ -65,7 +65,7 @@ getpid_invoker (GimpProcedure      *procedure,
   GValueArray *return_vals;
   gint32 pid = 0;
 
-  pid = get_pid ();
+  pid = gimp_get_pid ();
 
   return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
   g_value_set_int (&return_vals->values[1], pid);
diff --git a/app/widgets/gimpselectiondata.c b/app/widgets/gimpselectiondata.c
index 81311bc..b60d50b 100644
--- a/app/widgets/gimpselectiondata.c
+++ b/app/widgets/gimpselectiondata.c
@@ -27,9 +27,8 @@
 
 #include "widgets-types.h"
 
-#include "base/base-utils.h"
-
 #include "core/gimp.h"
+#include "core/gimp-utils.h"
 #include "core/gimpbrush.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpcurve.h"
@@ -424,7 +423,7 @@ gimp_selection_data_set_image (GtkSelectionData *selection,
   g_return_if_fail (selection != NULL);
   g_return_if_fail (GIMP_IS_IMAGE (image));
 
-  str = g_strdup_printf ("%d:%d", get_pid (), gimp_image_get_ID (image));
+  str = g_strdup_printf ("%d:%d", gimp_get_pid (), gimp_image_get_ID (image));
 
   gtk_selection_data_set (selection,
                           gtk_selection_data_get_target (selection),
@@ -450,7 +449,7 @@ gimp_selection_data_get_image (GtkSelectionData *selection,
       gint ID;
 
       if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
-          pid == get_pid ())
+          pid == gimp_get_pid ())
         {
           return gimp_image_get_by_ID (gimp, ID);
         }
@@ -469,7 +468,7 @@ gimp_selection_data_set_component (GtkSelectionData *selection,
   g_return_if_fail (selection != NULL);
   g_return_if_fail (GIMP_IS_IMAGE (image));
 
-  str = g_strdup_printf ("%d:%d:%d", get_pid (), gimp_image_get_ID (image),
+  str = g_strdup_printf ("%d:%d:%d", gimp_get_pid (), gimp_image_get_ID (image),
                          (gint) channel);
 
   gtk_selection_data_set (selection,
@@ -501,7 +500,7 @@ gimp_selection_data_get_component (GtkSelectionData *selection,
       gint ch;
 
       if (sscanf (str, "%i:%i:%i", &pid, &ID, &ch) == 3 &&
-          pid == get_pid ())
+          pid == gimp_get_pid ())
         {
           GimpImage *image = gimp_image_get_by_ID (gimp, ID);
 
@@ -524,7 +523,7 @@ gimp_selection_data_set_item (GtkSelectionData *selection,
   g_return_if_fail (selection != NULL);
   g_return_if_fail (GIMP_IS_ITEM (item));
 
-  str = g_strdup_printf ("%d:%d", get_pid (), gimp_item_get_ID (item));
+  str = g_strdup_printf ("%d:%d", gimp_get_pid (), gimp_item_get_ID (item));
 
   gtk_selection_data_set (selection,
                           gtk_selection_data_get_target (selection),
@@ -550,7 +549,7 @@ gimp_selection_data_get_item (GtkSelectionData *selection,
       gint ID;
 
       if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
-          pid == get_pid ())
+          pid == gimp_get_pid ())
         {
           return gimp_item_get_by_ID (gimp, ID);
         }
@@ -574,7 +573,7 @@ gimp_selection_data_set_object (GtkSelectionData *selection,
     {
       gchar *str;
 
-      str = g_strdup_printf ("%d:%p:%s", get_pid (), object, name);
+      str = g_strdup_printf ("%d:%p:%s", gimp_get_pid (), object, name);
 
       gtk_selection_data_set (selection,
                               gtk_selection_data_get_target (selection),
@@ -745,7 +744,7 @@ gimp_selection_data_get_object (GtkSelectionData *selection,
       gint     name_offset = 0;
 
       if (sscanf (str, "%i:%p:%n", &pid, &object_addr, &name_offset) >= 2 &&
-          pid == get_pid () && name_offset > 0)
+          pid == gimp_get_pid () && name_offset > 0)
         {
           const gchar *name = str + name_offset;
 
diff --git a/tools/pdbgen/pdb/gimp.pdb b/tools/pdbgen/pdb/gimp.pdb
index 7e985c7..98d6f8f 100644
--- a/tools/pdbgen/pdb/gimp.pdb
+++ b/tools/pdbgen/pdb/gimp.pdb
@@ -55,10 +55,10 @@ HELP
     );
 
     %invoke = (
-	headers => [ qw("base/base-utils.h") ],
+	headers => [ qw("core/gimp-utils.h") ],
 	code    => <<'CODE'
 {
-  pid = get_pid ();
+  pid = gimp_get_pid ();
 }
 CODE
     );



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]