Ejemplo n.º 1
0
void * GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS)
{
    void * base = GC_base(p);
    ptr_t clobbered;
    void * result;
    size_t copy_sz = lb;
    size_t old_sz;
    hdr * hhdr;
    
    if (p == 0) return(GC_debug_malloc(lb, OPT_RA s, i));
    if (base == 0) {
        GC_err_printf("Attempt to reallocate invalid pointer %p\n", p);
        ABORT("realloc(invalid pointer)");
    }
    if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
        GC_err_printf(
        	"GC_debug_realloc called on pointer %p wo debugging info\n", p);
        return(GC_realloc(p, lb));
    }
    hhdr = HDR(base);
    switch (hhdr -> hb_obj_kind) {
#    ifdef STUBBORN_ALLOC
      case STUBBORN:
        result = GC_debug_malloc_stubborn(lb, OPT_RA s, i);
        break;
#    endif
      case NORMAL:
        result = GC_debug_malloc(lb, OPT_RA s, i);
        break;
      case PTRFREE:
        result = GC_debug_malloc_atomic(lb, OPT_RA s, i);
        break;
      case UNCOLLECTABLE:
	result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i);
 	break;
#    ifdef ATOMIC_UNCOLLECTABLE
      case AUNCOLLECTABLE:
	result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i);
	break;
#    endif
      default:
        GC_err_printf("GC_debug_realloc: encountered bad kind\n");
        ABORT("bad kind");
    }
#   ifdef SHORT_DBG_HDRS
      old_sz = GC_size(base) - sizeof(oh);
#   else
      clobbered = GC_check_annotated_obj((oh *)base);
      if (clobbered != 0) {
        GC_err_printf("GC_debug_realloc: found smashed location at ");
        GC_print_smashed_obj(p, clobbered);
      }
      old_sz = ((oh *)base) -> oh_sz;
#   endif
    if (old_sz < copy_sz) copy_sz = old_sz;
    if (result == 0) return(0);
    BCOPY(p, result,  copy_sz);
    GC_debug_free(p);
    return(result);
}
Ejemplo n.º 2
0
void *
objc_realloc (void *mem, size_t size)
{
  void *res = (void *)(GC_realloc (mem, size));
  if (! res)
    _objc_abort ("Virtual memory exhausted\n");
  return res;
}
Ejemplo n.º 3
0
GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS)
{
    void * base;
    void * result;
    hdr * hhdr;
    if (p == 0)
      return(GC_debug_malloc(lb, OPT_RA s, i));

    base = GC_base(p);
    if (base == 0) {
        GC_err_printf("Attempt to reallocate invalid pointer %p\n", p);
        ABORT("Invalid pointer passed to realloc()");
    }
    if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
        GC_err_printf(
              "GC_debug_realloc called on pointer %p w/o debugging info\n", p);
        return(GC_realloc(p, lb));
    }
    hhdr = HDR(base);
    switch (hhdr -> hb_obj_kind) {
#    ifdef STUBBORN_ALLOC
      case STUBBORN:
        result = GC_debug_malloc_stubborn(lb, OPT_RA s, i);
        break;
#    endif
      case NORMAL:
        result = GC_debug_malloc(lb, OPT_RA s, i);
        break;
      case PTRFREE:
        result = GC_debug_malloc_atomic(lb, OPT_RA s, i);
        break;
      case UNCOLLECTABLE:
        result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i);
        break;
#    ifdef ATOMIC_UNCOLLECTABLE
      case AUNCOLLECTABLE:
        result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i);
        break;
#    endif
      default:
        result = NULL; /* initialized to prevent warning. */
        GC_err_printf("GC_debug_realloc: encountered bad kind\n");
        ABORT("Bad kind");
    }

    if (result != NULL) {
      size_t old_sz;
#     ifdef SHORT_DBG_HDRS
        old_sz = GC_size(base) - sizeof(oh);
#     else
        old_sz = ((oh *)base) -> oh_sz;
#     endif
      BCOPY(p, result, old_sz < lb ? old_sz : lb);
      GC_debug_free(p);
    }
    return(result);
}
Ejemplo n.º 4
0
/*
 * The wrapped realloc function.
 *
 */
