Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 1177) +++ trunk/src/Makefile.in (revision 1178) @@ -43,6 +43,7 @@ list_arc.o list_line.o list_text.o + list_poly.o lrealpath.o main.o mirror.o Index: trunk/src/buffer.c =================================================================== --- trunk/src/buffer.c (revision 1177) +++ trunk/src/buffer.c (revision 1178) @@ -331,10 +331,8 @@ r_delete_entry(layer->polygon_tree, (BoxType *) polygon); - layer->Polygon = g_list_remove(layer->Polygon, polygon); - layer->PolygonN--; - lay->Polygon = g_list_append(lay->Polygon, polygon); - lay->PolygonN++; + polylist_remove(polygon); + polylist_append(&lay->Polygon, polygon); CLEAR_FLAG(FOUNDFLAG, polygon); Index: trunk/src/file.c =================================================================== --- trunk/src/file.c (revision 1177) +++ trunk/src/file.c (revision 1178) @@ -756,11 +756,11 @@ */ static void WriteLayerData(FILE * FP, Cardinal Number, LayerTypePtr layer) { - GList *n; gdl_iterator_t it; LineType *line; ArcType *arc; TextType *text; + PolygonType *polygon; /* write information about non empty layers */ if (!LAYER_IS_EMPTY(layer) || (layer->Name && *layer->Name)) { @@ -784,8 +784,7 @@ PrintQuotedString(FP, (char *) EMPTY(text->TextString)); fprintf(FP, " %s]\n", F2S(text, TEXT_TYPE)); } - for (n = layer->Polygon; n != NULL; n = g_list_next(n)) { - PolygonType *polygon = n->data; + textlist_foreach(&layer->Polygon, &it, polygon) { int p, i = 0; Cardinal hole = 0; fprintf(FP, "\tPolygon(%s)\n\t(", F2S(polygon, POLYGON_TYPE)); Index: trunk/src/find.c =================================================================== --- trunk/src/find.c (revision 1177) +++ trunk/src/find.c (revision 1178) @@ -619,7 +619,6 @@ LayerTypePtr layer = LAYER_PTR(i); if (linelist_length(&layer->Line)) { - /* allocate memory for line pointer lists */ LineList[i].Size = linelist_length(&layer->Line); LineList[i].Data = (void **) calloc(LineList[i].Size, sizeof(LineTypePtr)); } @@ -627,12 +626,9 @@ ArcList[i].Size = arclist_length(&layer->Arc); ArcList[i].Data = (void **) calloc(ArcList[i].Size, sizeof(ArcTypePtr)); } - - - /* allocate memory for polygon list */ - if (layer->PolygonN) { - PolygonList[i].Data = (void **) calloc(layer->PolygonN, sizeof(PolygonTypePtr)); - PolygonList[i].Size = layer->PolygonN; + if (polylist_length(&layer->Polygon)) { + PolygonList[i].Size = polylist_length(&layer->Polygon); + PolygonList[i].Data = (void **) calloc(PolygonList[i].Size, sizeof(PolygonTypePtr)); } /* clear some struct members */ @@ -1687,6 +1683,9 @@ /* handle normal layers */ if (layer < max_copper_layer) { + PolygonType *polygon; + gdl_iterator_t it; + info.layer = layer; /* add arcs */ if (setjmp(info.env) == 0) @@ -1700,8 +1699,7 @@ return true; /* now check all polygons */ - for (i = PCB->Data->Layer[layer].Polygon; i != NULL; i = g_list_next(i)) { - PolygonType *polygon = i->data; + polylist_foreach(&(PCB->Data->Layer[layer].Polygon), &it, polygon) { if (!TEST_FLAG(TheFlag, polygon) && IsArcInPolygon(Arc, polygon) && ADD_POLYGON_TO_LIST(layer, polygon, ARC_TYPE, Arc, FCT_COPPER)) return true; @@ -1817,9 +1815,10 @@ return true; /* now check all polygons */ if (PolysTo) { - GList *i; - for (i = PCB->Data->Layer[layer].Polygon; i != NULL; i = g_list_next(i)) { - PolygonType *polygon = i->data; + gdl_iterator_t it; + PolygonType *polygon; + + polylist_foreach(&(PCB->Data->Layer[layer].Polygon), &it, polygon) { if (!TEST_FLAG(TheFlag, polygon) && IsLineInPolygon(Line, polygon) && ADD_POLYGON_TO_LIST(layer, polygon, LINE_TYPE, Line, FCT_COPPER)) return true; @@ -1888,7 +1887,8 @@ /* handle normal layers */ if (layer < max_copper_layer) { - GList *i; + gdl_iterator_t it; + PolygonType *polygon; /* find the first line that touches coordinates */ @@ -1902,8 +1902,7 @@ return (true); /* now check all polygons */ - for (i = PCB->Data->Layer[layer].Polygon; i != NULL; i = g_list_next(i)) { - PolygonType *polygon = i->data; + polylist_foreach(&(PCB->Data->Layer[layer].Polygon), &it, polygon) { if (!TEST_FLAG(TheFlag, polygon) && IsLineInPolygon(Line, polygon)) return (true); @@ -2275,11 +2274,11 @@ /* handle normal layers */ if (layer < max_copper_layer) { - GList *i; + gdl_iterator_t it; + PolygonType *polygon; /* check all polygons */ - for (i = PCB->Data->Layer[layer].Polygon; i != NULL; i = g_list_next(i)) { - PolygonType *polygon = i->data; + polylist_foreach(&(PCB->Data->Layer[layer].Polygon), &it, polygon) { if (!TEST_FLAG(TheFlag, polygon) && IsPolygonInPolygon(polygon, Polygon) && ADD_POLYGON_TO_LIST(layer, polygon, POLYGON_TYPE, Polygon, FCT_COPPER)) Index: trunk/src/global.h =================================================================== --- trunk/src/global.h (revision 1177) +++ trunk/src/global.h (revision 1178) @@ -64,6 +64,7 @@ #include "list_line.h" #include "list_arc.h" #include "list_text.h" +#include "list_poly.h" #include "hid.h" #include "polyarea.h" @@ -195,11 +196,9 @@ typedef struct { /* holds information about one layer */ char *Name; /* layer name */ - Cardinal /* number of... */ - PolygonN; /* polygons */ linelist_t Line; textlist_t Text; - GList *Polygon; + polylist_t Polygon; arclist_t Arc; rtree_t *line_tree, *text_tree, *polygon_tree, *arc_tree; bool On; /* visible flag */ Index: trunk/src/global_objs.h =================================================================== --- trunk/src/global_objs.h (revision 1177) +++ trunk/src/global_objs.h (revision 1178) @@ -95,7 +95,7 @@ Cardinal *HoleIndex; /* Index of hole data within the Points array */ Cardinal HoleIndexN; /* number of holes in polygon */ Cardinal HoleIndexMax; /* max number from malloc() */ - + gdl_elem_t link; /* a text is in a list of a layer */ }; typedef struct arc_st { /* holds information about arcs */ Index: trunk/src/list_poly.c =================================================================== --- trunk/src/list_poly.c (nonexistent) +++ trunk/src/list_poly.c (revision 1178) @@ -0,0 +1,26 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#define TDL_DONT_UNDEF +#include "global_objs.h" +#include "list_poly.h" +#include Index: trunk/src/list_poly.h =================================================================== --- trunk/src/list_poly.h (nonexistent) +++ trunk/src/list_poly.h (revision 1178) @@ -0,0 +1,41 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef LIST_POLY_H +#define LIST_POLY_H + +/* List of Lines */ +#define TDL(x) polylist_ ## x +#define TDL_LIST_T polylist_t +#define TDL_ITEM_T PolygonType +#define TDL_FIELD link +#define TDL_SIZE_T size_t +#define TDL_FUNC + +#define polylist_foreach(list, iterator, loop_elem) \ + gdl_foreach_((&((list)->lst)), (iterator), (loop_elem)) + + +#include +#include + +#endif Index: trunk/src/macro.h =================================================================== --- trunk/src/macro.h (revision 1177) +++ trunk/src/macro.h (revision 1178) @@ -297,12 +297,9 @@ linelist_foreach(&(layer)->Text, &__it__, text) { #define POLYGON_LOOP(layer) do { \ - GList *__iter, *__next; \ - Cardinal n = 0; \ - for (__iter = (layer)->Polygon, __next = g_list_next (__iter); \ - __iter != NULL; \ - __iter = __next, __next = g_list_next (__iter), n++) { \ - PolygonType *polygon = __iter->data; + PolygonType *polygon; \ + gdl_iterator_t __it__; \ + linelist_foreach(&(layer)->Polygon, &__it__, polygon) { #define POLYGONPOINT_LOOP(polygon) do { \ Cardinal n; \ @@ -467,5 +464,5 @@ #define LAYER_IS_EMPTY(layer) LAYER_IS_EMPTY_((layer)) #define LAYER_IS_EMPTY_(layer) \ - ((linelist_length(&layer->Line) == 0) && (arclist_length(&layer->Arc) == 0) && (layer->PolygonN == 0) && (textlist_length(&layer->Text) == 0)) + ((linelist_length(&layer->Line) == 0) && (arclist_length(&layer->Arc) == 0) && (polylist_length(&layer->Polygon) == 0) && (textlist_length(&layer->Text) == 0)) #endif Index: trunk/src/move.c =================================================================== --- trunk/src/move.c (revision 1177) +++ trunk/src/move.c (revision 1178) @@ -614,10 +614,8 @@ { r_delete_entry(Source->polygon_tree, (BoxType *) polygon); - Source->Polygon = g_list_remove(Source->Polygon, polygon); - Source->PolygonN--; - Destination->Polygon = g_list_append(Destination->Polygon, polygon); - Destination->PolygonN++; + polylist_remove(polygon); + polylist_append(&Destination->Polygon, polygon); if (!Destination->polygon_tree) Destination->polygon_tree = r_create_tree(NULL, 0, 0); Index: trunk/src/mymem.c =================================================================== --- trunk/src/mymem.c (revision 1177) +++ trunk/src/mymem.c (revision 1178) @@ -307,16 +307,16 @@ { PolygonType *new_obj; - new_obj = g_slice_new0(PolygonType); - layer->Polygon = g_list_append(layer->Polygon, new_obj); - layer->PolygonN++; + new_obj = calloc(sizeof(PolygonType), 1); + polylist_append(&layer->Polygon, new_obj); return new_obj; } -static void FreePolygon(PolygonType * data) +void RemoveFreePolygon(PolygonType * data) { - g_slice_free(PolygonType, data); + polylist_remove(data); + free(data); } /* --------------------------------------------------------------------------- @@ -670,7 +670,7 @@ FreePolygonMemory(polygon); } END_LOOP; - g_list_free_full(layer->Polygon, (GDestroyNotify) FreePolygon); + list_map0(&layer->Polygon, PolygonType, RemoveFreePolygon); if (layer->line_tree) r_destroy_tree(&layer->line_tree); if (layer->arc_tree) Index: trunk/src/mymem.h =================================================================== --- trunk/src/mymem.h (revision 1177) +++ trunk/src/mymem.h (revision 1178) @@ -96,6 +96,7 @@ void RemoveFreeArc(ArcType * data); void RemoveFreeLine(LineType * data); void RemoveFreeText(TextType * data); +void RemoveFreePolygon(PolygonType * data); #ifdef NEED_STRDUP char *strdup(const char *); Index: trunk/src/remove.c =================================================================== --- trunk/src/remove.c (revision 1177) +++ trunk/src/remove.c (revision 1178) @@ -167,11 +167,8 @@ r_delete_entry(Layer->polygon_tree, (BoxTypePtr) Polygon); FreePolygonMemory(Polygon); - Layer->Polygon = g_list_remove(Layer->Polygon, Polygon); - Layer->PolygonN--; + RemoveFreePolygon(Polygon); - g_slice_free(PolygonType, Polygon); - return NULL; } Index: trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c =================================================================== --- trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (revision 1177) +++ trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (revision 1178) @@ -66,7 +66,7 @@ switch(fld) { case LFLD_NUM_LINES: return linelist_length(&(PCB->Data->Layer[layer].Line)); case LFLD_NUM_TEXTS: return textlist_length(&(PCB->Data->Layer[layer].Text)); - case LFLD_NUM_POLYS: return PCB->Data->Layer[layer].PolygonN; + case LFLD_NUM_POLYS: return polylist_length(&(PCB->Data->Layer[layer].Polygon)); case LFLD_NUM_ARCS: return arclist_length(&(PCB->Data->Layer[layer].Arc)); case LFLD_VISIBLE: return PCB->Data->Layer[layer].On; case LFLD_NODRC: return PCB->Data->Layer[layer].no_drc; Index: trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c =================================================================== --- trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (revision 1177) +++ trunk/src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (revision 1178) @@ -145,7 +145,7 @@ select2(s, OM_ARC, flag, &layer->Arc); select2(s, OM_LINE, flag, &layer->Line); select2(s, OM_TEXT, flag, &layer->Text); - select(s, OM_POLYGON, flag, layer->Polygon); + select2(s, OM_POLYGON, flag, &layer->Polygon); } select(s, OM_VIA, flag, PCB->Data->Via); /* select(s, OM_PIN, flag, PCB->Data->Pin, PCB->Data->PinN); /* TODO */