[beast/devel: 22/77] BIRNET: remove more utilities that are provided by Rapicorn



commit 0570872860ff2f045dc5c4c6e32fd4aabd74cedc
Author: Tim Janik <timj gnu org>
Date:   Fri Mar 29 02:15:35 2013 +0000

    BIRNET: remove more utilities that are provided by Rapicorn

 beast-gtk/bstmain.cc       |    2 +-
 birnet/birnetdebugtools.hh |    2 +-
 birnet/birnetutils.cc      |  322 --------------------------------------------
 birnet/birnetutils.hh      |   50 +-------
 bse/bsecxxarg.hh           |    4 +-
 sfi/sfiwrapper.cc          |    7 -
 sfi/sfiwrapper.hh          |    2 -
 7 files changed, 6 insertions(+), 383 deletions(-)
---
diff --git a/beast-gtk/bstmain.cc b/beast-gtk/bstmain.cc
index 71be961..a0bd16e 100644
--- a/beast-gtk/bstmain.cc
+++ b/beast-gtk/bstmain.cc
@@ -409,7 +409,7 @@ main (int   argc,
     }
 
   // misc cleanups
-  birnet_cleanup_force_handlers();
+  Rapicorn::cleanup_force_handlers();
   bse_object_debug_leaks ();
   Bse::TaskRegistry::remove (Rapicorn::ThisThread::thread_pid());
 