void *GC_amiga_realloc(void *old_object,size_t new_size_in_bytes){
#ifndef GC_AMIGA_FASTALLOC
        return GC_realloc(old_object,new_size_in_bytes);
#else
        void *ret;
        latestsize=new_size_in_bytes;
        ret=GC_realloc(old_object,new_size_in_bytes);
        if(ret==NULL && new_size_in_bytes != 0
           && GC_AMIGA_MEMF==(MEMF_FAST | MEMF_CLEAR)){
                /* Out of fast-mem. */
#ifdef GC_AMIGA_GC
                if(!GC_dont_gc){
                        GC_gcollect();
#ifdef GC_AMIGA_PRINTSTATS
                        numcollects++;
#endif
                        ret=GC_realloc(old_object,new_size_in_bytes);
                }
#endif
                if(ret==NULL){
#ifndef GC_AMIGA_ONLYFAST
                        GC_AMIGA_MEMF=MEMF_ANY | MEMF_CLEAR;
                        if(GC_amiga_toany!=NULL) (*GC_amiga_toany)();
                        GC_amiga_allocwrapper_do=GC_amiga_allocwrapper_any;
                        ret=GC_realloc(old_object,new_size_in_bytes);
#endif
                }
#ifdef GC_AMIGA_PRINTSTATS
                else{
                        nullretries++;
                }
#endif
        }
        if(ret==NULL && new_size_in_bytes != 0){
                WARN("Out of Memory!  Returning NIL!\n", 0);
        }
#ifdef GC_AMIGA_PRINTSTATS
        if(((char *)ret)<chipmax && ret!=NULL){
                chipa+=new_size_in_bytes;
        }
#endif
        return ret;
#endif
}
Ejemplo n.º 5
0
void ZArray_EnsureSize(struct ZArray *ZArr, size_t bufsize) {
	if((size_t)ZArr->bufsize < bufsize) {
		void *newarr = GC_realloc((ZArr->element), bufsize);
		if(newarr == NULL) {
			exit(EXIT_FAILURE);
		}
		ZArr->bufsize = bufsize;
		ZArr->element = newarr;
	}
	return;
}
Ejemplo n.º 6
0
void *xrealloc(void *p, size_t newsize)
{
#ifdef BWGC
  void *x = GC_realloc(p, newsize);
#else
  void *x = realloc(p, newsize);
#endif

  if (!x) abort();

  return x;
}
Ejemplo n.º 7
0
char* recv_string (int sock) {
    char* buf = GC_malloc(MAX_BUFFER);
    uint msg_size = 0;
    uint got = 0;
    printf("recv...\n");
    got = CHECK(recv, sock, buf, MAX_BUFFER, 0);
        printf("%d\n", got);
        msg_size += got;
        buf = GC_realloc(buf, got + MAX_BUFFER);
    printf("Got a message.\n");
    buf[msg_size] = 0;
    return buf;
}
Ejemplo n.º 8
0
/* Scan a file and return an array of all the tokens */
static struct scanner_token *scan(struct scanner_input *I, unsigned int *n)
{
    size_t nallocated = 16, count = 0;
    struct scanner_token *ret = GC_malloc(nallocated * sizeof(struct scanner_token));
    struct scanner_token tok;

    do
    {
        tok = scan_next(I);
        if (count >= nallocated)
        {
            nallocated *= 2;
            ret = GC_realloc(ret, nallocated * sizeof(struct scanner_token));
        }
        ret[count++] = tok;
    } while (tok.type != TOK_EOF);

    if (n)
        *n = (unsigned int) count;

