Exemple #1
0
void 
__profile_call(ADDR caller, ADDR callee, char *caller_name, char *callee_name)
{
#ifdef _DEBUG
  return;
#else
  if (num_counts == 0)
    ir_prof_start();

  if (num_counts == sizeof_counts_array) {
    sizeof_counts_array *= 2;
    counts_array = (counts_entry *)REALLOC(
		    counts_array, sizeof_counts_array);
    PR_ASSERT(counts_array, "realloc of counts_array failed");
  }

  hash_entry(caller, callee, caller_name, callee_name);
#endif
}
Exemple #2
0
enum pipe_error
pb_validate_add_buffer(struct pb_validate *vl,
                       struct pb_buffer *buf)
{
    assert(buf);
    if(!buf)
        return PIPE_ERROR;

    /* We only need to store one reference for each buffer, so avoid storing
     * consecutive references for the same buffer. It might not be the more
     * common pasttern, but it is easy to implement.
     */
    if(vl->used && vl->buffers[vl->used - 1] == buf) {
        return PIPE_OK;
    }

    /* Grow the table */
    if(vl->used == vl->size) {
        unsigned new_size;
        struct pb_buffer **new_buffers;

        new_size = vl->size * 2;
        if(!new_size)
            return PIPE_ERROR_OUT_OF_MEMORY;

        new_buffers = (struct pb_buffer **)REALLOC(vl->buffers,
        vl->size*sizeof(struct pb_buffer *),
        new_size*sizeof(struct pb_buffer *));
        if(!new_buffers)
            return PIPE_ERROR_OUT_OF_MEMORY;

        memset(new_buffers + vl->size, 0, (new_size - vl->size)*sizeof(struct pb_buffer *));

        vl->size = new_size;
        vl->buffers = new_buffers;
    }

    assert(!vl->buffers[vl->used]);
    pb_reference(&vl->buffers[vl->used], buf);
    ++vl->used;

