示例#1
0
文件: eina_array.c 项目: jigpu/efl
EAPI Eina_Iterator *
eina_array_iterator_new(const Eina_Array *array)
{
   Eina_Iterator_Array *it;

   EINA_SAFETY_ON_NULL_RETURN_VAL(array, NULL);
   EINA_MAGIC_CHECK_ARRAY(array);

   eina_error_set(0);
   it = calloc(1, sizeof (Eina_Iterator_Array));
   if (!it)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   EINA_MAGIC_SET(it,            EINA_MAGIC_ARRAY_ITERATOR);
   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->array = array;

   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(eina_array_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
         eina_array_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(eina_array_iterator_free);

   return &it->iterator;
}
示例#2
0
EAPI Eina_Accessor *
eina_inarray_accessor_new(const Eina_Inarray *array)
{
   Eina_Accessor_Inarray *ac;

   EINA_MAGIC_CHECK_INARRAY(array, NULL);

   eina_error_set(0);
   ac = calloc(1, sizeof(Eina_Accessor_Inarray));
   if (!ac)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   EINA_MAGIC_SET(ac,            EINA_MAGIC_INARRAY_ACCESSOR);
   EINA_MAGIC_SET(&ac->accessor, EINA_MAGIC_ACCESSOR);

   ac->array = array;

   ac->accessor.version = EINA_ACCESSOR_VERSION;
   ac->accessor.get_at = FUNC_ACCESSOR_GET_AT(_eina_inarray_accessor_get_at);
   ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER
     (_eina_inarray_accessor_get_container);
   ac->accessor.free = FUNC_ACCESSOR_FREE(_eina_inarray_accessor_free);

   return &ac->accessor;
}
示例#3
0
EAPI Eina_Iterator *
eina_inarray_iterator_reversed_new(const Eina_Inarray *array)
{
   Eina_Iterator_Inarray *it;

   EINA_MAGIC_CHECK_INARRAY(array, NULL);

   eina_error_set(0);
   it = calloc(1, sizeof(Eina_Iterator_Inarray));
   if (!it)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   EINA_MAGIC_SET(it,            EINA_MAGIC_INARRAY_ITERATOR);
   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->array = array;
   it->pos = array->len;

   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(_eina_inarray_iterator_prev);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER
     (_eina_inarray_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_eina_inarray_iterator_free);

   return &it->iterator;
}
示例#4
0
void *data_new()
{
    eina_error_set(0);

    eina_error_set(MY_ERROR_NULL);
    return NULL;
}
/**
 * @brief Create a new Sparse Matrix.
 *
 * @param rows number of rows in matrix. Operations with rows greater than this
 *        value will fail.
 * @param cols number of columns in matrix. Operations with columns greater
 *        than this value will fail.
 * @param free_func used to delete cell data contents, used by
 *        eina_matrixsparse_free(), eina_matrixsparse_size_set(),
 *        eina_matrixsparse_row_idx_clear(),
 *        eina_matrixsparse_column_idx_clear(),
 *        eina_matrixsparse_cell_idx_clear() and possible others.
 * @param user_data given to @a free_func as first parameter.
 *
 * @return newly allocated matrix or NULL if allocation failed and eina_error
 *         is set.
 */
EAPI Eina_Matrixsparse *
eina_matrixsparse_new(unsigned long rows, unsigned long cols, void (*free_func)(void *user_data, void *cell_data), const void *user_data)
{
   Eina_Matrixsparse *m;

   EINA_SAFETY_ON_FALSE_RETURN_VAL(rows > 0, NULL);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(cols > 0, NULL);

   m = malloc(sizeof(Eina_Matrixsparse));
   if (!m)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	return NULL;
     }

   m->rows = NULL;
   m->last_row = NULL;
   m->last_used = NULL;

   m->size.rows = rows;
   m->size.cols = cols;
   m->free.func = free_func;
   m->free.user_data = (void *)user_data;

   EINA_MAGIC_SET(m, EINA_MAGIC_MATRIXSPARSE);
   eina_error_set(0);
   return m;
}
示例#6
0
/**
 * @brief Returns a new accessor associated to a list.
 *
 * @param list The list.
 * @return A new accessor.
 *
 * This function returns a newly allocated accessor associated to
 * @p list. If @p list is @c NULL or the count member of @p list is
 * less or equal than 0, this function returns NULL. If the memory can
 * not be allocated, NULL is returned and #EINA_ERROR_OUT_OF_MEMORY is
 * set. Otherwise, a valid accessor is returned.
 */
