[SCM] Debian Qt/KDE packaging tools branch, master, updated. debian/0.13.1-12-gef732bc

Modestas Vainius modax at alioth.debian.org
Wed May 25 12:11:30 UTC 2011


The following commit has been merged in the master branch:
commit 6387248f7f5634f91622b111cddc2e8f9be57f80
Author: Modestas Vainius <modax at debian.org>
Date:   Wed May 25 02:28:53 2011 +0300

    DLRestrictions: rework and cleanup error functions. Export new APIs.
---
 debian/changelog                |    1 +
 dlrestrictions/dlrestrictions.c |   54 ++++++++++++++++++++++++--------------
 dlrestrictions/dlrestrictions.h |    8 +++++-
 3 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4ba4c0f..8aced16 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ pkg-kde-tools (0.14.0~pre1) UNRELEASED; urgency=low
     debian_dlrestrictions special symbol).
   * pkgkde-symbolshelper: expand qreal subst to float on sh4. (Closes: #627486)
   * DLRestrictions: hide dlr_are_symbol_objects_compatible() symbol.
+  * DLRestrictions: rework and cleanup error functions. Export new APIs.
 
  -- Modestas Vainius <modax at debian.org>  Tue, 24 May 2011 21:47:52 +0300
 
diff --git a/dlrestrictions/dlrestrictions.c b/dlrestrictions/dlrestrictions.c
index a7fc99e..39a5717 100644
--- a/dlrestrictions/dlrestrictions.c
+++ b/dlrestrictions/dlrestrictions.c
@@ -32,8 +32,7 @@
 
 static int debug_level;
 static const char *symbol_name = DLR_SYMBOL_NAME;
-static char extended_error[1024];
-static unsigned char extended_error_state;
+static char dlr_error_buf[1024];
 
 typedef struct __dlr_library {
     struct link_map *link_map;
@@ -76,33 +75,34 @@ static void dlr_debug(int level, const char *format, ...)
 #define dlr_debug(level, format, ...)
 #endif
 
-void dlr_set_error(const char *format, ...)
+static void dlr_set_error(const char *format, ...)
 {
     va_list ap;
 
-    va_start(ap, format);
-    vsnprintf(extended_error, sizeof(extended_error), format, ap);
-    va_end(ap);
-    extended_error_state = 1;
-
+    if (format == NULL) {
+        /* Reset error */
+        dlr_error_buf[0] = 0;
+    } else {
+        va_start(ap, format);
+        vsnprintf(dlr_error_buf, sizeof(dlr_error_buf), format, ap);
+        va_end(ap);
+    }
 }
 
-const char* dlr_extended_error(void)
+const char* dlr_error(void)
 {
-    if (!extended_error_state)
-        return NULL;
-    extended_error_state = 0;
-    return extended_error;
+    return (dlr_error_buf[0]) ? dlr_error_buf : NULL;
 }
 
-void dlr_print_pretty_error(const char *context)
+int dlr_snprintf_pretty_error(char *str, size_t n, const char *context)
 {
-#define DLR_PRINTF_PRETTY_ERROR(format, ...) \
-    fprintf(stderr, DLR_LIBRARY_NAME " error (%s): " format "
", context, __VA_ARGS__)
+#define DLR_SNPRINTF_PRETTY_ERROR(format, ...) \
+    snprintf(str, n, DLR_LIBRARY_NAME " error (%s): " format, context, __VA_ARGS__)
 
     const char *dlr_err, *sys_err;
+    int r;
 
-    dlr_err = dlr_extended_error();
+    dlr_err = dlr_error();
     sys_err = (errno != 0) ? strerror(errno) : NULL;
 
     if (dlr_err == NULL && sys_err == NULL)
@@ -110,13 +110,24 @@ void dlr_print_pretty_error(const char *context)
 
     if (dlr_err) {
         if (sys_err != NULL) {
-            DLR_PRINTF_PRETTY_ERROR("%s (sys=%s)", dlr_err, sys_err);
+            r = DLR_SNPRINTF_PRETTY_ERROR("%s (sys=%s)", dlr_err, sys_err);
         } else {
-            DLR_PRINTF_PRETTY_ERROR("%s", dlr_err);
+            r = DLR_SNPRINTF_PRETTY_ERROR("%s", dlr_err);
         }
     } else {
-        DLR_PRINTF_PRETTY_ERROR("%s", sys_err);
+        r = DLR_SNPRINTF_PRETTY_ERROR("%s", sys_err);
     }
+    return r;
+}
+
+void dlr_print_pretty_error(const char *context)
+{
+    char buf[2048];
+
+    strcpy(buf, "Unable to pretty print DLRestrictions error. Too long?");
+    dlr_snprintf_pretty_error(buf, 2048, context);
+    fputs(buf, stderr);
+    fprintf(stderr, "
");
 }
 
 void dlr_set_symbol_name(const char *name)
@@ -481,7 +492,10 @@ void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_
     void *h_global, *h_file;
     int status;
 
+    /* Reset error state */
     errno = 0;
+    dlr_set_error(NULL);
+
     h_file = dlmopen(LM_ID_NEWLM, file, RTLD_LAZY | RTLD_LOCAL);
     if (h_file == NULL) {
         return NULL;
diff --git a/dlrestrictions/dlrestrictions.h b/dlrestrictions/dlrestrictions.h
index 6aec588..5f92b93 100644
--- a/dlrestrictions/dlrestrictions.h
+++ b/dlrestrictions/dlrestrictions.h
@@ -20,6 +20,8 @@
 #ifndef _LIBRUNTIMERESTRICTIONS_H_
 #define _LIBRUNTIMERESTRICTIONS_H_
 
+#include <sys/types.h>
+
 #ifndef DLR_LIBRARY_NAME
 #define DLR_LIBRARY_NAME            "DLRestrictions"
 #endif
@@ -49,7 +51,11 @@ typedef struct {
 
 void dlr_set_symbol_name(const char *name);
 const char* dlr_get_symbol_name(void);
-const char* dlr_extended_error(void);
+
+/* Error functions */
+const char* dlr_error(void);
+int dlr_snprintf_pretty_error(char *str, size_t n, const char *context);
+void dlr_print_pretty_error(const char *context);
 
 void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_on_error);
 

-- 
Debian Qt/KDE packaging tools



More information about the pkg-kde-commits mailing list