Пример #1
0
static void
_free_eina_array(Eina_Array *array, _free_func free_cb)
{
   if (!array)
      return;

   while (eina_array_count(array))
      free_cb(eina_array_pop(array));

   eina_array_free(array);
}
Пример #2
0
END_TEST

START_TEST(eina_binshare_collision)
{
   Eina_Array *ea;
   char buffer[50];
   int i;

   srand(time(NULL));

   eina_init();

   ea = eina_array_new(256);
   fail_if(!ea);

   for (i = 0; i < 10000; ++i)
     {
        eina_convert_itoa(rand(), buffer);
        eina_array_push(ea,
                        (void *)eina_binshare_add_length(buffer, strlen(buffer)));
        if (rand() > RAND_MAX / 2)
          {
             const char *r = eina_binshare_add_length(buffer, strlen(buffer));
             fail_if(r == NULL);
          }
     }

   for (i = 0; i < 10000; ++i)
     {
        const char *r;

        eina_convert_itoa(60000 - i, buffer);
        eina_array_push(ea,
                        (void *)eina_binshare_add_length(buffer, strlen(buffer)));
        r = eina_binshare_add_length(buffer, strlen(buffer));
        fail_if(r == NULL);
        r = eina_binshare_add_length(buffer, strlen(buffer));
        fail_if(r == NULL);
     }

   for (i = 0; i < 200; ++i)
      eina_binshare_del(eina_array_data_get(ea, i));

   for (i = 0; i < 1000; ++i)
      eina_binshare_del(eina_array_pop(ea));

   eina_shutdown();

   eina_array_free(ea);
}
Пример #3
0
static Eina_Bool
_elixir_eet_release(const Elixir_Loader_File *file)
{
   Elixir_Eet_Filename *lookup;
   Eina_List *last;

   /* LRU must never be bigger than 8 file. */
   if (eina_list_count(lru) > 8)
     {
	last = eina_list_last(lru);
	lookup = eina_list_data_get(last);

	eina_hash_del(cache, lookup->filename, lookup);

	lru = eina_list_remove_list(lru, last);
     }

   file->file->reference--;

   lookup = eina_hash_find(cache, file->file->filename);
   if (lookup == file->file)
     lru = eina_list_prepend(lru, file->file);
   else
     if (file->file->reference < 0)
       {
	  eet_close(file->file->eet);
	  free(file->file->filename);
	  free(file->file);
       }

   if (stack && eina_array_count_get(stack) > 0)
     eina_array_pop(stack);

   if (file->free_content) free(file->content);
   if (file->free_compiled) free(file->compiled);
   free(file->section);
   free((void*) file);

   return EINA_TRUE;
}
Пример #4
0
char *
_nedje_text_escape(const char *text)
{
   Eina_Strbuf *txt;
   char *ret;
   const char *text_end;
   size_t text_len;
   Eina_Array *arr;
   const char *cur_tag = NULL;

   if (!text) return NULL;

   txt = eina_strbuf_new();
   text_len = strlen(text);
   arr = eina_array_new(3);

   text_end = text + text_len;
   while (text < text_end)
     {
        int advance;

        if ((text[0] == '<') && text[1])
          {
             const char *tag, *popped;
             Eina_Bool closing = EINA_FALSE;

             if (text[1] == '/') //closing tag
               {
                  closing = EINA_TRUE;
                  tag = _get_tag(text + 2);
               }
             else
               tag = _get_tag(text + 1);
             if (closing)
               {
                  if (cur_tag && (tag != cur_tag))
                    {
                       /* tag mismatch: autoclose all failure tags
                        * not technically required by the spec,
                        * but it makes me feel better about myself
                        */
                       do
                         {
                            popped = eina_array_pop(arr);
                            if (eina_array_count(arr))
                              cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1);
                            else
                              cur_tag = NULL;
                            eina_strbuf_append_printf(txt, "</%c>", popped[1]);
                         } while (cur_tag && (popped != tag));
                       advance = 4;
                    }
                  else if (cur_tag)
                    {
                       /* tag match: just pop */
                       popped = eina_array_pop(arr);
                       if (eina_array_count(arr))
                         cur_tag = eina_array_data_get(arr, eina_array_count(arr) - 1);
                       else
                         cur_tag = NULL;
                       eina_strbuf_append_printf(txt, "</%c>", popped[1]);
                       advance = 4;
                    }
                  else
                    {
                       /* no current tag: escape */
                       advance = _text_escape(txt, text);
                    }
               }
             else
               {
                  if (tag)
                    {
                       cur_tag = tag;
                       eina_array_push(arr, tag);
                       eina_strbuf_append_printf(txt, "<%c>", tag[1]);
                       advance = 3;
                    }
                  else
                    advance = _text_escape(txt, text);
               }
          }
        else if (text[0] == '&')
          {
             const char *s;

             s = strchr(text, ';');
             if (s)
               s = evas_textblock_escape_string_range_get(text, s + 1);
             if (s)
               {
                  eina_strbuf_append_char(txt, text[0]);
                  advance = 1;
               }
             else
               advance = _text_escape(txt, text);
          }
        else
          advance = _text_escape(txt, text);

        text += advance;
     }

   eina_array_free(arr);
   ret = eina_strbuf_string_steal(txt);
   eina_strbuf_free(txt);
   return ret;
}