libtool-patches
[Top][All Lists]
Advanced

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

RE: Don't export lt__error_strings


From: Peter Ekberg
Subject: RE: Don't export lt__error_strings
Date: Sun, 25 Sep 2005 09:07:54 +0200

* Ralf Wildenhues wrote on Saturday, September 24, 2005 17:49 CEST:
> Hi Peter,
> 
> I noted that some of your mails are missing References: and 
> In-Reply-To:
> headers, which break threading (at least for the web 
> archives).  If it's
> easy to fix this, it would be nice if you could change it.  
> Don't bother
> wasting much time on this, though, it's not worth it.

*blush*

Only some? I have been expecting this request, and I will switch
to a "real" MUA once I get my "real" account back...

I will stop changing Subject: until that happens.

> * Peter Ekberg wrote on Fri, Sep 23, 2005 at 09:31:39PM CEST:
> > * Ralf Wildenhues wrote on Friday, September 23, 2005 15:37 CEST:
> > > * Peter Ekberg wrote on Fri, Sep 23, 2005 at 02:02:18PM CEST:
> 
> > > You wanted to set it to errormsg, not last_error.
> > 
> > Right. Sorry for wasting your time. I tested, then made one
> > last round of minor changes without retesting. I should know
> > better...
> 
> No problem at all.  The fix was really obvious.
> 
> > > If yes, please read dsohowto.pdf chapter 2.4.3 (or around 
> > > there) titled
> > 
> > Oh, that old worthless document. Who needs that crap? :-)
> 
> Hehe.  The only thing that bugs me is that it's not current wrt.
> libtool.  Oh well.
> 
> > Ok, going with the first method. I could not think up a good
> > way to get the preprocessor to find out the longest error string
> > so I counted it and defined LT_ERROR_LEN_MAX to 35. I then did
> > some tests to see if gcc warned about too long strings in case
> > someone carelessly adds a longer error string without changing
> > the define. To my discomfort gcc does not seem to count the
> > nul terminator when it decides whether to warn or not (-Wall).
> > But I might be mistaken and might have made a mistake counting
> > or something, but I don't think so. I checked a couple of times
> > because I was so baffled.
> 
> Well, the trick is easy: add the nul to the initialization strings
> explicitly:
>   const char s[4] = "abc\0";

Yes, figured that out myself after a while, but thanks for the
pointer.

> This way GCC will notify you.  The point is, when you say
>   const char t[3] = "abc";
> only 3 characters will be initialized, no trailing nul.  
> There are a few
> cases where this is beneficial: it saves you a byte, when you 
> know what
> you are doing.  (Side note: with the static storage, all 
> characters you
> do not specify explicitly will be initialized to nul.)
> 
> Feel free to change the error strings, or leave them as-is.

I changed them...

> >     * libltdl/libltdl/lt__private.h, libltdl/lt_error.c:
> >     Don't export the lt__last_error and lt__error_strings
> >     variables. Define lt__error_strings so that no relocations
> >     are needed.
> >     * libltdl/libltdl/lt__private.h (LT__STRERROR, LT__GETERROR)
> >     (LT__SETERRORSTR): Adjust to not use the above variables,
> >     instead use the following functions...
> >     * libltdl/lt_error.c: (lt__error_string, lt__get_last_error)
> >     (lt__set_last_error): Reimplement the functionality in
> >     these functions instead.
> 
> The patch is fine with one missing piece: please add assert()s for
> bounds-checked argument in lt__error_string().  A failure here is a
> clear sign of a programming error on our part (and not some 
> invalid but
> external-to-ltdl condition), so we may just fail here.  Go ahead and
> commit with this change.

