コード例 #1
0
ファイル: store.c プロジェクト: axelmuhr/Helios-NG
static void expand_segmax(int newsegmax)
{   int32 osize = (int32)segmax * sizeof(char *),
          nsize = (int32)newsegmax * sizeof(char *);
    synsegbase =  (char **)expand_array((VoidStar)synsegbase, osize, nsize);
    synsegptr  =  (char **)expand_array((VoidStar)synsegptr, osize, nsize);
    bindsegbase = (char **)expand_array((VoidStar)bindsegbase, osize, nsize);
    bindsegptr  = (char **)expand_array((VoidStar)bindsegptr, osize, nsize);
    segmax = newsegmax;
}
コード例 #2
0
static void save_class(pmix_class_t *cls)
{
    if (num_classes >= max_classes) {
        expand_array();
    }

    classes[num_classes] = cls->cls_construct_array;
    ++num_classes;
}
コード例 #3
0
ファイル: garray.c プロジェクト: jacadym/fuse-emulator
GArray*
g_array_set_size( GArray *array, guint length )
{
  if( length > array->allocated )
    if( !expand_array( array, length - array->allocated ) ) return array;

  array->len = length;

  return array;
}
コード例 #4
0
GArray*
g_array_sized_new( gboolean zero_terminated, gboolean clear,
                   guint element_size, guint reserved_size )
{
  GArray *array = g_array_new( zero_terminated, clear, element_size );

  expand_array( array, reserved_size );

  return array;
}
コード例 #5
0
ファイル: garray.c プロジェクト: jacadym/fuse-emulator
GArray*
g_array_append_vals( GArray *array, gconstpointer data, guint len )
{
  if( array->len + len > array->allocated )
    if( !expand_array( array, len ) ) return array;

  memcpy( array->data + array->len * array->element_size,
	  data,
	  len * array->element_size );

  array->len += len;

  return array;
}
コード例 #6
0
/*
 * DatumGetExpandedArray: get a writable expanded array from an input argument
 *
 * Caution: if the input is a read/write pointer, this returns the input
 * argument; so callers must be sure that their changes are "safe", that is
 * they cannot leave the array in a corrupt state.
 */
ExpandedArrayHeader *
DatumGetExpandedArray(Datum d)
{
	/* If it's a writable expanded array already, just return it */
	if (VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
	{
		ExpandedArrayHeader *eah = (ExpandedArrayHeader *) DatumGetEOHP(d);

		Assert(eah->ea_magic == EA_MAGIC);
		return eah;
	}

	/* Else expand the hard way */
	d = expand_array(d, CurrentMemoryContext, NULL);
	return (ExpandedArrayHeader *) DatumGetEOHP(d);
}
コード例 #7
0
ファイル: arraylist.c プロジェクト: ljodal/libslutils
int arraylist_add(arraylist_t *a, void *d, unsigned int l, unsigned int i)
{
    if (!a)
        return -1;

    if (a->size == a->count && expand_array(a) != 0)
        return -1;

    a->array[i].data = d;
    a->array[i].len = l;

    a->count++;

    fprintf(stderr, "Size: %d, count: %d\n", a->size, a->count);

    return 0;
}
コード例 #8
0
ファイル: vararray.c プロジェクト: aevernon/triggerman
// This function inserts the element at the index specified.
void va_insert_element (var_array *var_arr, int index, void *element)
{
	int iter;
	ASSERT (var_arr);
	SC_ASSERT (index >= 0 && index <= var_arr->num_elements);

	// If the array is full, expand its size.
	if (var_arr->num_elements == (int) var_arr->max_num_elements)
	{
		expand_array (var_arr);
	}

	// Move all the elements from index onwards one space forward.
	for (iter = var_arr->num_elements - 1; iter >= index; iter--)
	{
		var_arr->elements[iter+1] = var_arr->elements[iter];
	}

	var_arr->elements[index] = element;
	var_arr->num_elements++;
}
コード例 #9
0
ファイル: array_init.c プロジェクト: sensics/IR_LED_DRV
void default_array_init(void)
{
  uint8_t i;
  for (i = 0; i < PATTERN_COUNT; i++)
  {
    uint8_t j;
    for (j = 0; j < LED_LINE_LENGTH; j++)
    {
      pattern_array[i][j] = default_pattern_array[i][j];
    }
    line_array_init(i, (uint8_t *)pattern_array[i]);
  }
  {
    uint8_t mask[LED_LINE_LENGTH];
    uint8_t j;
    for (j = 0; j < LED_LINE_LENGTH; j++)
    {
      mask[j] = default_mask[j];
    }
    expand_array(driver_mask, mask);
  }
}
コード例 #10
0
/*
 * As above, when caller has the ability to cache element type info
 */
ExpandedArrayHeader *
DatumGetExpandedArrayX(Datum d, ArrayMetaState *metacache)
{
	/* If it's a writable expanded array already, just return it */
	if (VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
	{
		ExpandedArrayHeader *eah = (ExpandedArrayHeader *) DatumGetEOHP(d);

		Assert(eah->ea_magic == EA_MAGIC);
		/* Update cache if provided */
		if (metacache)
		{
			metacache->element_type = eah->element_type;
			metacache->typlen = eah->typlen;
			metacache->typbyval = eah->typbyval;
			metacache->typalign = eah->typalign;
		}
		return eah;
	}

	/* Else expand using caller's cache if any */
	d = expand_array(d, CurrentMemoryContext, metacache);
	return (ExpandedArrayHeader *) DatumGetEOHP(d);
}
コード例 #11
0
ファイル: array_init.c プロジェクト: sensics/IR_LED_DRV
void line_array_init(uint8_t index, uint8_t *value) { expand_array(ir_led_driver_buffer[index], value); }
コード例 #12
0
ファイル: wlmain.c プロジェクト: ctierney/c-class
char *
read_word(char *str, int *buffer_len) {

	int c; 
	int word_length = 0;
	static int eof_reached = 0;

	str[0] = '\0';

	if (eof_reached == 1) {

		if (DEBUG)
			printf("read_word: eof_reached was %d\n", eof_reached);

		return NULL;
	}

	while ((c = getchar()) != EOF ) {

		if (DEBUG)
			printf("c was %c, buffer_len is %d, word_length is %d, isspace(c) = %d\n", c, *buffer_len, word_length, isspace(c));

		// filter out spaces, tabs, etc.
		if (isspace(c) == 0 && c != '\n') {

			// if the buffer isn't long enough to 
			// hold another character, double it 
			if ( (word_length + 1) > *buffer_len ) {

				str = expand_array(&str, buffer_len);

				if (str == NULL) {
					fprintf(stderr,"read_word: out of memory\n");
					exit(1);
				}
			}

			str [word_length++] = c;
		
		// if it is a space, tab, or newline
		} else {

			// if we have a word in the buffer, return it
			if (word_length > 0) {
				break;

			// if the buffer is empty, keep looking for a word.	
			} else {
				continue;
			}
			
		}
	}

	if (c == EOF) {

		// if we have a word in the buffer, return it
		if (word_length > 0) {

			str[word_length++] = '\0'; 				// end it with a null char
			eof_reached = 1;
			return str;
		}

		if (DEBUG)
			printf("caught EOF getting ready to return\n");

		return NULL;
	}

	str[word_length++] = '\0';

	if (DEBUG)
		printf("word_length: %d, strlen(str): %d,  \n", word_length, (int) strlen(str) );

	return str; 

}