EAPI Eina_Accessor *
eina_inlist_accessor_new(const Eina_Inlist *list)
{
   Eina_Accessor_Inlist *ac;

        eina_error_set(0);
   ac = calloc(1, sizeof (Eina_Accessor_Inlist));
   if (!ac)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   ac->head = list;
   ac->current = list;
   ac->index = 0;

   ac->accessor.version = EINA_ACCESSOR_VERSION;
   ac->accessor.get_at = FUNC_ACCESSOR_GET_AT(eina_inlist_accessor_get_at);
   ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER(
         eina_inlist_accessor_get_container);
   ac->accessor.free = FUNC_ACCESSOR_FREE(eina_inlist_accessor_free);

   EINA_MAGIC_SET(&ac->accessor, EINA_MAGIC_ACCESSOR);

   return &ac->accessor;
}
示例#7
0
/**
 * @brief Returns a new iterator associated to @a list.
 *
 * @param list The list.
 * @return A new iterator.
 *
 * This function returns a newly allocated iterator associated to @p
 * list. If @p list is @c NULL or the count member of @p list is less
 * or equal than 0, this function still returns a valid iterator that
 * will always return false on eina_iterator_next(), thus keeping API
 * sane.
 *
 * If the memory can not be allocated, NULL is returned and
 * #EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, a valid iterator is
 * returned.
 *
 * @warning if the list structure changes then the iterator becomes
 *    invalid, and if you add or remove nodes iterator
 *    behavior is undefined, and your program may crash!
 */
EAPI Eina_Iterator *
eina_inlist_iterator_new(const Eina_Inlist *list)
{
   Eina_Iterator_Inlist *it;

   eina_error_set(0);
   it = calloc(1, sizeof (Eina_Iterator_Inlist));
   if (!it)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   it->head = list;
   it->current = list;

   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(eina_inlist_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
         eina_inlist_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(eina_inlist_iterator_free);

   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   return &it->iterator;
}
示例#8
0
static const char *
_eina_stringshare_small_bucket_insert_at(
    Eina_Stringshare_Small_Bucket **p_bucket,
    const char *str,
    unsigned char length,
    int idx)
{
    Eina_Stringshare_Small_Bucket *bucket = *p_bucket;
    int todo, off;
    char *snew;

    if (!bucket)
    {
        *p_bucket = bucket = calloc(1, sizeof(*bucket));
        if (!bucket)
        {
            eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
            return NULL;
        }
    }

    if (bucket->count + 1 >= bucket->size)
    {
        int size = bucket->size + EINA_STRINGSHARE_SMALL_BUCKET_STEP;
        if (!_eina_stringshare_small_bucket_resize(bucket, size))
            return NULL;
    }

    snew = malloc(length + 1);
    if (!snew)
    {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
    }

    memcpy(snew, str, length);
    snew[length] = '\0';

    off = idx + 1;
    todo = bucket->count - idx;
    if (todo > 0)
    {
        memmove((void *)(bucket->strings + off), bucket->strings + idx,
                todo * sizeof(bucket->strings[0]));
        memmove(bucket->lengths + off,           bucket->lengths + idx,
                todo * sizeof(bucket->lengths[0]));
        memmove(bucket->references + off,        bucket->references + idx,
                todo * sizeof(bucket->references[0]));
    }

    bucket->strings[idx] = snew;
    bucket->lengths[idx] = length;
    bucket->references[idx] = 1;
    bucket->count++;

    return snew;
}
示例#9
0
int test(int n)
{
    eina_error_set(0);

    if (n < 0)
    {
        eina_error_set(MY_ERROR_NEGATIVE);
        return 0;
    }

    return 1;
}
示例#10
0
/**
 * @internal
 *
 * init the buffer
 * @param buf the buffer to init
 *
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 */
static Eina_Bool _eina_strbuf_common_init(size_t csize, Eina_Strbuf * buf)
{
	buf->len = 0;
	buf->size = EINA_STRBUF_INIT_SIZE;
	buf->step = EINA_STRBUF_INIT_STEP;

	eina_error_set(0);
	buf->buf = calloc(csize, buf->size);
	if (EINA_UNLIKELY(!buf->buf)) {
		eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
		return EINA_FALSE;
	}

	return EINA_TRUE;
}
示例#11
0
static Eina_Mempool *
_new_va(const char *name,
        const char *context,
        const char *options,
        va_list args)
{
   Eina_Mempool_Backend *be;
   Eina_Mempool *mp;

   Eina_Error err = EINA_ERROR_NOT_MEMPOOL_MODULE;

   eina_error_set(0);
   be = eina_hash_find(_backends, name);
   if ((!be) || (!be->init))
      goto on_error;

   err = EINA_ERROR_OUT_OF_MEMORY;
   mp = calloc(1, sizeof(Eina_Mempool));
   if (!mp)
      goto on_error;

   /* Work around ABI incompability introduced in Eina 1.1 */
#define SBP(Property) mp->backend.Property = be->Property;
   SBP(name);
   SBP(init);
   SBP(free);
   SBP(alloc);
   SBP(realloc);
   SBP(garbage_collect);
   SBP(statistics);
   SBP(shutdown);
#undef SBP

   if (be->repack)
     {
        mp->backend2 = calloc(1, sizeof (Eina_Mempool_Backend_ABI2));
        if (mp->backend2)
          mp->backend2->repack = be->repack;
     }

   mp->backend_data = mp->backend.init(context, options, args);

   return mp;

on_error:
   eina_error_set(err);
   return NULL;
}
示例#12
0
static Eina_Bool
_eina_inarray_resize(Eina_Inarray *array, unsigned int new_size)
{
   unsigned int new_max;
   void *tmp;

   if (new_size < array->max) /* don't change this behaviour as eina_inarray_pop rely on it */
     return EINA_TRUE;

   if (new_size % array->step == 0)
     new_max = new_size;
   else
     new_max = ((new_size / array->step) + 1) * array->step;

   tmp = realloc(array->members, new_max * array->member_size);
   if ((!tmp) && (new_max > 0))
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return EINA_FALSE;
     }

   array->members = tmp;
   array->max = new_max;
   return EINA_TRUE;
}
示例#13
0
/*
 * Constructor for the Eupnp_HTTP_Header structure
 *
 * Receives pointers to key and value starting points and the length that will
 * be copied from that point on (length). The key will be automatically
 * converted to lowercase.
 *
 * @param key starting point of the key
 * @param key_len key length
 * @param value starting point of the value
 * @param value_len value length
 *
 * @return Eupnp_HTTP_Header instance
 */
