[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: pcb.git: branch: master updated (d30d31425fa318390e4632d5063e6bb655b01793)



The branch, master has been updated
       via  d30d31425fa318390e4632d5063e6bb655b01793 (commit)
      from  3afdb7efdaf6cc8094cc6143269e7df519183197 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 src/autoroute.c |    1 -
 src/macro.h     |  130 ++++++++++++++++++++++++-------------------------------
 2 files changed, 57 insertions(+), 74 deletions(-)


=================
 Commit Messages
=================

commit d30d31425fa318390e4632d5063e6bb655b01793
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    Remove memory allocation from src/macro.h
    
    When we started using GLists for various objects, we
    also changed the looping macros to allocate copies of
    the list in order to avoid problems with list integrity
    in case items were removed during the iteration.
    
    However, this caused memory leaks whenever there was an
    early return from the middle of the list. Bug lp-792139
    shows pcb using over 2Gb of memory and crashing when
    optimizing rats on a large board.
    
    This patch saves the next pointer before the loop body,
    rather than allocating a whole new list, to handle element
    deletions.
    
    Closes-bug: lp-792139

:100644 100644 c766c14... 9005259... M	src/autoroute.c
:100644 100644 b61f673... 7fa0927... M	src/macro.h

=========
 Changes
=========

commit d30d31425fa318390e4632d5063e6bb655b01793
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>

    Remove memory allocation from src/macro.h
    
    When we started using GLists for various objects, we
    also changed the looping macros to allocate copies of
    the list in order to avoid problems with list integrity
    in case items were removed during the iteration.
    
    However, this caused memory leaks whenever there was an
    early return from the middle of the list. Bug lp-792139
    shows pcb using over 2Gb of memory and crashing when
    optimizing rats on a large board.
    
    This patch saves the next pointer before the loop body,
    rather than allocating a whole new list, to handle element
    deletions.
    
    Closes-bug: lp-792139

diff --git a/src/autoroute.c b/src/autoroute.c
index c766c14..9005259 100644
--- a/src/autoroute.c
+++ b/src/autoroute.c
@@ -169,7 +169,6 @@ static hidGC ar_gc = 0;
 
 #define LIST_LOOP(init, which, x) do {\
      routebox_t *__next_one__ = (init);\
-   GList *__copy = NULL; /* DUMMY */\
    x = NULL;\
    if (!__next_one__)\
      assert(__next_one__);\
diff --git a/src/macro.h b/src/macro.h
index b61f673..7fa0927 100644
--- a/src/macro.h
+++ b/src/macro.h
@@ -163,7 +163,6 @@ extern int mem_any_set (unsigned char *, int);
 
 /* ---------------------------------------------------------------------------
  * some loop shortcuts
- * all object loops run backwards to prevent from errors when deleting objects
  *
  * a pointer is created from index addressing because the base pointer
  * may change when new memory is allocated;
@@ -171,12 +170,9 @@ extern int mem_any_set (unsigned char *, int);
  * all data is relativ to an objects name 'top' which can be either
  * PCB or PasteBuffer
  */
-#define END_LOOP  }                                                 \
-    g_list_free (__copy);                                           \
-  } while (0)
+#define END_LOOP  }} while (0)
 
 #define STYLE_LOOP(top)  do {                                       \
-        GList *__copy = NULL; /* DUMMY */                           \
         Cardinal n;                                                 \
         RouteStyleTypePtr style;                                    \
         for (n = 0; n < NUM_STYLES; n++)                            \
@@ -184,16 +180,15 @@ extern int mem_any_set (unsigned char *, int);
                 style = &(top)->RouteStyle[n]
 
 #define VIA_LOOP(top) do {                                          \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_copy ((top)->Via);                         \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = 0; __iter != NULL;                      \
-       __iter = g_list_next (__iter), n++) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (top)->Via, __next = g_list_next (__iter);          \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     PinType *via = __iter->data;
 
 #define DRILL_LOOP(top) do             {               \
         Cardinal        n;                                      \
