Changes in / [64aeca0:58fe85a]
- Files:
-
- 4 edited
-
libcfa/src/heap.cfa (modified) (25 diffs)
-
libcfa/src/startup.cfa (modified) (2 diffs)
-
src/Parser/ParseNode.h (modified) (2 diffs)
-
src/Parser/parser.yy (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
r64aeca0 r58fe85a 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 10 11:20:49 202113 // Update Count : 10 3112 // Last Modified On : Wed Dec 16 12:28:25 2020 13 // Update Count : 1023 14 14 // 15 15 … … 262 262 #ifdef __STATISTICS__ 263 263 // Heap statistics counters. 264 static unsigned int malloc_ zero_calls, malloc_calls;264 static unsigned int malloc_calls; 265 265 static unsigned long long int malloc_storage; 266 static unsigned int aalloc_ zero_calls, aalloc_calls;266 static unsigned int aalloc_calls; 267 267 static unsigned long long int aalloc_storage; 268 static unsigned int calloc_ zero_calls, calloc_calls;268 static unsigned int calloc_calls; 269 269 static unsigned long long int calloc_storage; 270 static unsigned int memalign_ zero_calls, memalign_calls;270 static unsigned int memalign_calls; 271 271 static unsigned long long int memalign_storage; 272 static unsigned int amemalign_ zero_calls, amemalign_calls;272 static unsigned int amemalign_calls; 273 273 static unsigned long long int amemalign_storage; 274 static unsigned int cmemalign_ zero_calls, cmemalign_calls;274 static unsigned int cmemalign_calls; 275 275 static unsigned long long int cmemalign_storage; 276 static unsigned int resize_ zero_calls, resize_calls;276 static unsigned int resize_calls; 277 277 static unsigned long long int resize_storage; 278 static unsigned int realloc_ zero_calls, realloc_calls;278 static unsigned int realloc_calls; 279 279 static unsigned long long int realloc_storage; 280 static unsigned int free_ zero_calls, free_calls;280 static unsigned int free_calls; 281 281 static unsigned long long int free_storage; 282 282 static unsigned int mmap_calls; … … 287 287 static unsigned long long int sbrk_storage; 288 288 // Statistics file descriptor (changed by malloc_stats_fd). 289 static int stat s_fd = STDERR_FILENO;// default stderr289 static int stat_fd = STDERR_FILENO; // default stderr 290 290 291 291 // Use "write" because streams may be shutdown when calls are made. … … 293 293 char helpText[1024]; 294 294 __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText), 295 "\nHeap statistics:\n"296 " malloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"297 " aalloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"298 " calloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"299 " memalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"300 " amemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"301 " cmemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"302 " resize 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"303 " realloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"304 " free 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"305 " mmap calls %'u; storage %'llu bytes\n"306 " munmap calls %'u; storage %'llu bytes\n"307 " sbrk calls %'u; storage %'llu bytes\n",308 malloc_zero_calls,malloc_calls, malloc_storage,309 aalloc_zero_calls,aalloc_calls, aalloc_storage,310 calloc_zero_calls,calloc_calls, calloc_storage,311 memalign_zero_calls,memalign_calls, memalign_storage,312 amemalign_zero_calls,amemalign_calls, amemalign_storage,313 cmemalign_zero_calls,cmemalign_calls, cmemalign_storage,314 resize_zero_calls,resize_calls, resize_storage,315 realloc_zero_calls,realloc_calls, realloc_storage,316 free_zero_calls,free_calls, free_storage,317 mmap_calls, mmap_storage,318 munmap_calls, munmap_storage,319 sbrk_calls, sbrk_storage295 "\nHeap statistics:\n" 296 " malloc: calls %u / storage %llu\n" 297 " aalloc: calls %u / storage %llu\n" 298 " calloc: calls %u / storage %llu\n" 299 " memalign: calls %u / storage %llu\n" 300 " amemalign: calls %u / storage %llu\n" 301 " cmemalign: calls %u / storage %llu\n" 302 " resize: calls %u / storage %llu\n" 303 " realloc: calls %u / storage %llu\n" 304 " free: calls %u / storage %llu\n" 305 " mmap: calls %u / storage %llu\n" 306 " munmap: calls %u / storage %llu\n" 307 " sbrk: calls %u / storage %llu\n", 308 malloc_calls, malloc_storage, 309 aalloc_calls, aalloc_storage, 310 calloc_calls, calloc_storage, 311 memalign_calls, memalign_storage, 312 amemalign_calls, amemalign_storage, 313 cmemalign_calls, cmemalign_storage, 314 resize_calls, resize_storage, 315 realloc_calls, realloc_storage, 316 free_calls, free_storage, 317 mmap_calls, mmap_storage, 318 munmap_calls, munmap_storage, 319 sbrk_calls, sbrk_storage 320 320 ); 321 321 } // printStats … … 328 328 "<sizes>\n" 329 329 "</sizes>\n" 330 "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"331 "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"332 "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"333 "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"334 "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"335 "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"336 "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"337 "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"338 "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"339 "<total type=\"mmap\" count=\"% 'u;\" size=\"%'llu\"/> bytes\n"340 "<total type=\"munmap\" count=\"% 'u;\" size=\"%'llu\"/> bytes\n"341 "<total type=\"sbrk\" count=\"% 'u;\" size=\"%'llu\"/> bytes\n"330 "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n" 331 "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n" 332 "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n" 333 "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n" 334 "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n" 335 "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n" 336 "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n" 337 "<total type=\"realloc\" count=\"%u\" size=\"%llu\"/>\n" 338 "<total type=\"free\" count=\"%u\" size=\"%llu\"/>\n" 339 "<total type=\"mmap\" count=\"%u\" size=\"%llu\"/>\n" 340 "<total type=\"munmap\" count=\"%u\" size=\"%llu\"/>\n" 341 "<total type=\"sbrk\" count=\"%u\" size=\"%llu\"/>\n" 342 342 "</malloc>", 343 malloc_ zero_calls, malloc_calls, malloc_storage,344 aalloc_ zero_calls, aalloc_calls, aalloc_storage,345 calloc_ zero_calls, calloc_calls, calloc_storage,346 memalign_ zero_calls, memalign_calls, memalign_storage,347 amemalign_ zero_calls, amemalign_calls, amemalign_storage,348 cmemalign_ zero_calls, cmemalign_calls, cmemalign_storage,349 resize_ zero_calls, resize_calls, resize_storage,350 realloc_ zero_calls, realloc_calls, realloc_storage,351 free_ zero_calls, free_calls, free_storage,343 malloc_calls, malloc_storage, 344 aalloc_calls, aalloc_storage, 345 calloc_calls, calloc_storage, 346 memalign_calls, memalign_storage, 347 amemalign_calls, amemalign_storage, 348 cmemalign_calls, cmemalign_storage, 349 resize_calls, resize_storage, 350 realloc_calls, realloc_storage, 351 free_calls, free_storage, 352 352 mmap_calls, mmap_storage, 353 353 munmap_calls, munmap_storage, … … 466 466 } // headers 467 467 468 //#ifdef __CFA_DEBUG__469 //#if __SIZEOF_POINTER__ == 4470 //#define MASK 0xdeadbeef471 //#else472 //#define MASK 0xdeadbeefdeadbeef473 //#endif474 //#define STRIDE size_t475 476 //static void * Memset( void * addr, STRIDE size ) { // debug only477 //if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );478 //if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );479 480 //STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);481 //for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;482 //return addr;483 //} // Memset484 //#endif // __CFA_DEBUG__468 #ifdef __CFA_DEBUG__ 469 #if __SIZEOF_POINTER__ == 4 470 #define MASK 0xdeadbeef 471 #else 472 #define MASK 0xdeadbeefdeadbeef 473 #endif 474 #define STRIDE size_t 475 476 static void * Memset( void * addr, STRIDE size ) { // debug only 477 if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) ); 478 if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) ); 479 480 STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE); 481 for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK; 482 return addr; 483 } // Memset 484 #endif // __CFA_DEBUG__ 485 485 486 486 … … 498 498 unlock( extlock ); 499 499 __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size ); 500 _exit( EXIT_FAILURE ); // give up 501 } // if 502 // Make storage executable for thunks. 500 _exit( EXIT_FAILURE ); 501 } // if 503 502 if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) { 504 503 unlock( extlock ); … … 771 770 772 771 772 static inline void * callocNoStats( size_t dim, size_t elemSize ) { 773 size_t size = dim * elemSize; 774 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER 775 char * addr = (char *)mallocNoStats( size ); 776 777 HeapManager.Storage.Header * header; 778 HeapManager.FreeHeader * freeElem; 779 size_t bsize, alignment; 780 #ifndef __CFA_DEBUG__ 781 bool mapped = 782 #endif // __CFA_DEBUG__ 783 headers( "calloc", addr, header, freeElem, bsize, alignment ); 784 #ifndef __CFA_DEBUG__ 785 786 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 787 if ( ! mapped ) 788 #endif // __CFA_DEBUG__ 789 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 790 // `-header`-addr `-size 791 memset( addr, '\0', size ); // set to zeros 792 793 header->kind.real.blockSize |= 2; // mark as zero filled 794 return addr; 795 } // callocNoStats 796 797 773 798 static inline void * memalignNoStats( size_t alignment, size_t size ) { 774 799 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER … … 809 834 810 835 836 static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) { 837 size_t size = dim * elemSize; 838 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER 839 char * addr = (char *)memalignNoStats( alignment, size ); 840 841 HeapManager.Storage.Header * header; 842 HeapManager.FreeHeader * freeElem; 843 size_t bsize; 844 #ifndef __CFA_DEBUG__ 845 bool mapped = 846 #endif // __CFA_DEBUG__ 847 headers( "cmemalign", addr, header, freeElem, bsize, alignment ); 848 849 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 850 #ifndef __CFA_DEBUG__ 851 if ( ! mapped ) 852 #endif // __CFA_DEBUG__ 853 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 854 // `-header`-addr `-size 855 memset( addr, '\0', size ); // set to zeros 856 857 header->kind.real.blockSize |= 2; // mark as zero filled 858 return addr; 859 } // cmemalignNoStats 860 861 811 862 extern "C" { 812 863 // Allocates size bytes and returns a pointer to the allocated memory. The contents are undefined. If size is 0, … … 814 865 void * malloc( size_t size ) { 815 866 #ifdef __STATISTICS__ 816 if ( likely( size > 0 ) ) { 817 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST ); 818 __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST ); 819 } else { 820 __atomic_add_fetch( &malloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 821 } // if 867 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST ); 868 __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST ); 822 869 #endif // __STATISTICS__ 823 870 … … 830 877 size_t size = dim * elemSize; 831 878 #ifdef __STATISTICS__ 832 if ( likely( size > 0 ) ) { 833 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 834 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST ); 835 } else { 836 __atomic_add_fetch( &aalloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 837 } // if 879 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 880 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST ); 838 881 #endif // __STATISTICS__ 839 882 … … 844 887 // Same as aalloc() with memory set to zero. 845 888 void * calloc( size_t dim, size_t elemSize ) { 846 size_t size = dim * elemSize;847 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER848 #ifdef __STATISTICS__849 __atomic_add_fetch( &calloc_zero_calls, 1, __ATOMIC_SEQ_CST );850 #endif // __STATISTICS__851 return 0p;852 } // if853 889 #ifdef __STATISTICS__ 854 890 __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST ); … … 856 892 #endif // __STATISTICS__ 857 893 858 char * addr = (char *)mallocNoStats( size ); 859 860 HeapManager.Storage.Header * header; 861 HeapManager.FreeHeader * freeElem; 862 size_t bsize, alignment; 863 864 #ifndef __CFA_DEBUG__ 865 bool mapped = 866 #endif // __CFA_DEBUG__ 867 headers( "calloc", addr, header, freeElem, bsize, alignment ); 868 869 #ifndef __CFA_DEBUG__ 870 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 871 if ( ! mapped ) 872 #endif // __CFA_DEBUG__ 873 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 874 // `-header`-addr `-size 875 memset( addr, '\0', size ); // set to zeros 876 877 header->kind.real.blockSize |= 2; // mark as zero filled 878 return addr; 894 return callocNoStats( dim, elemSize ); 879 895 } // calloc 880 896 … … 885 901 // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done. 886 902 void * resize( void * oaddr, size_t size ) { 903 #ifdef __STATISTICS__ 904 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 905 #endif // __STATISTICS__ 906 887 907 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 888 if ( unlikely( size == 0 ) ) { // special cases 889 #ifdef __STATISTICS__ 890 __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST ); 891 #endif // __STATISTICS__ 892 free( oaddr ); 893 return 0p; 894 } // if 895 #ifdef __STATISTICS__ 896 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 897 #endif // __STATISTICS__ 898 908 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 899 909 if ( unlikely( oaddr == 0p ) ) { 900 910 #ifdef __STATISTICS__ … … 908 918 size_t bsize, oalign; 909 919 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 910 911 920 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 921 912 922 // same size, DO NOT preserve STICKY PROPERTIES. 913 923 if ( oalign == libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size … … 930 940 // the old and new sizes. 931 941 void * realloc( void * oaddr, size_t size ) { 942 #ifdef __STATISTICS__ 943 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 944 #endif // __STATISTICS__ 945 932 946 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 933 if ( unlikely( size == 0 ) ) { // special cases 934 #ifdef __STATISTICS__ 935 __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 936 #endif // __STATISTICS__ 937 free( oaddr ); 938 return 0p; 939 } // if 940 #ifdef __STATISTICS__ 941 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 942 #endif // __STATISTICS__ 943 947 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 944 948 if ( unlikely( oaddr == 0p ) ) { 945 949 #ifdef __STATISTICS__ … … 995 999 void * memalign( size_t alignment, size_t size ) { 996 1000 #ifdef __STATISTICS__ 997 if ( likely( size > 0 ) ) { 998 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST ); 999 __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST ); 1000 } else { 1001 __atomic_add_fetch( &memalign_zero_calls, 1, __ATOMIC_SEQ_CST ); 1002 } // if 1001 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST ); 1002 __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST ); 1003 1003 #endif // __STATISTICS__ 1004 1004 … … 1011 1011 size_t size = dim * elemSize; 1012 1012 #ifdef __STATISTICS__ 1013 if ( likely( size > 0 ) ) { 1014 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1015 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST ); 1016 } else { 1017 __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST ); 1018 } // if 1013 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1014 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST ); 1019 1015 #endif // __STATISTICS__ 1020 1016 … … 1025 1021 // Same as calloc() with memory alignment. 1026 1022 void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) { 1027 size_t size = dim * elemSize;1028 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER1029 #ifdef __STATISTICS__1030 __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );1031 #endif // __STATISTICS__1032 return 0p;1033 } // if1034 1023 #ifdef __STATISTICS__ 1035 1024 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); … … 1037 1026 #endif // __STATISTICS__ 1038 1027 1039 char * addr = (char *)memalignNoStats( alignment, size ); 1040 1041 HeapManager.Storage.Header * header; 1042 HeapManager.FreeHeader * freeElem; 1043 size_t bsize; 1044 1045 #ifndef __CFA_DEBUG__ 1046 bool mapped = 1047 #endif // __CFA_DEBUG__ 1048 headers( "cmemalign", addr, header, freeElem, bsize, alignment ); 1049 1050 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 1051 #ifndef __CFA_DEBUG__ 1052 if ( ! mapped ) 1053 #endif // __CFA_DEBUG__ 1054 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 1055 // `-header`-addr `-size 1056 memset( addr, '\0', size ); // set to zeros 1057 1058 header->kind.real.blockSize |= 2; // mark as zero filled 1059 return addr; 1028 return cmemalignNoStats( alignment, dim, elemSize ); 1060 1029 } // cmemalign 1061 1030 … … 1096 1065 // 0p, no operation is performed. 1097 1066 void free( void * addr ) { 1067 #ifdef __STATISTICS__ 1068 __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST ); 1069 #endif // __STATISTICS__ 1070 1098 1071 if ( unlikely( addr == 0p ) ) { // special case 1099 #ifdef __STATISTICS__1100 __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST );1101 #endif // __STATISTICS__1102 1103 1072 // #ifdef __CFA_DEBUG__ 1104 1073 // if ( traceHeap() ) { … … 1213 1182 int malloc_stats_fd( int fd __attribute__(( unused )) ) { 1214 1183 #ifdef __STATISTICS__ 1215 int temp = stat s_fd;1216 stat s_fd = fd;1184 int temp = stat_fd; 1185 stat_fd = fd; 1217 1186 return temp; 1218 1187 #else … … 1245 1214 // The string is printed on the file stream stream. The exported string includes information about all arenas (see 1246 1215 // malloc). 1247 int malloc_info( int options, FILE * stream __attribute__(( unused ))) {1216 int malloc_info( int options, FILE * stream ) { 1248 1217 if ( options != 0 ) { errno = EINVAL; return -1; } 1249 1218 #ifdef __STATISTICS__ … … 1274 1243 // Must have CFA linkage to overload with C linkage realloc. 1275 1244 void * resize( void * oaddr, size_t nalign, size_t size ) { 1276 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1277 if ( unlikely( size == 0 ) ) { // special cases 1278 #ifdef __STATISTICS__ 1279 __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST ); 1280 #endif // __STATISTICS__ 1281 free( oaddr ); 1282 return 0p; 1283 } // if 1245 #ifdef __STATISTICS__ 1246 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 1247 #endif // __STATISTICS__ 1284 1248 1285 1249 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1286 1250 #ifdef __CFA_DEBUG__ 1287 else checkAlign( nalign ); // check alignment 1251 else 1252 checkAlign( nalign ); // check alignment 1288 1253 #endif // __CFA_DEBUG__ 1289 1254 1255 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1256 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 1290 1257 if ( unlikely( oaddr == 0p ) ) { 1291 1258 #ifdef __STATISTICS__ 1292 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );1293 1259 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 1294 1260 #endif // __STATISTICS__ … … 1336 1302 1337 1303 void * realloc( void * oaddr, size_t nalign, size_t size ) { 1338 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.1339 if ( unlikely( size == 0 ) ) { // special cases1340 #ifdef __STATISTICS__1341 __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );1342 #endif // __STATISTICS__1343 free( oaddr );1344 return 0p;1345 } // if1346 1347 1304 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1348 1305 #ifdef __CFA_DEBUG__ 1349 else checkAlign( nalign ); // check alignment 1306 else 1307 checkAlign( nalign ); // check alignment 1350 1308 #endif // __CFA_DEBUG__ 1351 1309 1310 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1311 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases 1352 1312 if ( unlikely( oaddr == 0p ) ) { 1353 1313 #ifdef __STATISTICS__ -
libcfa/src/startup.cfa
r64aeca0 r58fe85a 10 10 // Created On : Tue Jul 24 16:21:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 9 23:18:23 202113 // Update Count : 3 412 // Last Modified On : Tue Feb 4 13:03:18 2020 13 // Update Count : 30 14 14 // 15 15 16 #include <time.h> // tzset 17 #include <locale.h> // setlocale 18 #include <stdlib.h> // getenv 16 #include <time.h> // tzset 17 #include <locale.h> // setlocale 19 18 #include "startup.hfa" 20 19 … … 23 22 void __cfaabi_appready_startup( void ) { 24 23 tzset(); // initialize time global variables 25 setlocale( LC_NUMERIC, getenv("LANG"));24 setlocale(LC_NUMERIC, ""); 26 25 #ifdef __CFA_DEBUG__ 27 26 extern void heapAppStart(); -
src/Parser/ParseNode.h
r64aeca0 r58fe85a 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Jan 3 18:23:01 202113 // Update Count : 89 612 // Last Modified On : Sat Oct 24 03:53:54 2020 13 // Update Count : 895 14 14 // 15 15 … … 39 39 struct DeclarationNode; 40 40 class DeclarationWithType; 41 class ExpressionNode; 41 42 class Initializer; 42 class ExpressionNode;43 43 struct StatementNode; 44 44 -
src/Parser/parser.yy
r64aeca0 r58fe85a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Jan 10 17:41:00 202113 // Update Count : 462 512 // Last Modified On : Sat Oct 24 08:21:14 2020 13 // Update Count : 4624 14 14 // 15 15 … … 329 329 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 330 330 %type<en> comma_expression comma_expression_opt 331 %type<en> argument_expression_list_opt argument_expression default_initialize r_opt331 %type<en> argument_expression_list_opt argument_expression default_initialize_opt 332 332 %type<ifctl> if_control_expression 333 333 %type<fctl> for_control_expression for_control_expression_list … … 424 424 %type<decl> sue_declaration_specifier sue_declaration_specifier_nobody sue_type_specifier sue_type_specifier_nobody 425 425 426 %type<tclass> type_class new_type_class426 %type<tclass> type_class 427 427 %type<decl> type_declarator type_declarator_name type_declaring_list 428 428 … … 2223 2223 ; 2224 2224 2225 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real2225 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real 2226 2226 // empty 2227 2227 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } … … 2280 2280 cfa_parameter_declaration: // CFA, new & old style parameter declaration 2281 2281 parameter_declaration 2282 | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize r_opt2282 | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt 2283 2283 { $$ = $1->addName( $2 ); } 2284 | cfa_abstract_tuple identifier_or_type_name default_initialize r_opt2284 | cfa_abstract_tuple identifier_or_type_name default_initialize_opt 2285 2285 // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator). 2286 2286 { $$ = $1->addName( $2 ); } 2287 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize r_opt2287 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt 2288 2288 { $$ = $2->addName( $3 )->addQualifiers( $1 ); } 2289 2289 | cfa_function_specifier … … 2302 2302 parameter_declaration: 2303 2303 // No SUE declaration in parameter list. 2304 declaration_specifier_nobody identifier_parameter_declarator default_initialize r_opt2304 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt 2305 2305 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2306 | declaration_specifier_nobody type_parameter_redeclarator default_initialize r_opt2306 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt 2307 2307 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2308 2308 ; 2309 2309 2310 2310 abstract_parameter_declaration: 2311 declaration_specifier_nobody default_initialize r_opt2311 declaration_specifier_nobody default_initialize_opt 2312 2312 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); } 2313 | declaration_specifier_nobody abstract_parameter_declarator default_initialize r_opt2313 | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt 2314 2314 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2315 2315 ; … … 2441 2441 type_class identifier_or_type_name 2442 2442 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2443 type_initializer_opt assertion_list_opt2443 type_initializer_opt assertion_list_opt 2444 2444 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2445 | identifier_or_type_name new_type_class 2446 { typedefTable.addToScope( *$1, TYPEDEFname, "9" ); } 2447 type_initializer_opt assertion_list_opt 2448 { $$ = DeclarationNode::newTypeParam( $2, $1 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2449 | '[' identifier_or_type_name ']' 2450 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2451 // | type_specifier identifier_parameter_declarator 2445 | type_specifier identifier_parameter_declarator 2452 2446 | assertion_list 2453 2447 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2454 ;2455 2456 new_type_class: // CFA2457 // empty2458 { $$ = TypeDecl::Otype; }2459 | '&'2460 { $$ = TypeDecl::Dtype; }2461 | '*'2462 { $$ = TypeDecl::Dtype; }2463 | ELLIPSIS2464 { $$ = TypeDecl::Ttype; }2465 2448 ; 2466 2449 … … 3493 3476 ; 3494 3477 3495 default_initialize r_opt:3478 default_initialize_opt: 3496 3479 // empty 3497 3480 { $$ = nullptr; }
Note:
See TracChangeset
for help on using the changeset viewer.