The R Project SVN R

Rev

Rev 26945 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26945 Rev 29208
Line 276... Line 276...
276
static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);
276
static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);
277
*/
277
*/
278
 
278
 
279
#endif
279
#endif
280
 
280
 
281
/*
-
 
282
  __STD_C should be nonzero if using ANSI-standard C compiler, a C++
-
 
283
  compiler, or a C compiler sufficiently close to ANSI to get away
-
 
284
  with it.
-
 
285
*/
-
 
286
 
-
 
287
#ifndef __STD_C
-
 
288
#if defined(__STDC__) || defined(_cplusplus)
-
 
289
#define __STD_C     1
-
 
290
#else
-
 
291
#define __STD_C     0
-
 
292
#endif 
-
 
293
#endif /*__STD_C*/
-
 
294
 
281
 
295
 
282
 
296
/*
283
/*
297
  Void_t* is the pointer type that malloc should say it returns
284
  Void_t* is the pointer type that malloc should say it returns
298
*/
285
*/
299
 
286
 
300
#ifndef Void_t
287
#ifndef Void_t
301
#if (__STD_C || defined(WIN32))
-
 
302
#define Void_t      void
288
#define Void_t      void
303
#else
-
 
304
#define Void_t      char
-
 
305
#endif
-
 
306
#endif /*Void_t*/
289
#endif /*Void_t*/
307
 
290
 
308
#if __STD_C
-
 
309
#include <stddef.h>   /* for size_t */
291
#include <stddef.h>   /* for size_t */
310
#else
-
 
311
#include <sys/types.h>
-
 
312
#endif
-
 
313
 
292
 