-        GList *__copy = NULL; /* DUMMY */                       \
         DrillTypePtr    drill;                                  \
         for (n = 0; (top)->DrillN > 0 && n < (top)->DrillN; n++)                        \
         {                                                       \
@@ -201,7 +196,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define NETLIST_LOOP(top) do   {                         \
         Cardinal        n;                                      \
-        GList *__copy = NULL; /* DUMMY */                       \
         NetListTypePtr   netlist;                               \
         for (n = (top)->NetListN-1; n != -1; n--)               \
         {                                                       \
@@ -209,7 +203,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define NET_LOOP(top) do   {                             \
         Cardinal        n;                                      \
-        GList *__copy = NULL; /* DUMMY */                       \
         NetTypePtr   net;                                       \
         for (n = (top)->NetN-1; n != -1; n--)                   \
         {                                                       \
@@ -217,31 +210,29 @@ extern int mem_any_set (unsigned char *, int);
 
 #define CONNECTION_LOOP(net) do {                         \
         Cardinal        n;                                      \
-        GList *__copy = NULL; /* DUMMY */                       \
         ConnectionTypePtr       connection;                     \
         for (n = (net)->ConnectionN-1; n != -1; n--)            \
         {                                                       \
                 connection = & (net)->Connection[n]
 
 #define ELEMENT_LOOP(top) do {                                      \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((top)->Element));    \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (top)->ElementN - 1; __iter != NULL;    \
-       __iter = g_list_next (__iter), n--) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (top)->Element, __next = g_list_next (__iter);      \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     ElementType *element = __iter->data;
 
 #define RAT_LOOP(top) do {                                          \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((top)->Rat));        \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (top)->RatN - 1; __iter != NULL;        \
-       __iter = g_list_next (__iter), n--) {                        \
+  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;
 
 #define	ELEMENTTEXT_LOOP(element) do { 	\
 	Cardinal	n;				\
-	GList *__copy = NULL; /* DUMMY */		\
 	TextTypePtr	text;				\
 	for (n = MAX_ELEMENTNAMES-1; n != -1; n--)	\
 	{						\
@@ -249,7 +240,6 @@ extern int mem_any_set (unsigned char *, int);
 
 
 #define	ELEMENTNAME_LOOP(element) do	{ 			\
-	GList *__copy = NULL; /* DUMMY */			\
 	Cardinal	n;					\
 	char		*textstring;				\
 	for (n = MAX_ELEMENTNAMES-1; n != -1; n--)		\
@@ -257,78 +247,77 @@ extern int mem_any_set (unsigned char *, int);
 		textstring = (element)->Name[n].TextString
 
 #define PIN_LOOP(element) do {                                      \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_copy ((element)->Pin);                     \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = 0; __iter != NULL;                      \
-       __iter = g_list_next (__iter), n++) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (element)->Pin, __next = g_list_next (__iter);      \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     PinType *pin = __iter->data;
 
 #define PAD_LOOP(element) do {                                      \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_copy ((element)->Pad);                     \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = 0; __iter != NULL;                      \
-       __iter = g_list_next (__iter), n++) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (element)->Pad, __next = g_list_next (__iter);      \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     PadType *pad = __iter->data;
 
 #define ARC_LOOP(element) do {                                      \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((element)->Arc));    \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (element)->ArcN - 1; __iter != NULL;    \
-       __iter = g_list_next (__iter), n--) {                        \
+  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;
 
 #define ELEMENTLINE_LOOP(element) do {                              \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((element)->Line));   \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (element)->LineN - 1; __iter != NULL;   \
-       __iter = g_list_next (__iter), n--) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (element)->Line, __next = g_list_next (__iter);     \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     LineType *line = __iter->data;
 
 #define ELEMENTARC_LOOP(element) do {                               \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((element)->Arc));    \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (element)->ArcN - 1; __iter != NULL;    \
-       __iter = g_list_next (__iter), n--) {                        \
+  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;
 
 #define LINE_LOOP(layer) do {                                       \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((layer)->Line));     \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (layer)->LineN - 1; __iter != NULL;     \
-       __iter = g_list_next (__iter), n--) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (layer)->Line, __next = g_list_next (__iter);       \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     LineType *line = __iter->data;
 
 #define TEXT_LOOP(layer) do {                                       \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((layer)->Text));     \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (layer)->LineN - 1; __iter != NULL;     \
-       __iter = g_list_next (__iter), n--) {                        \
+  GList *__iter, *__next;                                           \
+  Cardinal n = 0;                                                   \
+  for (__iter = (layer)->Text, __next = g_list_next (__iter);       \
+       __iter != NULL;                                              \
+       __iter = __next, __next = g_list_next (__iter), n++) {       \
     TextType *text = __iter->data;
 
 #define POLYGON_LOOP(layer) do {                                    \
-  GList *__iter;                                                    \
-  GList *__copy = g_list_reverse (g_list_copy ((layer)->Polygon));  \
-  Cardinal n;                                                       \
-  for (__iter = __copy, n = (layer)->PolygonN - 1; __iter != NULL;  \
-       __iter = g_list_next (__iter), n--) {                        \
+  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;
 
 #define	POLYGONPOINT_LOOP(polygon) do	{	\
 	Cardinal			n;		\
-	GList *__copy = NULL; /* DUMMY */		\
 	PointTypePtr	point;				\
 	for (n = (polygon)->PointN-1; n != -1; n--)	\
 	{						\
 		point = &(polygon)->Points[n]
 
-#define ENDALL_LOOP }} while (0);  }} while (0)
+#define ENDALL_LOOP }} while (0); }} while(0)
 
 #define	ALLPIN_LOOP(top)	\
         ELEMENT_LOOP(top); \
@@ -445,7 +434,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define POINTER_LOOP(top) do	{	\
 	Cardinal	n;			\
-	GList *__copy = NULL; /* DUMMY */	\
 	void	**ptr;				\
 	for (n = (top)->PtrN-1; n != -1; n--)	\
 	{					\
@@ -453,7 +441,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define MENU_LOOP(top)	do {	\
 	Cardinal	l;			\
-	GList *__copy = NULL; /* DUMMY */	\
 	LibraryMenuTypePtr menu;		\
 	for (l = (top)->MenuN-1; l != -1; l--)	\
 	{					\
@@ -461,7 +448,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define ENTRY_LOOP(top) do	{	\
 	Cardinal	n;			\
-	GList *__copy = NULL; /* DUMMY */	\
 	LibraryEntryTypePtr entry;		\
 	for (n = (top)->EntryN-1; n != -1; n--)	\
 	{					\
@@ -469,7 +455,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define GROUP_LOOP(data, group) do { 	\
 	Cardinal entry; \
-	GList *__copy = NULL; /* DUMMY */	\
         for (entry = 0; entry < ((PCBTypePtr)(data->pcb))->LayerGroups.Number[(group)]; entry++) \
         { \
 		LayerTypePtr layer;		\
@@ -481,7 +466,6 @@ extern int mem_any_set (unsigned char *, int);
 
 #define LAYER_LOOP(data, ml) do { \
         Cardinal n; \
-        GList *__copy = NULL; /* DUMMY */ \
 	for (n = 0; n < ml; n++) \
 	{ \
 	   LayerTypePtr layer = (&data->Layer[(n)]);




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs