Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/elftoolchain/dist/common Sync 'utarray.h' and '...



details:   https://anonhg.NetBSD.org/src/rev/d3e5bd724e70
branches:  trunk
changeset: 957129:d3e5bd724e70
user:      jkoshy <jkoshy%NetBSD.org@localhost>
date:      Wed Nov 18 22:23:05 2020 +0000

description:
Sync 'utarray.h' and 'uthash.h' with elftoolchain revision [r3891].

This change upgrades these files to UT{HASH,ARRAY}_VERSION 2.1.0.

diffstat:

 external/bsd/elftoolchain/dist/common/utarray.h |   120 +-
 external/bsd/elftoolchain/dist/common/uthash.h  |  1283 +++++++++++++---------
 2 files changed, 822 insertions(+), 581 deletions(-)

diffs (truncated from 1855 to 300 lines):

diff -r 85405240e7af -r d3e5bd724e70 external/bsd/elftoolchain/dist/common/utarray.h
--- a/external/bsd/elftoolchain/dist/common/utarray.h   Wed Nov 18 20:00:15 2020 +0000
+++ b/external/bsd/elftoolchain/dist/common/utarray.h   Wed Nov 18 22:23:05 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: utarray.h,v 1.2 2014/03/09 16:58:03 christos Exp $     */
+/*     $NetBSD: utarray.h,v 1.3 2020/11/18 22:23:05 jkoshy Exp $       */
 
 /*
-Copyright (c) 2008-2013, Troy D. Hanson   http://uthash.sourceforge.net
+Copyright (c) 2008-2018, Troy D. Hanson   http://troydhanson.github.com/uthash/
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -23,28 +23,30 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/* Id: utarray.h 2694 2012-11-24 17:11:58Z kaiwang27  */
-
-/* a dynamic array implementation using macros 
- * see http://uthash.sourceforge.net/utarray
+/* a dynamic array implementation using macros
  */
 #ifndef UTARRAY_H
 #define UTARRAY_H
 
-#define UTARRAY_VERSION 1.9.7
-
-#ifdef __GNUC__
-#define _UNUSED_ __attribute__ ((__unused__)) 
-#else
-#define _UNUSED_ 
-#endif
+#define UTARRAY_VERSION 2.1.0
 
 #include <stddef.h>  /* size_t */
 #include <string.h>  /* memset, etc */
 #include <stdlib.h>  /* exit */
 
-#ifndef oom
-#define oom() exit(-1)
+#ifdef __GNUC__
+#define UTARRAY_UNUSED __attribute__((__unused__))
+#else
+#define UTARRAY_UNUSED
+#endif
+
+#ifdef oom
+#error "The name of macro 'oom' has been changed to 'utarray_oom'. Please update your code."
+#define utarray_oom() oom()
+#endif
+
+#ifndef utarray_oom
+#define utarray_oom() exit(-1)
 #endif
 
 typedef void (ctor_f)(void *dst, const void *src);
@@ -65,13 +67,13 @@
 
 #define utarray_init(a,_icd) do {                                             \
   memset(a,0,sizeof(UT_array));                                               \
-  (a)->icd=*_icd;                                                             \
+  (a)->icd = *(_icd);                                                         \
 } while(0)
 
 #define utarray_done(a) do {                                                  \
   if ((a)->n) {                                                               \
     if ((a)->icd.dtor) {                                                      \
-      size_t _ut_i;                                                           \
+      unsigned _ut_i;                                                         \
       for(_ut_i=0; _ut_i < (a)->i; _ut_i++) {                                 \
         (a)->icd.dtor(utarray_eltptr(a,_ut_i));                               \
       }                                                                       \
@@ -82,7 +84,10 @@
 } while(0)
 
 #define utarray_new(a,_icd) do {                                              \
-  a=(UT_array*)malloc(sizeof(UT_array));                                      \
+  (a) = (UT_array*)malloc(sizeof(UT_array));                                  \
+  if ((a) == NULL) {                                                          \
+    utarray_oom();                                                            \
+  }                                                                           \
   utarray_init(a,_icd);                                                       \
 } while(0)
 
@@ -92,9 +97,14 @@
 } while(0)
 
 #define utarray_reserve(a,by) do {                                            \
-  if (((a)->i+by) > ((a)->n)) {                                               \
-    while(((a)->i+by) > ((a)->n)) { (a)->n = ((a)->n ? (2*(a)->n) : 8); }     \
-    if ( ((a)->d=(char*)realloc((a)->d, (a)->n*(a)->icd.sz)) == NULL) oom();  \
+  if (((a)->i+(by)) > (a)->n) {                                               \
+    char *utarray_tmp;                                                        \
+    while (((a)->i+(by)) > (a)->n) { (a)->n = ((a)->n ? (2*(a)->n) : 8); }    \
+    utarray_tmp=(char*)realloc((a)->d, (a)->n*(a)->icd.sz);                   \
+    if (utarray_tmp == NULL) {                                                \
+      utarray_oom();                                                          \
+    }                                                                         \
+    (a)->d=utarray_tmp;                                                       \
   }                                                                           \
 } while(0)
 
@@ -119,11 +129,11 @@
 #define utarray_len(a) ((a)->i)
 
 #define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL)
-#define _utarray_eltptr(a,j) ((char*)((a)->d + ((a)->icd.sz*(j) )))
+#define _utarray_eltptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j))))
 
 #define utarray_insert(a,p,j) do {                                            \
+  if ((j) > (a)->i) utarray_resize(a,j);                                      \
   utarray_reserve(a,1);                                                       \
-  if (j > (a)->i) break;                                                      \
   if ((j) < (a)->i) {                                                         \
     memmove( _utarray_eltptr(a,(j)+1), _utarray_eltptr(a,j),                  \
              ((a)->i - (j))*((a)->icd.sz));                                   \
@@ -135,7 +145,7 @@
 
 #define utarray_inserta(a,w,j) do {                                           \
   if (utarray_len(w) == 0) break;                                             \
-  if (j > (a)->i) break;                                                      \
+  if ((j) > (a)->i) utarray_resize(a,j);                                      \
   utarray_reserve(a,utarray_len(w));                                          \
   if ((j) < (a)->i) {                                                         \
     memmove(_utarray_eltptr(a,(j)+utarray_len(w)),                            \
@@ -143,9 +153,9 @@
             ((a)->i - (j))*((a)->icd.sz));                                    \
   }                                                                           \
   if ((a)->icd.copy) {                                                        \
-    size_t _ut_i;                                                             \
+    unsigned _ut_i;                                                           \
     for(_ut_i=0;_ut_i<(w)->i;_ut_i++) {                                       \
-      (a)->icd.copy(_utarray_eltptr(a,j+_ut_i), _utarray_eltptr(w,_ut_i));    \
+      (a)->icd.copy(_utarray_eltptr(a, (j) + _ut_i), _utarray_eltptr(w, _ut_i)); \
     }                                                                         \
   } else {                                                                    \
     memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0),                        \
@@ -155,55 +165,55 @@
 } while(0)
 
 #define utarray_resize(dst,num) do {                                          \
-  size_t _ut_i;                                                               \
-  if (dst->i > (size_t)(num)) {                                               \
+  unsigned _ut_i;                                                             \
+  if ((dst)->i > (unsigned)(num)) {                                           \
     if ((dst)->icd.dtor) {                                                    \
-      for(_ut_i=num; _ut_i < dst->i; _ut_i++) {                               \
-        (dst)->icd.dtor(utarray_eltptr(dst,_ut_i));                           \
+      for (_ut_i = (num); _ut_i < (dst)->i; ++_ut_i) {                        \
+        (dst)->icd.dtor(_utarray_eltptr(dst, _ut_i));                         \
       }                                                                       \
     }                                                                         \
-  } else if (dst->i < (size_t)(num)) {                                        \
-    utarray_reserve(dst,num-dst->i);                                          \
+  } else if ((dst)->i < (unsigned)(num)) {                                    \
+    utarray_reserve(dst, (num) - (dst)->i);                                   \
     if ((dst)->icd.init) {                                                    \
-      for(_ut_i=dst->i; _ut_i < num; _ut_i++) {                               \
-        (dst)->icd.init(utarray_eltptr(dst,_ut_i));                           \
+      for (_ut_i = (dst)->i; _ut_i < (unsigned)(num); ++_ut_i) {              \
+        (dst)->icd.init(_utarray_eltptr(dst, _ut_i));                         \
       }                                                                       \
     } else {                                                                  \
-      memset(_utarray_eltptr(dst,dst->i),0,(dst)->icd.sz*(num-dst->i));       \
+      memset(_utarray_eltptr(dst, (dst)->i), 0, (dst)->icd.sz*((num) - (dst)->i)); \
     }                                                                         \
   }                                                                           \
-  dst->i = num;                                                               \
+  (dst)->i = (num);                                                           \
 } while(0)
 
 #define utarray_concat(dst,src) do {                                          \
-  utarray_inserta((dst),(src),utarray_len(dst));                              \
+  utarray_inserta(dst, src, utarray_len(dst));                                \
 } while(0)
 
 #define utarray_erase(a,pos,len) do {                                         \
   if ((a)->icd.dtor) {                                                        \
-    size_t _ut_i;                                                             \
-    for(_ut_i=0; _ut_i < len; _ut_i++) {                                      \
-      (a)->icd.dtor(utarray_eltptr((a),pos+_ut_i));                           \
+    unsigned _ut_i;                                                           \
+    for (_ut_i = 0; _ut_i < (len); _ut_i++) {                                 \
+      (a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i));                        \
     }                                                                         \
   }                                                                           \
-  if ((a)->i > (pos+len)) {                                                   \
-    memmove( _utarray_eltptr((a),pos), _utarray_eltptr((a),pos+len),          \
-            (((a)->i)-(pos+len))*((a)->icd.sz));                              \
+  if ((a)->i > ((pos) + (len))) {                                             \
+    memmove(_utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)),       \
+            ((a)->i - ((pos) + (len))) * (a)->icd.sz);                        \
   }                                                                           \
   (a)->i -= (len);                                                            \
 } while(0)
 
 #define utarray_renew(a,u) do {                                               \
-  if (a) utarray_clear(a); \
-  else utarray_new((a),(u));   \
-} while(0) 
+  if (a) utarray_clear(a);                                                    \
+  else utarray_new(a, u);                                                     \
+} while(0)
 
 #define utarray_clear(a) do {                                                 \
   if ((a)->i > 0) {                                                           \
     if ((a)->icd.dtor) {                                                      \
-      size_t _ut_i;                                                           \
+      unsigned _ut_i;                                                         \
       for(_ut_i=0; _ut_i < (a)->i; _ut_i++) {                                 \
-        (a)->icd.dtor(utarray_eltptr(a,_ut_i));                               \
+        (a)->icd.dtor(_utarray_eltptr(a, _ut_i));                             \
       }                                                                       \
     }                                                                         \
     (a)->i = 0;                                                               \
@@ -217,10 +227,10 @@
 #define utarray_find(a,v,cmp) bsearch((v),(a)->d,(a)->i,(a)->icd.sz,cmp)
 
 #define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL)
-#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((int)((a)->i) > (utarray_eltidx(a,e)+1)) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
-#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) > 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
+#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((a)->i != utarray_eltidx(a,e)+1) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
+#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) != 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
 #define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL)
-#define utarray_eltidx(a,e) (((char*)(e) >= (char*)((a)->d)) ? (int)(((char*)(e) - (char*)((a)->d))/(a)->icd.sz) : -1)
+#define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz)
 
 /* last we pre-define a few icd for common utarrays of ints and strings */
 static void utarray_str_cpy(void *dst, const void *src) {
@@ -229,11 +239,11 @@
 }
 static void utarray_str_dtor(void *elt) {
   char **eltc = (char**)elt;
-  if (*eltc) free(*eltc);
+  if (*eltc != NULL) free(*eltc);
 }
-static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
-static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL};
-static const UT_icd ut_ptr_icd _UNUSED_ = {sizeof(void*),NULL,NULL,NULL};
+static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
+static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int),NULL,NULL,NULL};
+static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void*),NULL,NULL,NULL};
 
 
 #endif /* UTARRAY_H */
diff -r 85405240e7af -r d3e5bd724e70 external/bsd/elftoolchain/dist/common/uthash.h
--- a/external/bsd/elftoolchain/dist/common/uthash.h    Wed Nov 18 20:00:15 2020 +0000
+++ b/external/bsd/elftoolchain/dist/common/uthash.h    Wed Nov 18 22:23:05 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: uthash.h,v 1.2 2014/03/09 16:58:03 christos Exp $      */
+/*     $NetBSD: uthash.h,v 1.3 2020/11/18 22:23:05 jkoshy Exp $        */
 
 /*
-Copyright (c) 2003-2013, Troy D. Hanson     http://uthash.sourceforge.net
+Copyright (c) 2003-2018, Troy D. Hanson     http://troydhanson.github.com/uthash/
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -23,62 +23,87 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-/* Id: uthash.h 2682 2012-11-23 22:04:22Z kaiwang27  */
+#ifndef UTHASH_H
+#define UTHASH_H
 
-#ifndef UTHASH_H
-#define UTHASH_H 
+#define UTHASH_VERSION 2.1.0
 
-#include <string.h>   /* memcmp,strlen */
+#include <string.h>   /* memcmp, memset, strlen */
 #include <stddef.h>   /* ptrdiff_t */
-#include <stdlib.h>   /* exit() */
+#include <stdlib.h>   /* exit */
 
 /* These macros use decltype or the earlier __typeof GNU extension.
    As decltype is only available in newer compilers (VS2010 or gcc 4.3+
    when compiling c++ source) this code uses whatever method is needed
    or, for VS2008 where neither is available, uses casting workarounds. */
-#ifdef _MSC_VER         /* MS compiler */
+#if !defined(DECLTYPE) && !defined(NO_DECLTYPE)
+#if defined(_MSC_VER)   /* MS compiler */
 #if _MSC_VER >= 1600 && defined(__cplusplus)  /* VS2010 or newer in C++ mode */
 #define DECLTYPE(x) (decltype(x))
 #else                   /* VS2008 or older (or VS2010 in C mode) */
 #define NO_DECLTYPE
-#define DECLTYPE(x)
 #endif
+#elif defined(__BORLANDC__) || defined(__ICCARM__) || defined(__LCC__) || defined(__WATCOMC__)
+#define NO_DECLTYPE
 #else                   /* GNU, Sun and other compilers */
 #define DECLTYPE(x) (__typeof(x))
 #endif
+#endif
 
 #ifdef NO_DECLTYPE
+#define DECLTYPE(x)
 #define DECLTYPE_ASSIGN(dst,src)                                                 \



Home | Main Index | Thread Index | Old Index