Eupnp_HTTP_Header *
eupnp_http_header_new(const char *key, int key_len, const char *value, int value_len)
{
   Eupnp_HTTP_Header *h;

   /* Alloc blob */
   h = malloc(sizeof(Eupnp_HTTP_Header) + key_len + 1 + value_len + 1);

   if (!h)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	ERROR("header alloc error.\n");
	return NULL;
     }

   h->key = (char *)h + sizeof(Eupnp_HTTP_Header);
   h->value = (char *)h + sizeof(Eupnp_HTTP_Header) + sizeof(char)*(key_len + 1);
   memcpy((void *)h->key, key, key_len);
   memcpy((void *)h->value, value, value_len);
   ((char *) h->key)[key_len] = '\0';
   ((char *) h->value)[value_len] = '\0';

   /*
    * Make key lowercase - no need to care about case insensitive.
    */
   char *p = (char *) h->key;

   while (*p != '\0')
     {
	*p = tolower(*p);
	(p)++;
     }

   return h;
}
示例#14
0
/**
 * Constructor for the Eupnp_Control_Point class.
 *
 * @return A new Eupnp_Control_Point instance. On error, returns NULL.
 */
EAPI Eupnp_Control_Point *
eupnp_control_point_new(void)
{
   Eupnp_Control_Point *c;

   c = malloc(sizeof(Eupnp_Control_Point));

   if (!c)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	ERR("Could not allocate a new control point.");
	return NULL;
     }

   c->ssdp_client = eupnp_ssdp_client_new();

   if (!c->ssdp_client)
     {
	ERR("Could not create a ssdp instance for the control point.");
	free(c);
	return NULL;
     }

   return c;
}
示例#15
0
EAPI Eina_Bool eina_module_load(Eina_Module *m)
{
#ifdef HAVE_DLOPEN
   void *dl_handle;
   Eina_Module_Init *initcall;

   EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);

   DBG("m=%p, handle=%p, file=%s, refs=%d", m, m->handle, m->file, m->ref);

   if (m->handle)
      goto loaded;

   dl_handle = dlopen(m->file, RTLD_NOW);
   if (!dl_handle)
     {
        WRN("could not dlopen(\"%s\", RTLD_NOW): %s", m->file, dlerror());
        eina_error_set(EINA_ERROR_WRONG_MODULE);
        return EINA_FALSE;
     }

   initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
   if ((!initcall) || (!(*initcall)))
      goto ok;

   if ((*initcall)() == EINA_TRUE)
      goto ok;

   WRN("could not find eina's entry symbol %s inside module %s",
       EINA_MODULE_SYMBOL_INIT, m->file);
   eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
   dlclose(dl_handle);
   return EINA_FALSE;