314
#ifdef __cplusplus
293
#ifdef __cplusplus
315
extern "C" {
294
extern "C" {
316
#endif
295
#endif
317
 
296
 
Line 595... Line 574...
595
#define USE_MEMCPY 0
574
#define USE_MEMCPY 0
596
#endif
575
#endif
597
#endif
576
#endif
598
 
577
 
599
 
578
 
600
#if (__STD_C || defined(HAVE_MEMCPY))
579
#if (defined(HAVE_MEMCPY))
601
 
-
 
602
#ifdef WIN32
580
#ifdef WIN32
603
/* On Win32 memset and memcpy are already declared in windows.h */
581
/* On Win32 memset and memcpy are already declared in windows.h */
604
#else
582
#else
605
#if __STD_C
-
 
606
void* memset(void*, int, size_t);
583
void* memset(void*, int, size_t);
607
void* memcpy(void*, const void*, size_t);
584
void* memcpy(void*, const void*, size_t);
608
#else
-
 
609
Void_t* memset();
-
 
610
Void_t* memcpy();
-
 
611
#endif
-
 
612
#endif
585
#endif
613
#endif
586
#endif
614
 
587
 
615
/*
588
/*
616
  MALLOC_FAILURE_ACTION is the action to take before "return 0" when
589
  MALLOC_FAILURE_ACTION is the action to take before "return 0" when
Line 619... Line 592...
619
  
592
  
620
  By default, sets errno if running on STD_C platform, else does nothing.  
593
  By default, sets errno if running on STD_C platform, else does nothing.  
621
*/
594
*/
622
 
595
 
623
#ifndef MALLOC_FAILURE_ACTION
596
#ifndef MALLOC_FAILURE_ACTION
624
#if __STD_C
-
 
625
#define MALLOC_FAILURE_ACTION \
597
#define MALLOC_FAILURE_ACTION \
626
   errno = ENOMEM;
598
   errno = ENOMEM;
627
 
-
 
628
#else
-
 
629
#define MALLOC_FAILURE_ACTION
-
 
630
#endif
-
 
631
#endif
599
#endif
632
 
600
 
633
/*
601
/*
634
  MORECORE-related declarations. By default, rely on sbrk
602
  MORECORE-related declarations. By default, rely on sbrk
635
*/
603
*/
636
 
604
 
637
 
605
 
638
#ifdef LACKS_UNISTD_H
606
#ifdef LACKS_UNISTD_H
639
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
607
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
640
#if __STD_C
-
 
641
extern Void_t*     sbrk(ptrdiff_t);
608
extern Void_t*     sbrk(ptrdiff_t);
642
#else
-
 
643
extern Void_t*     sbrk();
-
 
644
#endif
-
 
645
#endif
609
#endif
646
#endif
610
#endif
647
 
611
 
648
/*
612
/*
649
  MORECORE is the name of the routine to call to obtain more memory
613
  MORECORE is the name of the routine to call to obtain more memory
Line 900... Line 864...
900
  with negative arguments are interpreted as requests for huge amounts
864
  with negative arguments are interpreted as requests for huge amounts
901
  of space, which will often fail. The maximum supported value of n
865
  of space, which will often fail. The maximum supported value of n
902
  differs across systems, but is in all cases less than the maximum
866
  differs across systems, but is in all cases less than the maximum
903
  representable value of a size_t.
867
  representable value of a size_t.
904
*/
868
*/
905
#if __STD_C
-
 
906
Void_t*  public_mALLOc(size_t);
869
Void_t*  public_mALLOc(size_t);
907
#else
-
 
908
Void_t*  public_mALLOc();
-
 
909
#endif
-
 
910
 
870
 
911
/*
871
/*
912
  free(Void_t* p)
872
  free(Void_t* p)
913
  Releases the chunk of memory pointed to by p, that had been previously
873
  Releases the chunk of memory pointed to by p, that had been previously
914
  allocated using malloc or a related routine such as realloc.
874
  allocated using malloc or a related routine such as realloc.
Line 917... Line 877...
917
 
877
 
918
  Unless disabled (using mallopt), freeing very large spaces will
878
  Unless disabled (using mallopt), freeing very large spaces will
919
  when possible, automatically trigger operations that give
879
  when possible, automatically trigger operations that give
920
  back unused memory to the system, thus reducing program footprint.
880
  back unused memory to the system, thus reducing program footprint.
921
*/
881
*/
922
#if __STD_C
-
 
923
void     public_fREe(Void_t*);
882
void     public_fREe(Void_t*);
924
#else
-
 
925
void     public_fREe();
-
 
926
#endif
-
 
927
 
883
 
928
/*
884
/*
929
  calloc(size_t n_elements, size_t element_size);
885
  calloc(size_t n_elements, size_t element_size);
930
  Returns a pointer to n_elements * element_size bytes, with all locations
886
  Returns a pointer to n_elements * element_size bytes, with all locations
931
  set to zero.
887
  set to zero.
932
*/
888
*/
933
#if __STD_C
-
 
934
Void_t*  public_cALLOc(size_t, size_t);
889
Void_t*  public_cALLOc(size_t, size_t);
935
#else
-
 
936
Void_t*  public_cALLOc();
-
 
937
#endif
-
 
938
 
890
 
939
/*
891
/*
940
  realloc(Void_t* p, size_t n)
892
  realloc(Void_t* p, size_t n)
941
  Returns a pointer to a chunk of size n that contains the same data
893
  Returns a pointer to a chunk of size n that contains the same data
942
  as does chunk p up to the minimum of (n, p's size) bytes, or null
894
  as does chunk p up to the minimum of (n, p's size) bytes, or null
Line 961... Line 913...
961
  the system supports MREMAP (currently only linux).
913
  the system supports MREMAP (currently only linux).
962
 
914
 
963
  The old unix realloc convention of allowing the last-free'd chunk
915
  The old unix realloc convention of allowing the last-free'd chunk
964
  to be used as an argument to realloc is not supported.
916
  to be used as an argument to realloc is not supported.
965
*/
917
*/
966
#if __STD_C
918
 
967
Void_t*  public_rEALLOc(Void_t*, size_t);
919
Void_t*  public_rEALLOc(Void_t*, size_t);
968
#else
-
 
969
Void_t*  public_rEALLOc();
-
 
970
#endif
-
 
971
 
920
 
972
/*
921
/*
973
  memalign(size_t alignment, size_t n);
922
  memalign(size_t alignment, size_t n);
974
  Returns a pointer to a newly allocated chunk of n bytes, aligned
923
  Returns a pointer to a newly allocated chunk of n bytes, aligned
975
  in accord with the alignment argument.
924
  in accord with the alignment argument.
Line 979... Line 928...
979
  8-byte alignment is guaranteed by normal malloc calls, so don't
928
  8-byte alignment is guaranteed by normal malloc calls, so don't
980
  bother calling memalign with an argument of 8 or less.
929
  bother calling memalign with an argument of 8 or less.
981
 
930
 
982
  Overreliance on memalign is a sure way to fragment space.
931
  Overreliance on memalign is a sure way to fragment space.
983
*/
932
*/
984
#if __STD_C
-
 
985
Void_t*  public_mEMALIGn(size_t, size_t);
933
Void_t*  public_mEMALIGn(size_t, size_t);
986
#else
-
 
987
Void_t*  public_mEMALIGn();
-
 
988
#endif
-
 
989
 
934
 
990
/*
935
/*
991
  valloc(size_t n);
936
  valloc(size_t n);
992
  Equivalent to memalign(pagesize, n), where pagesize is the page
937
  Equivalent to memalign(pagesize, n), where pagesize is the page
993
  size of the system. If the pagesize is unknown, 4096 is used.
938
  size of the system. If the pagesize is unknown, 4096 is used.
994
*/
939
*/
995
#if __STD_C
-
 
996
Void_t*  public_vALLOc(size_t);
940
Void_t*  public_vALLOc(size_t);
997
#else
-
 
998
Void_t*  public_vALLOc();
-
 
999
#endif
-
 
1000
 
-
 
1001
 
941
 
1002
 
942
 
1003
/*
943
/*
1004
  mallopt(int parameter_number, int parameter_value)
944
  mallopt(int parameter_number, int parameter_value)
1005
  Sets tunable parameters The format is to provide a
945
  Sets tunable parameters The format is to provide a
Line 1019... Line 959...
1019
  M_TRIM_THRESHOLD -1         256*1024   any   (-1U disables trimming)
959
  M_TRIM_THRESHOLD -1         256*1024   any   (-1U disables trimming)
1020
  M_TOP_PAD        -2         0          any  
960
  M_TOP_PAD        -2         0          any  
1021
  M_MMAP_THRESHOLD -3         256*1024   any   (or 0 if no MMAP support)
961
  M_MMAP_THRESHOLD -3         256*1024   any   (or 0 if no MMAP support)
1022
  M_MMAP_MAX       -4         65536      any   (0 disables use of mmap)
962
  M_MMAP_MAX       -4         65536      any   (0 disables use of mmap)
1023
*/
963
*/
1024
#if __STD_C
-
 
1025
int      public_mALLOPt(int, int);
964
int      public_mALLOPt(int, int);
1026
#else
-
 
1027
int      public_mALLOPt();
-
 
1028
#endif
-
 
1029
 
965
 
1030
 
966
 
1031
/*
967
/*
1032
  mallinfo()
968
  mallinfo()
1033
  Returns (by copy) a struct containing various summary statistics:
969
  Returns (by copy) a struct containing various summary statistics:
Line 1049... Line 985...
1049
 
985
 
1050
  Because these fields are ints, but internal bookkeeping may
986
  Because these fields are ints, but internal bookkeeping may
1051
  be kept as longs, the reported values may wrap around zero and 
987
  be kept as longs, the reported values may wrap around zero and 
1052
  thus be inaccurate.
988
  thus be inaccurate.
1053
*/
989
*/
1054
#if __STD_C
-
 
1055
struct mallinfo public_mALLINFo(void);
990
struct mallinfo public_mALLINFo(void);
1056
#else
-
 
1057
struct mallinfo public_mALLINFo();
-
 
1058
#endif
-
 
1059
 
991
 
1060
/*
992
/*
1061
  independent_calloc(size_t n_elements, size_t element_size, Void_t* chunks[]);
993
  independent_calloc(size_t n_elements, size_t element_size, Void_t* chunks[]);
1062
 
994
 
1063
  independent_calloc is similar to calloc, but instead of returning a
995
  independent_calloc is similar to calloc, but instead of returning a
Line 1107... Line 1039...
1107
      pool[i]->next = pool[i+1];
1039
      pool[i]->next = pool[i+1];
1108
    free(pool);     // Can now free the array (or not, if it is needed later)
1040
    free(pool);     // Can now free the array (or not, if it is needed later)
1109
    return first;
1041
    return first;
1110
  }
1042
  }
1111
*/
1043
*/
1112
#if __STD_C
-
 
1113
Void_t** public_iCALLOc(size_t, size_t, Void_t**);
1044
Void_t** public_iCALLOc(size_t, size_t, Void_t**);
1114
#else
-
 
1115
Void_t** public_iCALLOc();
-
 
1116
#endif
-
 
1117
 
1045
 
1118
/*
1046
/*
1119
  independent_comalloc(size_t n_elements, size_t sizes[], Void_t* chunks[]);
1047
  independent_comalloc(size_t n_elements, size_t sizes[], Void_t* chunks[]);
1120
 
1048
 
1121
  independent_comalloc allocates, all at once, a set of n_elements
1049
  independent_comalloc allocates, all at once, a set of n_elements
Line 1172... Line 1100...
1172
 
1100
 
1173
  Overuse of independent_comalloc can increase overall memory usage,
1101
  Overuse of independent_comalloc can increase overall memory usage,
1174
  since it cannot reuse existing noncontiguous small chunks that
1102
  since it cannot reuse existing noncontiguous small chunks that
1175
  might be available for some of the elements.
1103
  might be available for some of the elements.
1176
*/
1104
*/
1177
#if __STD_C
-
 
1178
Void_t** public_iCOMALLOc(size_t, size_t*, Void_t**);
1105
Void_t** public_iCOMALLOc(size_t, size_t*, Void_t**);
1179
#else
-
 
1180
Void_t** public_iCOMALLOc();
-
 
1181
#endif
-
 
1182
 
1106
 
1183
 
1107
 
1184
/*
1108
/*
1185
  pvalloc(size_t n);
1109
  pvalloc(size_t n);
1186
  Equivalent to valloc(minimum-page-that-holds(n)), that is,
1110
  Equivalent to valloc(minimum-page-that-holds(n)), that is,
1187
  round up n to nearest pagesize.
1111
  round up n to nearest pagesize.
1188
 */
1112
 */
1189
#if __STD_C
-
 
1190
Void_t*  public_pVALLOc(size_t);
1113
Void_t*  public_pVALLOc(size_t);
1191
#else
-
 
1192
Void_t*  public_pVALLOc();
-
 
1193
#endif
-
 
1194
 
1114
 
1195
/*
1115
/*
1196
  cfree(Void_t* p);
1116
  cfree(Void_t* p);
1197
  Equivalent to free(p).
1117
  Equivalent to free(p).
1198
 
1118
 
1199
  cfree is needed/defined on some systems that pair it with calloc,
1119
  cfree is needed/defined on some systems that pair it with calloc,
1200
  for odd historical reasons (such as: cfree is used in example 
1120
  for odd historical reasons (such as: cfree is used in example 
1201
  code in the first edition of K&R).
1121
  code in the first edition of K&R).
1202
*/
1122
*/
1203
#if __STD_C
-
 
1204
void     public_cFREe(Void_t*);
1123
void     public_cFREe(Void_t*);
1205
#else
-
 
1206
void     public_cFREe();
-
 
1207
#endif
-
 
1208
 
1124
 
1209
/*
1125
/*
1210
  malloc_trim(size_t pad);
1126
  malloc_trim(size_t pad);
1211
 
1127
 
1212
  If possible, gives memory back to the system (via negative
1128
  If possible, gives memory back to the system (via negative
Line 1228... Line 1144...
1228
  
1144
  
1229
  Malloc_trim returns 1 if it actually released any memory, else 0.
1145
  Malloc_trim returns 1 if it actually released any memory, else 0.
1230
  On systems that do not support "negative sbrks", it will always
1146
  On systems that do not support "negative sbrks", it will always
1231
  rreturn 0.
1147
  rreturn 0.
1232
*/
1148
*/
1233
#if __STD_C
-
 
1234
int      public_mTRIm(size_t);
1149
int      public_mTRIm(size_t);
1235
#else
-
 
1236
int      public_mTRIm();
-
 
1237
#endif
-
 
1238
 
1150
 
1239
/*
1151
/*
1240
  malloc_usable_size(Void_t* p);
1152
  malloc_usable_size(Void_t* p);
1241
 
1153
 
1242
  Returns the number of bytes you can actually use in
1154
  Returns the number of bytes you can actually use in
Line 1249... Line 1161...
1249
 
1161
 
1250
  p = malloc(n);
1162
  p = malloc(n);
1251
  assert(malloc_usable_size(p) >= 256);
1163
  assert(malloc_usable_size(p) >= 256);
1252
 
1164
 
1253
*/
1165
*/
1254
#if __STD_C
-
 
1255
size_t   public_mUSABLe(Void_t*);
1166
size_t   public_mUSABLe(Void_t*);
1256
#else
-
 
1257
size_t   public_mUSABLe();
-
 
1258
#endif
-
 
1259
 
1167
 
1260
/*
1168
/*
1261
  malloc_stats();
1169
  malloc_stats();
1262
  Prints on stderr the amount of space obtained from the system (both
1170
  Prints on stderr the amount of space obtained from the system (both
1263
  via sbrk and mmap), the maximum amount (which may be more than
1171
  via sbrk and mmap), the maximum amount (which may be more than
Line 1275... Line 1183...
1275
 
1183
 
1276
  malloc_stats prints only the most commonly interesting statistics.
1184
  malloc_stats prints only the most commonly interesting statistics.
1277
  More information can be obtained by calling mallinfo.
1185
  More information can be obtained by calling mallinfo.
1278
 
1186
 
1279
*/
1187
*/
1280
#if __STD_C
-
 
1281
void     public_mSTATs();
-
 
1282
#else
-
 
1283
void     public_mSTATs();
1188
void     public_mSTATs();
1284
#endif
-
 
1285
 
1189
 
1286
/* mallopt tuning options */
1190
/* mallopt tuning options */
1287
 
1191
 
1288
/*
1192
/*
1289
  M_MXFAST is the maximum request size used for "fastbins", special bins
1193
  M_MXFAST is the maximum request size used for "fastbins", special bins
Line 1507... Line 1411...
1507
/* --------------------- public wrappers ---------------------- */
1411
/* --------------------- public wrappers ---------------------- */
1508
 
1412
 
1509
#ifdef USE_PUBLIC_MALLOC_WRAPPERS
1413
#ifdef USE_PUBLIC_MALLOC_WRAPPERS
1510
 
1414
 
1511
/* Declare all routines as internal */
1415
/* Declare all routines as internal */
1512
#if __STD_C
-
 
1513
static Void_t*  mALLOc(size_t);
1416
static Void_t*  mALLOc(size_t);
1514
static void     fREe(Void_t*);
1417
static void     fREe(Void_t*);
1515
static Void_t*  rEALLOc(Void_t*, size_t);
1418
static Void_t*  rEALLOc(Void_t*, size_t);
1516
static Void_t*  mEMALIGn(size_t, size_t);
1419
static Void_t*  mEMALIGn(size_t, size_t);
1517
static Void_t*  vALLOc(size_t);
1420
static Void_t*  vALLOc(size_t);
Line 1523... Line 1426...
1523
static int      mTRIm(size_t);
1426
static int      mTRIm(size_t);
1524
static size_t   mUSABLe(Void_t*);
1427
static size_t   mUSABLe(Void_t*);
1525
static void     mSTATs();
1428
static void     mSTATs();
1526
static int      mALLOPt(int, int);
1429
static int      mALLOPt(int, int);
1527
static struct mallinfo mALLINFo(void);
1430
static struct mallinfo mALLINFo(void);
1528
#else
-
 
1529
static Void_t*  mALLOc();
-
 
1530
static void     fREe();
-
 
1531
static Void_t*  rEALLOc();
-
 
1532
static Void_t*  mEMALIGn();
-
 
1533
static Void_t*  vALLOc();
-
 
1534
static Void_t*  pVALLOc();
-
 
1535
static Void_t*  cALLOc();
-
 
1536
static Void_t** iCALLOc();
-
 
1537
static Void_t** iCOMALLOc();
-
 
1538
static void     cFREe();
-
 
1539
static int      mTRIm();
-
 
1540
static size_t   mUSABLe();
-
 
1541
static void     mSTATs();
-
 
1542
static int      mALLOPt();
-
 
1543
static struct mallinfo mALLINFo();
-
 
1544
#endif
-
 
1545
 
1431
 
1546
/*
1432
/*
1547
  MALLOC_PREACTION and MALLOC_POSTACTION should be
1433
  MALLOC_PREACTION and MALLOC_POSTACTION should be
1548
  defined to return 0 on success, and nonzero on failure.
1434
  defined to return 0 on success, and nonzero on failure.
1549
  The return value of MALLOC_POSTACTION is currently ignored
1435
  The return value of MALLOC_POSTACTION is currently ignored
Line 2475... Line 2361...
2475
  outside of malloc_consolidate because some optimizing compilers try
2361
  outside of malloc_consolidate because some optimizing compilers try
2476
  to inline it at all call points, which turns out not to be an
2362
  to inline it at all call points, which turns out not to be an
2477
  optimization at all. (Inlining it in malloc_consolidate is fine though.)
2363
  optimization at all. (Inlining it in malloc_consolidate is fine though.)
2478
*/
2364
*/
2479
 
2365
 
2480
#if __STD_C
-
 
2481
static void malloc_init_state(mstate av)
2366
static void malloc_init_state(mstate av)
2482
#else
-
 
2483
static void malloc_init_state(av) mstate av;
-
 
2484
#endif
-
 
2485
{
2367
{
2486
  int     i;
2368
  int     i;
2487
  mbinptr bin;
2369
  mbinptr bin;
2488
  
2370
  
2489
  /* Establish circular links for normal bins */
2371
  /* Establish circular links for normal bins */
Line 2512... Line 2394...
2512
 
2394
 
2513
/* 
2395
/* 
2514
   Other internal utilities operating on mstates
2396
   Other internal utilities operating on mstates
2515
*/
2397
*/
2516
 
2398
 
2517
#if __STD_C
-
 
2518
static Void_t*  sYSMALLOc(INTERNAL_SIZE_T, mstate);
2399
static Void_t*  sYSMALLOc(INTERNAL_SIZE_T, mstate);
2519
#ifndef MORECORE_CANNOT_TRIM        
2400
#ifndef MORECORE_CANNOT_TRIM        
2520
static int      sYSTRIm(size_t, mstate);
2401
static int      sYSTRIm(size_t, mstate);
2521
#endif
2402
#endif
2522
static void     malloc_consolidate(mstate);
2403
static void     malloc_consolidate(mstate);
2523
static Void_t** iALLOc(size_t, size_t*, int, Void_t**);
2404
static Void_t** iALLOc(size_t, size_t*, int, Void_t**);
2524
#else
-
 
2525
static Void_t*  sYSMALLOc();
-
 
2526
#ifndef MORECORE_CANNOT_TRIM        
-
 
2527
static int      sYSTRIm();
-
 
2528
#endif
-
 
2529
static void     malloc_consolidate();
-
 
2530
static Void_t** iALLOc();
-
 
2531
#endif
-
 
2532
 
2405
 
2533
/*
2406
/*
2534
  Debugging support
2407
  Debugging support
2535
 
2408
 
2536
  These routines make a number of assertions about the states
2409
  These routines make a number of assertions about the states
Line 2559... Line 2432...
2559
 
2432
 
2560
/*
2433
/*
2561
  Properties of all chunks
2434
  Properties of all chunks
2562
*/
2435
*/
2563
 
2436
 
2564
#if __STD_C
-
 
2565
static void do_check_chunk(mchunkptr p)
2437
static void do_check_chunk(mchunkptr p)
2566
#else
-
 
2567
static void do_check_chunk(p) mchunkptr p;
-
 
2568
#endif
-
 
2569
{
2438
{
2570
  mstate av = get_malloc_state();
2439
  mstate av = get_malloc_state();
2571
  CHUNK_SIZE_T  sz = chunksize(p);
2440
  CHUNK_SIZE_T  sz = chunksize(p);
2572
  /* min and max possible addresses assuming contiguous allocation */
2441
  /* min and max possible addresses assuming contiguous allocation */
2573
  char* max_address = (char*)(av->top) + chunksize(av->top);
2442
  char* max_address = (char*)(av->top) + chunksize(av->top);
Line 2609... Line 2478...
2609
 
2478
 
2610
/*
2479
/*
2611
  Properties of free chunks
2480
  Properties of free chunks
2612
*/
2481
*/
2613
 
2482
 
2614
#if __STD_C
-
 
2615
static void do_check_free_chunk(mchunkptr p)
2483
static void do_check_free_chunk(mchunkptr p)
2616
#else
-
 
2617
static void do_check_free_chunk(p) mchunkptr p;
-
 
2618
#endif
-
 
2619
{
2484
{
2620
  mstate av = get_malloc_state();
2485
  mstate av = get_malloc_state();
2621
 
2486
 
2622
  INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;
2487
  INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;
2623
  mchunkptr next = chunk_at_offset(p, sz);
2488
  mchunkptr next = chunk_at_offset(p, sz);
Line 2649... Line 2514...
2649
 
2514
 
2650
/*
2515
/*
2651
  Properties of inuse chunks
2516
  Properties of inuse chunks
2652
*/
2517
*/
2653
 
2518
 
2654
#if __STD_C
-
 
2655
static void do_check_inuse_chunk(mchunkptr p)
2519
static void do_check_inuse_chunk(mchunkptr p)
2656
#else
-
 
2657
static void do_check_inuse_chunk(p) mchunkptr p;
-
 
2658
#endif
-
 
2659
{
2520
{
2660
  mstate av = get_malloc_state();
2521
  mstate av = get_malloc_state();
2661
  mchunkptr next;
2522
  mchunkptr next;
2662
  do_check_chunk(p);
2523
  do_check_chunk(p);
2663
 
2524
 
Line 2690... Line 2551...
2690
 
2551
 
2691
/*
2552
/*
2692
  Properties of chunks recycled from fastbins
2553
  Properties of chunks recycled from fastbins
2693
*/
2554
*/
2694
 
2555
 
2695
#if __STD_C
-
 
2696
static void do_check_remalloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)
2556
static void do_check_remalloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)
2697
#else
-
 
2698
static void do_check_remalloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;
-
 
2699
#endif
-
 
2700
{
2557
{
2701
  INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;
2558
  INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;
2702
 
2559
 
2703
  do_check_inuse_chunk(p);
2560
  do_check_inuse_chunk(p);
2704
 
2561
 
Line 2714... Line 2571...
2714
 
2571
 
2715
/*
2572
/*
2716
  Properties of nonrecycled chunks at the point they are malloced
2573
  Properties of nonrecycled chunks at the point they are malloced
2717
*/
2574
*/
2718
 
2575
 
2719
#if __STD_C
-
 
2720
static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)
2576
static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)
2721
#else
-
 
2722
static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;
-
 
2723
#endif
-
 
2724
{
2577
{
2725
  /* same as recycled case ... */
2578
  /* same as recycled case ... */
2726
  do_check_remalloced_chunk(p, s);
2579
  do_check_remalloced_chunk(p, s);
2727
 
2580
 
2728
  /*
2581
  /*
Line 2873... Line 2726...
2873
  On entry, it is assumed that av->top does not have enough
2726
  On entry, it is assumed that av->top does not have enough
2874
  space to service request for nb bytes, thus requiring that av->top
2727
  space to service request for nb bytes, thus requiring that av->top
2875
  be extended or replaced.
2728
  be extended or replaced.
2876
*/
2729
*/
2877
 
2730
 
2878
#if __STD_C
-
 
2879
static Void_t* sYSMALLOc(INTERNAL_SIZE_T nb, mstate av)
2731
static Void_t* sYSMALLOc(INTERNAL_SIZE_T nb, mstate av)
2880
#else
-
 
2881
static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb; mstate av;
-
 
2882
#endif
-
 
2883
{
2732
{
2884
  mchunkptr       old_top;        /* incoming value of av->top */
2733
  mchunkptr       old_top;        /* incoming value of av->top */
2885
  INTERNAL_SIZE_T old_size;       /* its size */
2734
  INTERNAL_SIZE_T old_size;       /* its size */
2886
  char*           old_end;        /* its end address */
2735
  char*           old_end;        /* its end address */
2887
 
2736
 
Line 3323... Line 3172...
3323
  automatically by free() when top space exceeds the trim
3172
  automatically by free() when top space exceeds the trim
3324
  threshold. It is also called by the public malloc_trim routine.  It
3173
  threshold. It is also called by the public malloc_trim routine.  It
3325
  returns 1 if it actually released any memory, else 0.
3174
  returns 1 if it actually released any memory, else 0.
3326
*/
3175
*/
3327
 
3176
 
3328
#if __STD_C
-
 
3329
static int sYSTRIm(size_t pad, mstate av)
3177
static int sYSTRIm(size_t pad, mstate av)
3330
#else
-
 
3331
static int sYSTRIm(pad, av) size_t pad; mstate av;
-
 
3332
#endif
-
 
3333
{
3178
{
3334
  long  top_size;        /* Amount of top-most memory */
3179
  long  top_size;        /* Amount of top-most memory */
3335
  long  extra;           /* Amount to release */
3180
  long  extra;           /* Amount to release */
3336
  long  released;        /* Amount actually released */
3181
  long  released;        /* Amount actually released */
3337
  char* current_brk;     /* address returned by pre-check sbrk call */
3182
  char* current_brk;     /* address returned by pre-check sbrk call */
Line 3386... Line 3231...
3386
/*
3231
/*
3387
  ------------------------------ malloc ------------------------------
3232
  ------------------------------ malloc ------------------------------
3388
*/
3233
*/
3389
 
3234
 
3390
 
3235
 
3391
#if __STD_C
-
 
3392
Void_t* mALLOc(size_t bytes)
3236
Void_t* mALLOc(size_t bytes)
3393
#else
-
 
3394
  Void_t* mALLOc(bytes) size_t bytes;
-
 
3395
#endif
-
 
3396
{
3237
{
3397
  mstate av = get_malloc_state();
3238
  mstate av = get_malloc_state();
3398
 
3239
 
3399
  INTERNAL_SIZE_T nb;               /* normalized request size */
3240
  INTERNAL_SIZE_T nb;               /* normalized request size */
3400
  unsigned int    idx;              /* associated bin index */
3241
  unsigned int    idx;              /* associated bin index */
Line 3739... Line 3580...
3739
 
3580
 
3740
/*
3581
/*
3741
  ------------------------------ free ------------------------------
3582
  ------------------------------ free ------------------------------
3742
*/
3583
*/
3743
 
3584
 
3744
#if __STD_C
-
 
3745
void fREe(Void_t* mem)
3585
void fREe(Void_t* mem)
3746
#else
-
 
3747
void fREe(mem) Void_t* mem;
-
 
3748
#endif
-
 
3749
{
3586
{
3750
  mstate av = get_malloc_state();
3587
  mstate av = get_malloc_state();
3751
 
3588
 
3752
  mchunkptr       p;           /* chunk corresponding to mem */
3589
  mchunkptr       p;           /* chunk corresponding to mem */
3753
  INTERNAL_SIZE_T size;        /* its size */
3590
  INTERNAL_SIZE_T size;        /* its size */
Line 3907... Line 3744...
3907
  Also, because this routine needs to be called the first time through
3744
  Also, because this routine needs to be called the first time through
3908
  malloc anyway, it turns out to be the perfect place to trigger
3745
  malloc anyway, it turns out to be the perfect place to trigger
3909
  initialization code.
3746
  initialization code.
3910
*/
3747
*/
3911
 
3748
 
3912
#if __STD_C
-
 
3913
static void malloc_consolidate(mstate av)
3749
static void malloc_consolidate(mstate av)
3914
#else
-
 
3915
static void malloc_consolidate(av) mstate av;
-
 
3916
#endif
-
 
3917
{
3750
{
3918
  mfastbinptr*    fb;                 /* current fastbin being consolidated */
3751
  mfastbinptr*    fb;                 /* current fastbin being consolidated */
3919
  mfastbinptr*    maxfb;              /* last fastbin (for loop control) */
3752
  mfastbinptr*    maxfb;              /* last fastbin (for loop control) */
3920
  mchunkptr       p;                  /* current chunk being consolidated */
3753
  mchunkptr       p;                  /* current chunk being consolidated */
3921
  mchunkptr       nextp;              /* next chunk to consolidate */
3754
  mchunkptr       nextp;              /* next chunk to consolidate */
Line 4010... Line 3843...
4010
/*
3843
/*
4011
  ------------------------------ realloc ------------------------------
3844
  ------------------------------ realloc ------------------------------
4012
*/
3845
*/
4013
 
3846
 
4014
 
3847
 
4015
#if __STD_C
-
 
4016
Void_t* rEALLOc(Void_t* oldmem, size_t bytes)
3848
Void_t* rEALLOc(Void_t* oldmem, size_t bytes)
4017
#else
-
 
4018
Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
-
 
4019
#endif
-
 
4020
{
3849
{
4021
  mstate av = get_malloc_state();
3850
  mstate av = get_malloc_state();
4022
 
3851
 
4023
  INTERNAL_SIZE_T  nb;              /* padded request size */
3852
  INTERNAL_SIZE_T  nb;              /* padded request size */
4024
 
3853
 
Line 4236... Line 4065...
4236
 
4065
 
4237
/*
4066
/*
4238
  ------------------------------ memalign ------------------------------
4067
  ------------------------------ memalign ------------------------------
4239
*/
4068
*/
4240
 
4069
 
4241
#if __STD_C
-
 
4242
Void_t* mEMALIGn(size_t alignment, size_t bytes)
4070
Void_t* mEMALIGn(size_t alignment, size_t bytes)
4243
#else
-
 
4244
Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
-
 
4245
#endif
-
 
4246
{
4071
{
4247
  INTERNAL_SIZE_T nb;             /* padded  request size */
4072
  INTERNAL_SIZE_T nb;             /* padded  request size */
4248
  char*           m;              /* memory returned by malloc call */
4073
  char*           m;              /* memory returned by malloc call */
4249
  mchunkptr       p;              /* corresponding chunk */
4074
  mchunkptr       p;              /* corresponding chunk */
4250
  char*           brk;            /* alignment point within p */
4075
  char*           brk;            /* alignment point within p */
Line 4341... Line 4166...
4341
 
4166
 
4342
/*
4167
/*
4343
  ------------------------------ calloc ------------------------------
4168
  ------------------------------ calloc ------------------------------
4344
*/
4169
*/
4345
 
4170
 
4346
#if __STD_C
-
 
4347
Void_t* cALLOc(size_t n_elements, size_t elem_size)
4171
Void_t* cALLOc(size_t n_elements, size_t elem_size)
4348
#else
-
 
4349
Void_t* cALLOc(n_elements, elem_size) size_t n_elements; size_t elem_size;
-
 
4350
#endif
-
 
4351
{
4172
{
4352
  mchunkptr p;
4173
  mchunkptr p;
4353
  CHUNK_SIZE_T  clearsize;
4174
  CHUNK_SIZE_T  clearsize;
4354
  CHUNK_SIZE_T  nclears;
4175
  CHUNK_SIZE_T  nclears;
4355
  INTERNAL_SIZE_T* d;
4176
  INTERNAL_SIZE_T* d;
Line 4410... Line 4231...
4410
 
4231
 
4411
/*
4232
/*
4412
  ------------------------------ cfree ------------------------------
4233
  ------------------------------ cfree ------------------------------
4413
*/
4234
*/
4414
 
4235
 
4415
#if __STD_C
-
 
4416
void cFREe(Void_t *mem)
4236
void cFREe(Void_t *mem)
4417
#else
-
 
4418
void cFREe(mem) Void_t *mem;
-
 
4419
#endif
-
 
4420
{
4237
{
4421
  fREe(mem);
4238
  fREe(mem);
4422
}
4239
}
4423
 
4240
 
4424
/*
4241
/*
4425
  ------------------------- independent_calloc -------------------------
4242
  ------------------------- independent_calloc -------------------------
4426
*/
4243
*/
4427
 
4244
 
4428
#if __STD_C
-
 
4429
Void_t** iCALLOc(size_t n_elements, size_t elem_size, Void_t* chunks[])
4245
Void_t** iCALLOc(size_t n_elements, size_t elem_size, Void_t* chunks[])
4430
#else
-
 
4431
Void_t** iCALLOc(n_elements, elem_size, chunks) size_t n_elements; size_t elem_size; Void_t* chunks[];
-
 
4432
#endif
-
 
4433
{
4246
{
4434
  size_t sz = elem_size; /* serves as 1-element array */
4247
  size_t sz = elem_size; /* serves as 1-element array */
4435
  /* opts arg of 3 means all elements are same size, and should be cleared */
4248
  /* opts arg of 3 means all elements are same size, and should be cleared */
4436
  return iALLOc(n_elements, &sz, 3, chunks);
4249
  return iALLOc(n_elements, &sz, 3, chunks);
4437
}
4250
}
4438
 
4251
 
4439
/*
4252
/*
4440
  ------------------------- independent_comalloc -------------------------
4253
  ------------------------- independent_comalloc -------------------------
4441
*/
4254
*/
4442
 
4255
 
4443
#if __STD_C
-
 
4444
Void_t** iCOMALLOc(size_t n_elements, size_t sizes[], Void_t* chunks[])
4256
Void_t** iCOMALLOc(size_t n_elements, size_t sizes[], Void_t* chunks[])
4445
#else
-
 
4446
Void_t** iCOMALLOc(n_elements, sizes, chunks) size_t n_elements; size_t sizes[]; Void_t* chunks[];
-
 
4447
#endif
-
 
4448
{
4257
{
4449
  return iALLOc(n_elements, sizes, 0, chunks);
4258
  return iALLOc(n_elements, sizes, 0, chunks);
4450
}
4259
}
4451
 
4260
 
4452
 
4261
 
Line 4459... Line 4268...
4459
    bit 0 set if all elements are same size (using sizes[0])
4268
    bit 0 set if all elements are same size (using sizes[0])
4460
    bit 1 set if elements should be zeroed
4269
    bit 1 set if elements should be zeroed
4461
*/
4270
*/
4462
 
4271
 
4463
 
4272
 
4464
#if __STD_C
-
 
4465
static Void_t** iALLOc(size_t n_elements, 
4273
static Void_t** iALLOc(size_t n_elements, 
4466
                       size_t* sizes,  
4274
                       size_t* sizes,  
4467
                       int opts,
4275
                       int opts,
4468
                       Void_t* chunks[])
4276
                       Void_t* chunks[])
4469
#else
-
 
4470
static Void_t** iALLOc(n_elements, sizes, opts, chunks) size_t n_elements; size_t* sizes; int opts; Void_t* chunks[];
-
 
4471
#endif
-
 
4472
{
4277
{
4473
  mstate av = get_malloc_state();
4278
  mstate av = get_malloc_state();
4474
  INTERNAL_SIZE_T element_size;   /* chunksize of each element, if all same */
4279
  INTERNAL_SIZE_T element_size;   /* chunksize of each element, if all same */
4475
  INTERNAL_SIZE_T contents_size;  /* total size of elements */
4280
  INTERNAL_SIZE_T contents_size;  /* total size of elements */
4476
  INTERNAL_SIZE_T array_size;     /* request size of pointer array */
4281
  INTERNAL_SIZE_T array_size;     /* request size of pointer array */
Line 4583... Line 4388...
4583
 
4388
 
4584
/*
4389
/*
4585
  ------------------------------ valloc ------------------------------
4390
  ------------------------------ valloc ------------------------------
4586
*/
4391
*/
4587
 
4392
 
4588
#if __STD_C
-
 
4589
Void_t* vALLOc(size_t bytes)
4393
Void_t* vALLOc(size_t bytes)
4590
#else
-
 
4591
Void_t* vALLOc(bytes) size_t bytes;
-
 
4592
#endif
-
 
4593
{
4394
{
4594
  /* Ensure initialization */
4395
  /* Ensure initialization */
4595
  mstate av = get_malloc_state();
4396
  mstate av = get_malloc_state();
4596
  if (av->max_fast == 0) malloc_consolidate(av);
4397
  if (av->max_fast == 0) malloc_consolidate(av);
4597
  return mEMALIGn(av->pagesize, bytes);
4398
  return mEMALIGn(av->pagesize, bytes);
Line 4600... Line 4401...
4600
/*
4401
/*
4601
  ------------------------------ pvalloc ------------------------------
4402
  ------------------------------ pvalloc ------------------------------
4602
*/
4403
*/
4603
 
4404
 
4604
 
4405
 
4605
#if __STD_C
-
 
4606
Void_t* pVALLOc(size_t bytes)
4406
Void_t* pVALLOc(size_t bytes)
4607
#else
-
 
4608
Void_t* pVALLOc(bytes) size_t bytes;
-
 
4609
#endif
-
 
4610
{
4407
{
4611
  mstate av = get_malloc_state();
4408
  mstate av = get_malloc_state();
4612
  size_t pagesz;
4409
  size_t pagesz;
4613
 
4410
 
4614
  /* Ensure initialization */
4411
  /* Ensure initialization */
Line 4620... Line 4417...
4620
 
4417
 
4621
/*
4418
/*
4622
  ------------------------------ malloc_trim ------------------------------
4419
  ------------------------------ malloc_trim ------------------------------
4623
*/
4420
*/
4624
 
4421
 
4625
#if __STD_C
-
 
4626
int mTRIm(size_t pad)
4422
int mTRIm(size_t pad)
4627
#else
-
 
4628
int mTRIm(pad) size_t pad;
-
 
4629
#endif
-
 
4630
{
4423
{
4631
  mstate av = get_malloc_state();
4424
  mstate av = get_malloc_state();
4632
  /* Ensure initialization/consolidation */
4425
  /* Ensure initialization/consolidation */
4633
  malloc_consolidate(av);
4426
  malloc_consolidate(av);
4634
 
4427
 
Line 4642... Line 4435...
4642
 
4435
 
4643
/*
4436
/*
4644
  ------------------------- malloc_usable_size -------------------------
4437
  ------------------------- malloc_usable_size -------------------------
4645
*/
4438
*/
4646
 
4439
 
4647
#if __STD_C
-
 
4648
size_t mUSABLe(Void_t* mem)
4440
size_t mUSABLe(Void_t* mem)
4649
#else
-
 
4650
size_t mUSABLe(mem) Void_t* mem;
-
 
4651
#endif
-
 
4652
{
4441
{
4653
  mchunkptr p;
4442
  mchunkptr p;
4654
  if (mem != 0) {
4443
  if (mem != 0) {
4655
    p = mem2chunk(mem);
4444
    p = mem2chunk(mem);
4656
    if (chunk_is_mmapped(p))
4445
    if (chunk_is_mmapped(p))
Line 4793... Line 4582...
4793
 
4582
 
4794
/*
4583
/*
4795
  ------------------------------ mallopt ------------------------------
4584
  ------------------------------ mallopt ------------------------------
4796
*/
4585
*/
4797
 
4586
 
4798
#if __STD_C
-
 
4799
int mALLOPt(int param_number, int value)
4587
int mALLOPt(int param_number, int value)
4800
#else
-
 
4801
int mALLOPt(param_number, value) int param_number; int value;
-
 
4802
#endif
-
 
4803
{
4588
{
4804
  mstate av = get_malloc_state();
4589
  mstate av = get_malloc_state();
4805
  /* Ensure initialization/consolidation */
4590
  /* Ensure initialization/consolidation */
4806
  malloc_consolidate(av);
4591
  malloc_consolidate(av);
4807
 
4592