Ok, commited this:

        * libltdl/libltdl/lt__private.h, libltdl/lt_error.c:
        Don't export the lt__last_error and lt__error_strings
        variables. Define lt__error_strings so that no relocations
        are needed.
        * libltdl/libltdl/lt__private.h (LT__STRERROR, LT__GETERROR)
        (LT__SETERRORSTR): Adjust to not use the above variables,
        instead use the following functions...
        * libltdl/lt_error.c: (lt__error_string, lt__get_last_error)
        (lt__set_last_error): Reimplement the functionality in
        these functions instead.
        * libltdl/libltdl/lt_error.h: Add LT_ERROR_LEN_MAX define for
        max error string length.
        (lt_dlerror_table): Append explicit nul terminators so that
        compilers warn more reliably if the above define is too small.


Index: libltdl/libltdl/lt__private.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt__private.h,v
retrieving revision 1.5
diff -u -r1.5 lt__private.h
--- libltdl/libltdl/lt__private.h       17 Sep 2005 07:29:03 -0000
1.5
+++ libltdl/libltdl/lt__private.h       24 Sep 2005 20:28:52 -0000
@@ -122,15 +122,15 @@
 /* Extract the diagnostic strings from the error table macro in the
same
    order as the enumerated indices in lt_error.h. */
 
-LT_SCOPE const char            *lt__error_strings[];
+#define LT__STRERROR(name)
lt__error_string(LT_CONC(LT_ERROR_,name))
 
-#define LT__STRERROR(name)
lt__error_strings[LT_CONC(LT_ERROR_,name)]
-
-#define LT__GETERROR(lvalue)         (lvalue) = lt__last_error;
-#define LT__SETERRORSTR(errormsg)     lt__last_error = (errormsg)
+#define LT__GETERROR(lvalue)         (lvalue) = lt__get_last_error()
+#define LT__SETERRORSTR(errormsg)     lt__set_last_error(errormsg)
 #define LT__SETERROR(errorcode)
LT__SETERRORSTR(LT__STRERROR(errorcode))
 
-LT_SCOPE const char            *lt__last_error;
+LT_SCOPE const char *lt__error_string  (int errorcode);
+LT_SCOPE const char *lt__get_last_error        (void);
+LT_SCOPE const char *lt__set_last_error        (const char *errormsg);
 
 LT_END_C_DECLS
 
Index: libltdl/libltdl/lt_error.h
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/libltdl/lt_error.h,v
retrieving revision 1.2
diff -u -r1.2 lt_error.h
--- libltdl/libltdl/lt_error.h  22 Apr 2005 10:10:30 -0000      1.2
+++ libltdl/libltdl/lt_error.h  24 Sep 2005 20:28:52 -0000
@@ -37,27 +37,28 @@
 /* Defining error strings alongside their symbolic names in a macro in
    this way allows us to expand the macro in different contexts with
    confidence that the enumeration of symbolic names will map correctly
-   onto the table of error strings.  */
+   onto the table of error strings.  \0 is appended to the strings to
+   expilicitely initialize the string terminator. */
 #define lt_dlerror_table
