Browse code

32 and 64 bit pools

git-svn-id: file:///var/lib/svn/clamav-devel/branches/mpool@4301 77e5149b-7576-45b1-b177-96237e5ba77b

aCaB authored on 2008/10/29 07:45:31
Showing 5 changed files
... ...
@@ -371,12 +371,18 @@
371 371
 /* The number of bytes in type short */
372 372
 #undef SIZEOF_SHORT
373 373
 
374
+/* The number of bytes in type void * */
375
+#undef SIZEOF_VOID_P
376
+
374 377
 /* Define to 1 if you have the ANSI C header files. */
375 378
 #undef STDC_HEADERS
376 379
 
377 380
 /* Support for IPv6 */
378 381
 #undef SUPPORT_IPv6
379 382
 
383
+/* enable memory pools */
384
+#undef USE_MPOOL
385
+
380 386
 /* use syslog */
381 387
 #undef USE_SYSLOG
382 388
 
... ...
@@ -1515,6 +1515,7 @@ Optional Features:
1515 1515
   --disable-libtool-lock  avoid locking (might break parallel builds)
1516 1516
   --disable-gcc-vcheck	  do not check for buggy gcc version
1517 1517
   --enable-experimental	enable experimental code
1518
+  --enable-mempool	enable memory pools
1518 1519
   --enable-check           Enable 'check' unit tests (default=auto)
1519 1520
   --disable-rpath         do not hardcode runtime library paths
1520 1521
   --enable-coverage       turn on test coverage [default=no]
... ...
@@ -4754,13 +4755,13 @@ if test "${lt_cv_nm_interface+set}" = set; then
4754 4754
 else
4755 4755
   lt_cv_nm_interface="BSD nm"
4756 4756
   echo "int some_variable = 0;" > conftest.$ac_ext
4757
-  (eval echo "\"\$as_me:4757: $ac_compile\"" >&5)
4757
+  (eval echo "\"\$as_me:4758: $ac_compile\"" >&5)
4758 4758
   (eval "$ac_compile" 2>conftest.err)
4759 4759
   cat conftest.err >&5
4760
-  (eval echo "\"\$as_me:4760: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
4760
+  (eval echo "\"\$as_me:4761: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
4761 4761
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
4762 4762
   cat conftest.err >&5
4763
-  (eval echo "\"\$as_me:4763: output\"" >&5)
4763
+  (eval echo "\"\$as_me:4764: output\"" >&5)
4764 4764
   cat conftest.out >&5
4765 4765
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
4766 4766
     lt_cv_nm_interface="MS dumpbin"
... ...
@@ -5971,7 +5972,7 @@ ia64-*-hpux*)
5971 5971
   ;;
5972 5972
 *-*-irix6*)
5973 5973
   # Find out which ABI we are using.
5974
-  echo '#line 5974 "configure"' > conftest.$ac_ext
5974
+  echo '#line 5975 "configure"' > conftest.$ac_ext
5975 5975
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
5976 5976
   (eval $ac_compile) 2>&5
5977 5977
   ac_status=$?
... ...
@@ -7822,11 +7823,11 @@ else
7822 7822
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
7823 7823
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
7824 7824
    -e 's:$: $lt_compiler_flag:'`
7825
-   (eval echo "\"\$as_me:7825: $lt_compile\"" >&5)
7825
+   (eval echo "\"\$as_me:7826: $lt_compile\"" >&5)
7826 7826
    (eval "$lt_compile" 2>conftest.err)
7827 7827
    ac_status=$?
7828 7828
    cat conftest.err >&5
7829
-   echo "$as_me:7829: \$? = $ac_status" >&5
7829
+   echo "$as_me:7830: \$? = $ac_status" >&5
7830 7830
    if (exit $ac_status) && test -s "$ac_outfile"; then
7831 7831
      # The compiler can only warn and ignore the option if not recognized
7832 7832
      # So say no if there are warnings other than the usual output.
... ...
@@ -8161,11 +8162,11 @@ else
8161 8161
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8162 8162
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8163 8163
    -e 's:$: $lt_compiler_flag:'`
