PennMUSH Community

Changeset 1291

Show
Ignore:
Timestamp:
09/24/08 22:38:28 (2 months ago)
Author:
shawnw
Message:

GC: Various gc conversion work

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/gc/hdrs/mymalloc.h

    r1023 r1291  
    99 
    1010/* GC functions */ 
    11 #include <gc.h> 
     11#include <gc/gc.h> 
     12 
     13#define alloc_buf() GC_MALLOC_ATOMIC(BUFFER_LEN) 
    1214 
    1315typedef struct slab slab; 
     
    2931                             that slab. Defaults to 0. */ 
    3032 
    31   SLAB_HINTLESS_THRESHOLD /**< The number of free objects that must 
     33  SLAB_HINTLESS_THRESHOLD, /**< The number of free objects that must 
    3234                              exist in a page for a hintless object to 
    3335                              be allocated from it. Defaults to 
     
    3638                              deletions, to improve caching -- e.g., 
    3739                              attributes. */ 
     40 
     41  SLAB_NO_EXT_POINTERS /**< Objects allocated through this slab have 
     42              no pointers to other objects. */ 
    3843}; 
    3944 
  • 1.8.3/branches/gc/src/bsd.c

    r1284 r1291  
    404404 
    405405  GC_INIT(); 
     406 
     407#if 0 /* TODO: Make this a config/options.h setting */ 
    406408  GC_enable_incremental(); 
     409#endif 
     410 
     411#ifdef HAVE_PCRE 
     412  pcre_malloc = GC_malloc; 
     413  pcre_free = GC_free; 
     414#endif 
    407415 
    408416/* disallow running as root on unix. 
  • 1.8.3/branches/gc/src/conf.c

    r1284 r1291  
    568568new_config(void) 
    569569{ 
    570   return ((PENNCONF *) mush_malloc(sizeof(PENNCONF), "config")); 
     570  return mush_malloc(sizeof(PENNCONF), "config"); 
    571571} 
    572572 
     
    610610get_config(const char *name) 
    611611{ 
    612   return ((PENNCONF *) hashfind(name, &local_options)); 
     612  return hashfind(name, &local_options); 
    613613} 
    614614 
     
    12911291  static char cfile[BUFFER_LEN];        /* Remember the last one */ 
    12921292  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 
    12931297    if (conf && *conf) 
    12941298      strcpy(cfile, conf); 
  • 1.8.3/branches/gc/src/funlist.c

    r1284 r1291  
    292292 
    293293  ptrs = mush_calloc(MAX_SORTSIZE, sizeof(char *), "ptrarray"); 
    294   wordlist = mush_malloc(BUFFER_LEN, "string"); 
     294  wordlist = alloc_buf(); 
    295295  if (!ptrs || !wordlist) 
    296296    mush_panic("Unable to allocate memory in fun_elements"); 
     
    18821882 
    18831883  ptrs = mush_calloc(MAX_SORTSIZE, sizeof(char *), "ptrarray"); 
    1884   wordlist = mush_malloc(BUFFER_LEN, "string"); 
     1884  wordlist = alloc_buf(); 
    18851885  if (!ptrs || !wordlist) 
    18861886    mush_panic("Unable to allocate memory in fun_elements"); 
     
    20252025 
    20262026  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; 
    20312029 
    20322030  safe_str(words[--count], buff, bp); 
     
    21332131    return; 
    21342132 
    2135   outsep = (char *) mush_malloc(BUFFER_LEN, "string"); 
    2136   list = (char *) mush_malloc(BUFFER_LEN, "string"); 
     2133  outsep = alloc_buf(); 
     2134  list = alloc_buf(); 
    21372135  if (!outsep || !list) 
    21382136    mush_panic("Unable to allocate memory in fun_iter"); 
  • 1.8.3/branches/gc/src/game.c

    r1284 r1291  
    987987  static int initialized = 0; 
    988988  static pcre *pass_ptn, *newpass_ptn; 
    989   static char buff[BUFFER_LEN]; 
    990   char *bp = buff; 
     989  char *buff, *bp; 
    991990  int ovec[20]; 
    992991  size_t cmdlen; 
     
    10071006    initialized = 1; 
    10081007  } 
     1008 
     1009  bp = buff = alloc_buf(); 
    10091010 
    10101011  cmdlen = strlen(cmd); 
     
    15491550scan_list(dbref player, char *command) 
    15501551{ 
    1551   static char tbuf[BUFFER_LEN]; 
    1552   char *tp; 
     1552  char *tbuf, *tp; 
    15531553  dbref thing; 
    15541554  char atrname[BUFFER_LEN]; 
    15551555  char *ptr; 
    15561556  int num; 
     1557 
     1558  tbuf = tp = alloc_buf(); 
    15571559 
    15581560  if (!GoodObject(Location(player))) { 
  • 1.8.3/branches/gc/src/mymalloc.c

    r1129 r1291  
    4040#include <windows.h> 
    4141#endif 
    42 #include <gc.h> 
     42#include <gc/gc.h> 
    4343#include "options.h" 
    4444#include "conf.h" 
     
    9090    do_rawlog(LT_TRACE, "mush_calloc failed to allocate %lu bytes for %s", 
    9191              (unsigned long) (size * count), check); 
    92   memset(ptr, 0, bytes); 
     92  /*  memset(ptr, 0, bytes); */ 
    9393  return ptr; 
    9494} 
     
    126126  int hintless_threshold; /**< See documentation for 
    127127                             SLAB_HINTLESS_THRESHOLD option */ 
     128  bool atomic; /**< SLAB_NO_EXT_POINTERS */ 
    128129  struct slab_page *slabs; /**< Pointer to the head of the list of 
    129130                              allocated pages. */ 
     
    153154  sl->keep_last_empty = 0; 
    154155  sl->hintless_threshold = 0; 
     156  sl->atomic = 0; 
    155157  sl->slabs = NULL; 
    156158  if (item_size < SIZEOF_VOID_P) 
     
    196198    sl->hintless_threshold = val; 
    197199    break; 
     200  case SLAB_NO_EXT_POINTERS: 
     201    sl->atomic = val; 
     202    break; 
    198203  default: 
    199204    /* Unknown option */ 
     
    272277  if (sl->items_per_page == 0) 
    273278    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); 
    274283 
    275284  /* If no pages have been allocated, make one and use it. */ 
     
    352361 
    353362  /* 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
    355364    GC_FREE(obj); 
    356365 
  • 1.8.3/branches/gc/src/plyrlist.c

    r1129 r1291  
    4747  hash_init(&htab_player_list, 256, delete_dbref); 
    4848  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); 
    5050  hft_initialized = 1; 
    5151} 
  • 1.8.3/branches/gc/src/strutil.c

    r1284 r1291  
    192192/** Return an uppercased version of a string in a static buffer. 
    193193 * \param s string to uppercase. 
    194  * \return pointer to a static buffer containing the uppercased version. 
     194 * \return pointer to a buffer containing the uppercased version. 
    195195 */ 
    196196char * 
    197197strupper(const char *s) 
    198198{ 
    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); 
    207205  for (p = buf1; *p; p++) 
    208206    *p = UPCASE(*p); 
     
    212210/** Return a lowercased version of a string in a static buffer. 
    213211 * \param s string to lowercase. 
    214  * \return pointer to a static buffer containing the lowercased version. 
     212 * \return pointer to a buffer containing the lowercased version. 
    215213 */ 
    216214char * 
    217215strlower(const char *s) 
    218216{ 
    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); 
    227223  for (p = buf1; *p; p++) 
    228224    *p = DOWNCASE(*p); 
     
    13191315  size_t s1_len, s2_len; 
    13201316 
    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); 
    13231319  memcpy(ns1, s1, t); 
    13241320  ns1[t] = '\0'; 
     
    13281324  s2_len = strxfrm(NULL, ns2, 0) + 1; 
    13291325 
    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); 
    13321328  (void) strxfrm(d1, ns1, s1_len); 
    13331329  (void) strxfrm(d2, ns2, s2_len); 
    13341330  result = strcmp(d1, d2); 
    1335   mush_free(ns1, "string"); 
    1336   mush_free(ns2, "string"); 
    1337   mush_free(d1, "string"); 
    1338   mush_free(d2, "string"); 
    13391331  return result; 
    13401332#else 
     
    13631355  s2_len = strxfrm(NULL, s2, 0) + 1; 
    13641356 
    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); 
    13671359  (void) strxfrm(d1, strupper(s1), s1_len); 
    13681360  (void) strxfrm(d2, strupper(s2), s2_len); 
    13691361  result = strcmp(d1, d2); 
    1370   mush_free(d1, "string"); 
    1371   mush_free(d2, "string"); 
    13721362  return result; 
    13731363#else 
     
    13941384  size_t s1_len, s2_len; 
    13951385 
    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); 
    13981388  memcpy(ns1, s1, t); 
    13991389  ns1[t] = '\0'; 
     
    14031393  s2_len = strxfrm(NULL, ns2, 0) + 1; 
    14041394 
    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); 
    14071397  (void) strxfrm(d1, strupper(ns1), s1_len); 
    14081398  (void) strxfrm(d2, strupper(ns2), s2_len); 
    14091399  result = strcmp(d1, d2); 
    1410   mush_free(ns1, "string"); 
    1411   mush_free(ns2, "string"); 
    1412   mush_free(d1, "string"); 
    1413   mush_free(d2, "string"); 
    14141400  return result; 
    14151401#else 
     
    15071493 * Just like asctime() except without the trailing newlines. 
    15081494 * \param when the time to format. 
    1509  * \return a pointer to a static buffer with the stringified time. 
     1495 * \return a pointer to a buffer with the stringified time. 
    15101496 */ 
    15111497char * 
    15121498show_tm(struct tm *when) 
    15131499{ 
    1514   static char buffer[BUFFER_LEN]
     1500  char *buffer
    15151501  int p; 
    15161502 
     
    15181504    return NULL; 
    15191505 
    1520   strcpy(buffer, asctime(when)); 
     1506  buffer = GC_STRDUP(asctime(when)); 
    15211507 
    15221508  p = strlen(buffer) - 1;