unified copy_symbol() and copy_symbol1(), better new symbol allocation policy
This commit is contained in:
parent
f5ce5987c9
commit
a2de3cd787
|
|
@ -539,6 +539,16 @@ void remove_symbol(int j)
|
|||
}
|
||||
}
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].text);
|
||||
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].line);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].rect);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].arc);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].poly);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].lines);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].polygons);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].arcs);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[j].rects);
|
||||
|
||||
xctx->sym[j].texts = 0;
|
||||
|
||||
save = xctx->sym[j]; /* save cleared symbol slot */
|
||||
|
|
@ -1208,8 +1218,7 @@ const char *get_sym_name(int inst, int ext)
|
|||
return sym;
|
||||
}
|
||||
|
||||
|
||||
static void copy_symbol1(xSymbol *dest_sym, xSymbol *src_sym)
|
||||
void copy_symbol(xSymbol *dest_sym, xSymbol *src_sym)
|
||||
{
|
||||
int c, j;
|
||||
|
||||
|
|
@ -1230,7 +1239,6 @@ static void copy_symbol1(xSymbol *dest_sym, xSymbol *src_sym)
|
|||
my_strdup2(_ALLOC_ID_, &dest_sym->templ, src_sym->templ);
|
||||
my_strdup2(_ALLOC_ID_, &dest_sym->prop_ptr, src_sym->prop_ptr);
|
||||
|
||||
/*
|
||||
dest_sym->line = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *));
|
||||
dest_sym->poly = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *));
|
||||
dest_sym->arc = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *));
|
||||
|
|
@ -1239,7 +1247,6 @@ static void copy_symbol1(xSymbol *dest_sym, xSymbol *src_sym)
|
|||
dest_sym->rects = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->arcs = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->polygons = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
*/
|
||||
|
||||
dest_sym->text = my_calloc(_ALLOC_ID_, src_sym->texts, sizeof(xText));
|
||||
memcpy(dest_sym->lines, src_sym->lines, sizeof(dest_sym->lines[0]) * cadlayers);
|
||||
|
|
@ -1335,7 +1342,7 @@ void get_additional_symbols(int what)
|
|||
int_hash_lookup(&sym_table, sym, j, XINSERT);
|
||||
dbg(1, "get_additional_symbols(): adding symbol %s\n", sym);
|
||||
check_symbol_storage();
|
||||
copy_symbol1(&xctx->sym[j], xctx->inst[i].ptr + xctx->sym);
|
||||
copy_symbol(&xctx->sym[j], xctx->inst[i].ptr + xctx->sym);
|
||||
xctx->sym[j].base_name = (xctx->inst[i].ptr + xctx->sym)->name;
|
||||
my_strdup(_ALLOC_ID_, &xctx->sym[j].name, sym);
|
||||
|
||||
|
|
|
|||
|
|
@ -251,84 +251,6 @@ void mem_delete_undo(void)
|
|||
xctx->undo_initialized = 0;
|
||||
}
|
||||
|
||||
void copy_symbol(xSymbol *dest_sym, xSymbol *src_sym)
|
||||
{
|
||||
int c, j;
|
||||
*dest_sym = *src_sym;
|
||||
dest_sym->name = NULL;
|
||||
dest_sym->base_name = NULL;
|
||||
dest_sym->prop_ptr = NULL;
|
||||
dest_sym->type = NULL;
|
||||
dest_sym->templ = NULL;
|
||||
my_strdup2(_ALLOC_ID_, &dest_sym->name, src_sym->name);
|
||||
my_strdup2(_ALLOC_ID_, &dest_sym->type, src_sym->type);
|
||||
my_strdup2(_ALLOC_ID_, &dest_sym->templ, src_sym->templ);
|
||||
my_strdup2(_ALLOC_ID_, &dest_sym->prop_ptr, src_sym->prop_ptr);
|
||||
dest_sym->line = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *));
|
||||
dest_sym->poly = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *));
|
||||
dest_sym->arc = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *));
|
||||
dest_sym->rect = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xRect *));
|
||||
dest_sym->lines = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->rects = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->arcs = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->polygons = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
dest_sym->text = my_calloc(_ALLOC_ID_, src_sym->texts, sizeof(xText));
|
||||
|
||||
memcpy(dest_sym->lines, src_sym->lines, sizeof(dest_sym->lines[0]) * cadlayers);
|
||||
memcpy(dest_sym->rects, src_sym->rects, sizeof(dest_sym->rects[0]) * cadlayers);
|
||||
memcpy(dest_sym->arcs, src_sym->arcs, sizeof(dest_sym->arcs[0]) * cadlayers);
|
||||
memcpy(dest_sym->polygons, src_sym->polygons, sizeof(dest_sym->polygons[0]) * cadlayers);
|
||||
for(c = 0;c<cadlayers; ++c) {
|
||||
/* symbol lines */
|
||||
dest_sym->line[c] = my_calloc(_ALLOC_ID_, src_sym->lines[c], sizeof(xLine));
|
||||
for(j = 0; j < src_sym->lines[c]; ++j) {
|
||||
dest_sym->line[c][j] = src_sym->line[c][j];
|
||||
dest_sym->line[c][j].prop_ptr = NULL;
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->line[c][j].prop_ptr, src_sym->line[c][j].prop_ptr);
|
||||
}
|
||||
/* symbol rects */
|
||||
dest_sym->rect[c] = my_calloc(_ALLOC_ID_, src_sym->rects[c], sizeof(xRect));
|
||||
for(j = 0; j < src_sym->rects[c]; ++j) {
|
||||
dest_sym->rect[c][j] = src_sym->rect[c][j];
|
||||
dest_sym->rect[c][j].prop_ptr = NULL;
|
||||
dest_sym->rect[c][j].extraptr = NULL;
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->rect[c][j].prop_ptr, src_sym->rect[c][j].prop_ptr);
|
||||
}
|
||||
/* symbol arcs */
|
||||
dest_sym->arc[c] = my_calloc(_ALLOC_ID_, src_sym->arcs[c], sizeof(xArc));
|
||||
for(j = 0; j < src_sym->arcs[c]; ++j) {
|
||||
dest_sym->arc[c][j] = src_sym->arc[c][j];
|
||||
dest_sym->arc[c][j].prop_ptr = NULL;
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->arc[c][j].prop_ptr, src_sym->arc[c][j].prop_ptr);
|
||||
}
|
||||
/* symbol polygons */
|
||||
dest_sym->poly[c] = my_calloc(_ALLOC_ID_, src_sym->polygons[c], sizeof(xPoly));
|
||||
for(j = 0; j < src_sym->polygons[c]; ++j) {
|
||||
int points = src_sym->poly[c][j].points;
|
||||
dest_sym->poly[c][j] = src_sym->poly[c][j];
|
||||
dest_sym->poly[c][j].prop_ptr = NULL;
|
||||
dest_sym->poly[c][j].x = my_malloc(_ALLOC_ID_, points * sizeof(double));
|
||||
dest_sym->poly[c][j].y = my_malloc(_ALLOC_ID_, points * sizeof(double));
|
||||
dest_sym->poly[c][j].selected_point = my_malloc(_ALLOC_ID_, points * sizeof(unsigned short));
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->poly[c][j].prop_ptr, src_sym->poly[c][j].prop_ptr);
|
||||
memcpy(dest_sym->poly[c][j].x, src_sym->poly[c][j].x, points * sizeof(double));
|
||||
memcpy(dest_sym->poly[c][j].y, src_sym->poly[c][j].y, points * sizeof(double));
|
||||
memcpy(dest_sym->poly[c][j].selected_point, src_sym->poly[c][j].selected_point,
|
||||
points * sizeof(unsigned short));
|
||||
}
|
||||
}
|
||||
/* symbol texts */
|
||||
for(j = 0; j < src_sym->texts; ++j) {
|
||||
dest_sym->text[j] = src_sym->text[j];
|
||||
dest_sym->text[j].prop_ptr = NULL;
|
||||
dest_sym->text[j].txt_ptr = NULL;
|
||||
dest_sym->text[j].font = NULL;
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->text[j].prop_ptr, src_sym->text[j].prop_ptr);
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->text[j].txt_ptr, src_sym->text[j].txt_ptr);
|
||||
my_strdup(_ALLOC_ID_, &dest_sym->text[j].font, src_sym->text[j].font);
|
||||
}
|
||||
}
|
||||
|
||||
void mem_push_undo(void)
|
||||
{
|
||||
int slot, i, c;
|
||||
|
|
|
|||
11
src/save.c
11
src/save.c
|
|
@ -3191,6 +3191,17 @@ int load_sym_def(const char *name, FILE *embed_fd, int embedded)
|
|||
symbol[symbols].templ = NULL;
|
||||
symbol[symbols].base_name=NULL;
|
||||
symbol[symbols].name=NULL;
|
||||
|
||||
symbol[symbols].line=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *));
|
||||
symbol[symbols].poly=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *));
|
||||
symbol[symbols].arc=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *));
|
||||
symbol[symbols].rect=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xRect *));
|
||||
symbol[symbols].lines=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
symbol[symbols].rects=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
symbol[symbols].arcs=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
symbol[symbols].polygons=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
|
||||
|
||||
my_strdup2(_ALLOC_ID_, &symbol[symbols].name,name);
|
||||
/* read symbol from file */
|
||||
while(1)
|
||||
|
|
|
|||
10
src/store.c
10
src/store.c
|
|
@ -59,16 +59,6 @@ void check_symbol_storage(void)
|
|||
xctx->sch[xctx->currsch] );
|
||||
xctx->maxs=(1 + xctx->symbols / ELEMDEF) * ELEMDEF;
|
||||
my_realloc(_ALLOC_ID_, &xctx->sym, sizeof(xSymbol)*xctx->maxs);
|
||||
for(i=xctx->symbols;i<xctx->maxs; ++i) {
|
||||
xctx->sym[i].poly=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *));
|
||||
xctx->sym[i].arc=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *));
|
||||
xctx->sym[i].line=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *));
|
||||
xctx->sym[i].rect=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xRect *));
|
||||
xctx->sym[i].lines=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].rects=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].polygons=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].arcs=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
20
src/xinit.c
20
src/xinit.c
|
|
@ -335,16 +335,6 @@ static void free_xschem_data()
|
|||
my_free(_ALLOC_ID_, &xctx->poly[i]);
|
||||
my_free(_ALLOC_ID_, &xctx->arc[i]);
|
||||
}
|
||||
for(i=0;i<xctx->maxs; ++i) {
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].line);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].rect);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].arc);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].poly);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].lines);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].polygons);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].arcs);
|
||||
my_free(_ALLOC_ID_, &xctx->sym[i].rects);
|
||||
}
|
||||
my_free(_ALLOC_ID_, &xctx->sym);
|
||||
my_free(_ALLOC_ID_, &xctx->rect);
|
||||
my_free(_ALLOC_ID_, &xctx->line);
|
||||
|
|
@ -561,16 +551,6 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
|
|||
xctx->wire=my_calloc(_ALLOC_ID_, xctx->maxw,sizeof(xWire));
|
||||
xctx->inst=my_calloc(_ALLOC_ID_, xctx->maxi , sizeof(xInstance) );
|
||||
xctx->sym=my_calloc(_ALLOC_ID_, xctx->maxs , sizeof(xSymbol) );
|
||||
for(i=0;i<xctx->maxs; ++i) {
|
||||
xctx->sym[i].line=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *));
|
||||
xctx->sym[i].poly=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *));
|
||||
xctx->sym[i].arc=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *));
|
||||
xctx->sym[i].rect=my_calloc(_ALLOC_ID_, cadlayers, sizeof(xRect *));
|
||||
xctx->sym[i].lines=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].rects=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].arcs=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->sym[i].polygons=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
}
|
||||
xctx->maxr=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->maxa=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
xctx->maxp=my_calloc(_ALLOC_ID_, cadlayers, sizeof(int));
|
||||
|
|
|
|||
Loading…
Reference in New Issue