ok:
   DBG("successfully loaded %s", m->file);
   m->handle = dl_handle;
loaded:
   m->ref++;
   DBG("ref %d", m->ref);

   eina_error_set(0);
   return EINA_TRUE;
#else
   (void) m;
   return EINA_FALSE;
#endif
}
示例#16
0
/*============================================================================*
*                                   API                                      *
*============================================================================*/
EAPI Eina_Inarray *
eina_inarray_new(unsigned int member_size, unsigned int step)
{
   Eina_Inarray *ret;

   EINA_SAFETY_ON_TRUE_RETURN_VAL(member_size == 0, NULL);

   ret = malloc(sizeof(*ret));
   if (!ret)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }
   eina_error_set(0);
   _eina_inarray_setup(ret, member_size, step);
   return ret;
}
示例#17
0
/**
 * @brief Create a new string buffer.
 *
 * @return Newly allocated string buffer instance.
 *
 * This function creates a new string buffer. On error, @c NULL is
 * returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
 * free the resources, use eina_strbuf_common_free().
 *
 * @see eina_strbuf_common_free()
 * @see eina_strbuf_common_append()
 * @see eina_strbuf_common_string_get()
 */
Eina_Strbuf *eina_strbuf_common_new(size_t csize)
{
	Eina_Strbuf *buf;

	eina_error_set(0);
	buf = malloc(sizeof(Eina_Strbuf));
	if (EINA_UNLIKELY(!buf)) {
		eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
		return NULL;
	}

	if (EINA_UNLIKELY(!_eina_strbuf_common_init(csize, buf))) {
		eina_strbuf_common_free(buf);
		return NULL;
	}

	return buf;
}
示例#18
0
/*
 * Constructor for the Eupnp_HTTP_Request structure
 *
 * Receives pointers to starting points and lengths of the method, uri
 * and http version attributes and constructs the object. Also initializes the
 * headers array. For dealing with headers, refer to the
 * eupnp_http_request_header_* functions.
 *
 * @param method starting point of the method
 * @param method_len method length
 * @param uri starting point of the uri
 * @param uri_len uri length
 * @param httpver starting point of the http version
 * @param httpver_len http version length
 *
 * @return Eupnp_HTTP_Request instance
 */
