]> sjero.net Git - wget/blobdiff - src/wget.h
[svn] Renamed DEBUG to ENABLE_DEBUG.
[wget] / src / wget.h
index 45e2fd82f784f3c68a44501823e4dbfbfece4fe9..e742d47abffe09848e239a2a4ffe893a89a1cd39 100644 (file)
@@ -34,9 +34,10 @@ so, delete this exception statement from your version.  */
 #ifndef WGET_H
 #define WGET_H
 
-#ifndef DEBUG
-# define NDEBUG /* To kill off assertions */
-#endif /* not DEBUG */
+/* Disable assertions when debug support is not compiled in. */
+#ifndef ENABLE_DEBUG
+# define NDEBUG
+#endif
 
 /* Define this if you want primitive but extensive malloc debugging.
    It will make Wget extremely slow, so only do it in development
@@ -65,7 +66,7 @@ so, delete this exception statement from your version.  */
 /* No-op version of gettext, used for constant strings. */
 #define N_(string) (string)
 
-/* I18N NOTE: You will notice that none of the DEBUG messages are
+/* I18N NOTE: You will notice that none of the DEBUGP messages are
    marked as translatable.  This is intentional, for a few reasons:
 
    1) The debug messages are not meant for the users to look at, but
@@ -90,11 +91,11 @@ so, delete this exception statement from your version.  */
 #define DO_NOTHING do {} while (0)
 
 /* Print X if debugging is enabled; a no-op otherwise.  */
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG
 # define DEBUGP(x) do { if (opt.debug) { debug_logprintf x; } } while (0)
-#else  /* not DEBUG */
+#else  /* not ENABLE_DEBUG */
 # define DEBUGP(x) DO_NOTHING
-#endif /* not DEBUG */
+#endif /* not ENABLE_DEBUG */
 
 /* Make gcc check for the format of logmsg() and debug_logmsg().  */
 #ifdef __GNUC__
@@ -185,18 +186,13 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int));
 
    int a[5] = {1, 2};           -- countof(a) == 5
 
-   char *a[3] = {               -- countof(a) == 3
+   char *a[] = {                -- countof(a) == 3
      "foo", "bar", "baz"
-   };
-
-   And, most importantly, it works when the compiler counts the array
-   elements for you:
-
-   char *a[] = {                -- countof(a) == 4
-     "foo", "bar", "baz", "qux"
-   }  */
+   }; */
 #define countof(array) (sizeof (array) / sizeof (*(array)))
 
+#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))
+
 /* Copy the data delimited with BEG and END to alloca-allocated
    storage, and zero-terminate it.  Arguments are evaluated only once,
    in the order BEG, END, PLACE.  */
@@ -232,14 +228,9 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int));
 
 #define STRDUP_ALLOCA(ptr, str) do {           \
   (ptr) = (char *)alloca (strlen (str) + 1);   \
-  strcpy (ptr, str);                           \
+  strcpy ((ptr), (str));                       \
 } while (0)
 
-#define ALLOCA_ARRAY(type, len) ((type *) alloca ((len) * sizeof (type)))
-
-#define XREALLOC_ARRAY(ptr, type, len)                                 \
-     ((void) (ptr = (type *) xrealloc (ptr, (len) * sizeof (type))))
-
 /* Generally useful if you want to avoid arbitrary size limits but
    don't need a full dynamic array.  Assumes that BASEVAR points to a
    malloced array of TYPE objects (or possibly a NULL pointer, if
@@ -247,51 +238,19 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int));
    will realloc BASEVAR as necessary so that it can hold at least
    NEEDED_SIZE objects.  The reallocing is done by doubling, which
    ensures constant amortized time per element.  */
-#define DO_REALLOC(basevar, sizevar, needed_size, type)        do      \
-{                                                              \
-  /* Avoid side-effectualness.  */                             \
-  long do_realloc_needed_size = (needed_size);                 \
-  long do_realloc_newsize = 0;                                 \
-  while ((sizevar) < (do_realloc_needed_size)) {               \
-    do_realloc_newsize = 2*(sizevar);                          \
-    if (do_realloc_newsize < 32)                               \
-      do_realloc_newsize = 32;                                 \
-    (sizevar) = do_realloc_newsize;                            \
-  }                                                            \
-  if (do_realloc_newsize)                                      \
-    XREALLOC_ARRAY (basevar, type, do_realloc_newsize);                \
-} while (0)
-
-/* Use this for small stack-allocated memory chunks that might grow.
-   The initial array is created using alloca(), and this macro
-   requests it to grow.  If the needed size is larger than the array,
-   this macro will use malloc to allocate it to new size, and copy the
-   old contents.  After that, successive invocations behave just like
-   DO_REALLOC.  */
-#define DO_REALLOC_FROM_ALLOCA(basevar, sizevar, needed_size, allocap, type) do        \
+#define DO_REALLOC(basevar, sizevar, needed_size, type)        do                      \
 {                                                                              \
   /* Avoid side-effectualness.  */                                             \
   long do_realloc_needed_size = (needed_size);                                 \
-  long do_realloc_newsize = (sizevar);                                         \
-  while (do_realloc_newsize < do_realloc_needed_size) {                                \
-    do_realloc_newsize <<= 1;                                                  \
-    if (do_realloc_newsize < 16)                                               \
-      do_realloc_newsize = 16;                                                 \
+  long do_realloc_newsize = 0;                                                 \
+  while ((sizevar) < (do_realloc_needed_size)) {                               \
+    do_realloc_newsize = 2*(sizevar);                                          \
+    if (do_realloc_newsize < 32)                                               \
+      do_realloc_newsize = 32;                                                 \
+    (sizevar) = do_realloc_newsize;                                            \
   }                                                                            \
-  if (do_realloc_newsize != (sizevar))                                         \
-    {                                                                          \
-      if (!allocap)                                                            \
-       XREALLOC_ARRAY (basevar, type, do_realloc_newsize);                     \
-      else                                                                     \
-       {                                                                       \
-         void *drfa_new_basevar =                                              \
-               xmalloc (do_realloc_newsize * sizeof (type));                   \
-         memcpy (drfa_new_basevar, basevar, (sizevar) * sizeof (type));        \
-         (basevar) = drfa_new_basevar;                                         \
-         allocap = 0;                                                          \
-       }                                                                       \
-      (sizevar) = do_realloc_newsize;                                          \
-    }                                                                          \
+  if (do_realloc_newsize)                                                      \
+    basevar = (type *)xrealloc (basevar, do_realloc_newsize * sizeof (type));  \
 } while (0)
 
 /* Free FOO if it is non-NULL.  */