8164
-   (eval echo "\"\$as_me:8164: $lt_compile\"" >&5)
8164
+   (eval echo "\"\$as_me:8165: $lt_compile\"" >&5)
8165 8165
    (eval "$lt_compile" 2>conftest.err)
8166 8166
    ac_status=$?
8167 8167
    cat conftest.err >&5
8168
-   echo "$as_me:8168: \$? = $ac_status" >&5
8168
+   echo "$as_me:8169: \$? = $ac_status" >&5
8169 8169
    if (exit $ac_status) && test -s "$ac_outfile"; then
8170 8170
      # The compiler can only warn and ignore the option if not recognized
8171 8171
      # So say no if there are warnings other than the usual output.
... ...
@@ -8266,11 +8267,11 @@ else
8266 8266
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8267 8267
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8268 8268
    -e 's:$: $lt_compiler_flag:'`
8269
-   (eval echo "\"\$as_me:8269: $lt_compile\"" >&5)
8269
+   (eval echo "\"\$as_me:8270: $lt_compile\"" >&5)
8270 8270
    (eval "$lt_compile" 2>out/conftest.err)
8271 8271
    ac_status=$?
8272 8272
    cat out/conftest.err >&5
8273
-   echo "$as_me:8273: \$? = $ac_status" >&5
8273
+   echo "$as_me:8274: \$? = $ac_status" >&5
8274 8274
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
8275 8275
    then
8276 8276
      # The compiler can only warn and ignore the option if not recognized
... ...
@@ -8321,11 +8322,11 @@ else
8321 8321
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8322 8322
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8323 8323
    -e 's:$: $lt_compiler_flag:'`
8324
-   (eval echo "\"\$as_me:8324: $lt_compile\"" >&5)
8324
+   (eval echo "\"\$as_me:8325: $lt_compile\"" >&5)
8325 8325
    (eval "$lt_compile" 2>out/conftest.err)
8326 8326
    ac_status=$?
8327 8327
    cat out/conftest.err >&5
8328
-   echo "$as_me:8328: \$? = $ac_status" >&5
8328
+   echo "$as_me:8329: \$? = $ac_status" >&5
8329 8329
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
8330 8330
    then
8331 8331
      # The compiler can only warn and ignore the option if not recognized
... ...
@@ -11077,7 +11078,7 @@ else
11077 11077
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
11078 11078
   lt_status=$lt_dlunknown
11079 11079
   cat > conftest.$ac_ext <<_LT_EOF
11080
-#line 11080 "configure"
11080
+#line 11081 "configure"
11081 11081
 #include "confdefs.h"
11082 11082
 
11083 11083
 #if HAVE_DLFCN_H
... ...
@@ -11173,7 +11174,7 @@ else
11173 11173
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
11174 11174
   lt_status=$lt_dlunknown
11175 11175
   cat > conftest.$ac_ext <<_LT_EOF
11176
-#line 11176 "configure"
11176
+#line 11177 "configure"
11177 11177
 #include "confdefs.h"
11178 11178
 
11179 11179
 #if HAVE_DLFCN_H
... ...
@@ -13238,6 +13239,74 @@ cat >>confdefs.h <<_ACEOF
13238 13238
 _ACEOF
13239 13239
 
13240 13240
 
