Changeset 1291
- Timestamp:
- 09/24/08 22:38:28 (2 months ago)
- Files:
-
- 1.8.3/branches/gc/hdrs/mymalloc.h (modified) (3 diffs)
- 1.8.3/branches/gc/src/bsd.c (modified) (1 diff)
- 1.8.3/branches/gc/src/conf.c (modified) (3 diffs)
- 1.8.3/branches/gc/src/funlist.c (modified) (4 diffs)
- 1.8.3/branches/gc/src/game.c (modified) (3 diffs)
- 1.8.3/branches/gc/src/mymalloc.c (modified) (7 diffs)
- 1.8.3/branches/gc/src/plyrlist.c (modified) (1 diff)
- 1.8.3/branches/gc/src/strutil.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/gc/hdrs/mymalloc.h
r1023 r1291 9 9 10 10 /* GC functions */ 11 #include <gc.h> 11 #include <gc/gc.h> 12 13 #define alloc_buf() GC_MALLOC_ATOMIC(BUFFER_LEN) 12 14 13 15 typedef struct slab slab; … … 29 31 that slab. Defaults to 0. */ 30 32 31 SLAB_HINTLESS_THRESHOLD /**< The number of free objects that must33 SLAB_HINTLESS_THRESHOLD, /**< The number of free objects that must 32 34 exist in a page for a hintless object to 33 35 be allocated from it. Defaults to … … 36 38 deletions, to improve caching -- e.g., 37 39 attributes. */ 40 41 SLAB_NO_EXT_POINTERS /**< Objects allocated through this slab have 42 no pointers to other objects. */ 38 43 }; 39 44 1.8.3/branches/gc/src/bsd.c
r1284 r1291 404 404 405 405 GC_INIT(); 406 407 #if 0 /* TODO: Make this a config/options.h setting */ 406 408 GC_enable_incremental(); 409 #endif 410 411 #ifdef HAVE_PCRE 412 pcre_malloc = GC_malloc; 413 pcre_free = GC_free; 414 #endif 407 415 408 416 /* disallow running as root on unix. 1.8.3/branches/gc/src/conf.c
r1284 r1291 568 568 new_config(void) 569 569 { 570 return ((PENNCONF *) mush_malloc(sizeof(PENNCONF), "config"));570 return mush_malloc(sizeof(PENNCONF), "config"); 571 571 } 572 572 … … 610 610 get_config(const char *name) 611 611 { 612 return ((PENNCONF *) hashfind(name, &local_options));612 return hashfind(name, &local_options); 613 613 } 614 614 … … 1291 1291 static char cfile[BUFFER_LEN]; /* Remember the last one */ 1292 1292 if (conf_recursion == 0) { 1293 GC_exclude_static_roots(&options, &options + sizeof(options) + 1); 1294 GC_exclude_static_roots(conftable, 1295 conftable + sizeof(conftable) + 1); 1296 1293 1297 if (conf && *conf) 1294 1298 strcpy(cfile, conf); 1.8.3/branches/gc/src/funlist.c
r1284 r1291 292 292 293 293 ptrs = mush_calloc(MAX_SORTSIZE, sizeof(char *), "ptrarray"); 294 wordlist = mush_malloc(BUFFER_LEN, "string");294 wordlist = alloc_buf(); 295 295 if (!ptrs || !wordlist) 296 296 mush_panic("Unable to allocate memory in fun_elements"); … … 1882 1882 1883 1883 ptrs = mush_calloc(MAX_SORTSIZE, sizeof(char *), "ptrarray"); 1884 wordlist = mush_malloc(BUFFER_LEN, "string");1884 wordlist = alloc_buf(); 1885 1885 if (!ptrs || !wordlist) 1886 1886 mush_panic("Unable to allocate memory in fun_elements"); … … 2025 2025 2026 2026 origcount = count = list2arr_ansi(words, BUFFER_LEN, args[0], sep); 2027 if (count == 0) { 2028 mush_free(words, "wordlist"); 2029 return; 2030 } 2027 if (count == 0) 2028 return; 2031 2029 2032 2030 safe_str(words[--count], buff, bp); … … 2133 2131 return; 2134 2132 2135 outsep = (char *) mush_malloc(BUFFER_LEN, "string");2136 list = (char *) mush_malloc(BUFFER_LEN, "string");2133 outsep = alloc_buf(); 2134 list = alloc_buf(); 2137 2135 if (!outsep || !list) 2138 2136 mush_panic("Unable to allocate memory in fun_iter"); 1.8.3/branches/gc/src/game.c
r1284 r1291 987 987 static int initialized = 0; 988 988 static pcre *pass_ptn, *newpass_ptn; 989 static char buff[BUFFER_LEN]; 990 char *bp = buff; 989 char *buff, *bp; 991 990 int ovec[20]; 992 991 size_t cmdlen; … … 1007 1006 initialized = 1; 1008 1007 } 1008 1009 bp = buff = alloc_buf(); 1009 1010 1010 1011 cmdlen = strlen(cmd); … … 1549 1550 scan_list(dbref player, char *command) 1550 1551 { 1551 static char tbuf[BUFFER_LEN]; 1552 char *tp; 1552 char *tbuf, *tp; 1553 1553 dbref thing; 1554 1554 char atrname[BUFFER_LEN]; 1555 1555 char *ptr; 1556 1556 int num; 1557 1558 tbuf = tp = alloc_buf(); 1557 1559 1558 1560 if (!GoodObject(Location(player))) { 1.8.3/branches/gc/src/mymalloc.c
r1129 r1291 40 40 #include <windows.h> 41 41 #endif 42 #include <gc .h>42 #include <gc/gc.h> 43 43 #include "options.h" 44 44 #include "conf.h" … … 90 90 do_rawlog(LT_TRACE, "mush_calloc failed to allocate %lu bytes for %s", 91 91 (unsigned long) (size * count), check); 92 memset(ptr, 0, bytes);92 /* memset(ptr, 0, bytes); */ 93 93 return ptr; 94 94 } … … 126 126 int hintless_threshold; /**< See documentation for 127 127 SLAB_HINTLESS_THRESHOLD option */ 128 bool atomic; /**< SLAB_NO_EXT_POINTERS */ 128 129 struct slab_page *slabs; /**< Pointer to the head of the list of 129 130 allocated pages. */ … … 153 154 sl->keep_last_empty = 0; 154 155 sl->hintless_threshold = 0; 156 sl->atomic = 0; 155 157 sl->slabs = NULL; 156 158 if (item_size < SIZEOF_VOID_P) … … 196 198 sl->hintless_threshold = val; 197 199 break; 200 case SLAB_NO_EXT_POINTERS: 201 sl->atomic = val; 202 break; 198 203 default: 199 204 /* Unknown option */ … … 272 277 if (sl->items_per_page == 0) 273 278 return GC_MALLOC(sl->item_size); 279 280 /* If atomic. just allocate it. Consider always doing this. */ 281 if (sl->atomic) 282 return GC_MALLOC_ATOMIC(sl->item_size); 274 283 275 284 /* If no pages have been allocated, make one and use it. */ … … 352 361 353 362 /* If objects are too big to fit in a single page, use plain free */ 354 if (sl->items_per_page == 0 )363 if (sl->items_per_page == 0 || sl->atomic) 355 364 GC_FREE(obj); 356 365 1.8.3/branches/gc/src/plyrlist.c
r1129 r1291 47 47 hash_init(&htab_player_list, 256, delete_dbref); 48 48 player_dbref_slab = slab_create("player list dbrefs", sizeof(dbref)); 49 player_dbref_slab = slab_create("player list dbrefs", sizeof(dbref));49 slab_set_opt(player_dbref_slab, SLAB_NO_EXT_POINTERS, 1); 50 50 hft_initialized = 1; 51 51 } 1.8.3/branches/gc/src/strutil.c
r1284 r1291 192 192 /** Return an uppercased version of a string in a static buffer. 193 193 * \param s string to uppercase. 194 * \return pointer to a staticbuffer containing the uppercased version.194 * \return pointer to a buffer containing the uppercased version. 195 195 */ 196 196 char * 197 197 strupper(const char *s) 198 198 { 199 static char buf1[BUFFER_LEN]; 200 char *p; 201 202 if (!s || !*s) { 203 buf1[0] = '\0'; 204 return buf1; 205 } 206 mush_strncpy(buf1, s, BUFFER_LEN); 199 char *p, *buf1; 200 201 if (!s || !*s) 202 return ""; 203 204 buf1 = GC_STRDUP(s); 207 205 for (p = buf1; *p; p++) 208 206 *p = UPCASE(*p); … … 212 210 /** Return a lowercased version of a string in a static buffer. 213 211 * \param s string to lowercase. 214 * \return pointer to a staticbuffer containing the lowercased version.212 * \return pointer to a buffer containing the lowercased version. 215 213 */ 216 214 char * 217 215 strlower(const char *s) 218 216 { 219 static char buf1[BUFFER_LEN]; 220 char *p; 221 222 if (!s || !*s) { 223 buf1[0] = '\0'; 224 return buf1; 225 } 226 mush_strncpy(buf1, s, BUFFER_LEN); 217 char *p, *buf1; 218 219 if (!s || !*s) 220 return ""; 221 222 buf1 = GC_STRDUP(s); 227 223 for (p = buf1; *p; p++) 228 224 *p = DOWNCASE(*p); … … 1319 1315 size_t s1_len, s2_len; 1320 1316 1321 ns1 = mush_malloc(t + 1, "string");1322 ns2 = mush_malloc(t + 1, "string");1317 ns1 = GC_MALLOC_ATOMIC(t + 1); 1318 ns2 = GC_MALLOC_ATOMIC(t + 1); 1323 1319 memcpy(ns1, s1, t); 1324 1320 ns1[t] = '\0'; … … 1328 1324 s2_len = strxfrm(NULL, ns2, 0) + 1; 1329 1325 1330 d1 = mush_malloc(s1_len + 1, "string");1331 d2 = mush_malloc(s2_len + 1, "string");1326 d1 = GC_MALLOC_ATOMIC(s1_len + 1); 1327 d2 = GC_MALLOC_ATOMIC(s2_len + 1); 1332 1328 (void) strxfrm(d1, ns1, s1_len); 1333 1329 (void) strxfrm(d2, ns2, s2_len); 1334 1330 result = strcmp(d1, d2); 1335 mush_free(ns1, "string");1336 mush_free(ns2, "string");1337 mush_free(d1, "string");1338 mush_free(d2, "string");1339 1331 return result; 1340 1332 #else … … 1363 1355 s2_len = strxfrm(NULL, s2, 0) + 1; 1364 1356 1365 d1 = mush_malloc(s1_len, "string");1366 d2 = mush_malloc(s2_len, "string");1357 d1 = GC_MALLOC_ATOMIC(s1_len); 1358 d2 = GC_MALLOC_ATOMIC(s2_len); 1367 1359 (void) strxfrm(d1, strupper(s1), s1_len); 1368 1360 (void) strxfrm(d2, strupper(s2), s2_len); 1369 1361 result = strcmp(d1, d2); 1370 mush_free(d1, "string");1371 mush_free(d2, "string");1372 1362 return result; 1373 1363 #else … … 1394 1384 size_t s1_len, s2_len; 1395 1385 1396 ns1 = mush_malloc(t + 1, "string");1397 ns2 = mush_malloc(t + 1, "string");1386 ns1 = GC_MALLOC_ATOMIC(t + 1); 1387 ns2 = GC_MALLOC_ATOMIC(t + 1); 1398 1388 memcpy(ns1, s1, t); 1399 1389 ns1[t] = '\0'; … … 1403 1393 s2_len = strxfrm(NULL, ns2, 0) + 1; 1404 1394 1405 d1 = mush_malloc(s1_len, "string");1406 d2 = mush_malloc(s2_len, "string");1395 d1 = GC_MALLOC_ATOMIC(s1_len); 1396 d2 = GC_MALLOC_ATOMIC(s2_len); 1407 1397 (void) strxfrm(d1, strupper(ns1), s1_len); 1408 1398 (void) strxfrm(d2, strupper(ns2), s2_len); 1409 1399 result = strcmp(d1, d2); 1410 mush_free(ns1, "string");1411 mush_free(ns2, "string");1412 mush_free(d1, "string");1413 mush_free(d2, "string");1414 1400 return result; 1415 1401 #else … … 1507 1493 * Just like asctime() except without the trailing newlines. 1508 1494 * \param when the time to format. 1509 * \return a pointer to a staticbuffer with the stringified time.1495 * \return a pointer to a buffer with the stringified time. 1510 1496 */ 1511 1497 char * 1512 1498 show_tm(struct tm *when) 1513 1499 { 1514 static char buffer[BUFFER_LEN];1500 char *buffer; 1515 1501 int p; 1516 1502 … … 1518 1504 return NULL; 1519 1505 1520 strcpy(buffer,asctime(when));1506 buffer = GC_STRDUP(asctime(when)); 1521 1507 1522 1508 p = strlen(buffer) - 1;