\
-    LT_ERROR(UNKNOWN,              "unknown error")
\
-    LT_ERROR(DLOPEN_NOT_SUPPORTED,  "dlopen support not available")
\
-    LT_ERROR(INVALID_LOADER,       "invalid loader")
\
-    LT_ERROR(INIT_LOADER,          "loader initialization failed")
\
-    LT_ERROR(REMOVE_LOADER,        "loader removal failed")
\
-    LT_ERROR(FILE_NOT_FOUND,       "file not found")
\
-    LT_ERROR(DEPLIB_NOT_FOUND,      "dependency library not found")
\
-    LT_ERROR(NO_SYMBOLS,           "no symbols defined")
\
-    LT_ERROR(CANNOT_OPEN,          "can't open the module")
\
-    LT_ERROR(CANNOT_CLOSE,         "can't close the module")
\
-    LT_ERROR(SYMBOL_NOT_FOUND,      "symbol not found")
\
-    LT_ERROR(NO_MEMORY,                    "not enough memory")
\
-    LT_ERROR(INVALID_HANDLE,       "invalid module handle")
\
-    LT_ERROR(BUFFER_OVERFLOW,      "internal buffer overflow")
\
-    LT_ERROR(INVALID_ERRORCODE,     "invalid errorcode")
\
-    LT_ERROR(SHUTDOWN,             "library already shutdown")
\
-    LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module")
\
-    LT_ERROR(INVALID_MUTEX_ARGS,    "internal error (code withdrawn)")
\
-    LT_ERROR(INVALID_POSITION,     "invalid search path insert
position")
+    LT_ERROR(UNKNOWN,              "unknown error\0")
\
+    LT_ERROR(DLOPEN_NOT_SUPPORTED,  "dlopen support not available\0")
\
+    LT_ERROR(INVALID_LOADER,       "invalid loader\0")
\
+    LT_ERROR(INIT_LOADER,          "loader initialization failed\0")
\
+    LT_ERROR(REMOVE_LOADER,        "loader removal failed\0")
\
+    LT_ERROR(FILE_NOT_FOUND,       "file not found\0")
\
+    LT_ERROR(DEPLIB_NOT_FOUND,     "dependency library not found\0")
\
+    LT_ERROR(NO_SYMBOLS,           "no symbols defined\0")
\
+    LT_ERROR(CANNOT_OPEN,          "can't open the module\0")
\
+    LT_ERROR(CANNOT_CLOSE,         "can't close the module\0")
\
+    LT_ERROR(SYMBOL_NOT_FOUND,     "symbol not found\0")
\
+    LT_ERROR(NO_MEMORY,                    "not enough memory\0")
\
+    LT_ERROR(INVALID_HANDLE,       "invalid module handle\0")
\
+    LT_ERROR(BUFFER_OVERFLOW,      "internal buffer overflow\0")
\
+    LT_ERROR(INVALID_ERRORCODE,            "invalid errorcode\0")
\
+    LT_ERROR(SHUTDOWN,             "library already shutdown\0")
\
+    LT_ERROR(CLOSE_RESIDENT_MODULE, "can't close resident module\0")
\
+    LT_ERROR(INVALID_MUTEX_ARGS,    "internal error (code
withdrawn)\0")\
+    LT_ERROR(INVALID_POSITION,     "invalid search path insert
position\0")
 
 /* Enumerate the symbolic error names. */
 enum {
@@ -67,6 +68,9 @@
 
        LT_ERROR_MAX
 };
+
+/* Should be max of the error string lengths above */
+#define LT_ERROR_LEN_MAX (35)
 
 /* These functions are only useful from inside custom module loaders.
*/
 LT_SCOPE int   lt_dladderror   (const char *diagnostic);
Index: libltdl/lt_error.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/lt_error.c,v
retrieving revision 1.4
diff -u -r1.4 lt_error.c
--- libltdl/lt_error.c  22 Apr 2005 10:10:30 -0000      1.4
+++ libltdl/lt_error.c  24 Sep 2005 20:28:53 -0000
@@ -29,14 +29,12 @@
 #include "lt_error.h"
 #include "lt__private.h"
 
-LT_GLOBAL_DATA const char      *lt__last_error = 0;
-LT_GLOBAL_DATA const char      *lt__error_strings[] =
+static const char      *lt__last_error = 0;
+static const char      lt__error_strings[LT_ERROR_MAX][LT_ERROR_LEN_MAX
+ 1] =
   {
 #define LT_ERROR(name, diagnostic)     (diagnostic),
     lt_dlerror_table
 #undef LT_ERROR
-
-    0
   };
 
 static const char    **user_error_strings      = 0;
@@ -86,4 +84,25 @@
     }
 
   return errors;
+}
+
+const char *
+lt__error_string (int errorcode)
+{
+  assert (errorcode >= 0);
+  assert (errorcode < LT_ERROR_MAX);
+
+  return lt__error_strings[errorcode];
+}
+
+const char *
+lt__get_last_error (void)
+{
+  return lt__last_error;
+}
+
+const char *
+lt__set_last_error (const char *errormsg)
+{
+  return lt__last_error = errormsg;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]