    return PIPE_OK;
}
Exemple #3
0
void *
__gf_realloc (void *ptr, size_t size)
{
        size_t          tot_size = 0;
        char            *orig_ptr = NULL;
        xlator_t        *xl = NULL;
        uint32_t        type = 0;
        char            *new_ptr;

        if (!THIS->ctx->mem_acct_enable)
                return REALLOC (ptr, size);

        REQUIRE(NULL != ptr);

        tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;

        orig_ptr = (char *)ptr - 8 - 4;

        GF_ASSERT (*(uint32_t *)orig_ptr == GF_MEM_HEADER_MAGIC);

        orig_ptr = orig_ptr - sizeof(xlator_t *);
        xl = *((xlator_t **)orig_ptr);

        orig_ptr = (char *)ptr - GF_MEM_HEADER_SIZE;
        type = *(uint32_t *)orig_ptr;

        new_ptr = realloc (orig_ptr, tot_size);
        if (!new_ptr) {
                gf_log_nomem ("", GF_LOG_ALERT, tot_size);
                return NULL;
        }

        /*
         * We used to pass (char **)&ptr as the second
         * argument after the value of realloc was saved
         * in ptr, but the compiler warnings complained
         * about the casting to and forth from void ** to
         * char **.
         */
        gf_mem_set_acct_info (xl, &new_ptr, size, type);

        return (void *)new_ptr;
}
Exemple #4
0
int add_init_section(InitFile *inif, InitSection *inis)
{
    int i;
    InitSection *oinis;
    if ((i = find_init_section(inif, inis->section_name)) >= 0) {
	oinis = inif->sections[i];
	inif->sections[i] = inis;
	free_init_section(oinis);
	return INIT_FILE_PRESENT;
    } 
    if (inif->num_sections == inif->size_sections) {
	inif->size_sections += 10;
	inif->sections = REALLOC(inif->sections, 
				 sizeof(InitSection *) * inif->size_sections);
    }
    inif->sections[inif->num_sections] = inis;
    ++(inif->num_sections);
    return INIT_FILE_NOT_PRESENT;
}
Exemple #5
0
sStatment* sStatment_new(sObject* block, int sline, char* sname)
{
    if(SBLOCK(block).mStatmentsNum >= SBLOCK(block).mStatmentsSize) {
        const int statments_size = SBLOCK(block).mStatmentsSize;

        int new_statments_size = SBLOCK(block).mStatmentsSize * 2;
        SBLOCK(block).mStatments = REALLOC(SBLOCK(block).mStatments, sizeof(sStatment)*new_statments_size);
        memset(SBLOCK(block).mStatments + SBLOCK(block).mStatmentsSize, 0, sizeof(sStatment)*(new_statments_size - SBLOCK(block).mStatmentsSize));
        SBLOCK(block).mStatmentsSize = new_statments_size;
    }

    sStatment* self = SBLOCK(block).mStatments + SBLOCK(block).mStatmentsNum;
    SBLOCK(block).mStatmentsNum++;
    self->mLine = sline;
    self->mFName = STRDUP(sname);
    self->mFlags = 0;

    return self;
}
VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id,
                         unsigned int num_elements)
{
   vlVaBuffer *buf;

   if (!ctx)
      return VA_STATUS_ERROR_INVALID_CONTEXT;

   buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
   buf->data = REALLOC(buf->data, buf->size * buf->num_elements,
                       buf->size * num_elements);
   buf->num_elements = num_elements;

   if (!buf->data)
      return VA_STATUS_ERROR_ALLOCATION_FAILED;

   return VA_STATUS_SUCCESS;
}
Exemple #7
0
void AddLine(int SkipLineInfo)
{
	if(/*ooutptr!=outptr&&*/dbgact==0&&(oline!=linenumber||omodule!=currentfileinfo)){
		while(ooutptr>outptr&&pdbg!=0&&ooutptr!=0xffffffff)KillLastLine();
		if(pdbg==pdbgmax){
			pdbgmax+=MAXDBGS;
			dbgloc=(unsigned int *)  REALLOC(dbgloc,pdbgmax*sizeof(unsigned int));
			dbgnum=(unsigned int *)  REALLOC(dbgnum,pdbgmax*sizeof(unsigned int));
			dbgmod=(unsigned short *)REALLOC(dbgmod,pdbgmax*sizeof(unsigned short));
			if(lstflag){
				lststring=(char **)REALLOC(lststring,pdbgmax*sizeof(char *));
				lstflag=(unsigned char *)REALLOC(lstflag,pdbgmax*sizeof(char));
				lstend=(unsigned int *)REALLOC(lstend,pdbgmax*sizeof(unsigned int));
				memset((char *)lstflag+(pdbgmax-MAXDBGS),-1,MAXDBGS*sizeof(char));
				memset((unsigned int *)lstend+(pdbgmax-MAXDBGS),0,MAXDBGS*sizeof(unsigned int));
			}
		}
		dbgloc[pdbg]=ooutptr=outptr;
		dbgnum[pdbg]=oline=linenumber;
		dbgmod[pdbg]=(unsigned short)currentfileinfo;
		omodule=currentfileinfo;
		if(dbg&2){
			if(SkipLineInfo)lststring[pdbg]=NULL;
			else{
				char *ofs=startline;
				char c;
				int sizestring=0;
				char buf[MAXLSTSTR];
				for(;sizestring<(MAXLSTSTR-1);sizestring++){
					c=*ofs;
					ofs=ofs+1;
					if(c==13||ofs==endinput)break;
					buf[sizestring]=c;
				}
				buf[sizestring]=0;
				strbtrim(buf);
				if((sizestring=strlen(buf))==0)lststring[pdbg]=NULL;
				else{
					lststring[pdbg]=(char *)MALLOC(sizestring+1);
					strcpy(lststring[pdbg],buf);
				}
			}
			lstflag[pdbg]=(unsigned char)(am32|lsttypedata);
			AddEndLine();
//		printf("%s(%d) outptr=%d\n",(startfileinfo+currentfileinfo)->filename,linenumber,outptr);
		}
		pdbg++;
		(startfileinfo+currentfileinfo)->numdline++;
	}
}
Exemple #8
0
void oputs ( int streamid, int detail, char *string )
{
     int i, j;

     if ( streamid == OUT_SYS && !quietmode )
     {
          printf ( string );
          fflush ( stdout );
     }

     if ( detail_level < detail )
          return;
     
     for ( i = 0; i < output_stream_count; ++i )
     {
          if ( streamid == streams[i].id )
          {
               if ( streams[i].valid )
               {
                    fputs ( string, streams[i].f );
                    if ( streams[i].autoflush )
                         fflush ( streams[i].f );
                    break;
               }
	       else
	       {
		    if ( streams[i].buffer )
		    {
			 j = strlen ( streams[i].buffer ) +
			      strlen ( string ) + 1;
			 streams[i].buffer = (char *)REALLOC ( streams[i].buffer, j );
			 strcat ( streams[i].buffer, string );
		    }
		    else
		    {
			 streams[i].buffer = (char *)MALLOC ( strlen ( string ) + 1 );
			 strcpy ( streams[i].buffer, string );
		    }
	       }
          }
     }
}
Exemple #9
0
boolean TS_AddExtension(char ** ppszExtList, char * psz)
{
   char *   pExt;
   
   if (!ppszExtList || !psz)
      return FALSE;

   if (*ppszExtList)
      pExt = REALLOC(*ppszExtList, STRLEN(*ppszExtList) + STRLEN(psz) + STRLEN(MP_EXT_SEPARATOR) + 1);
   else
      pExt = MALLOC(STRLEN(psz) + STRLEN(MP_EXT_SEPARATOR) + 1);

   if (!pExt)
      return FALSE;

   STRCAT(pExt, psz);
   STRCAT(pExt, MP_EXT_SEPARATOR);
   *ppszExtList = pExt;
   return TRUE;
}
Exemple #10
0
static a_reduce_action *addReduceAction( a_pro *pro, a_word *follow, a_reduce_action *r )
{
    a_reduce_action *raction;
    a_reduce_action *new_raction;
    a_word *new_follow;
    size_t i;

    for( raction = r; raction->pro != NULL; ) {
        ++raction;
    }
    i = raction - r;
    new_follow = AllocSet( 1 );
    Assign( new_follow, follow );
    new_raction = REALLOC( r, i + 2, a_reduce_action );
    new_raction[i].pro = pro;
    new_raction[i].follow = new_follow;
    new_raction[i + 1].pro = NULL;
    new_raction[i + 1].follow = NULL;
    return( new_raction );
}
Exemple #11
0
Fichier : str.c Projet : mej/libast
spif_bool_t
spif_str_trim(spif_str_t self)
{
    spif_charptr_t start, end;

    ASSERT_RVAL(!SPIF_STR_ISNULL(self), FALSE);
    start = self->s;
    end = self->s + self->len - 1;
    for (; isspace((spif_uchar_t) (*start)) && (start < end); start++);
    for (; isspace((spif_uchar_t) (*end)) && (start < end); end--);
    if (start > end) {
        return spif_str_done(self);
    }
    *(++end) = 0;
    self->len = (spif_stridx_t) (end - start);
    self->size = self->len + 1;
    memmove(self->s, start, self->size);
    self->s = (spif_charptr_t) REALLOC(self->s, self->size);
    return TRUE;
}
Exemple #12
0
static void expand_n_viterbi_egraphs(int req_n_viterbi_egraph_size)
{
    int old_size,i;

    if (req_n_viterbi_egraph_size > max_n_viterbi_egraph_size) {
        old_size = max_n_viterbi_egraph_size;

        while (req_n_viterbi_egraph_size > max_n_viterbi_egraph_size) {
            max_n_viterbi_egraph_size *= 2;
        }

        n_viterbi_egraphs =
            (V_ENT_PTR *)REALLOC(n_viterbi_egraphs,
                                 max_n_viterbi_egraph_size * sizeof(V_ENT_PTR));

        for (i = old_size; i < max_n_viterbi_egraph_size; i++) {
            n_viterbi_egraphs[i] = NULL;
        }
    }
}
Exemple #13
0
void *Clear_realloc(void *OldPtr,size_t OldSize,size_t NewSize)