Eupnp_HTTP_Request *
eupnp_http_request_new(const char *method, int method_len, const char *uri, int uri_len, const char *httpver, int httpver_len)
{
   Eupnp_HTTP_Request *h;
   h = calloc(1, sizeof(Eupnp_HTTP_Request));

   if (!h)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	ERROR("Could not create HTTP message.\n");
	return NULL;
     }

   h->headers = eina_array_new(10);

   if (!h->headers)
     {
	ERROR("Could not allocate memory for HTTP headers table.\n");
	free(h);
	return NULL;
     }

   h->method = eina_stringshare_add_length(method, method_len);

   if (!h->method)
     {
	ERROR("Could not stringshare HTTP request method.\n");
	eina_array_free(h->headers);
	free(h);
	return NULL;
     }

   h->http_version = eina_stringshare_add_length(httpver, httpver_len);

   if (!h->http_version)
     {
	ERROR("Could not stringshare HTTP request version.\n");
	eina_array_free(h->headers);
	eina_stringshare_del(h->method);
	free(h);
	return NULL;
     }

   h->uri = eina_stringshare_add_length(uri, uri_len);

   if (!h->uri)
     {
	ERROR("Could not stringshare HTTP request URI.\n");
	eina_array_free(h->headers);
	eina_stringshare_del(h->method);
	eina_stringshare_del(h->http_version);
	free(h);
	return NULL;
     }

   return h;
}
示例#19
0
/**
 * @internal
 *
 * resize the buffer
 * @param buf the buffer to resize
 * @param size the minimum size of the buffer
 *
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 */
static inline Eina_Bool
_eina_strbuf_common_resize(size_t csize, Eina_Strbuf * buf, size_t size)
{
	size_t new_size, new_step, delta;
	void *buffer;

	size += 1;		// Add extra space for '\0'

	if (size == buf->size)
		/* nothing to do */
		return EINA_TRUE;
	else if (size > buf->size)
		delta = size - buf->size;
	else
		delta = buf->size - size;

	/* check if should keep the same step (just used while growing) */
	if ((delta <= buf->step) && (size > buf->size))
		new_step = buf->step;
	else {
		new_step = (((delta / EINA_STRBUF_INIT_STEP) + 1)
			    * EINA_STRBUF_INIT_STEP);

		if (new_step > EINA_STRBUF_MAX_STEP)
			new_step = EINA_STRBUF_MAX_STEP;
	}

	new_size = (((size / new_step) + 1) * new_step);

	/* reallocate the buffer to the new size */
	buffer = realloc(buf->buf, new_size * csize);
	if (EINA_UNLIKELY(!buffer)) {
		eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
		return EINA_FALSE;
	}

	buf->buf = buffer;
	buf->size = new_size;
	buf->step = new_step;
	eina_error_set(0);
	return EINA_TRUE;
}
示例#20
0
EAPI Eina_Bool
eupnp_service_parse_buffer(const char *buffer, int buffer_len, Eupnp_Service_Proxy *s)
{
   Eina_Bool ret = EINA_FALSE;
   if ((!buffer) || (!buffer_len) || (!s)) return ret;

   Eupnp_Service_Parser *parser;

   if (!s->xml_parser)
     {
	/* Creates the parser, which parses the first chunk */
	DBG("Creating service parser.");

	s->xml_parser = eupnp_service_parser_new(buffer, buffer_len, s);

	if (!s->xml_parser)
          {
	     ERR("Failed to parse first chunk");
	     goto parse_ret;
	  }

        ret = EINA_TRUE;
	goto parse_ret;
     }

   parser = s->xml_parser;

   if (!parser->ctx)
     {
	// first_chunk_len < 4 case
	eina_error_set(EUPNP_ERROR_SERVICE_PARSER_INSUFFICIENT_FEED);
	return EINA_FALSE;
     }

   // Progressive feeds
   if (parser->state.state == FINISH)
     {
	WRN("Already finished parsing");
	ret = EINA_TRUE;
	goto parse_ret;
     }

   DBG("Parsing XML (%d) at %p", buffer_len, buffer);

   if (!xmlParseChunk(parser->ctx, buffer, buffer_len, 0))
     {
	ret = EINA_TRUE;
	goto parse_ret;
     }

   parse_ret:
      eupnp_service_parse_check_finished(s);
      return ret;
}
示例#21
0
文件: eina_magic.c 项目: Limsik/e17
EAPI void
eina_magic_fail(void *d,
                Eina_Magic m,
                Eina_Magic req_m,
                const char *file,
                const char *fnc,
                int line)
{
   eina_error_set(EINA_ERROR_MAGIC_FAILED);
   if (!d)
      eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL,
                     file, fnc, line,
                     "*** Eina Magic Check Failed !!!\n"
                     "    Input handle pointer is NULL !\n"
                     "*** NAUGHTY PROGRAMMER!!!\n"
                     "*** SPANK SPANK SPANK!!!\n"
                     "*** Now go fix your code. Tut tut tut!\n"
                     "\n");
   else
   if (m == EINA_MAGIC_NONE)
      eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL,
                     file, fnc, line,
                     "*** Eina Magic Check Failed !!!\n"
                     "    Input handle has already been freed!\n"
                     "*** NAUGHTY PROGRAMMER!!!\n"
                     "*** SPANK SPANK SPANK!!!\n"
                     "*** Now go fix your code. Tut tut tut!\n"
                     "\n");
   else
   if (m != req_m)
      eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL,
                     file, fnc, line,
                     "*** Eina Magic Check Failed !!!\n"
                     "    Input handle is wrong type\n"
                     "    Expected: %08x - %s\n"
                     "    Supplied: %08x - %s\n"
                     "*** NAUGHTY PROGRAMMER!!!\n"
                     "*** SPANK SPANK SPANK!!!\n"
                     "*** Now go fix your code. Tut tut tut!\n"
                     "\n",
                     req_m, eina_magic_string_get(req_m),
                     m, eina_magic_string_get(m));
   else
      eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL,
                     file, fnc, line,
                     "*** Eina Magic Check Failed !!!\n"
                     "    Why did you call me !\n"
                     "*** NAUGHTY PROGRAMMER!!!\n"
                     "*** SPANK SPANK SPANK!!!\n"
                     "*** Now go fix your code. Tut tut tut!\n"
                     "\n");
}
示例#22
0
文件: eina_array.c 项目: jigpu/efl
EAPI Eina_Array *
eina_array_new(unsigned int step)
{
   Eina_Array *array;

   eina_error_set(0);
   array = malloc(sizeof (Eina_Array));
   if (!array)
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return NULL;
     }

   EINA_MAGIC_SET(array, EINA_MAGIC_ARRAY);

   array->version = EINA_ARRAY_VERSION;
   array->data = NULL;
   array->total = 0;
   array->count = 0;
   array->step = step;

   return array;
}
示例#23
0
文件: eina_array.c 项目: jigpu/efl
/* used from eina_inline_array.x, thus a needed symbol */
EAPI Eina_Bool
eina_array_grow(Eina_Array *array)
{
   void **tmp;
   unsigned int total;

   EINA_SAFETY_ON_NULL_RETURN_VAL(array, EINA_FALSE);

   EINA_MAGIC_CHECK_ARRAY(array);

   total = array->total + array->step;
   eina_error_set(0);
   tmp = realloc(array->data, sizeof (void *) * total);
   if (EINA_UNLIKELY(!tmp))
     {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return 0;
     }

   array->total = total;
   array->data = tmp;

   return 1;
}
示例#24
0
static Eina_Bool
_eina_stringshare_small_bucket_resize(Eina_Stringshare_Small_Bucket *bucket,
                                      int size)
{
    void *tmp;

    tmp = realloc((void *)bucket->strings, size * sizeof(bucket->strings[0]));
    if (!tmp)
    {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return 0;
    }

    bucket->strings = tmp;

    tmp = realloc(bucket->lengths, size * sizeof(bucket->lengths[0]));
    if (!tmp)
    {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return 0;
    }

    bucket->lengths = tmp;

    tmp = realloc(bucket->references, size * sizeof(bucket->references[0]));
    if (!tmp)
    {
        eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
        return 0;
    }

    bucket->references = tmp;

    bucket->size = size;
    return 1;
}
示例#25
0
/*
 * Constructor for the Eupnp_HTTP_Response structure
 *
 * Receives pointers to starting points and lengths of the http version, status
 * code and http version attributes and constructs the object. Also initializes
 * the headers array. For dealing with headers, refer to the
 * eupnp_http_response_header_* functions.
 *
 * @param httpver starting point of the http version
 * @param httpver_len http version length
 * @param status_code starting point of the status code
 * @param status_len status length
 * @param reason_phrase starting point of the reason phrase
 * @param reason_phrase_len reason phrase length
 *
 * @return Eupnp_HTTP_Response instance
 */