    // Shrink it down to the right size
    ret = GC_realloc(ret, count * sizeof(struct scanner_token));
    return ret;
}
Ejemplo n.º 9
0
void *
FACT_realloc (void *to_resize, size_t new_size)
{
  void * temp_pointer;

  temp_pointer = GC_realloc (to_resize, new_size);

  if (temp_pointer == NULL)
    {
      fprintf (stderr, "Could not allocate block of size %lu, exiting.\n", (unsigned long) new_size);
      abort ();
    }
  
  return temp_pointer;
}
Ejemplo n.º 10
0
const char* query_api (const char* lat, const char* lon) {

  struct sockaddr_in sa;
  char buffer[MAX_BUFFER];
  static char RequestBegin[] = "GET /api/e5df4405be67dec2/geolookup/q/";
  static char RequestEnd[] = ".xml\r\n\r\n";
  char Request[strlen(lat) + strlen(lon) + strlen(RequestBegin) + strlen(RequestEnd) + 2];
  Request[0] = 0;
  strcat(Request, RequestBegin);
  strcat(Request, lat);
  strcat(Request, ",");
  strcat(Request, lon);
  strcat(Request, RequestEnd);
  puts(Request);
  static char WunderServer[] = "38.102.136.138";
  int sockfd = CHECK(socket, AF_INET, SOCK_STREAM, 0);
  inet_pton(AF_INET, WunderServer, &(sa.sin_addr));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(80);
  int sockconn = CHECK(connect, sockfd, (struct sockaddr *)&sa, sizeof(sa));
  int socksend = CHECK(send, sockfd, Request, strlen(Request), 0);
  int sockrecv = 1;
  int len = 1;
  char* str = GC_malloc(len);
  str[0] = '\0';
  do {
    sockrecv = CHECK(recv, sockfd, &buffer, MAX_BUFFER, 0);
    if(sockrecv > 0) {
      buffer[sockrecv] = '\0';
      printf("%s", buffer);
      len += sockrecv;
      str = GC_realloc(str, len);
      strcat(str, buffer);
    }
  } while(sockrecv > 0);
  int sockclose = CHECK(close, sockfd);
  puts(str);
  return str;
}
Ejemplo n.º 11
0
void *talloc_realloc__(void *v, size_t new_size, const char *filename, int linenumber){
#ifdef DISABLE_BDWGC
  # if defined(VALIDATE_MEM)
    return V_realloc(v,new_size);
  # else
    return realloc(v,new_size);
  # endif
#else
  #if !defined(VALIDATE_MEM)
    return GC_realloc(v,new_size);
  #else
    {
      MemoryAllocator allocator = V_get_MemoryAllocator(v);
      int old_size = V_get_size(v);
      
      void *new_mem = tracker_alloc__(new_size, allocator, filename, linenumber);
      memcpy(new_mem, v, R_MIN((int)new_size, old_size));
      
      return new_mem;
    }
  #endif
#endif
}
Ejemplo n.º 12
0
/* FIXME: Add escape sequences \n etc */
static char *read_quoted_string(struct scanner_input *I)
{
    unsigned int len = 32, pos = 0;
    char *s = GC_malloc(len), c;
    if (s == NULL)
        die("read_quoted_string(): GC_malloc() failed!", 1);
    do
    {
        c = next_char(I);
        if (pos >= len - 1)
        {
            char *NewStr;
            len *= 2;
            NewStr = GC_realloc(s, len);
            if (NewStr == NULL)
                die("read_quoted_string: GC_realloc() failed!", 1);
            s = NewStr;
        }
        s[pos++] = c;
    } while (c != '\"');
    /* Use pos - 1 to remove the final quote */
    s[pos - 1] = '\0';
    return s;
}
Ejemplo n.º 13
0
/**
 * do initial initialization of gmp library.  set allocators,
 * etc.
 */
void *gmp_realloc_wrapper(void *ptr, size_t old_size, size_t new_size) {
    return GC_realloc(ptr, new_size);
}
Ejemplo n.º 14
0
/**
 * bson_malloc:
 * @num_bytes: The number of bytes to allocate.
 *
 * Allocates @num_bytes of memory and returns a pointer to it.
 * If malloc failed to allocate the memory, abort() is called.
 *
 * Libbson does not try to handle OOM conditions as it is beyond
 * the scope of this library to handle so appropriately.
 *
 * Returns: A pointer if successful; otherwise abort() is called
 *   and this function will never return.
 */