13241
+{ echo "$as_me:$LINENO: checking size of void *" >&5
13242
+echo $ECHO_N "checking size of void *... $ECHO_C" >&6; }
13243
+if test "${ac_cv_sizeof_void_p+set}" = set; then
13244
+  echo $ECHO_N "(cached) $ECHO_C" >&6
13245
+else
13246
+  for ac_size in 4 8 1 2 16  ; do # List sizes in rough order of prevalence.
13247
+  cat >conftest.$ac_ext <<_ACEOF
13248
+/* confdefs.h.  */
13249
+_ACEOF
13250
+cat confdefs.h >>conftest.$ac_ext
13251
+cat >>conftest.$ac_ext <<_ACEOF
13252
+/* end confdefs.h.  */
13253
+#include "confdefs.h"
13254
+#include <sys/types.h>
13255
+
13256
+
13257
+int
13258
+main ()
13259
+{
13260
+switch (0) case 0: case (sizeof (void *) == $ac_size):;
13261
+  ;
13262
+  return 0;
13263
+}
13264
+_ACEOF
13265
+rm -f conftest.$ac_objext
13266
+if { (ac_try="$ac_compile"
13267
+case "(($ac_try" in
13268
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13269
+  *) ac_try_echo=$ac_try;;
13270
+esac
13271
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13272
+  (eval "$ac_compile") 2>conftest.er1
13273
+  ac_status=$?
13274
+  grep -v '^ *+' conftest.er1 >conftest.err
13275
+  rm -f conftest.er1
13276
+  cat conftest.err >&5
13277
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
13278
+  (exit $ac_status); } && {
13279
+	 test -z "$ac_c_werror_flag" ||
13280
+	 test ! -s conftest.err
13281
+       } && test -s conftest.$ac_objext; then
13282
+  ac_cv_sizeof_void_p=$ac_size
13283
+else
13284
+  echo "$as_me: failed program was:" >&5
13285
+sed 's/^/| /' conftest.$ac_ext >&5
13286
+
13287
+
13288
+fi
13289
+
13290
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13291
+  if test x$ac_cv_sizeof_void_p != x ; then break; fi
13292
+done
13293
+
13294
+fi
13295
+
13296
+if test x$ac_cv_sizeof_void_p = x ; then
13297
+  { { echo "$as_me:$LINENO: error: cannot determine a size for void *" >&5
13298
+echo "$as_me: error: cannot determine a size for void *" >&2;}
13299
+   { (exit 1); exit 1; }; }
13300
+fi
13301
+{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_void_p" >&5
13302
+echo "${ECHO_T}$ac_cv_sizeof_void_p" >&6; }
13303
+
13304
+cat >>confdefs.h <<_ACEOF
13305
+#define SIZEOF_VOID_P $ac_cv_sizeof_void_p
13306
+_ACEOF
13307
+
13308
+
13241 13309
 
13242 13310
 # Check whether --enable-experimental was given.
13243 13311
 if test "${enable_experimental+set}" = set; then
... ...
@@ -13256,6 +13325,22 @@ _ACEOF
13256 13256
   VERSION_SUFFIX="$VERSION_SUFFIX-exp"
13257 13257
 fi
13258 13258
 
13259
+# Check whether --enable-mempool was given.
13260
+if test "${enable_mempool+set}" = set; then
13261
+  enableval=$enable_mempool; enable_mempool=$enableval
13262
+else
13263
+  enable_mempool="no"
13264
+fi
13265
+
13266
+
13267
+if test "$enable_mempool" = "yes"; then
13268
+
13269
+cat >>confdefs.h <<\_ACEOF
13270
+#define USE_MPOOL 1
13271
+_ACEOF
13272
+
13273
+fi
13274
+
13259 13275
 { echo "$as_me:$LINENO: checking for bind in -lsocket" >&5
13260 13276
 echo $ECHO_N "checking for bind in -lsocket... $ECHO_C" >&6; }
13261 13277
 if test "${ac_cv_lib_socket_bind+set}" = set; then
... ...
@@ -305,6 +305,7 @@ AC_COMPILE_CHECK_SIZEOF([short])
305 305
 AC_COMPILE_CHECK_SIZEOF([int])
306 306
 AC_COMPILE_CHECK_SIZEOF([long])
307 307
 AC_COMPILE_CHECK_SIZEOF([long long])
308
+AC_COMPILE_CHECK_SIZEOF([void *])
308 309
 