Eupnp_HTTP_Response *
eupnp_http_response_new(const char *httpver, int httpver_len, const char *status_code, int status_code_len, const char *reason_phrase, int reason_phrase_len)
{
   Eupnp_HTTP_Response *r;
   r = calloc(1, sizeof(Eupnp_HTTP_Response));

   if (!r)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	ERROR("Could not create HTTP response.\n");
	return NULL;
     }

   r->headers = eina_array_new(10);

   if (!r->headers)
     {
	ERROR("Could not allocate memory for HTTP headers.\n");
	free(r);
	return NULL;
     }

   r->http_version = eina_stringshare_add_length(httpver, httpver_len);

   if (!r->http_version)
     {
	ERROR("Could not stringshare http response version.\n");
	eina_array_free(r->headers);
	free(r);
	return NULL;
     }

   r->status_code = strtol(status_code, NULL, 10);
   r->reason_phrase = eina_stringshare_add_length(reason_phrase,
						    reason_phrase_len);

   if (!r->reason_phrase)
     {
	ERROR("Could not stringshare http response phrase.\n");
	eina_array_free(r->headers);
	eina_stringshare_del(r->http_version);
	free(r);
	return NULL;
     }

   return r;
}
示例#26
0
/*
 * Adds a header to a response
 *
 * Adds a header to the response object given pointers to the key
 * and value starting points and respective string lengths.
 *
 * @param m request to add the header into
 * @param key starting point for the key
 * @param key_len key length
 * @param value starting point for the value
 * @param value_len value length
 *
 * @note This function does not check duplicate headers. If added twice,
 *       header will be duplicated.
 *
 * @return On success returns EINA_TRUE, otherwise EINA_FALSE.
 */
Eina_Bool
eupnp_http_response_header_add(Eupnp_HTTP_Response *r, const char *key, int key_len, const char *value, int value_len)
{
   Eupnp_HTTP_Header *h;

   h = eupnp_http_header_new(key, key_len, value, value_len);

   if (!h)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	ERROR("header alloc error.\n");
	return EINA_FALSE;
     }

   if (!eina_array_push(r->headers, h))
     {
	WARN("incomplete headers\n");
	eupnp_http_header_free(h);
	return EINA_FALSE;
     }

   return EINA_TRUE;
}
示例#27
0
/**
 * Remove node from list.
 *
 * @note this code is meant to be fast: appends are O(1) and do not
 *       walk @a list.
 *
 * @note @a item is considered to be inside @a list, no checks are
 *       done to confirm that and giving nodes from different lists
 *       will lead to problems, especially if @a item is the head since
 *       it will be different from @a list and the wrong new head will
 *       be returned.
 *
 * @param list existing list head, must not be NULL.
 * @param item existing list node, must not be NULL.
 *
 * @return the new list head. Use it and not @a list anymore.
 */
