Dear Anyone concerned group inherit

I changed the part of type-change in group inherit.
Lately, raster removed the code about the prohibition of type-change in
group inherit.
But about the "part" of different type, the data structure of the their
"description" is different.
So if the type is changed, it have to be reallocated. Current, it is not.

At first, we have to remove the lookups. If we don't, when lookup module
executes, the memory
may be broken. So I removed all lookups for reallocated description before
it is reallocated.
And I changed all description of the "part" is reallocated when the type is
changed.
The attribute of the "part" is remained. Just it reallocated the part of
**_Spec_**.

Even if there is no problem currently, this change is necessary.
Please review my patch.
If it is proper, I will upload it in the svn.

Thanks.
--
Jaehwan Kim.
Index: src/bin/edje_cc_out.c
===================================================================
--- src/bin/edje_cc_out.c	(revision 66135)
+++ src/bin/edje_cc_out.c	(work copy)
@@ -1391,7 +1391,7 @@ data_queue_part_lookup(Edje_Part_Collection *pc, c
         if ((pl->pc == pc) && (pl->dest == dest))
           {
              free(pl->name);
-             if (name[0])
+             if (name && name[0])
                pl->name = mem_strdup(name);
              else
                {
@@ -1401,7 +1401,7 @@ data_queue_part_lookup(Edje_Part_Collection *pc, c
              return;
           }
      }
-   if (!name[0]) return;
+   if (!name || !name[0]) return;
 
    pl = mem_alloc(SZ(Part_Lookup));
    part_lookups = eina_list_append(part_lookups, pl);
@@ -1536,8 +1536,25 @@ data_queue_copied_program_lookup(Edje_Part_Collect
 void
 data_queue_image_lookup(char *name, int *dest, Eina_Bool *set)
 {
+   Eina_List *l;
    Image_Lookup *il;
 
+   EINA_LIST_FOREACH(image_lookups, l, il)
+     {
+        if (il->dest == dest)
+          {
+             free(il->name);
+             if (name && name[0])
+               il->name = mem_strdup(name);
+             else
+               {
+                  image_lookups = eina_list_remove(image_lookups, il);
+                  free(il);
+               }
+          }
+     }
+   if (!name || !name[0]) return;
+
    il = mem_alloc(SZ(Image_Lookup));
    image_lookups = eina_list_append(image_lookups, il);
    il->name = mem_strdup(name);
Index: src/bin/edje_cc_mem.c
===================================================================
--- src/bin/edje_cc_mem.c	(revision 66135)
+++ src/bin/edje_cc_mem.c	(work copy)
@@ -26,6 +26,22 @@ mem_alloc(size_t size)
    return NULL;
 }
 
+void *
+mem_realloc(void *p, size_t size)
+{
+   void *mem;
+
+   if (!p)
+     mem = calloc(1, size);
+   else
+     mem = realloc(p, size);
+   if (mem) return mem;
+   ERR("%s: Error. %s:%i memory allocation of " FMT_SIZE_T " bytes failed. %s",
+       progname, file_in, line, size, strerror(errno));
+   exit(-1);
+   return NULL;
+}
+
 char *
 mem_strdup(const char *s)
 {
Index: src/bin/edje_cc_handlers.c
===================================================================
--- src/bin/edje_cc_handlers.c	(revision 66135)
+++ src/bin/edje_cc_handlers.c	(work copy)
@@ -831,7 +831,7 @@ _edje_part_description_fill(Edje_Part_Description_
 }
 
 static Edje_Part_Description_Common *
-_edje_part_description_alloc(unsigned char type, const char *collection, const char *part)
+_edje_part_description_alloc(Edje_Part_Description_Common *ced, unsigned char type, const char *collection, const char *part)
 {
    Edje_Part_Description_Common *result = NULL;
 
@@ -840,14 +840,15 @@ static Edje_Part_Description_Common *
       case EDJE_PART_TYPE_RECTANGLE:
       case EDJE_PART_TYPE_SWALLOW:
       case EDJE_PART_TYPE_GROUP:
-	 result = mem_alloc(SZ(Edje_Part_Description_Common));
+	 result = mem_realloc(ced, SZ(Edje_Part_Description_Common));
 	 break;
       case EDJE_PART_TYPE_TEXT:
       case EDJE_PART_TYPE_TEXTBLOCK:
 	{
 	   Edje_Part_Description_Text *ed;
 
-	   ed = mem_alloc(SZ(Edje_Part_Description_Text));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_Text));
+           memset(&(ed->text), 0, SZ(Edje_Part_Description_Spec_Text));
 
 	   ed->text.color3.r = 0;
 	   ed->text.color3.g = 0;
@@ -865,7 +866,8 @@ static Edje_Part_Description_Common *
 	{
 	   Edje_Part_Description_Image *ed;
 
-	   ed = mem_alloc(SZ(Edje_Part_Description_Image));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_Image));
+           memset(&(ed->image), 0, SZ(Edje_Part_Description_Spec_Image));
 
 	   ed->image.id = -1;
 
@@ -878,7 +880,8 @@ static Edje_Part_Description_Common *
         {
            Edje_Part_Description_Proxy *ed;
 
-           ed = mem_alloc(SZ(Edje_Part_Description_Proxy));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_Proxy));
+           memset(&(ed->proxy), 0, SZ(Edje_Part_Description_Spec_Proxy));
 
            ed->proxy.id = -1;
 
@@ -891,7 +894,8 @@ static Edje_Part_Description_Common *
 	{
 	   Edje_Part_Description_Box *ed;
 
-	   ed = mem_alloc(SZ(Edje_Part_Description_Box));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_Box));
+           memset(&(ed->box), 0, SZ(Edje_Part_Description_Spec_Box));
 
 	   ed->box.layout = NULL;
 	   ed->box.alt_layout = NULL;
@@ -907,7 +911,8 @@ static Edje_Part_Description_Common *
 	{
 	   Edje_Part_Description_Table *ed;
 
-	   ed = mem_alloc(SZ(Edje_Part_Description_Table));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_Table));
+           memset(&(ed->table), 0, SZ(Edje_Part_Description_Spec_Table));
 
 	   ed->table.homogeneous = EDJE_OBJECT_TABLE_HOMOGENEOUS_NONE;
 	   ed->table.align.x = FROM_DOUBLE(0.5);
