Exemplo n.º 1
0
/**
 * @brief  Creates new cstring.
 * @param  str string that will be written into newly created cstring.
 * @return pointer to new cstring.
 *
 * Writes char from parameters into newly created cstring.
 */
cstring *cstr_create_chr(const char chr)
{
    cstring *s = gc_calloc("cstring", sizeof(cstring), 1);	///allocates new cstring with size of the CSTRING_START_SIZE

    if (!s)
    {
        debug("Memory allocation for cstrig has failed.\n");
        return NULL;
    }

    s->str = gc_calloc("cstring", CSTRING_START_SIZE, 1);

    if (!s->str)
    {
        debug("Memory allocation for cstrig has failed.\n");
        return NULL;
    }

    s->tab_size = CSTRING_START_SIZE;
    s->size = 1;
    s->str[0] = chr;
    s->str[1] = '\0';

    return s;
}
Exemplo n.º 2
0
frame_t* new_frame( frame_t* parent )
{
  frame_t* newframe = gc_calloc( 1, sizeof( frame_t ) );
  newframe->parent = parent;

  return newframe;
}
Exemplo n.º 3
0
/**
 * @brief  Creates new cstring.
 * @param  str string that will be written into newly created cstring.
 * @return pointer to new cstring.
 *
 * Writes str from parameters into newly created cstring.
 */
cstring *cstr_create_str(char const *str)
{
    cstring *s = gc_calloc("cstring", sizeof(*s), 1);

	if(!str)
	{
		debug("str not given.\n");
		return s;
	}


    if (s)
        return cstr_append_str(s, str);

    debug("Memory allocation for cstrig has failed.\n");
    return NULL;
}
Exemplo n.º 4
0
static int string_string_tuple_array_val (caml_gc *gc, char ***c_val, value v)
{
	CAMLparam1(v);
	CAMLlocal1(a);
	int i;
	char **array;

	for (i = 0, a = Field(v, 5); a != Val_emptylist; a = Field(a, 1)) { i++; }

	array = gc_calloc(gc, (i + 1) * 2, sizeof(char *));
	if (!array)
		return 1;
	for (i = 0, a = Field(v, 5); a != Val_emptylist; a = Field(a, 1), i++) {
		value b = Field(a, 0);
		array[i * 2] = dup_String_val(gc, Field(b, 0));
		array[i * 2 + 1] = dup_String_val(gc, Field(b, 1));
	}
	*c_val = array;
	CAMLreturn(0);
}