EAPI Eina_Inlist *
eina_inlist_remove(Eina_Inlist *list, Eina_Inlist *item)
{
   Eina_Inlist *return_l;

   /* checkme */
   EINA_SAFETY_ON_NULL_RETURN_VAL(list, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(item, list);
   if (EINA_UNLIKELY((item != list) && (!item->prev) && (!item->next)))
     {
        eina_error_set(EINA_ERROR_SAFETY_FAILED);
        EINA_LOG_ERR("safety check failed: item %p does not appear to be part of an inlist!", item);
        return list;
     }

   if (item->next)
      item->next->prev = item->prev;

   if (item->prev)
     {
        item->prev->next = item->next;
        return_l = list;
     }
   else
     {
        return_l = item->next;
        if (return_l)
           return_l->last = list->last;
     }

   if (item == list->last)
      list->last = item->prev;

   item->next = NULL;
   item->prev = NULL;
   return return_l;
}
/**
 * Creates a new iterator over existing matrix cells.
 *
 * This is a cheap walk, it will just report existing cells and holes
 * in the sparse matrix will be ignored. That means the reported
 * indexes will not be sequential.
 *
 * The iterator data will be the cell reference, one may query current
 * position with eina_matrixsparse_cell_position_get() and cell value
 * with eina_matrixsparse_cell_data_get().
 *
 * @param m The Sparse Matrix reference, must @b not be @c NULL.
 * @return A new iterator.
 *
 * @warning if the matrix structure changes then the iterator becomes
 *    invalid! That is, if you add or remove cells this iterator
 *    behavior is undefined and your program may crash!
 */
EAPI Eina_Iterator *
eina_matrixsparse_iterator_new(const Eina_Matrixsparse *m)
{
   Eina_Matrixsparse_Iterator *it;

   it = calloc(1, sizeof(*it));
   if (!it)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	return NULL;
     }

   EINA_MAGIC_SET(it, EINA_MAGIC_MATRIXSPARSE_ITERATOR);
   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->m = m;
   it->ref.row = m->rows;
   it->ref.col = m->rows ? m->rows->cols : NULL;

   it->iterator.next = FUNC_ITERATOR_NEXT(_eina_matrixsparse_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_matrixsparse_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_eina_matrixsparse_iterator_free);
   return &it->iterator;
}
/**
 * Creates a new iterator over all matrix cells.
 *
 * Unlike eina_matrixsparse_iterator_new() this one will report all
 * matrix cells, even those that are still empty (holes). These will
 * be reported as dummy cells that contains no data.
 *
 * Be aware that iterating a big matrix (1000x1000) will call your
 * function that number of times (1000000 times in that case) even if
 * your matrix have no elements at all!
 *
 * The iterator data will be the cell reference, one may query current
 * position with eina_matrixsparse_cell_position_get() and cell value
 * with eina_matrixsparse_cell_data_get(). If cell is empty then the
 * reference will be a dummy/placeholder, thus setting value with
 * eina_matrixsparse_cell_data_set() will leave pointer unreferenced.
 *
 * @param m The Sparse Matrix reference, must @b not be @c NULL.
 * @return A new iterator.
 *
 * @warning if the matrix structure changes then the iterator becomes
 *    invalid! That is, if you add or remove cells this iterator
 *    behavior is undefined and your program may crash!
 */