@@ -922,7 +927,8 @@ static Edje_Part_Description_Common *
 	{
 	   Edje_Part_Description_External *ed;
 
-	   ed = mem_alloc(SZ(Edje_Part_Description_External));
+           ed = mem_realloc(ced, SZ(Edje_Part_Description_External));
+           ed->external_params = NULL;
 
 	   ed->external_params = NULL;
 
@@ -941,6 +947,53 @@ static Edje_Part_Description_Common *
 }
 
 static void
+_edje_part_description_lookup_del(Edje_Part_Collection *pc, Edje_Part_Description_Common *ced, unsigned char type)
+{
+   switch (type)
+     {
+      case EDJE_PART_TYPE_RECTANGLE:
+      case EDJE_PART_TYPE_SWALLOW:
+      case EDJE_PART_TYPE_GROUP:
+         break;
+      case EDJE_PART_TYPE_TEXT:
+      case EDJE_PART_TYPE_TEXTBLOCK:
+        {
+           Edje_Part_Description_Text *ed = (Edje_Part_Description_Text*)ced;
+
+           data_queue_part_lookup(pc, NULL, &(ed->text.id_source));
+           data_queue_part_lookup(pc, NULL, &(ed->text.id_text_source));
+           break;
+        }
+      case EDJE_PART_TYPE_IMAGE:
+        {
+           int i;
+           Edje_Part_Description_Image *ed = (Edje_Part_Description_Image*)ced;
+           Edje_Part_Image_Id *iid;
+
+           data_queue_image_lookup(NULL, &(ed->image.id), NULL);
+
+           for (i = 0; i < ed->image.tweens_count; i++)
+             {
+                iid = ed->image.tweens[i];
+                data_queue_image_lookup(NULL, &(iid->id), NULL);
+             }
+           break;
+        }
+      case EDJE_PART_TYPE_PROXY:
+        {
+           Edje_Part_Description_Proxy *ed = (Edje_Part_Description_Proxy*)ced;
+
+           data_queue_part_lookup(pc, NULL, &(ed->proxy.id));
+           break;
+        }
+      case EDJE_PART_TYPE_BOX:
+      case EDJE_PART_TYPE_TABLE:
+      case EDJE_PART_TYPE_EXTERNAL:
+         break;
+     }
+}
+
+static void
 _edje_program_check(const char *name, Edje_Program *me, Edje_Program **pgrms, unsigned int count)
 {
    Edje_Part_Collection *pc;
@@ -2944,9 +2997,22 @@ st_collections_group_parts_part_name(void)
 static void
 st_collections_group_parts_part_type(void)
 {
+   Edje_Part_Collection *pc;
+   Edje_Part *ep;
+   int i;
+
    check_arg_count(1);
 
-   current_part->type = parse_enum(0,
+   pc = eina_list_data_get(eina_list_last(edje_collections));
+   ep = current_part;
+
+   if (ep->default_desc)
+     _edje_part_description_lookup_del(pc, ep->default_desc, ep->type);
+
+   for (i = 0; i < ep->other.desc_count; i++)
+     _edje_part_description_lookup_del(pc, ep->other.desc[i], ep->type);
+
+   ep->type = parse_enum(0,
                                    "NONE", EDJE_PART_TYPE_NONE,
                                    "RECT", EDJE_PART_TYPE_RECTANGLE,
                                    "TEXT", EDJE_PART_TYPE_TEXT,
@@ -2959,6 +3025,11 @@ st_collections_group_parts_part_type(void)
                                    "EXTERNAL", EDJE_PART_TYPE_EXTERNAL,
                                    "PROXY", EDJE_PART_TYPE_PROXY,
                                    NULL);
+   if (ep->default_desc)
+     ep->default_desc = _edje_part_description_alloc(ep->default_desc, ep->type, pc->part, ep->name);
+
+   for (i = 0; i < ep->other.desc_count; i++)
+     ep->other.desc[i] = _edje_part_description_alloc(ep->other.desc[i], ep->type, pc->part, ep->name);
 }
 
 /**
@@ -4070,7 +4141,7 @@ ob_collections_group_parts_part_description(void)
    pc = eina_list_data_get(eina_list_last(edje_collections));
    ep = current_part;
 
-   ed = _edje_part_description_alloc(ep->type, pc->part, ep->name);
+   ed = _edje_part_description_alloc(ed, ep->type, pc->part, ep->name);
 
    if (!ep->default_desc)
      {
------------------------------------------------------------------------------
10 Tips for Better Server Consolidation
Server virtualization is being driven by many needs.  
But none more important than the need to reduce IT complexity 
while improving strategic productivity.  Learn More! 
http://www.accelacomm.com/jaw/sdnl/114/51507609/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to