{
void *NewPtr ;

NewPtr = REALLOC(OldPtr,NewSize) ;

if (!NewPtr)
  {
  printf("ERROR - No more memory\n") ;
/*  werror(E_OUT_OF_MEM,__FILE__,NewSize);*/
  exit (1);
  }

if (NewPtr)
  if (NewSize > OldSize)
    memset((char *) NewPtr + OldSize,0x00,NewSize - OldSize) ;

return NewPtr ;
}
Exemple #14
0
static void add_completer_widget(Widget w, int row)
{
  if (row >= 0)
    {
      if (cmpwids_size <= row)
	{
	  int i;
	  i = cmpwids_size;
	  cmpwids_size = row + 8;
	  if (cmpwids == NULL)
	    cmpwids = (Widget *)CALLOC(cmpwids_size, sizeof(Widget));
	  else 
	    {
	      cmpwids = (Widget *)REALLOC(cmpwids, cmpwids_size * sizeof(Widget));
	      for (; i < cmpwids_size; i++) cmpwids[i] = NULL;
	    }
	}
      cmpwids[row] = w;
    }
}
Exemple #15
0
void add_unique_range_nosort(
                            range_list_t *ranges, 
                            GElf_Off start, 
                            GElf_Off length, 
                            void *user,
                            void (*err_fn)(range_error_t, range_t *, range_t *),
                            void (*user_dtor)(void * )) 
{
    if (ranges->num_ranges == ranges->array_length) {
        ranges->array_length += PARALLEL_ARRAY_SIZE;
        ranges->array = REALLOC(ranges->array, 
                                ranges->array_length*sizeof(range_t));
    }
    ranges->array[ranges->num_ranges].start  = start;
    ranges->array[ranges->num_ranges].length = length;
    ranges->array[ranges->num_ranges].user   = user;
    ranges->array[ranges->num_ranges].err_fn = err_fn;
    ranges->array[ranges->num_ranges].user_dtor = user_dtor;
    ranges->num_ranges++;
}
Exemple #16
0
static void tokens_expand( struct ureg_tokens *tokens,
                           unsigned count )
{
   unsigned old_size = tokens->size * sizeof(unsigned);

   if (tokens->tokens == error_tokens) {
      return;
   }

   while (tokens->count + count > tokens->size) {
      tokens->size = (1 << ++tokens->order);
   }

   tokens->tokens = REALLOC(tokens->tokens, 
                            old_size,
                            tokens->size * sizeof(unsigned));
   if (tokens->tokens == NULL) {
      tokens_error(tokens);
   }
}
Exemple #17
0
BOOL
PutEvent (
    PINPUT_RECORD	InputRecord
    )
{

    EnterCriticalSection(&(EventBuffer.CriticalSection));

    //
    //	If no space at beginning of buffer, resize and shift right
    //
    if ( EventBuffer.EventIndex == 0 ) {

	EventBuffer.EventBuffer = REALLOC( EventBuffer.EventBuffer,
					   (EventBuffer.MaxEvents + EVENT_INCREMENT) * sizeof(INPUT_RECORD));

	if ( !EventBuffer.EventBuffer ) {
	    CleanExit(1, 0);
	}

	memmove( EventBuffer.EventBuffer + EVENT_INCREMENT,
		 EventBuffer.EventBuffer ,
		 EventBuffer.NumberOfEvents * sizeof(INPUT_RECORD) );

	EventBuffer.EventIndex = EVENT_INCREMENT;
    }

    //
    //	Add event
    //
    EventBuffer.EventIndex--;
    EventBuffer.NumberOfEvents++;

    memcpy( EventBuffer.EventBuffer + EventBuffer.EventIndex,
	    InputRecord,
	    sizeof(INPUT_RECORD ));

    LeaveCriticalSection(&(EventBuffer.CriticalSection));

    return TRUE;
}
Exemple #18
0
/**
 * Resize the bitmask if necessary 
 */