309 310
 AC_ARG_ENABLE([experimental],
310 311
 [  --enable-experimental	enable experimental code],
... ...
@@ -315,6 +316,14 @@ if test "$enable_experimental" = "yes"; then
315 315
   VERSION_SUFFIX="$VERSION_SUFFIX-exp"
316 316
 fi
317 317
 
318
+AC_ARG_ENABLE([mempool],
319
+[  --enable-mempool	enable memory pools],
320
+enable_mempool=$enableval, enable_mempool="no")
321
+
322
+if test "$enable_mempool" = "yes"; then
323
+  AC_DEFINE([USE_MPOOL],1,[enable memory pools])
324
+fi
325
+
318 326
 AC_CHECK_LIB([socket], [bind], [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsocket"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsocket"; CLAMD_LIBS="$CLAMD_LIBS -lsocket"])
319 327
 AC_SEARCH_LIBS([gethostent],[nsl], [(LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl")])
320 328
 
... ...
@@ -39,7 +39,7 @@
39 39
 #include <stddef.h>
40 40
 
41 41
 
42
-#define DEBUGMPOOL
42
+/* #define DEBUGMPOOL */
43 43
 #ifdef DEBUGMPOOL
44 44
 #include <stdio.h>
45 45
 FILE *lfd = NULL;
... ...
@@ -61,6 +61,253 @@ FILE *lfd = NULL;
61 61
 /* #define MIN_FRAGSIZE 1048576	/\* 0m2.392s *\/ */
62 62
 /* #define MIN_FRAGSIZE 2097152	/\* 0m2.402s *\/ */
63 63
 
64
+#if SIZEOF_VOID_P==8
65
+static const unsigned int fragsz[] = {
66
+24, /* (33067) */
67
+32, /* (93970) */
68
+40, /* (731473) */
69
+48, /* (35342) */
70
+56, /* (6967) */
71
+64, /* (442053) */
72
+72, /* (2706) */
73
+80, /* (2281) */
74
+88, /* (3658) */
75
+96, /* (2620) */
76
+104, /* (3705) */
77
+112, /* (3722) */
78
+120, /* (4012) */
79
+128, /* (5161) */
80
+136, /* (22458) */
81
+144, /* (4339) */
82
+152, /* (4315) */
83
+160, /* (12195) */
84
+168, /* (18042) */
85
+/* 176, /\* (341) *\/ */
86
+/* 184, /\* (329) *\/ */
87
+192, /* (202) */
88
+/* 200, /\* (238) *\/ */
89
+/* 208, /\* (166) *\/ */
90
+/* 216, /\* (179) *\/ */
91
+224, /* (216) */
92
+/* 232, /\* (189) *\/ */
93
+/* 240, /\* (157) *\/ */
94
+/* 248, /\* (178) *\/ */
95
+256, /* (133) */
96
+/* 264, /\* (157) *\/ */
97
+/* 272, /\* (140) *\/ */
98
+/* 280, /\* (161) *\/ */
99
+/* 288, /\* (125) *\/ */
100
+/* 296, /\* (141) *\/ */
101
+304, /* (100) */
102
+/* 312, /\* (114) *\/ */
103
+/* 320, /\* (70) *\/ */
104
+/* 328, /\* (13) *\/ */
105
+/* 336, /\* (21) *\/ */
106
+/* 344, /\* (21) *\/ */
107
+352, /* (13) */
108
+/* 360, /\* (26) *\/ */
109
+/* 368, /\* (8) *\/ */
110
+/* 376, /\* (14) *\/ */
111
+/* 384, /\* (5) *\/ */
112
+/* 392, /\* (6) *\/ */
113
+/* 400, /\* (4) *\/ */
114
+/* 408, /\* (2) *\/ */
115
+/* 416, /\* (6) *\/ */
116
+424, /* (20) */
117
+/* 432, /\* (4) *\/ */
118
+/* 440, /\* (4) *\/ */
119
+/* 448, /\* (4) *\/ */
120
+/* 464, /\* (2) *\/ */
121
+/* 472, /\* (2) *\/ */
122
+/* 480, /\* (1) *\/ */
123
+/* 496, /\* (1) *\/ */
124
+/* 512, /\* (2) *\/ */
125
+528, /* (15) */
126
+/* 536, /\* (1) *\/ */
127
+/* 544, /\* (2) *\/ */
128
+/* 552, /\* (1) *\/ */
129
+/* 584, /\* (3) *\/ */
130
+/* 600, /\* (1) *\/ */
131
+/* 624, /\* (1) *\/ */
132
+/* 656, /\* (1) *\/ */
133
+/* 784, /\* (2) *\/ */
134
+1040, /* (15) */
135
+/* 2064, /\* (7456) *\/ */
136
+2072, /* (14) */
137
+4112, /* (14) */
138
+8208, /* (9) */
139
+16400, /* (6) */
140
+32784, /* (4) */
141
+63512, /* (7) */
142
+134408, /* (2) */
143
+507984, /* (7) */
144
+1051040, /* (1) */
145
+2097152 /* FIXME: FAIL HERE OR ABOVE */
146
+};
147
+
148
+#else
149
+
150
+static const unsigned int fragsz[] = {
151
+12, /* (2297) */
152
+16, /* (30785) */
153
+20, /* (41460) */
154
+24, /* (69214) */
155
+28, /* (639488) */
156
+32, /* (107920) */
157
+36, /* (454213) */
158
+40, /* (11497) */
159
+44, /* (1688) */
160
+48, /* (5294) */
161
+52, /* (1496) */
162
+56, /* (3738) */
163
+60, /* (1719) */
164
+64, /* (918) */
165
+68, /* (956) */
166
+72, /* (1324) */
167
+76, /* (1905) */
168
+80, /* (1745) */
169
+84, /* (1053) */
170
+88, /* (1566) */
171
+92, /* (2081) */
172
+96, /* (20851) */
173
+100, /* (1882) */
174
+104, /* (1848) */
175
+108, /* (1931) */
176
+112, /* (2079) */
177
+116, /* (1736) */
178
+120, /* (3425) */
179
+124, /* (2115) */
180
+128, /* (1298) */
181
+132, /* (2307) */
182
+136, /* (2033) */
183
+140, /* (2837) */
184
+144, /* (1479) */
185
+148, /* (1607) */
186
+152, /* (10587) */
187
+156, /* (2719) */
188
+160, /* (15311) */
189
+164, /* (196) */
190
+168, /* (145) */
191
+172, /* (211) */
192
+176, /* (140) */
193
+180, /* (116) */
194
+/* 184, /\* (86) *\/ */
195
+188, /* (119) */
196
+192, /* (104) */
197
+/* 196, /\* (99) *\/ */
198
+/* 200, /\* (84) *\/ */
199
+/* 204, /\* (94) *\/ */
200
+/* 208, /\* (86) *\/ */
201
+212, /* (136) */
202
+/* 216, /\* (80) *\/ */
203
+/* 220, /\* (75) *\/ */
204
+/* 224, /\* (97) *\/ */
205
+/* 228, /\* (99) *\/ */
206
+/* 232, /\* (74) *\/ */
207
+236, /* (114) */
208
+/* 240, /\* (64) *\/ */
209
+/* 244, /\* (73) *\/ */
210
+/* 248, /\* (62) *\/ */
211
+/* 252, /\* (71) *\/ */
212
+/* 256, /\* (69) *\/ */
213
+/* 260, /\* (85) *\/ */
214
+/* 264, /\* (71) *\/ */
215
+268, /* (92) */
216
+/* 272, /\* (69) *\/ */
217
+/* 276, /\* (56) *\/ */
218
+/* 280, /\* (69) *\/ */
219
+/* 284, /\* (71) *\/ */
220
+/* 288, /\* (70) *\/ */
221
+/* 292, /\* (62) *\/ */
222
+/* 296, /\* (39) *\/ */
223
+/* 300, /\* (54) *\/ */
224
+/* 304, /\* (43) *\/ */
225
+/* 308, /\* (54) *\/ */
226
+312, /* (30) */
227
+/* 316, /\* (8) *\/ */
228
+/* 320, /\* (5) *\/ */
229
+/* 324, /\* (7) *\/ */
230
+/* 328, /\* (14) *\/ */
231
+/* 332, /\* (13) *\/ */
232
+/* 336, /\* (8) *\/ */
233
+/* 340, /\* (7) *\/ */
234
+/* 344, /\* (6) *\/ */
235
+/* 348, /\* (2) *\/ */
236
+/* 352, /\* (7) *\/ */
237
+/* 356, /\* (18) *\/ */
238
+/* 360, /\* (5) *\/ */
239
+364, /* (12) */
240
+/* 368, /\* (2) *\/ */
241
+/* 372, /\* (4) *\/ */
242
+/* 376, /\* (2) *\/ */
243
+/* 380, /\* (5) *\/ */
244
+/* 384, /\* (1) *\/ */
245
+/* 392, /\* (4) *\/ */
246
+/* 396, /\* (3) *\/ */
247
+/* 404, /\* (4) *\/ */
248
+/* 408, /\* (2) *\/ */
249
+/* 412, /\* (3) *\/ */
250
+/* 416, /\* (2) *\/ */
251
+/* 420, /\* (3) *\/ */
252
+/* 424, /\* (2) *\/ */
253
+428, /* (16) */
254
+/* 432, /\* (4) *\/ */
255
+/* 436, /\* (1) *\/ */
256
+/* 440, /\* (3) *\/ */
257
+/* 452, /\* (1) *\/ */
258
+/* 456, /\* (2) *\/ */
259
+/* 460, /\* (8) *\/ */
260
+/* 468, /\* (1) *\/ */
261
+/* 472, /\* (2) *\/ */
262
+/* 484, /\* (1) *\/ */
263
+/* 492, /\* (4) *\/ */
264
+/* 500, /\* (1) *\/ */
265
+/* 504, /\* (2) *\/ */
266
+/* 508, /\* (1) *\/ */
267
+/* 516, /\* (2) *\/ */
268
+/* 524, /\* (5) *\/ */
269
+532, /* (15) */
270
+/* 536, /\* (3) *\/ */
271
+/* 540, /\* (1) *\/ */
272
+/* 556, /\* (4) *\/ */
273
+/* 576, /\* (3) *\/ */
274
+/* 588, /\* (8) *\/ */
275
+/* 612, /\* (1) *\/ */
276
+/* 616, /\* (1) *\/ */
277
+/* 620, /\* (5) *\/ */
278
+/* 648, /\* (1) *\/ */
279
+/* 652, /\* (1) *\/ */
280
+/* 680, /\* (1) *\/ */
281
+/* 704, /\* (1) *\/ */
282
+/* 716, /\* (1) *\/ */
283
+/* 772, /\* (1) *\/ */
284
+/* 776, /\* (1) *\/ */
285
+1032, /* (7549) */
286
+/* 1044, /\* (14) *\/ */
287
+2076, /* (14) */
288
+4116, /* (9) */
289
+8212, /* (6) */
290
+16404, /* (4) */
291
+63504, /* (7) */
292
+135636, /* (2) */
293
+253992, /* (7) */
294
+1050864, /* (1) */
295
+2097152 /* FIXME: FAIL HERE OR ABOVE */
296
+};
297
+#endif
298
+#define FRAGSBITS (sizeof(fragsz)/sizeof(fragsz[0]))
299
+
300
+struct MPMAP {
301
+  struct MPMAP *next;
302
+  unsigned int size;
303
+  unsigned int usize;
304
+};
305
+
306
+struct MP {
307
+  unsigned int psize;
308
+  struct FRAG *avail[FRAGSBITS];
309
+  struct MPMAP mpm;
310
+};
64 311
 
65 312
 struct FRAG {
66 313
   struct FRAG *next;
... ...
@@ -83,17 +330,9 @@ static unsigned int to_bits(unsigned int size) {
83 83
   return i; /* NOTREACHED */
84 84
 }
85 85
 static unsigned int from_bits(unsigned int bits) {
86
+  if (bits >= FRAGSBITS) return 0;
86 87
   return fragsz[bits];
87 88
 }
88
-/* static unsigned int to_bits(unsigned int size) { */
89
-/*   unsigned int i; */
90
-/*   for(i=0; i<32; i++) */
91
-/*     if((unsigned int)1<<i >= size) return i; */
92
-/*   return i; /\* NOTREACHED *\/ */
93
-/* } */
94
-/* static unsigned int from_bits(unsigned int bits) { */
95
-/*   return 1<<bits; */
96
-/* } */
97 89
 
98 90
 struct MP *mp_create() {
99 91
   struct MP mp, *mp_p;
... ...
@@ -155,25 +394,16 @@ void *mp_malloc(struct MP *mp, size_t size) {
155 155
   struct MPMAP *mpm = &mp->mpm;
156 156
 
157 157
   /*  check_all(mp); */
158
-  if (!size) return NULL;
159
-
160
-  j = sbits+2;
161
-  if (j<7) j = 7;
162
-  if (j > 32) j = 32;
163
-
164
-  j=sbits;
165
-
166
-  for (i=sbits; i<j; i++)
167
-    if((f = mp->avail[i])) break;
158
+  if (!size || sbits == FRAGSBITS) return NULL;
168 159
 
169 160
   /* Case 1: We have a free'd frag */
170
-  if(f) {
161
+  if((f = mp->avail[sbits])) {
171 162
     spam("malloc %p size %u (freed)\n", f, roundup(size));
172
-    mp->avail[i] = f->next;
163
+    mp->avail[sbits] = f->next;
173 164
     return &f->fake;
174 165
   }
175 166
 
176
-  needed = from_bits(sbits);
167
+  if (!(needed = from_bits(sbits))) return NULL;
177 168
 
178 169
   /* Case 2: We have nuff room available for this frag already */
179 170
   while(mpm) {
... ...
@@ -233,7 +463,8 @@ void *mp_realloc(struct MP *mp, void *ptr, size_t size) {
233 233
   if (!ptr) return mp_malloc(mp, size);
234 234
 
235 235
   spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->sbits), size);
236
-  csize = from_bits(f->sbits) - FRAG_OVERHEAD;
236
+  if(!(csize = from_bits(f->sbits))) return NULL;
237
+  csize -= FRAG_OVERHEAD;
237 238
   if (csize >= size) return ptr;
238 239
   if (!(new_ptr = mp_malloc(mp, size)))
239 240
     return NULL;
... ...
@@ -249,7 +480,11 @@ void *mp_realloc2(struct MP *mp, void *ptr, size_t size) {
249 249
   if (!ptr) return mp_malloc(mp, size);
250 250
 
251 251
   spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->sbits), size);
252
-  csize = from_bits(f->sbits) - FRAG_OVERHEAD;
252
+  if(!(csize = from_bits(f->sbits))) {
253
+    mp_free(mp, ptr);
254
+    return NULL;
255
+  }
256
+  csize -= FRAG_OVERHEAD;
253 257
   if (csize >= size) return ptr;
254 258
   if ((new_ptr = mp_malloc(mp, size)))
255 259
     memcpy(new_ptr, ptr, csize);
... ...
@@ -23,103 +23,6 @@
23 23
 
24 24
 #ifdef USE_MPOOL
25 25
 
26
-static const unsigned int fragsz[] = {
27
-24, /* (33067) */
28
-32, /* (93876) */
29
-40, /* (731459) */
30
-48, /* (35286) */
31
-56, /* (6930) */
32
-64, /* (442013) */
33
-72, /* (2706) */
34
-80, /* (2252) */
35
-88, /* (3631) */
36
-96, /* (2594) */
37
-104, /* (3679) */
38
-112, /* (3697) */
39
-120, /* (3991) */
40
-128, /* (5141) */
41
-136, /* (22458) */
42
-144, /* (4320) */
43
-152, /* (4296) */
44
-160, /* (12177) */
45
-168, /* (18024) */
46
-/* 176, /\* (323) *\/ */
47
-/* 184, /\* (329) *\/ */
48
-/* 192, /\* (202) *\/ */
49
-/* 200, /\* (221) *\/ */
50
-/* 208, /\* (166) *\/ */
51
-/* 216, /\* (179) *\/ */
52
-/* 224, /\* (216) *\/ */
53
-/* 232, /\* (172) *\/ */
54
-/* 240, /\* (157) *\/ */
55
-/* 248, /\* (178) *\/ */
56
-256, /* (133) */
57
-/* 264, /\* (157) *\/ */
58
-/* 272, /\* (140) *\/ */
59
-/* 280, /\* (161) *\/ */
60
-/* 288, /\* (125) *\/ */
61
-/* 296, /\* (141) *\/ */
62
-/* 304, /\* (100) *\/ */
63
-/* 312, /\* (97) *\/ */
64
-/* 320, /\* (70) *\/ */
65
-/* 328, /\* (13) *\/ */
66
-/* 336, /\* (21) *\/ */
67
-/* 344, /\* (21) *\/ */
68
-/* 352, /\* (13) *\/ */
69
-/* 360, /\* (9) *\/ */
70
-/* 368, /\* (8) *\/ */
71
-/* 376, /\* (14) *\/ */
72
-/* 384, /\* (5) *\/ */
73
-/* 392, /\* (6) *\/ */
74
-/* 400, /\* (4) *\/ */
75
-/* 408, /\* (2) *\/ */
76
-/* 416, /\* (6) *\/ */
77
-/* 424, /\* (5) *\/ */
78
-/* 432, /\* (4) *\/ */
79
-/* 440, /\* (4) *\/ */
80
-/* 448, /\* (4) *\/ */
81
-/* 464, /\* (2) *\/ */
82
-/* 472, /\* (2) *\/ */
83
-/* 480, /\* (1) *\/ */
84
-/* 496, /\* (1) *\/ */
85
-/* 512, /\* (2) *\/ */
86
-520, /* (11) */
87
-/* 536, /\* (1) *\/ */
88
-/* 544, /\* (2) *\/ */
89
-/* 552, /\* (1) *\/ */
90
-/* 584, /\* (3) *\/ */
91
-/* 600, /\* (1) *\/ */
92
-/* 624, /\* (1) *\/ */
93
-/* 656, /\* (1) *\/ */
94
-/* 784, /\* (2) *\/ */
95
-1032, /* (11) */
96
-/* 2056, /\* (14) *\/ */
97
-2064, /* (7456) */
98
-4104, /* (14) */
99
-8200, /* (9) */
100
-16392, /* (6) */
101
-32776, /* (4) */
102
-63512, /* (7) */
103
-134408, /* (1) */
104
-507984, /* (7) */
105
-1051040, /* (1) */
106
-2097152
107
-};
108
-
109
-#define FRAGSBITS (sizeof(fragsz)/sizeof(fragsz[0]))
110
-
111
-struct MPMAP {
112
-  struct MPMAP *next;
113
-  unsigned int size;
114
-  unsigned int usize;
115
-};
116
-
117
-struct MP {
118
-  unsigned int psize;
119
-  struct FRAG *avail[FRAGSBITS];
120
-  struct MPMAP mpm;
121
-};
122
-
123 26
 typedef struct MP mp_t;
124 27
 
125 28
 mp_t *mp_create(void);
... ...
@@ -142,5 +45,3 @@ void mp_flush(mp_t *mp);
142 142
 #endif /* USE_MPOOL */
143 143
 
144 144
 #endif
145
-
146
-