Index: trunk/doc-rnd/TODO =================================================================== --- trunk/doc-rnd/TODO (revision 1181) +++ trunk/doc-rnd/TODO (revision 1182) @@ -9,6 +9,7 @@ - can't click into a text and get it selected (rtree?)?! - closing the shift+D pin dialog double frees()? - buffer element breakup double frees? + - drawing new rats cause double free? - get rid of lists.h Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 1181) +++ trunk/src/Makefile.in (revision 1182) @@ -47,6 +47,7 @@ list_pad.o list_pin.o list_poly.o + list_rat.o lrealpath.o main.o mirror.o Index: trunk/src/buffer.c =================================================================== --- trunk/src/buffer.c (revision 1181) +++ trunk/src/buffer.c (revision 1182) @@ -243,10 +243,8 @@ { r_delete_entry(Source->rat_tree, (BoxType *) rat); - Source->Rat = g_list_remove(Source->Rat, rat); - Source->RatN--; - Dest->Rat = g_list_append(Dest->Rat, rat); - Dest->RatN++; + ratlist_remove(rat); + ratlist_append(&Dest->Rat, rat); CLEAR_FLAG(FOUNDFLAG, rat); Index: trunk/src/file.c =================================================================== --- trunk/src/file.c (revision 1181) +++ trunk/src/file.c (revision 1182) @@ -633,10 +633,11 @@ */ static void WritePCBRatData(FILE * FP) { - GList *iter; + gdl_iterator_t it; + RatType *line; + /* write information about rats */ - for (iter = PCB->Data->Rat; iter != NULL; iter = g_list_next(iter)) { - RatType *line = iter->data; + ratlist_foreach(&PCB->Data->Rat, &it, line) { pcb_fprintf(FP, "Rat[%mr %mr %d %mr %mr %d ", line->Point1.X, line->Point1.Y, line->group1, line->Point2.X, line->Point2.Y, line->group2); fprintf(FP, " %s]\n", F2S(line, RATLINE_TYPE)); Index: trunk/src/find.c =================================================================== --- trunk/src/find.c (revision 1181) +++ trunk/src/find.c (revision 1182) @@ -658,8 +658,8 @@ PVList.DrawLocation = 0; PVList.Number = 0; /* Initialize ratline data */ - RatList.Data = (void **) calloc(PCB->Data->RatN, sizeof(RatTypePtr)); - RatList.Size = PCB->Data->RatN; + RatList.Size = ratlist_length(&PCB->Data->Rat); + RatList.Data = (void **) calloc(RatList.Size, sizeof(RatTypePtr)); RatList.Location = 0; RatList.DrawLocation = 0; RatList.Number = 0; Index: trunk/src/global.h =================================================================== --- trunk/src/global.h (revision 1181) +++ trunk/src/global.h (revision 1182) @@ -67,6 +67,7 @@ #include "list_poly.h" #include "list_pad.h" #include "list_pin.h" +#include "list_rat.h" #include "hid.h" #include "polyarea.h" @@ -195,11 +196,10 @@ } LayerType, *LayerTypePtr; typedef struct { /* holds all objects */ - Cardinal RatN; /* and rat-lines */ int LayerN; /* number of layers in this board */ pinlist_t Via; elementlist_t Element; - GList *Rat; + ratlist_t Rat; rtree_t *via_tree, *element_tree, *pin_tree, *pad_tree, *name_tree[3], /* for element names */ *rat_tree; struct PCBType *pcb; Index: trunk/src/global_objs.h =================================================================== --- trunk/src/global_objs.h (revision 1181) +++ trunk/src/global_objs.h (revision 1182) @@ -112,6 +112,7 @@ typedef struct rat_st { /* a rat-line */ ANYLINEFIELDS; Cardinal group1, group2; /* the layer group each point is on */ + gdl_elem_t link; /* an arc is in a list on a design */ } RatType, *RatTypePtr; struct pad_st { /* a SMD pad */ Index: trunk/src/hid/lesstif/main.c =================================================================== --- trunk/src/hid/lesstif/main.c (revision 1181) +++ trunk/src/hid/lesstif/main.c (revision 1182) @@ -2631,10 +2631,10 @@ static int old_nrats = -1; static char buf[20]; - if (old_nrats != PCB->Data->RatN) { - old_nrats = PCB->Data->RatN; - sprintf(buf, "%d rat%s", PCB->Data->RatN, PCB->Data->RatN == 1 ? "" : "s"); - if (PCB->Data->RatN) { + if (old_nrats != ratlist_length(&PCB->Data->Rat)) { + old_nrats = ratlist_length(&PCB->Data->Rat); + sprintf(buf, "%d rat%s", ratlist_length(&PCB->Data->Rat), ratlist_length(&PCB->Data->Rat) == 1 ? "" : "s"); + if (ratlist_length(&PCB->Data->Rat)) { XtManageChild(XtParent(m_rats)); XtManageChild(m_rats); n = 0; @@ -2646,7 +2646,7 @@ stdarg(XmNlabelString, XmStringCreatePCB(buf)); XtSetValues(m_rats, args, n); - if (!PCB->Data->RatN) { + if (!ratlist_length(&PCB->Data->Rat)) { n = 0; stdarg(XmNleftWidget, m_mode); XtSetValues(XtParent(m_status), args, n); Index: trunk/src/list_rat.c =================================================================== --- trunk/src/list_rat.c (nonexistent) +++ trunk/src/list_rat.c (revision 1182) @@ -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_rat.h" +#include Index: trunk/src/list_rat.h =================================================================== --- trunk/src/list_rat.h (nonexistent) +++ trunk/src/list_rat.h (revision 1182) @@ -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_RAT_H +#define LIST_RAT_H + +/* List of Rats */ +#define TDL(x) ratlist_ ## x +#define TDL_LIST_T ratlist_t +#define TDL_ITEM_T RatType +#define TDL_FIELD link +#define TDL_SIZE_T size_t +#define TDL_FUNC + +#define ratlist_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 1181) +++ trunk/src/macro.h (revision 1182) @@ -223,12 +223,9 @@ pinlist_foreach(&(top)->Element, &__it__, element) { #define RAT_LOOP(top) do { \ - GList *__iter, *__next; \ - Cardinal n = 0; \ - for (__iter = (top)->Rat, __next = g_list_next (__iter); \ - __iter != NULL; \ - __iter = __next, __next = g_list_next (__iter), n++) { \ - RatType *line = __iter->data; + RatType *line; \ + gdl_iterator_t __it__; \ + ratlist_foreach(&(top)->Rat, &__it__, line) { #define ELEMENTTEXT_LOOP(element) do { \ Cardinal n; \ @@ -237,7 +234,6 @@ { \ text = &(element)->Name[n] - #define ELEMENTNAME_LOOP(element) do { \ Cardinal n; \ char *textstring; \ @@ -260,7 +256,6 @@ gdl_iterator_t __it__; \ linelist_foreach(&(element)->Arc, &__it__, arc) { - #define ELEMENTLINE_LOOP(element) do { \ LineType *line; \ gdl_iterator_t __it__; \ @@ -267,12 +262,9 @@ linelist_foreach(&(element)->Line, &__it__, line) { #define ELEMENTARC_LOOP(element) do { \ - GList *__iter, *__next; \ - Cardinal n = 0; \ - for (__iter = (element)->Arc, __next = g_list_next (__iter); \ - __iter != NULL; \ - __iter = __next, __next = g_list_next (__iter), n++) { \ - ArcType *arc = __iter->data; + ArcType *arc; \ + gdl_iterator_t __it__; \ + linelist_foreach(&(element)->Arc, &__it__, arc) { #define LINE_LOOP(layer) do { \ LineType *line; \ Index: trunk/src/mymem.c =================================================================== --- trunk/src/mymem.c (revision 1181) +++ trunk/src/mymem.c (revision 1182) @@ -49,9 +49,6 @@ /* --------------------------------------------------------------------------- * local prototypes */ -static void DSRealloc(DynamicStringTypePtr, size_t); - - /* memset object to 0, but keep the link field */ #define reset_obj_mem(type, obj) \ do { \ @@ -60,16 +57,6 @@ obj->link = __lnk__; \ } while(0) \ - -/* This API is quite new, provide a version here */ -#if !GLIB_CHECK_VERSION (2, 28, 0) -static void g_list_free_full(GList * list, GDestroyNotify free_func) -{ - g_list_foreach(list, (GFunc) free_func, NULL); - g_list_free(list); -} -#endif - /* --------------------------------------------------------------------------- * get next slot for a rubberband connection, allocates memory if necessary */ @@ -229,7 +216,8 @@ void RemoveFreeVia(PinType * data) { - g_slice_free(PinType, data); + pinlist_remove(data); + free(data); } /* --------------------------------------------------------------------------- @@ -239,16 +227,16 @@ { RatType *new_obj; - new_obj = g_slice_new0(RatType); - data->Rat = g_list_append(data->Rat, new_obj); - data->RatN++; + new_obj = calloc(sizeof(RatType), 1); + ratlist_append(&data->Rat, new_obj); return new_obj; } -static void FreeRat(RatType * data) +void RemoveFreeRat(RatType * data) { - g_slice_free(RatType, data); + ratlist_remove(data); + free(data); } /* --------------------------------------------------------------------------- @@ -652,7 +640,7 @@ } END_LOOP; list_map0(&data->Element, ElementType, RemoveFreeElement); - g_list_free_full(data->Rat, (GDestroyNotify) FreeRat); + list_map0(&data->Rat, RatType, RemoveFreeRat); for (layer = data->Layer, i = 0; i < MAX_LAYER + 2; layer++, i++) { FreeAttributeListMemory(&layer->Attributes); Index: trunk/src/mymem.h =================================================================== --- trunk/src/mymem.h (revision 1181) +++ trunk/src/mymem.h (revision 1182) @@ -101,6 +101,7 @@ void RemoveFreePad(PadType * data); void RemoveFreeVia(PinType * data); void RemoveFreeElement(ElementType * data); +void RemoveFreeRat(RatType * data); #ifdef NEED_STRDUP char *strdup(const char *); Index: trunk/src/rats.c =================================================================== --- trunk/src/rats.c (revision 1181) +++ trunk/src/rats.c (revision 1182) @@ -726,13 +726,13 @@ if (changed) { IncrementUndoSerialNumber(); - if (PCB->Data->RatN > 0) { - Message("%d rat line%s remaining\n", PCB->Data->RatN, PCB->Data->RatN > 1 ? "s" : ""); + if (ratlist_length(&PCB->Data->Rat) > 0) { + Message("%d rat line%s remaining\n", ratlist_length(&PCB->Data->Rat), ratlist_length(&PCB->Data->Rat) > 1 ? "s" : ""); } return (true); } if (!SelectedOnly && !Warned) { - if (!PCB->Data->RatN && !badnet) + if (!ratlist_length(&PCB->Data->Rat) && !badnet) Message(_("Congratulations!!\n" "The layout is complete and has no shorted nets.\n")); else Message(_("Nothing more to add, but there are\n" Index: trunk/src/remove.c =================================================================== --- trunk/src/remove.c (revision 1181) +++ trunk/src/remove.c (revision 1182) @@ -260,11 +260,7 @@ if (DestroyTarget->rat_tree) r_delete_entry(DestroyTarget->rat_tree, &Rat->BoundingBox); - DestroyTarget->Rat = g_list_remove(DestroyTarget->Rat, Rat); - DestroyTarget->RatN--; - - g_slice_free(RatType, Rat); - + RemoveFreeRat(Rat); return NULL; } Index: trunk/src_plugins/autoroute/autoroute.c =================================================================== --- trunk/src_plugins/autoroute/autoroute.c (revision 1181) +++ trunk/src_plugins/autoroute/autoroute.c (revision 1182) @@ -4542,7 +4542,7 @@ return (false); } } - if (PCB->Data->RatN == 0) + if (ratlist_length(&PCB->Data->Rat) == 0) return (false); SaveFindFlag(DRCFLAG); rd = CreateRouteData();