void *
bson_malloc (size_t num_bytes)
{
   void *mem;

#ifdef BSON_LIB_GC
   if (!(mem = GC_malloc (num_bytes))) {
#else
   if (!(mem = malloc (num_bytes))) {
#endif
      abort ();
   }

   return mem;
}


/**
 * bson_malloc0:
 * @num_bytes: The number of bytes to allocate.
 *
 * Like bson_malloc() except the memory is zeroed first. This is similar
 * to calloc() except that abort() is called in case of failure to allocate
 * memory.
 *
 * Returns: A pointer if successful; otherwise abort() is called
 *   and this function will never return.
 */
void *
bson_malloc0 (size_t num_bytes)
{
   void *mem;

#ifdef BSON_LIB_GC
   if (!(mem = GC_malloc (num_bytes))) {
#else
   if (!(mem = calloc (1, num_bytes))) {
#endif
      abort ();
   }

#ifdef BSON_LIB_GC
   return memset(mem, 0, num_bytes);
#else
   return mem;
#endif
}


/**
 * bson_memalign0:
 * @alignment: The alignment (such as 8 for 64-bit).
 * @size: The size of the allocation.
 *
 * Like posix_memalign() except abort() is called in the case of
 * failure to allocate memory.
 *
 * Returns: A pointer if successful; otherwise abort() is called
 *   and this function will never return.
 */
void *
bson_memalign0 (size_t alignment,
                size_t size)
{
   void *mem;

#if HAVE_POSIX_MEMALIGN

#ifdef BSON_LIB_GC
   if (0 != GC_posix_memalign (&mem, alignment, size)) {
#else
   if (0 != posix_memalign (&mem, alignment, size)) {
#endif
      perror ("posix_memalign() failure:");
      abort ();
   }

#elif HAVE_MEMALIGN

#ifdef BSON_LIB_GC
   mem = GC_memalign (alignment, size);
#else
   mem = memalign (alignment, size);
#endif

   if (!mem) {
      perror ("memalign() failure:");
      abort ();
   }

#else
   mem = bson_malloc (size);
#endif

   memset (mem, 0, size);

   return mem;
}


/**
 * bson_realloc:
 * @mem: The memory to realloc, or NULL.
 * @num_bytes: The size of the new allocation or 0 to free.
 *
 * This function behaves similar to realloc() except that if there
 * is a failure abort() is called.
 *
 * Returns: The new allocation if successful; otherwise abort() is
 *   called and this function never returns.
 */
void *
bson_realloc (void  *mem,
              size_t num_bytes)
{
#ifdef BSON_LIB_GC
   if (!(mem = GC_realloc (mem, num_bytes))) {
#else
   if (!(mem = realloc (mem, num_bytes))) {
#endif
      if (!num_bytes) {
         return mem;
      }

      abort ();
   }

   return mem;
}


/**
 * bson_free:
 * @mem: An allocation to free.
 *
 * Frees @mem using the underlying allocator.
 *
 * Currently, this only calls free() directly, but that is subject to change.
 */
void
bson_free (void *mem)
{
#ifndef BSON_LIB_GC
   free (mem);
#endif
}


/**
 * bson_zero_free:
 * @mem: An allocation to free.
 * @size: The number of bytes in @mem.
 *
 * Frees @mem using the underlying allocator. @size bytes of @mem will be
 * zeroed before freeing the memory. This is useful in scenarios where
 * @mem contains passwords or other sensitive information.
 */
void
bson_zero_free (void  *mem,
                size_t size)
{
   if (mem) {
      memset (mem, 0, size);
      bson_free (mem);
   }
}
Ejemplo n.º 15
0
// main entry into parser
void encode_rpn()
{
  statement *stmt, *tempstmt = gprog->firststmt;
  struct labelset *label;
  unsigned int x = 0, y = 0;
  int channum = 0, lastfnc = 0, lastvar = 0, ifcount = 0;
  byte display = 0, watchchannel = 0, special = 0; 
  char *cont;
  symbol *sym;

begin:

  stmt = SafeMalloc(sizeof(statement));
  stmtinit(stmt);

  for (x=0; x<MAX_STMT_METAS; x++) {
    stmt->metalist[x].operation = 0;
    stmt->metalist[x].floatarg.mantisa.i = 0;
    stmt->metalist[x].floatarg.exp = 0;
    stmt->metalist[x].shortarg = 0;
    for (y=0; y<MAX_STRING_LENGTH; y++)
      stmt->metalist[x].stringarg[y] = 0;
  }

  special = 0;
  foundequals = 0;
  firstvar = 1;
  numlabels = 0;
  envinfo.stmttype = 0;
  tokenpos = 0;
  token_type = 1;
  lastopcode = 0;

  for (x=0; x<32; x++) { numargs[x] = 0; parenstack[x] = 0; }

  do {
     get_token();
     tokenpos += strlen(token);
     if(!checkoption(get_cmdindex(get_opname(stmt->opcode)), token, token_type))
       lineerror(stmt, __FILE__, __LINE__);
     // hack to avoid using runtime system
     // using runtime system would change the last executed line info.
//     if ((!strcmp(token, "PBSTEP")) && (token_type == TOK_COMMAND)) 
//       dbg_step();

     switch (token_type) {
       case TOK_ERROR:
         lineerror(stmt, __FILE__, __LINE__);
         break;

       case TOK_COMMAND:
         lastopcode = get_opcode(token);
         if (cmdtable[get_cmdindex(token)].options & IO_CHANNEL)
           watchchannel = 1;
         else watchchannel = 0;
         stmt->opcode = get_opcode(token);
         if (stmt->opcode == CMD_LET) goto loop2;
         else goto loop;

       case TOK_NUMBER:
         stmt->opcode = 0;
         stmt->linenum = atoi(token);
         break;

       default:
         buffermeta(stmt, token_type, token);
         goto loop2; 
     }

     buffermeta(stmt, token_type, token);

loop:
     get_token();
     if (checkerr == 2) checkerr = 1;
     else if (checkerr == 1) {
       if (token[0] == '=') {
         if (stmt->metalist[stmt->metapos-2].operation == 0xEC)
           stmt->metapos-=2;
         else stmt->metapos--;
         push("ERR", TOK_OPERATOR);
       } else if (token[0] == '(') {
         prog--;
         stmt->metapos--;
         strcpy(token, "ERR");
         token_type = TOK_FUNCTION;
       } 
       checkerr = 0;
     }
     if (lastopcode == CMD_SETERR) {
       if (!strcmp(token, "ON")) lastopcode = CMD_SETERRON;
       if (!strcmp(token, "OFF")) lastopcode = CMD_SETERROFF;
     }
     if (!strcmp(token, "RECORD")) {
       if (stmt->opcode == CMD_READ) lastopcode = CMD_READRECORD;
       if (stmt->opcode == CMD_WRITE) lastopcode = CMD_WRITERECORD;
       if (stmt->opcode == CMD_EXTRACT) lastopcode = CMD_EXTRACTRECORD;
       if (stmt->opcode == CMD_FIND) lastopcode = CMD_FINDRECORD;
       if (stmt->opcode == CMD_PRINT) lastopcode = CMD_PRINTRECORD;
       token_type = lasttype;
       goto loop;
     }
     if (lastopcode == CMD_REM) {
       stmt->metalist[1].operation = 0xF5;
       tokenpos -= 2;
       if (input[tokenpos] == '\"') x = tokenpos; else x = tokenpos+2;
       stmt->metalist[1].shortarg = strlen(input) - x;
       y = 0;
       for (x=x; x<strlen(input); x++)
       { stmt->metalist[1].stringarg[y] = input[x]; y++; }
       stmt->metalist[1].stringarg[y] = '\0';
       stmt->metapos++;
       if (stmt->linenum) insertstmt(gprog, stmt);
       return; 
     }
     tokenpos += strlen(token);
     if(!checkoption(get_cmdindex(get_opname(lastopcode)), token, token_type))
       lineerror(stmt, __FILE__, __LINE__);

loop2:
     switch (token_type) {
       case TOK_SEMICOLON:
         popstack(stmt, -1);
         if (!stmt->linenum) { execline(gprog, stmt); stmtinit(stmt); }
         break;

       case TOK_COLON:
         if ((stmt->metalist[stmt->metapos-1].operation == SETVAL_NUMERIC) ||
             (stmt->metalist[stmt->metapos-1].operation == GETVAL_NUMERIC) ||
             (stmt->metalist[stmt->metapos-1].operation == LABELREF)) {
           label = SafeMalloc(sizeof(struct labelset));
           sym = idx2sym(gprog, stmt->metalist[stmt->metapos-1].shortarg); 
           label->labelnum = addlabel(gprog, sym->name, stmt->linenum);
           for (x=0; x<MAX_STRING_LENGTH; x++)
             sym->name[x] = '\0';
           x = 0;
           stmt->metapos--;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->opcode = 0;
           stmt->labelset[stmt->numlabels] = label;
           stmt->numlabels++;
           firstvar = 1;
         } else {
           do {
             if (stmt->linenum == tempstmt->linenum) {
               for (x=0; x<strlen(input); x++) 
                 if (input[x] == ':') break;
               y = x;
               for (x=0; x<=y; x++) input[x] = ' ';
               cont = SafeMalloc(1024*64);
               *cont = 0;
               listline(cont, tempstmt, 1);
               strcat(cont, input);
               *prog = 0; 
               prog = cont;
               display = 1;
               goto begin;
             }
             tempstmt = tempstmt->nextstmt;
           } while (tempstmt != NULL);
           numlabels++;
         }
         goto loop;

       case TOK_COMMA:
         if (parencount > 0) { 
           // comma being delimiter for system functions
           popstack(stmt, -2);
           push("(", TOK_OPERATOR);
           if (chaninfo == 1) {
             if (!channum) {
               channum = 1;
               stmt->metalist[stmt->metapos].operation = 0xE1;
               stmt->metapos++;
             }
           } else { 
             if (special == 1) numargs[parencount-1]+=10;
             else numargs[parencount-1]++; 
             envinfo.stmttype = 0; 
           }
         } else {
           // comma being delimiter for verbs
           popstack(stmt, -1); 
           buffermeta(stmt, TOK_COMMA, token); 
           for (x=0; x<32; x++) numargs[x] = 0;
           envinfo.stmttype = 0;
           foundequals = 0;
           firstvar = 1;
         }
         goto loop;

       case TOK_ERROR:
         lineerror(stmt, __FILE__, __LINE__);
         return;

       case TOK_COMMAND:
         lastopcode = get_opcode(token);
         if (cmdtable[get_cmdindex(token)].options & IO_CHANNEL)
           watchchannel = 1;
         else watchchannel = 0;
         if (!strcmp(token, "IF")) ifcount++;
         if (!stmt->opcode) {
           stmt->opcode = get_opcode(token);
           envinfo.stmttype = 0;
           goto loop;
         } else {
           popstack(stmt, -1);
           envinfo.stmttype = 0;
           if (ifcount > 0) {
             stmt->metalist[stmt->metapos].operation = 0xE7;
             stmt->metalist[stmt->metapos].shortarg = 0;
             stmt->metalist[stmt->metapos].intarg = 0;
             stmt->metapos++;
             stmt->length++;
//             watchchannel = 0;
             chaninfo = 0;
             channum = 0;
             ifcount--;
           }
           if (lastopcode == CMD_ON) {
             special = 1;
             if (!strcmp(token, "GOTO")) 
               stmt->metalist[stmt->metapos].operation = 0x00F4;
             else stmt->metalist[stmt->metapos].operation = 0x01F4;
             stmt->length += 2;
             stmt->metapos++;
           } else
             buffermeta(stmt, TOK_COMMAND, token);
           goto loop;
         }
       break;
       
       case TOK_RESERVED:
         popstack(stmt, -1);
         envinfo.stmttype = 0;
         lineref = 0;
         if (!strcmp(token, "ELSE")) {
           stmt->metalist[stmt->metapos].operation = 0xE7;
           stmt->metalist[stmt->metapos].intarg = 0;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->metapos++;
           stmt->metalist[stmt->metapos].operation = 0xE2;
           stmt->metalist[stmt->metapos].intarg = 0;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->metapos++; 
           stmt->length+=2;
           envinfo.stmttype = 0;
           chaninfo = 0;
           channum = 0;
         }
         goto loop;

       case TOK_DONE:
         if ((stmt->linenum) && (!stmt->opcode)) deletestmt(gprog,stmt->linenum);
         else {
           popstack(stmt, -1);
           if (stmt->opcode == CMD_LET && foundequals == 0) lineerror(stmt, __FILE__, __LINE__);
           if (parencount > 0 || numlabels < 0) lineerror(stmt, __FILE__, __LINE__);
           if (stmt->linenum) { if (!stmt->errorflag) insertstmt(gprog, stmt); }
           else if (stmt->opcode) { if (!stmt->errorflag) 
                  { execline(gprog, stmt); } }
         }
         if (display) {
           GC_realloc(cont, strlen(cont));
           listprog(gprog, stmt->linenum, stmt->linenum);
         }
         return;

       case TOK_USERFUNCTION:
         if (lastopcode == CMD_DEFFN)
           addfunction(gprog, token, stmt->linenum, 1);
         else addfunction(gprog, token, stmt->linenum, 0);
         if (token[strlen(token)-1] == '$') parenstack[parencount] = 8;
           else parenstack[parencount] = 7;
         buffermeta(stmt, TOK_USERFUNCTION, token);
         break;

       case TOK_FUNCTION:
         lastfnc = get_fnc(token);
         numlabels++;
       case TOK_OPERATOR: 
         if (token[0] == '[') {
           special = 1;
           cont = get_symname(lastvar);
           if (cont[strlen(cont)-1] == '$') 
             parenstack[parencount] = 2;
           else parenstack[parencount] = 1;
           numlabels++;
           goto openparen;
         } else if (token[0] == ']') {  
           numargs[parencount-1] += 9;
           popstack(stmt, -2);
           envinfo.stmttype = parenstack[parencount];
           token_type = TOK_ARRAY;
           special = 0;
           goto loop;
         } else if (token[0] == '-') {
           // placeholder
           if ((lasttype == TOK_OPERATOR) || (lasttype == TOK_RESERVED))
             token[0] = '_';
           evalstack(stmt);
           goto loop;
         } else if (token[0] == '(') {
openparen:
           if (lasttype == TOK_COMMAND) {
             if (watchchannel == 1)
               chaninfo = 1;
           } else if (lasttype == TOK_ARRAY) {
             envinfo.stmttype = 0;
             numargs[parencount]++;
             push(token, token_type);
             goto loop;
           } else if (lasttype == TOK_SETVAL) { 
             push(get_symname(lastvar), TOK_SETVAL);
             stmt->metapos--;
             stmt->metalist[stmt->metapos].shortarg = 0; 
             numlabels++;
             cont = get_symname(lastvar);
             if (cont[strlen(cont)-1] == '$') 
               parenstack[parencount] = 2;
             else parenstack[parencount] = 1;
           } else if (lasttype == TOK_VARIABLE) {
             push(get_symname(lastvar), TOK_VARIABLE);
             numlabels++;
             stmt->metapos--;
             stmt->metalist[stmt->metapos].shortarg = 0; 
             cont = get_symname(lastvar);
             if (cont[strlen(cont)-1] == '$') 
               parenstack[parencount] = 2;
             else parenstack[parencount] = 1;
           } else if (lasttype == TOK_USERFUNCTION) {
             stmt->metapos--;
             stmt->metalist[stmt->metapos].operation = 0xF5;
             stmt->metapos++;
             stmt->length++;
           } else if (lasttype == TOK_FUNCTION) {
             if ((envinfo.stmttype != fnctable[lastfnc].returntype) &&
                 (envinfo.stmttype != 0))
               lineerror(stmt, __FILE__, __LINE__);
             else parenstack[parencount] = fnctable[lastfnc].returntype;
           } else parenstack[parencount] = 1;
           envinfo.stmttype = 0;
           numargs[parencount] = 1;
           push(token, token_type);
           goto loop;
         } else if (token[0] == ')') {
           if (parencount == 0) lineerror(stmt, __FILE__, __LINE__); 
           popstack(stmt, -2); 
           if (parenstack[parencount] == 7) {
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
             stmt->length++;
             envinfo.stmttype = 1;
           } else if (parenstack[parencount] == 8) {
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
             stmt->length++;
             envinfo.stmttype = 2;
           } else envinfo.stmttype = parenstack[parencount];
           if (lastopcode == CMD_DEFFN && foundequals == 0) {
             stmt->metapos--;
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
           }
           if (chaninfo == 1) {
             chaninfo = 0;
             if (!channum) {
               stmt->metalist[stmt->metapos].operation = 0xE1;
               stmt->metapos++;
             }
             stmt->metalist[stmt->metapos].operation = 0xF4F1;
             stmt->metapos++;
             numargs[parencount] = 0;
           }
           goto loop;
         } else { 
           evalstack(stmt); 
           goto loop; 
         }
         break;   

       case TOK_VARIABLE:
         if (get_sysvar(token)) { 
           buffermeta(stmt, TOK_SYSVAR, token); 
           numlabels++;
           goto loop;
         } else { addsymbol(gprog, token); lastvar = get_symref(token); }

       case TOK_NUMBER:
       default:
        if(!stmt->opcode) { envinfo.stmttype = 0; lastopcode = stmt->opcode = CMD_LET; }
        if ((firstvar == 1) && (token_type == TOK_VARIABLE) && 
            (lastopcode == CMD_LET || lastopcode == CMD_FOR ||
             lastopcode == CMD_FOR || lastopcode == CMD_NEXT ||
             lastopcode == CMD_DIM || lastopcode == CMD_INPUT)) {
           buffermeta(stmt, TOK_SETVAL, token);
           firstvar = 0;
           token_type = TOK_SETVAL;
        } else { numlabels++; buffermeta(stmt, token_type, token); }
        goto loop;
     }
  } while (1);
}
Ejemplo n.º 16
0
GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS)
{
    void * base;
    void * result;
    hdr * hhdr;

    if (p == 0) {
      return GC_debug_malloc(lb, OPT_RA s, i);
    }
    if (0 == lb) /* and p != NULL */ {
      GC_debug_free(p);
      return NULL;
    }

#   ifdef GC_ADD_CALLER
      if (s == NULL) {
        GC_caller_func_offset(ra, &s, &i);
      }
#   endif
    base = GC_base(p);
    if (base == 0) {
        ABORT_ARG1("Invalid pointer passed to realloc()", ": %p", p);
    }
    if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
        GC_err_printf(
              "GC_debug_realloc called on pointer %p w/o debugging info\n", p);
        return(GC_realloc(p, lb));
    }
    hhdr = HDR(base);
    switch (hhdr -> hb_obj_kind) {
      case NORMAL:
        result = GC_debug_malloc(lb, OPT_RA s, i);
        break;
      case PTRFREE:
        result = GC_debug_malloc_atomic(lb, OPT_RA s, i);
        break;
      case UNCOLLECTABLE:
        result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i);
        break;
#    ifdef GC_ATOMIC_UNCOLLECTABLE
      case AUNCOLLECTABLE:
        result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i);
        break;
#    endif
      default:
        result = NULL; /* initialized to prevent warning. */
        ABORT_RET("GC_debug_realloc: encountered bad kind");
    }

    if (result != NULL) {
      size_t old_sz;
#     ifdef SHORT_DBG_HDRS
        old_sz = GC_size(base) - sizeof(oh);
#     else
        old_sz = ((oh *)base) -> oh_sz;
#     endif
      if (old_sz > 0)
        BCOPY(p, result, old_sz < lb ? old_sz : lb);
      GC_debug_free(p);
    }
    return(result);
}