static inline boolean
util_bitmask_resize(struct util_bitmask *bm,
                    unsigned minimum_index)
{
   unsigned minimum_size = minimum_index + 1;
   unsigned new_size;
   util_bitmask_word *new_words;

   /* Check integer overflow */
   if(!minimum_size)
      return FALSE;
      
   if(bm->size >= minimum_size)
      return TRUE;

   assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0);
   new_size = bm->size;
   while(new_size < minimum_size) {
      new_size *= 2;
      /* Check integer overflow */
      if(new_size < bm->size)
         return FALSE;
   }
   assert(new_size);
   assert(new_size % UTIL_BITMASK_BITS_PER_WORD == 0);
   
   new_words = (util_bitmask_word *)REALLOC((void *)bm->words,
                                            bm->size / UTIL_BITMASK_BITS_PER_BYTE,
                                            new_size / UTIL_BITMASK_BITS_PER_BYTE);
   if (!new_words)
      return FALSE;
   
   memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD, 
          0, 
          (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE);
   
   bm->size = new_size;
   bm->words = new_words;
   
   return TRUE;
}
//
// Add the given value to the list of suggested values for this parameter 
//
bool ParameterDefinition::addValueOption(const char *value)
{
    int position;

    if (!this->valueOptions) {
	int size = 4;
	this->valueOptions = (char**)MALLOC(size * sizeof(char*));
	memset(this->valueOptions,0, size * sizeof(char*));
	position = 0;
    } else {
	position = 0;
	while (this->valueOptions[position])
	    position++;	
	int nextpos = position + 1;
	switch (nextpos) {
	    case 4:
	    case 8:
	    case 16:
	    case 32:
	    case 64:
		this->valueOptions = (char**)REALLOC((void*)this->valueOptions,
					2 * nextpos * sizeof(char*));
		memset(this->valueOptions + nextpos, 0, nextpos*sizeof(char*));
		break;
	    default:
		if (nextpos > 64) {
		    fprintf(stderr,
			"Too many value options for parameter (ignoring)");
		    position = -1;
		}
		break;
	}
    }
    if (position >= 0) {
	this->valueOptions[position] = DuplicateString(value);
	return true;
    } else {
	return false;
    }

}
Exemple #20
0
void gges_mapping_append_symbol(struct gges_mapping *mapping, char *token)
{
    int tlen;

    if (mapping) {
        tlen = strlen(token);
        /* first, check to see if the string buffer needs
         * extending, and realloc as required */
        if ((mapping->l + tlen + 1) > mapping->sz) {
            while (mapping->sz < (mapping->l + tlen + 1)) mapping->sz += BUFFER_INC;

            mapping->buffer = REALLOC(mapping->buffer, mapping->sz, sizeof(char));
        }

        /* then, push terminal symbol into stream */
        strcat(mapping->buffer, token);
        mapping->l += tlen;
    } else {
        fprintf(stdout, "%s", token);
    }
}
Exemple #21
0
static void expand_viterbi_egraphs(int req_viterbi_egraph_size)
{
    int old_size,i;

    if (req_viterbi_egraph_size > max_viterbi_egraph_size) {
        old_size = max_viterbi_egraph_size;

        while (req_viterbi_egraph_size > max_viterbi_egraph_size) {
            max_viterbi_egraph_size *= 2;
        }

        viterbi_egraphs =
            (EG_NODE_PTR *)
            REALLOC(viterbi_egraphs,
                    max_viterbi_egraph_size * sizeof(EG_NODE_PTR));

        for (i = old_size; i < max_viterbi_egraph_size; i++) {
            viterbi_egraphs[i] = NULL;
        }
    }
}
Exemple #22
0
void resizeMatrix(sparseMatrix *matrix, int newSize)
{
  int oldSize;

  if(matrix == NULL)
    oldSize = 0;
  else
    oldSize = matrix->size;
  while(oldSize>newSize) {
	  oldSize--;
	  freeVector(matrix->list[oldSize]);
    return;
  }
  REALLOC(matrix->list, newSize);
  while(oldSize<newSize) {
	  matrix->list[oldSize] = NULL;
	  oldSize++;
  }
  if(newSize>0)
    matrix->size = newSize;
}
Exemple #23
0
void mesh_addluafaces(struct mesh *m, lua_State *L, int index)
{
	int n, i;

	DEBUG(2, "Adding faces from Lua array at index %d\n", index);
	n = lua_objlen(L, index);
	DEBUG(2, "Length of array reported as %d\n", n);
	REALLOC(m->faces, m->nfaces + n);
	MEMSET(&m->faces[m->nfaces], 0, n);
	for (i=1; i<=n; i++)
	{
		lua_getfieldi(L, index, i);
		if (!lua_istable(L, -1))
			luaL_error(L, "index %d: table expected, got %s",
				i, luaL_typename(L, -1));
		facefromlua(&m->faces[m->nfaces], L, -1);
		lua_pop(L, 1);
		m->nfaces++;
	}
	DEBUG(2, "%d faces added, current total is %d\n", i-1, m->nfaces);
}
Exemple #24
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : acr_lookup_vr_name
@INPUT      : vr_name - the 2-letter VR name to look up
@OUTPUT     : (none)
@RETURNS    : Internal VR code
@DESCRIPTION: Looks up a VR name in the table. If it does not exist, the
              name is added to the unknown table.
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : January 31, 1997 (Peter Neelin)
@MODIFIED   : 
---------------------------------------------------------------------------- */
Acr_VR_Type acr_lookup_vr_name(char *vr_name)
{
   Acr_VR_Type vr_code;
   int ientry;
   char *string;

   /* Look up the name and return the matching code if found */
   vr_code = find_vr_name(vr_name);
   if (vr_code >= 0) {
      return vr_code;
   }

   /* If name is not found, add it to the unknown table */
   if (unknown_VR_table_length <= 0) {
      unknown_VR_table_length = 1;
      unknown_VR_table = MALLOC((size_t) unknown_VR_table_length * 
                                sizeof(*unknown_VR_table));
   }
   else {
      unknown_VR_table_length++;
      unknown_VR_table = REALLOC(unknown_VR_table,
                                 (size_t) unknown_VR_table_length * 
                                 sizeof(*unknown_VR_table));
   }

   /* Fill in the entry */
   ientry = unknown_VR_table_length-1;
   unknown_VR_table[ientry].vr_code = ientry + ACR_VR_NUM_TYPES;
   string = MALLOC(3);
   string[0] = vr_name[0];
   string[1] = vr_name[1];
   string[2] = '\0';
   unknown_VR_table[ientry].vr_name = string;
   unknown_VR_table[ientry].convert_to_numeric = return_zero;
   unknown_VR_table[ientry].convert_to_string = return_empty_string;

   /* Return the code */
   return unknown_VR_table[ientry].vr_code;

}
Exemple #25
0
/*
 * NAME:	rsrc->resize()
 * DESCRIPTION:	change the length of a resource
 */