EAPI Eina_Iterator *
eina_matrixsparse_iterator_complete_new(const Eina_Matrixsparse *m)
{
   Eina_Matrixsparse_Iterator_Complete *it;

   it = calloc(1, sizeof(*it));
   if (!it)
     {
	eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
	return NULL;
     }

   EINA_MAGIC_SET(it, EINA_MAGIC_MATRIXSPARSE_ITERATOR);
   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->m = m;
   it->idx.row = 0;
   it->idx.col = 0;
   it->ref.row = m->rows;
   it->ref.col = m->rows ? m->rows->cols : NULL;

   it->dummy.row.next = it->dummy.row.prev = NULL;
   it->dummy.row.cols = it->dummy.row.last_col = it->dummy.row.last_used = NULL;
   it->dummy.row.parent = (Eina_Matrixsparse *)m;
   EINA_MAGIC_SET(&it->dummy.row, EINA_MAGIC_MATRIXSPARSE_ROW);

   it->dummy.col.next = it->dummy.col.prev = NULL;
   it->dummy.col.data = NULL;
   it->dummy.col.parent = &it->dummy.row;
   EINA_MAGIC_SET(&it->dummy.col, EINA_MAGIC_MATRIXSPARSE_CELL);

   it->iterator.next = FUNC_ITERATOR_NEXT(_eina_matrixsparse_iterator_complete_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_matrixsparse_iterator_complete_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_eina_matrixsparse_iterator_complete_free);
   return &it->iterator;
}
示例#30
0
文件: eina_hash_06.c 项目: Limsik/e17
int
main(int argc, const char *argv[])
{
   Eina_Hash *phone_book = NULL;
   int i;
   int64_t entry_id = 4;
   char *phone = NULL;
   Eina_Bool r;
   Eina_Iterator *it;
   void *data;

   eina_init();

   phone_book = eina_hash_int64_new(_phone_entry_free_cb);

   // Add initial entries to our hash
   for (i = 0; _start_entries[i].id != -1; i++)
     {
	eina_hash_add(phone_book, &_start_entries[i].id,
		      strdup(_start_entries[i].number));
     }

   // Look for a specific entry and get its phone number
   phone = eina_hash_find(phone_book, &entry_id);
   if (phone)
     {
	printf("Printing entry.\n");
	printf("Id: %lld\n", entry_id);
	printf("Number: %s\n\n", phone);
     }

   // Delete this entry
   r = eina_hash_del(phone_book, &entry_id, NULL);
   printf("Hash entry successfully deleted? %d\n\n", r);

   // Modify the pointer data of an entry and free the old one
   int64_t id3 = 3;
   phone = eina_hash_modify(phone_book, &id3,
			    strdup("+23 45 111-11111"));
   free(phone);

   // Modify or add an entry to the hash with eina_hash_set
   // Let's first add a new entry
   int64_t id5 = 5;
   eina_error_set(0);
   phone = eina_hash_set(phone_book, &id5,
			 strdup("+55 01 234-56789"));
   if (!phone)
     {
	Eina_Error err = eina_error_get();
	if (!err)
	  {
	     printf("No previous phone found for id5. ");
	     printf("Creating new entry.\n");
	  }
	else
	  printf("Error when setting phone for Raul Seixas\n");
     }
   else
     {
	printf("Old phone for id5 was %s\n", phone);
	free(phone);
     }

   printf("\n");

   // Now change the phone number
   eina_error_set(0);
   phone = eina_hash_set(phone_book, &id5,
			 strdup("+55 02 222-22222"));
   if (phone)
     {
	printf("Changing phone for id5 to +55 02 222-22222. ");
	printf("Old phone was %s\n", phone);
	free(phone);
     }
   else
     {
	Eina_Error err = eina_error_get();
	if (err)
	  printf("Error when changing phone for id5\n");
	else
	  {
	     printf("No previous phone found for id5. ");
	     printf("Creating new entry.\n");
	  }
     }

   // There are many ways to iterate over our Phone book.
   // First, iterate showing the names and associated numbers.
   printf("List of phones:\n");
   eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL);
   printf("\n");

   // Now iterate using an iterator
   printf("List of phones:\n");
   it = eina_hash_iterator_tuple_new(phone_book);
   while (eina_iterator_next(it, &data))
     {
	Eina_Hash_Tuple *t = data;
	const int64_t *id = t->key;
	const char *number = t->data;
	printf("%lld: %s\n", *id, number);
     }
   eina_iterator_free(it); // Always free the iterator after its use
   printf("\n");

   // Just iterate over the keys (names)
   printf("List of ids in the phone book:\n");
   it = eina_hash_iterator_key_new(phone_book);
   while (eina_iterator_next(it, &data))
     {
	const int64_t *id = data;
	printf("%lld\n", *id);
     }
   eina_iterator_free(it);
   printf("\n");

   // Just iterate over the data (numbers)
   printf("List of numbers in the phone book:\n");
   it = eina_hash_iterator_data_new(phone_book);
   while (eina_iterator_next(it, &data))
     {
	const char *number = data;
	printf("%s\n", number);
     }
   eina_iterator_free(it);
   printf("\n");

   // Check how many items are in the phone book
   printf("There are %d items in the hash.\n\n",
	  eina_hash_population(phone_book));

   // Change the name (key) on an entry
   int64_t id6 = 6;
   eina_hash_move(phone_book, &id5, &id6);
   printf("List of phones after change:\n");
   eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL);
   printf("\n");

   // Empty the phone book, but don't destroy it
   eina_hash_free_buckets(phone_book);
   printf("There are %d items in the hash.\n\n",
	  eina_hash_population(phone_book));

   // Phone book could still be used, but we are freeing it since we are
   // done for now
   eina_hash_free(phone_book);

   eina_shutdown();
}