diff --git a/birnet/birnetdebugtools.hh b/birnet/birnetdebugtools.hh
index 0b272b8..e5be61e 100644
--- a/birnet/birnetdebugtools.hh
+++ b/birnet/birnetdebugtools.hh
@@ -4,7 +4,7 @@
 #include <birnet/birnetutils.hh>
 #include <stdarg.h>
 namespace Birnet {
-class DebugChannel : public virtual ReferenceCountImpl {
+class DebugChannel : public virtual ReferenceCountable {
   BIRNET_PRIVATE_CLASS_COPY (DebugChannel);
 protected:
   explicit              DebugChannel        ();
diff --git a/birnet/birnetutils.cc b/birnet/birnetutils.cc
index cb9825b..8671735 100644
--- a/birnet/birnetutils.cc
+++ b/birnet/birnetutils.cc
@@ -318,187 +318,6 @@ birnet_runtime_problemv (char        ewran_tag,
     }
 }
 
-/* --- file utils --- */
-/**
- * @namespace Birnet::Path
- * The Birnet::Path namespace covers function for file path manipulation and evaluation.
- */
-namespace Path {
-const String
-dirname (const String &path)
-{
-  const char *filename = path.c_str();
-  const char *base = strrchr (filename, BIRNET_DIR_SEPARATOR);
-  if (!base)
-    return ".";
-  while (*base == BIRNET_DIR_SEPARATOR && base > filename)
-    base--;
-  return String (filename, base - filename + 1);
-}
-const String
-basename (const String &path)
-{
-  const char *filename = path.c_str();
-  const char *base = strrchr (filename, BIRNET_DIR_SEPARATOR);
-  if (!base)
-    return filename;
-  return String (base + 1);
-}
-bool
-isabs (const String &path)
-{
-  return g_path_is_absolute (path.c_str());
-}
-const String
-skip_root (const String &path)
-{
-  const char *frag = g_path_skip_root (path.c_str());
-  return frag;
-}
-const String
-join (const String &frag0, const String &frag1,
-      const String &frag2, const String &frag3,
-      const String &frag4, const String &frag5,
-      const String &frag6, const String &frag7,
-      const String &frag8, const String &frag9,
-      const String &frag10, const String &frag11,
-      const String &frag12, const String &frag13,
-      const String &frag14, const String &frag15)
-{
-  char *cpath = g_build_path (BIRNET_DIR_SEPARATOR_S, frag0.c_str(),
-                              frag1.c_str(), frag2.c_str(), frag3.c_str(), frag4.c_str(), 
-                              frag5.c_str(), frag6.c_str(), frag7.c_str(), frag8.c_str(),
-                              frag9.c_str(), frag10.c_str(), frag11.c_str(), frag12.c_str(),
-                              frag13.c_str(), frag14.c_str(), frag15.c_str(), NULL);
-  String path (cpath);
-  g_free (cpath);
-  return path;
-}
-static int
-errno_check_file (const char *file_name,
-                  const char *mode)
-{
-  uint access_mask = 0, nac = 0;
-  if (strchr (mode, 'e'))       /* exists */
-    nac++, access_mask |= F_OK;
-  if (strchr (mode, 'r'))       /* readable */
-    nac++, access_mask |= R_OK;
-  if (strchr (mode, 'w'))       /* writable */
-    nac++, access_mask |= W_OK;
-  bool check_exec = strchr (mode, 'x') != NULL;
-  if (check_exec)               /* executable */
-    nac++, access_mask |= X_OK;
-  /* on some POSIX systems, X_OK may succeed for root without any
-   * executable bits set, so we also check via stat() below.
-   */
-  if (nac && access (file_name, access_mask) < 0)
-    return -errno;
-  bool check_file = strchr (mode, 'f') != NULL;     /* open as file */
-  bool check_dir  = strchr (mode, 'd') != NULL;     /* open as directory */
-  bool check_link = strchr (mode, 'l') != NULL;     /* open as link */
-  bool check_char = strchr (mode, 'c') != NULL;     /* open as character device */
-  bool check_block = strchr (mode, 'b') != NULL;    /* open as block device */
-  bool check_pipe = strchr (mode, 'p') != NULL;     /* open as pipe */
-  bool check_socket = strchr (mode, 's') != NULL;   /* open as socket */
-  if (check_exec || check_file || check_dir || check_link || check_char || check_block || check_pipe || 
check_socket)
-    {
-      struct stat st;
-      if (check_link)
-        {
-          if (lstat (file_name, &st) < 0)
-            return -errno;
-        }
-      else if (stat (file_name, &st) < 0)
-        return -errno;
-      if (0)
-        g_printerr ("file-check(\"%s\",\"%s\"): %s%s%s%s%s%s%s\n",
-                    file_name, mode,
-                    S_ISREG (st.st_mode) ? "f" : "",
-                    S_ISDIR (st.st_mode) ? "d" : "",
-                    S_ISLNK (st.st_mode) ? "l" : "",
-                    S_ISCHR (st.st_mode) ? "c" : "",
-                    S_ISBLK (st.st_mode) ? "b" : "",
-                    S_ISFIFO (st.st_mode) ? "p" : "",
-                    S_ISSOCK (st.st_mode) ? "s" : "");
-      if (S_ISDIR (st.st_mode) && (check_file || check_link || check_char || check_block || check_pipe))
-        return -EISDIR;
-      if (check_file && !S_ISREG (st.st_mode))
-        return -EINVAL;
-      if (check_dir && !S_ISDIR (st.st_mode))
-        return -ENOTDIR;
-      if (check_link && !S_ISLNK (st.st_mode))
-        return -EINVAL;
-      if (check_char && !S_ISCHR (st.st_mode))
-        return -ENODEV;
-      if (check_block && !S_ISBLK (st.st_mode))
-        return -ENOTBLK;
-      if (check_pipe && !S_ISFIFO (st.st_mode))
-        return -ENXIO;
-      if (check_socket && !S_ISSOCK (st.st_mode))
-        return -ENOTSOCK;
-      if (check_exec && !(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
-        return -EACCES; /* for root executable, any +x bit is good enough */
-    }
-  return 0;
-}
-/**
- * @param file  possibly relative filename
- * @param mode  feature string
- * @return      true if @a file adhears to @a mode
- *
- * Perform various checks on @a file and return whether all
- * checks passed. On failure, errno is set appropriately, and
- * FALSE is returned. Available features to be checked for are:
- * @li @c e - @a file must exist
- * @li @c r - @a file must be readable
- * @li @c w - @a file must be writable
- * @li @c x - @a file must be executable
- * @li @c f - @a file must be a regular file
- * @li @c d - @a file must be a directory
- * @li @c l - @a file must be a symbolic link
- * @li @c c - @a file must be a character device
- * @li @c b - @a file must be a block device
- * @li @c p - @a file must be a named pipe
- * @li @c s - @a file must be a socket.
- */
-bool
-check (const String &file,
-       const String &mode)
-{
-  int err = file.size() && mode.size() ? errno_check_file (file.c_str(), mode.c_str()) : -EFAULT;
-  errno = err < 0 ? -err : 0;
-  return errno == 0;
-}
-/**
- * @param file1  possibly relative filename
- * @param file2  possibly relative filename
- * @return       TRUE if @a file1 and @a file2 are equal
- *
- * Check whether @a file1 and @a file2 are pointing to the same inode
- * in the same file system on the same device.
- */
-bool
-equals (const String &file1,
-        const String &file2)
-{
-  if (!file1.size() || !file2.size())
-    return file1.size() == file2.size();
-  struct stat st1 = { 0, }, st2 = { 0, };
-  int err1 = 0, err2 = 0;
-  errno = 0;
-  if (stat (file1.c_str(), &st1) < 0 && stat (file1.c_str(), &st1) < 0)
-    err1 = errno;
-  errno = 0;
-  if (stat (file2.c_str(), &st2) < 0 && stat (file2.c_str(), &st2) < 0)
-    err2 = errno;
-  if (err1 || err2)
-    return err1 == err2;
-  return (st1.st_dev  == st2.st_dev &&
-          st1.st_ino  == st2.st_ino &&
-          st1.st_rdev == st2.st_rdev);
-}
-} // Path
-
 /* --- url handling --- */
 bool
 url_test_show (const char *url)
@@ -681,146 +500,5 @@ url_show_with_cookie (const char *url,
   if (!success)
     browser_launch_warning (url);
 }
-/* --- cleanups --- */
-typedef struct {
-  uint           id;
-  GDestroyNotify handler;
-  void          *data;
-} Cleanup;
-static Rapicorn::Mutex cleanup_mutex;
-static GSList *cleanup_list = NULL;
-static void
-cleanup_exec_Lm (Cleanup *cleanup)
-{
-  cleanup_list = g_slist_remove (cleanup_list, cleanup);
-  g_source_remove (cleanup->id);
-  GDestroyNotify handler = cleanup->handler;
-  void *data = cleanup->data;
-  g_free (cleanup);
-  cleanup_mutex.unlock();
-  handler (data);
-  cleanup_mutex.lock();
-}
-/**
- * Force all cleanup handlers (see birnet_cleanup_add()) to be immediately
- * executed. This function should be called at program exit to execute
- * cleanup handlers which have timeouts that have not yet expired.
- */
-void
-cleanup_force_handlers (void)
-{
-  cleanup_mutex.lock();
-  while (cleanup_list)
-    cleanup_exec_Lm ((Cleanup*) cleanup_list->data);
-  cleanup_mutex.unlock();
-}
-static gboolean
-cleanup_exec (gpointer data)
-{
-  cleanup_mutex.lock();
-  cleanup_exec_Lm ((Cleanup*) data);
-  cleanup_mutex.unlock();
-  return FALSE;
-}
-/**
- * @param timeout_ms    timeout in milliseconds
- * @param handler       cleanup handler to run
- * @param data          cleanup handler data
- *
- * Register a cleanup handler, the @a handler is guaranteed to be run
- * asyncronously (i.e. not from within cleanup_add()). The cleanup
- * handler will be called as soon as @a timeout_ms has elapsed or
- * cleanup_force_handlers() is called.
- */
-uint
-cleanup_add (guint          timeout_ms,
-             GDestroyNotify handler,
-             void          *data)
-{
-  Cleanup *cleanup = g_new0 (Cleanup, 1);
-  cleanup->handler = handler;
-  cleanup->data = data;
-  cleanup->id = g_timeout_add (timeout_ms, cleanup_exec, cleanup);
-  cleanup_mutex.lock();
-  cleanup_list = g_slist_prepend (cleanup_list, cleanup);
-  cleanup_mutex.unlock();
-  return cleanup->id;
-}
-/* --- string utils --- */
-void
-memset4 (guint32        *mem,
-         guint32         filler,
-         guint           length)
-{
-  BIRNET_STATIC_ASSERT (sizeof (*mem) == 4);
-  BIRNET_STATIC_ASSERT (sizeof (filler) == 4);
-  BIRNET_STATIC_ASSERT (sizeof (wchar_t) == 4);
-  wmemset ((wchar_t*) mem, filler, length);
-}
 
-/* --- zintern support --- */
-#include <zlib.h>
-/**
- * @param decompressed_size exact size of the decompressed data to be returned
- * @param cdata             compressed data block
- * @param cdata_size        exact size of the compressed data block
- * @returns                 decompressed data block or NULL in low memory situations
- *
- * Decompress the data from @a cdata of length @a cdata_size into a newly
- * allocated block of size @a decompressed_size which is returned.
- * The returned block needs to be freed with g_free().
- * This function is intended to decompress data which has been compressed
- * with the birnet-zintern utility, so no errors should occour during
- * decompression.
- * Consequently, if any error occours during decompression or if the resulting
- * data block is of a size other than @a decompressed_size, the program will
- * abort with an appropriate error message.
- * If not enough memory could be allocated for decompression, NULL is returned.
- */
-uint8*
-zintern_decompress (unsigned int          decompressed_size,
-                    const unsigned char  *cdata,
-                    unsigned int          cdata_size)
-{
-  uLongf dlen = decompressed_size;
-  uint64 len = dlen + 1;
-  uint8 *text = (uint8*) g_try_malloc (len);
-  if (!text)
-    return NULL;        /* handle ENOMEM gracefully */
-  int64 result = uncompress (text, &dlen, cdata, cdata_size);
-  const char *err;
-  switch (result)
-    {
-    case Z_OK:
-      if (dlen == decompressed_size)
-        {
-          err = NULL;
-          break;
-        }
-      /* fall through */
-    case Z_DATA_ERROR:
-      err = "internal data corruption";
-      break;
-    case Z_MEM_ERROR:
-      err = "out of memory";
-      g_free (text);
-      return NULL;      /* handle ENOMEM gracefully */
-      break;
-    case Z_BUF_ERROR:
-      err = "insufficient buffer size";
-      break;
-    default:
-      err = "unknown error";
-      break;
-    }
-  if (err)
-    g_error ("failed to decompress (%p, %u): %s", cdata, cdata_size, err);
-  text[dlen] = 0;
-  return text;          /* success */
-}
-void
-zintern_free (uint8 *dc_data)
-{
-  g_free (dc_data);
-}
 } // Birnet
diff --git a/birnet/birnetutils.hh b/birnet/birnetutils.hh
index b9f607a..46626ba 100644
--- a/birnet/birnetutils.hh
+++ b/birnet/birnetutils.hh
@@ -3,7 +3,6 @@
 #define __BIRNET_UTILS_XX_HH__
 #include <birnet/birnetcdefs.h>
 #include <rapicorn.hh>
-#include <glib.h> /* g_free */
 #include <string>
 #include <vector>
 #include <map>
@@ -42,6 +41,7 @@ void birnet_runtime_problemv (char        ewran_tag,
                               const char *funcname,
                               const char *msgformat,
                               va_list     msgargs);
+
 /* --- private copy constructor and assignment operator --- */
 #define BIRNET_PRIVATE_CLASS_COPY(Class)        private: Class (const Class&); Class& operator= (const 
Class&);
 #ifdef  _BIRNET_SOURCE_EXTENSIONS
@@ -49,6 +49,7 @@ void birnet_runtime_problemv (char        ewran_tag,
 #define return_if_fail                          g_return_if_fail
 #define return_val_if_fail                      g_return_val_if_fail
 #endif  /* _BIRNET_SOURCE_EXTENSIONS */
+
 /* --- initialization --- */
 typedef BirnetInitValue    InitValue;
 typedef BirnetInitSettings InitSettings;
@@ -73,26 +74,6 @@ public:
                      int          _priority = 0);
 };
 
-/* --- file/path functionality --- */
-namespace Path {
-const String    dirname   (const String &path);
-const String    basename  (const String &path);
-bool            isabs     (const String &path);
-const String    skip_root (const String &path);
-const String    join      (const String &frag0, const String &frag1,
-                           const String &frag2 = "", const String &frag3 = "",
-                           const String &frag4 = "", const String &frag5 = "",
-                           const String &frag6 = "", const String &frag7 = "",
-                           const String &frag8 = "", const String &frag9 = "",
-                           const String &frag10 = "", const String &frag11 = "",
-                           const String &frag12 = "", const String &frag13 = "",
-                           const String &frag14 = "", const String &frag15 = "");
-bool            check     (const String &file,
-                           const String &mode);
-bool            equals    (const String &file1,
-                           const String &file2);
-} // Path
-
 /* --- url handling --- */
 void url_show                   (const char           *url);
 void url_show_with_cookie       (const char           *url,
@@ -103,33 +84,6 @@ bool url_test_show_with_cookie  (const char       *url,
                                  const char           *url_title,
                                  const char           *cookie);
 
-/* --- cleanup registration --- */
-uint cleanup_add                (uint                  timeout_ms,
-                                 void                (*destroy_data) (void*),
-                                 void                 *data);
-void cleanup_force_handlers     (void);
-
-/* --- string utils --- */
-void memset4                   (uint32              *mem,
-                                 uint32               filler,
-                                 uint                 length);
-
-/* --- zintern support --- */
-uint8*  zintern_decompress      (unsigned int          decompressed_size,
-                                 const unsigned char  *cdata,
-                                 unsigned int          cdata_size);
-void    zintern_free            (uint8                *dc_data);
-
-/* --- template errors --- */
-namespace TEMPLATE_ERROR {
-// to error out, call invalid_type<YourInvalidType>();
-template<typename Type> void invalid_type () { bool force_compiler_error = void (0); }
-// to error out, derive from InvalidType<YourInvalidType>
-template<typename Type> class InvalidType;
-}
-
-typedef Rapicorn::ReferenceCountable ReferenceCountImpl;
-
 } // Birnet
 
 #endif /* __BIRNET_UTILS_XX_HH__ */
diff --git a/bse/bsecxxarg.hh b/bse/bsecxxarg.hh
index 613e355..8a122b9 100644
--- a/bse/bsecxxarg.hh
+++ b/bse/bsecxxarg.hh
@@ -24,7 +24,7 @@ private:
   ptokenize (void const *)
   {     // other pointer types are not supported
     return "?";
-    Birnet::TEMPLATE_ERROR::invalid_type<U*>();
+    static_assert (0 == sizeof (U*), "unsupported pointer type");
   }
   template<typename U> const String
   tokenize (void (*) (U*))
@@ -36,7 +36,7 @@ private:
   tokenize (void (*) (U))
   {     // non-pointer type, not supported
     return "?";
-    Birnet::TEMPLATE_ERROR::invalid_type<U>();
+    static_assert (sizeof (U) != sizeof (U), "unsupported non-pointer type");
   }
 };
 const String tokenize_gtype (GType t);