void *rsrc_resize(void *rdata, unsigned long newsize)
{
  rsrchandle *newrsrc, *rsrc = gethandle(rdata);

  if (rsrc->len == newsize)
    goto done;

  newrsrc = (rsrchandle *) REALLOC(rsrc, byte, sizeof(rsrchandle) + newsize);
  if (newrsrc == 0)
    ERROR(ENOMEM, 0);

  newrsrc->attrs |= RSRC_RES_CHANGED;
  newrsrc->len    = newsize;

  rdata = getrdata(newrsrc);

done:
  return rdata;

fail:
  return 0;
}
Exemple #26
0
void ALLOCEXPANDARRAY::SetAt (size_t iElement, PVOID pData)
{
   size_t iHeap = iElement / m_cElementsPerHeap;
   size_t iIndex = iElement % m_cElementsPerHeap;

   if (!REALLOC (m_aHeaps, m_cHeaps, 1+iHeap, cREALLOC_EXPANDARRAYHEAPS))
      return;

   if (!m_aHeaps[ iHeap ])
      {
      size_t cbHeap = sizeof(EXPANDARRAYHEAP) + (m_cElementsPerHeap * m_cbElement);
      if ((m_aHeaps[ iHeap ] = (LPEXPANDARRAYHEAP)GlobalAlloc (GMEM_FIXED, cbHeap)) == NULL)
         return;
      memset (m_aHeaps[ iHeap ], 0x00, cbHeap);
      m_aHeaps[ iHeap ]->aElements = ((PBYTE)m_aHeaps[ iHeap ]) + sizeof(EXPANDARRAYHEAP);
      }

   if (!pData)
      memset (&((PBYTE)m_aHeaps[ iHeap ]->aElements)[ iIndex * m_cbElement ], 0x00, m_cbElement);
   else
      memcpy (&((PBYTE)m_aHeaps[ iHeap ]->aElements)[ iIndex * m_cbElement ], pData, m_cbElement);
}
Exemple #27
0
static boolean
batch_query_add(struct hud_batch_query_context **pbq,
                struct pipe_context *pipe, unsigned query_type,
                unsigned *result_index)
{
   struct hud_batch_query_context *bq = *pbq;
   unsigned i;

   if (!bq) {
      bq = CALLOC_STRUCT(hud_batch_query_context);
      if (!bq)
         return false;
      bq->pipe = pipe;
      *pbq = bq;
   }

   for (i = 0; i < bq->num_query_types; ++i) {
      if (bq->query_types[i] == query_type) {
         *result_index = i;
         return true;
      }
   }

   if (bq->num_query_types == bq->allocated_query_types) {
      unsigned new_alloc = MAX2(16, bq->allocated_query_types * 2);
      unsigned *new_query_types
         = REALLOC(bq->query_types,
                   bq->allocated_query_types * sizeof(unsigned),
                   new_alloc * sizeof(unsigned));
      if (!new_query_types)
         return false;
      bq->query_types = new_query_types;
      bq->allocated_query_types = new_alloc;
   }

   bq->query_types[bq->num_query_types] = query_type;
   *result_index = bq->num_query_types++;
   return true;
}
Exemple #28
0
Fichier : str.c Projet : mej/libast
spif_bool_t
spif_str_splice_from_ptr(spif_str_t self, spif_stridx_t idx, spif_stridx_t cnt, spif_charptr_t other)
{
    spif_charptr_t tmp, ptmp;
    spif_stridx_t len, newsize;

    ASSERT_RVAL(!SPIF_STR_ISNULL(self), FALSE);
    len = (other ? strlen((const char *) other) : 0);
    if (idx < 0) {
        idx = self->len + idx;
    }
    REQUIRE_RVAL(idx >= 0, FALSE);
    REQUIRE_RVAL(idx < self->len, FALSE);
    if (cnt < 0) {
        cnt = idx + self->len + cnt;
    }
    REQUIRE_RVAL(cnt >= 0, FALSE);
    REQUIRE_RVAL(cnt <= (self->len - idx), FALSE);

    newsize = self->len + len - cnt + 1;
    ptmp = tmp = (spif_charptr_t) MALLOC(newsize);
    if (idx > 0) {
        memcpy(tmp, self->s, idx);
        ptmp += idx;
    }
    if (len) {
        memcpy(ptmp, other, len);
        ptmp += len;
    }
    memcpy(ptmp, self->s + idx + cnt, self->len - idx - cnt + 1);
    if (self->size < newsize) {
        self->s = (spif_charptr_t) REALLOC(self->s, newsize);
        self->size = newsize;
    }
    self->len = newsize - 1;
    memcpy(self->s, tmp, newsize);
    FREE(tmp);
    return TRUE;
}
Exemple #29
0
int pc_mp_send_switches_0(void)
{
    char  *msg, *str;
    TERM  msw;
    int   msglen, msgsiz;
    int   vals[2];
    int   i, n;

    msglen = 0;
    msgsiz = 65536;
    msg = MALLOC(msgsiz);

    for (i = 0; i < occ_switch_tab_size; i++) {
        msw = bpx_get_arg(1, prism_sw_ins_term(occ_switches[i]->id));
        str = (char *)bpx_term_2_string(msw);

        n = strlen(str) + 1;

        if (msgsiz <= msglen + n) {
            msgsiz = (msglen + n + 65536) & ~65535;
            msg = REALLOC(msg, msgsiz);
        }

        strcpy(msg + msglen, str);
        msglen += n;
    }

    msg[msglen++] = '\0'; /* this is safe */

    vals[0] = msglen;
    vals[1] = occ_switch_tab_size;

    MPI_Gather(vals, 2, MPI_INT, NULL, 0, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Send(msg, msglen, MPI_CHAR, 0, TAG_SWITCH_REQ, MPI_COMM_WORLD);

    free(msg);

    return BP_TRUE;
}
Exemple #30
0
static boolean svga_shader_expand( struct svga_shader_emitter *emit )
{
   char *new_buf;
   unsigned newsize = emit->size * 2;

   if(emit->buf != err_buf)
      new_buf = REALLOC(emit->buf, emit->size, newsize);
   else
      new_buf = NULL;

   if (new_buf == NULL) {
      emit->ptr = err_buf;
      emit->buf = err_buf;
      emit->size = sizeof(err_buf);
      return FALSE;
   }

   emit->size = newsize;
   emit->ptr = new_buf + (emit->ptr - emit->buf);
   emit->buf = new_buf;
   return TRUE;
}