Index: trunk/src/netlist.c =================================================================== --- trunk/src/netlist.c (revision 29011) +++ trunk/src/netlist.c (revision 29012) @@ -50,6 +50,8 @@ #include "netlist.h" #include +#include + void pcb_net_term_free_fields(pcb_net_term_t *term) { pcb_attribute_free(&term->Attributes); @@ -180,10 +182,12 @@ return pcb_true; } -static pcb_net_t *pcb_net_alloc(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname) +static pcb_net_t *pcb_net_alloc(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname, pcb_net_alloc_t alloc) { pcb_net_t *net; + assert(alloc != 0); + net = calloc(sizeof(pcb_net_t), 1); net->type = PCB_OBJ_NET; net->parent_type = PCB_PARENT_BOARD; @@ -193,7 +197,7 @@ return net; } -pcb_net_t *pcb_net_get(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname, pcb_bool alloc) +pcb_net_t *pcb_net_get(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname, pcb_net_alloc_t alloc) { pcb_net_t *net; @@ -208,7 +212,7 @@ return net; if (alloc) - return pcb_net_alloc(pcb, nl, netname); + return pcb_net_alloc(pcb, nl, netname, alloc); return NULL; } @@ -767,7 +771,7 @@ pcb_net_term_t *src_term, *dst_term; src_net = e->value; - dst_net = pcb_net_alloc(pcb, dst, src_net->name); + dst_net = pcb_net_alloc(pcb, dst, src_net->name, PCB_NETA_ALLOC); dst_net->export_tmp = src_net->export_tmp; dst_net->inhibit_rats = src_net->inhibit_rats; pcb_attribute_copy_all(&dst_net->Attributes, &src_net->Attributes); @@ -864,7 +868,7 @@ } else ratname = ratname_; - target_net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], ratname, 1); + target_net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], ratname, PCB_NETA_ALLOC); assert(target_net != NULL); if (ratname != ratname_) Index: trunk/src/netlist.h =================================================================== --- trunk/src/netlist.h (revision 29011) +++ trunk/src/netlist.h (revision 29012) @@ -33,6 +33,13 @@ #include "board.h" #include "obj_common.h" +/* some calls may create new nets as side effect; they are normally controlled by this enum */ +typedef enum { + PCB_NETA_NOALLOC=0, + PCB_NETA_ALLOC=1, + PCB_NETA_ALLOC_UNDOABLE=2 +} pcb_net_alloc_t; + struct pcb_net_term_s { PCB_ANY_OBJ_FIELDS; char *refdes; @@ -82,7 +89,7 @@ void pcb_netlist_copy(pcb_board_t *pcb, pcb_netlist_t *dst, pcb_netlist_t *src); /* Look up (or allocate) a net by name within a netlist. Returns NULL on error */ -pcb_net_t *pcb_net_get(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname, pcb_bool alloc); +pcb_net_t *pcb_net_get(pcb_board_t *pcb, pcb_netlist_t *nl, const char *netname, pcb_net_alloc_t alloc); pcb_net_t *pcb_net_get_icase(pcb_board_t *pcb, pcb_netlist_t *nl, const char *name); /* read-only, case-insnensitive */ pcb_net_t *pcb_net_get_regex(pcb_board_t *pcb, pcb_netlist_t *nl, const char *regex); pcb_net_t *pcb_net_get_user(pcb_board_t *pcb, pcb_netlist_t *nl, const char *name_or_rx); /* run all three above in order, until one succeeds */ Index: trunk/src/netlist_act.c =================================================================== --- trunk/src/netlist_act.c (revision 29011) +++ trunk/src/netlist_act.c (revision 29012) @@ -133,7 +133,7 @@ if ((*netname == '\0') || (*pinname == '\0')) return -1; - n = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT+(!!patch)], netname, 1); + n = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT+(!!patch)], netname, PCB_NETA_ALLOC); t = pcb_net_term_get_by_pinname(n, pinname, 0); if (t == NULL) { if (!patch) { @@ -328,7 +328,7 @@ pcb_message(PCB_MSG_ERROR, "Net name '%s' already in use\n", to); return 1; } - nto = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_EDITED], to, 1); + nto = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_EDITED], to, PCB_NETA_ALLOC); } /* move over all terminals from nfrom to nto */ @@ -600,7 +600,7 @@ return 0; } - net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_EDITED], netname, 1); + net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_EDITED], netname, PCB_NETA_ALLOC); free(free_netname); if (net == NULL) { Index: trunk/src/rats_patch.c =================================================================== --- trunk/src/rats_patch.c (revision 29011) +++ trunk/src/rats_patch.c (revision 29012) @@ -171,7 +171,7 @@ if (refdeslen < 1) return 1; /* invalid id */ - net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], patch->arg1.net_name, 1); + net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], patch->arg1.net_name, PCB_NETA_ALLOC); for(term = pcb_termlist_first(&net->conns); term != NULL; term = pcb_termlist_next(term)) { if ((strncmp(patch->id, term->refdes, refdeslen) == 0) && (strcmp(termid, term->term) == 0)) { if (del) { @@ -199,7 +199,7 @@ static int rats_patch_apply_attrib(pcb_board_t *pcb, pcb_ratspatch_line_t *patch) { - pcb_net_t *net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], patch->id, 1); + pcb_net_t *net = pcb_net_get(pcb, &pcb->netlist[PCB_NETLIST_EDITED], patch->id, PCB_NETA_ALLOC); if (net == NULL) return 1; if ((patch->arg2.attrib_val == NULL) || (*patch->arg2.attrib_val == '\0')) Index: trunk/src_plugins/import_edif/edif.c =================================================================== --- trunk/src_plugins/import_edif/edif.c (revision 29011) +++ trunk/src_plugins/import_edif/edif.c (revision 29012) @@ -189,7 +189,7 @@ pair_list_free(nodes); return; } - net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], name->str1, 1); + net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], name->str1, PCB_NETA_ALLOC); free(name->str1); /* if renamed str2 also exists and must be freed */ if ( name->str2 ) free(name->str2); Index: trunk/src_plugins/import_edif/edif.y =================================================================== --- trunk/src_plugins/import_edif/edif.y (revision 29011) +++ trunk/src_plugins/import_edif/edif.y (revision 29012) @@ -112,7 +112,7 @@ pair_list_free(nodes); return; } - net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], name->str1, 1); + net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], name->str1, PCB_NETA_ALLOC); free(name->str1); /* if renamed str2 also exists and must be freed */ if ( name->str2 ) free(name->str2); Index: trunk/src_plugins/import_netlist/import_netlist.c =================================================================== --- trunk/src_plugins/import_netlist/import_netlist.c (revision 29011) +++ trunk/src_plugins/import_netlist/import_netlist.c (revision 29012) @@ -127,7 +127,7 @@ while (inputline[i] != '\0' && BLANK(inputline[i])) i++; if (kind == 0) { - net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], temp, 1); + net = pcb_net_get(PCB, &PCB->netlist[PCB_NETLIST_INPUT], temp, PCB_NETA_ALLOC); kind++; } else { Index: trunk/src_plugins/io_kicad/read.c =================================================================== --- trunk/src_plugins/io_kicad/read.c (revision 29011) +++ trunk/src_plugins/io_kicad/read.c (revision 29012) @@ -1545,7 +1545,7 @@ if (*netname == '\0') return 0; /* do not create the anonymous net (is it the no-connect net in kicad?) */ - if (pcb_net_get(st->pcb, &st->pcb->netlist[PCB_NETLIST_INPUT], netname, 1) == NULL) + if (pcb_net_get(st->pcb, &st->pcb->netlist[PCB_NETLIST_INPUT], netname, PCB_NETA_ALLOC) == NULL) return kicad_error(subtree->next, "Failed to create net %s", netname); return 0; Index: trunk/src_plugins/io_lihata/read.c =================================================================== --- trunk/src_plugins/io_lihata/read.c (revision 29011) +++ trunk/src_plugins/io_lihata/read.c (revision 29012) @@ -2132,7 +2132,7 @@ style = nstyle->data.text.value; } - net = pcb_net_get(pcb, nl, nnet->name, 1); + net = pcb_net_get(pcb, nl, nnet->name, PCB_NETA_ALLOC); if (net == NULL) return iolht_error(nnet, "failed to add network\n"); if (nconn != NULL) { Index: trunk/src_plugins/io_mentor_cell/read.c =================================================================== --- trunk/src_plugins/io_mentor_cell/read.c (revision 29011) +++ trunk/src_plugins/io_mentor_cell/read.c (revision 29012) @@ -995,7 +995,7 @@ const hkp_netclass_t *nc = NULL; if (strcmp(netname, "Unconnected_Net") != 0) - pcb_net_get(ctx->pcb, &ctx->pcb->netlist[PCB_NETLIST_INPUT], netname, 1); + pcb_net_get(ctx->pcb, &ctx->pcb->netlist[PCB_NETLIST_INPUT], netname, PCB_NETA_ALLOC); for(n = netroot->first_child; n != NULL; n = n->next) { if ((strcmp(n->argv[0], "TRACE") == 0) || (strcmp(n->argv[0], "CONDUCTIVE_AREA") == 0)) { Index: trunk/src_plugins/io_mentor_cell/read_net.c =================================================================== --- trunk/src_plugins/io_mentor_cell/read_net.c (revision 29011) +++ trunk/src_plugins/io_mentor_cell/read_net.c (revision 29012) @@ -153,7 +153,7 @@ for(nnet = net_tree.root->first_child; nnet != NULL; nnet = nnet->next) { if (strcmp(nnet->argv[0], "NETNAME") == 0) { - pcb_net_t *net = pcb_net_get(ctx->pcb, &ctx->pcb->netlist[PCB_NETLIST_INPUT], nnet->argv[1], 1); + pcb_net_t *net = pcb_net_get(ctx->pcb, &ctx->pcb->netlist[PCB_NETLIST_INPUT], nnet->argv[1], PCB_NETA_ALLOC); if (net == NULL) { hkp_error(nnet, "Failed to create net '%s' - netlist will be incomplete\n", nnet->argv[1]); continue; Index: trunk/src_plugins/io_pcb/parse_y.c =================================================================== --- trunk/src_plugins/io_pcb/parse_y.c (revision 29011) +++ trunk/src_plugins/io_pcb/parse_y.c (revision 29012) @@ -2890,7 +2890,7 @@ case 183: #line 1246 "parse_y.y" /* yacc.c:1652 */ { - currnet = pcb_net_get(yyPCB, &yyPCB->netlist[PCB_NETLIST_INPUT], (yyvsp[-3].string), 1); + currnet = pcb_net_get(yyPCB, &yyPCB->netlist[PCB_NETLIST_INPUT], (yyvsp[-3].string), PCB_NETA_ALLOC); if (((yyvsp[-2].string) != NULL) && (*(yyvsp[-2].string) != '\0')) pcb_attribute_put(&currnet->Attributes, "style", (yyvsp[-2].string)); free ((yyvsp[-3].string)); Index: trunk/src_plugins/io_pcb/parse_y.y =================================================================== --- trunk/src_plugins/io_pcb/parse_y.y (revision 29011) +++ trunk/src_plugins/io_pcb/parse_y.y (revision 29012) @@ -1244,7 +1244,7 @@ /* name style pin pin ... */ : T_NET '(' STRING STRING ')' '(' { - currnet = pcb_net_get(yyPCB, &yyPCB->netlist[PCB_NETLIST_INPUT], $3, 1); + currnet = pcb_net_get(yyPCB, &yyPCB->netlist[PCB_NETLIST_INPUT], $3, PCB_NETA_ALLOC); if (($4 != NULL) && (*$4 != '\0')) pcb_attribute_put(&currnet->Attributes, "style", $4); free ($3);