diff --git a/sfi/sfiwrapper.cc b/sfi/sfiwrapper.cc
index a635ec9..c3e2e25 100644
--- a/sfi/sfiwrapper.cc
+++ b/sfi/sfiwrapper.cc
@@ -230,13 +230,6 @@ sfi_url_test_show_with_cookie (const char *url,
   return Birnet::url_test_show_with_cookie (url, url_title, cookie);
 }
 
-/* --- cleanup handlers --- */
-void
-birnet_cleanup_force_handlers (void)
-{
-  return Birnet::cleanup_force_handlers();
-}
-
 void
 sfi_runtime_problem (char        ewran_tag,
                      const char *domain,
diff --git a/sfi/sfiwrapper.hh b/sfi/sfiwrapper.hh
index 3ed5b6c..a775d76 100644
--- a/sfi/sfiwrapper.hh
+++ b/sfi/sfiwrapper.hh
@@ -154,8 +154,6 @@ bool sfi_url_test_show                      (const char           *url);
 bool sfi_url_test_show_with_cookie     (const char           *url,
                                         const char           *url_title,
                                         const char           *cookie);
-/* --- cleanup handlers --- */
-void birnet_cleanup_force_handlers     (void); // FIXME: remove
 
 #ifndef BIRNET__RUNTIME_PROBLEM
 #define BIRNET__RUNTIME_PROBLEM(ErrorWarningReturnAssertNotreach,domain,file,line,funcname,...) \


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