mathematical 1.6.20 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2008-2016, Troy D. Hanson http://troydhanson.github.com/uthash/
2
+ Copyright (c) 2008-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -26,21 +26,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #ifndef UTARRAY_H
27
27
  #define UTARRAY_H
28
28
 
29
- #define UTARRAY_VERSION 2.0.1
30
-
31
- #ifdef __GNUC__
32
- #define _UNUSED_ __attribute__ ((__unused__))
33
- #else
34
- #define _UNUSED_
35
- #endif
29
+ #define UTARRAY_VERSION 2.3.0
36
30
 
37
31
  #include <stddef.h> /* size_t */
38
32
  #include <string.h> /* memset, etc */
39
33
  #include <stdlib.h> /* exit */
40
- #include "../../src/string_dup.h"
41
34
 
42
- #ifndef oom
43
- #define oom() exit(-1)
35
+ #ifdef __GNUC__
36
+ #define UTARRAY_UNUSED __attribute__((__unused__))
37
+ #else
38
+ #define UTARRAY_UNUSED
39
+ #endif
40
+
41
+ #ifndef utarray_oom
42
+ #define utarray_oom() exit(-1)
44
43
  #endif
45
44
 
46
45
  typedef void (ctor_f)(void *dst, const void *src);
@@ -79,7 +78,9 @@ typedef struct {
79
78
 
80
79
  #define utarray_new(a,_icd) do { \
81
80
  (a) = (UT_array*)malloc(sizeof(UT_array)); \
82
- if ((a) == NULL) oom(); \
81
+ if ((a) == NULL) { \
82
+ utarray_oom(); \
83
+ } \
83
84
  utarray_init(a,_icd); \
84
85
  } while(0)
85
86
 
@@ -93,7 +94,9 @@ typedef struct {
93
94
  char *utarray_tmp; \
94
95
  while (((a)->i+(by)) > (a)->n) { (a)->n = ((a)->n ? (2*(a)->n) : 8); } \
95
96
  utarray_tmp=(char*)realloc((a)->d, (a)->n*(a)->icd.sz); \
96
- if (utarray_tmp == NULL) oom(); \
97
+ if (utarray_tmp == NULL) { \
98
+ utarray_oom(); \
99
+ } \
97
100
  (a)->d=utarray_tmp; \
98
101
  } \
99
102
  } while(0)
@@ -119,7 +122,7 @@ typedef struct {
119
122
  #define utarray_len(a) ((a)->i)
120
123
 
121
124
  #define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL)
122
- #define _utarray_eltptr(a,j) ((a)->d + ((a)->icd.sz * (j)))
125
+ #define _utarray_eltptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j))))
123
126
 
124
127
  #define utarray_insert(a,p,j) do { \
125
128
  if ((j) > (a)->i) utarray_resize(a,j); \
@@ -217,23 +220,33 @@ typedef struct {
217
220
  #define utarray_find(a,v,cmp) bsearch((v),(a)->d,(a)->i,(a)->icd.sz,cmp)
218
221
 
219
222
  #define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL)
220
- #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))
221
- #define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) > 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
223
+ #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))
224
+ #define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) != 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
222
225
  #define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL)
223
- #define utarray_eltidx(a,e) (((char*)(e) >= (a)->d) ? (((char*)(e) - (a)->d)/(a)->icd.sz) : -1)
226
+ #define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz)
224
227
 
225
228
  /* last we pre-define a few icd for common utarrays of ints and strings */
226
229
  static void utarray_str_cpy(void *dst, const void *src) {
227
- char **_src = (char**)src, **_dst = (char**)dst;
228
- *_dst = (*_src == NULL) ? NULL : string_dup(*_src);
230
+ char *const *srcc = (char *const *)src;
231
+ char **dstc = (char**)dst;
232
+ if (*srcc == NULL) {
233
+ *dstc = NULL;
234
+ } else {
235
+ *dstc = (char*)malloc(strlen(*srcc) + 1);
236
+ if (*dstc == NULL) {
237
+ utarray_oom();
238
+ } else {
239
+ strcpy(*dstc, *srcc);
240
+ }
241
+ }
229
242
  }
230
243
  static void utarray_str_dtor(void *elt) {
231
244
  char **eltc = (char**)elt;
232
245
  if (*eltc != NULL) free(*eltc);
233
246
  }
234
- static const UT_icd ut_str_icd _UNUSED_ = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
235
- static const UT_icd ut_int_icd _UNUSED_ = {sizeof(int),NULL,NULL,NULL};
236
- static const UT_icd ut_ptr_icd _UNUSED_ = {sizeof(void*),NULL,NULL,NULL};
247
+ static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
248
+ static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int),NULL,NULL,NULL};
249
+ static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void*),NULL,NULL,NULL};
237
250
 
238
251
 
239
252
  #endif /* UTARRAY_H */