1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: identfier handling |
---|
8 | */ |
---|
9 | |
---|
10 | #include <string.h> |
---|
11 | |
---|
12 | #include <kernel/mod2.h> |
---|
13 | #include <Singular/static.h> |
---|
14 | #include <omalloc/omalloc.h> |
---|
15 | #include <Singular/tok.h> |
---|
16 | #include <kernel/options.h> |
---|
17 | #include <Singular/ipshell.h> |
---|
18 | #include <kernel/intvec.h> |
---|
19 | #include <kernel/febase.h> |
---|
20 | #include <kernel/numbers.h> |
---|
21 | #include <kernel/longrat.h> |
---|
22 | #include <kernel/polys.h> |
---|
23 | #include <kernel/ring.h> |
---|
24 | #include <kernel/ideals.h> |
---|
25 | #include <kernel/matpol.h> |
---|
26 | #include <Singular/lists.h> |
---|
27 | #include <Singular/attrib.h> |
---|
28 | #include <Singular/silink.h> |
---|
29 | #include <kernel/syz.h> |
---|
30 | #include <Singular/ipid.h> |
---|
31 | #include <Singular/blackbox.h> |
---|
32 | |
---|
33 | #ifdef HAVE_FANS |
---|
34 | #include <gfanlib/gfanlib.h> |
---|
35 | #endif |
---|
36 | |
---|
37 | #ifdef HAVE_DYNAMIC_LOADING |
---|
38 | #include <kernel/mod_raw.h> |
---|
39 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
40 | |
---|
41 | omBin sip_command_bin = omGetSpecBin(sizeof(sip_command)); |
---|
42 | omBin sip_package_bin = omGetSpecBin(sizeof(sip_package)); |
---|
43 | //omBin ip_package_bin = omGetSpecBin(sizeof(ip_package)); |
---|
44 | omBin idrec_bin = omGetSpecBin(sizeof(idrec)); |
---|
45 | |
---|
46 | proclevel *procstack=NULL; |
---|
47 | #define TEST |
---|
48 | //idhdl idroot = NULL; |
---|
49 | |
---|
50 | idhdl currPackHdl = NULL; |
---|
51 | idhdl basePackHdl = NULL; |
---|
52 | package currPack =NULL; |
---|
53 | package basePack =NULL; |
---|
54 | idhdl currRingHdl = NULL; |
---|
55 | ring currRing = NULL; |
---|
56 | ideal currQuotient = NULL; |
---|
57 | const char* iiNoName="_"; |
---|
58 | |
---|
59 | void paCleanUp(package pack); |
---|
60 | |
---|
61 | /*0 implementation*/ |
---|
62 | |
---|
63 | int iiS2I(const char *s) |
---|
64 | { |
---|
65 | int i; |
---|
66 | i=s[0]; |
---|
67 | if (s[1]!='\0') |
---|
68 | { |
---|
69 | i=(i<<8)+s[1]; |
---|
70 | if (s[2]!='\0') |
---|
71 | { |
---|
72 | i=(i<<8)+s[2]; |
---|
73 | if (s[3]!='\0') |
---|
74 | { |
---|
75 | i=(i<<8)+s[3]; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | return i; |
---|
80 | } |
---|
81 | |
---|
82 | idhdl idrec::get(const char * s, int lev) |
---|
83 | { |
---|
84 | assume(s!=NULL); |
---|
85 | assume((lev>=0) && (lev<=1000)); //not really, but if it isnt in that bounds.. |
---|
86 | idhdl h = this; |
---|
87 | idhdl found=NULL; |
---|
88 | int l; |
---|
89 | const char *id; |
---|
90 | int i=iiS2I(s); |
---|
91 | int less4=(i < (1<<24)); |
---|
92 | while (h!=NULL) |
---|
93 | { |
---|
94 | omCheckAddr((ADDRESS)IDID(h)); |
---|
95 | l=IDLEV(h); |
---|
96 | if ((l==0)||(l==lev)) |
---|
97 | { |
---|
98 | if (i==h->id_i) |
---|
99 | { |
---|
100 | id=IDID(h); |
---|
101 | if (less4 || (0 == strcmp(s+4,id+4))) |
---|
102 | { |
---|
103 | if (l==lev) return h; |
---|
104 | found=h; |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | h = IDNEXT(h); |
---|
109 | } |
---|
110 | return found; |
---|
111 | } |
---|
112 | |
---|
113 | //idrec::~idrec() |
---|
114 | //{ |
---|
115 | // if (id!=NULL) |
---|
116 | // { |
---|
117 | // omFree((ADDRESS)id); |
---|
118 | // id=NULL; |
---|
119 | // } |
---|
120 | // /* much more !! */ |
---|
121 | //} |
---|
122 | |
---|
123 | void *idrecDataInit(int t) |
---|
124 | { |
---|
125 | switch (t) |
---|
126 | { |
---|
127 | //the type with init routines: |
---|
128 | case INTVEC_CMD: |
---|
129 | case INTMAT_CMD: |
---|
130 | return (void *)new intvec(); |
---|
131 | case NUMBER_CMD: |
---|
132 | return (void *) nInit(0); |
---|
133 | case BIGINT_CMD: |
---|
134 | return (void *) nlInit(0, NULL /* dummy for nlInit*/); |
---|
135 | case IDEAL_CMD: |
---|
136 | case MODUL_CMD: |
---|
137 | case MATRIX_CMD: |
---|
138 | return (void*) idInit(1,1); |
---|
139 | case MAP_CMD: |
---|
140 | { |
---|
141 | map m = (map)idInit(1,1); |
---|
142 | m->preimage = omStrDup(IDID(currRingHdl)); |
---|
143 | return (void *)m; |
---|
144 | } |
---|
145 | case STRING_CMD: |
---|
146 | return (void *)omAlloc0(1); |
---|
147 | case LIST_CMD: |
---|
148 | { |
---|
149 | lists l=(lists)omAllocBin(slists_bin); |
---|
150 | l->Init(); |
---|
151 | return (void*)l; |
---|
152 | } |
---|
153 | #ifdef HAVE_FANS |
---|
154 | case FAN_CMD: |
---|
155 | return (void*)(new gfan::ZFan(0)); |
---|
156 | case CONE_CMD: |
---|
157 | return (void*)(new gfan::ZCone()); |
---|
158 | #endif |
---|
159 | //the types with the standard init: set the struct to zero |
---|
160 | case LINK_CMD: |
---|
161 | return (void*) omAlloc0Bin(sip_link_bin); |
---|
162 | case RING_CMD: |
---|
163 | return (void*) omAlloc0Bin(sip_sring_bin); |
---|
164 | case PACKAGE_CMD: |
---|
165 | return (void*) omAlloc0Bin(sip_package_bin); |
---|
166 | case PROC_CMD: |
---|
167 | return (void *) omAlloc0Bin(procinfo_bin); |
---|
168 | case RESOLUTION_CMD: |
---|
169 | return (void *)omAlloc0(sizeof(ssyStrategy)); |
---|
170 | //other types: without init (int,script,poly,def,package) |
---|
171 | case INT_CMD: |
---|
172 | case DEF_CMD: |
---|
173 | case POLY_CMD: |
---|
174 | case VECTOR_CMD: |
---|
175 | case QRING_CMD: |
---|
176 | return (void*)0L; |
---|
177 | default: |
---|
178 | { |
---|
179 | if (t>MAX_TOK) |
---|
180 | { |
---|
181 | #ifdef BLACKBOX_DEVEL |
---|
182 | Print("bb-type %d\n",t); |
---|
183 | #endif |
---|
184 | blackbox *bb=getBlackboxStuff(t); |
---|
185 | if (bb!=NULL) |
---|
186 | return (void *)bb->blackbox_Init(bb); |
---|
187 | } |
---|
188 | else |
---|
189 | Werror("unknown type %d",t); |
---|
190 | break; |
---|
191 | } |
---|
192 | } |
---|
193 | return (void *)0L; |
---|
194 | } |
---|
195 | idhdl idrec::set(const char * s, int lev, int t, BOOLEAN init) |
---|
196 | { |
---|
197 | //printf("define %s, %x, lev: %d, typ: %d\n", s,s,lev,t); |
---|
198 | idhdl h = (idrec *)omAlloc0Bin(idrec_bin); |
---|
199 | IDID(h) = s; |
---|
200 | IDTYP(h) = t; |
---|
201 | IDLEV(h) = lev; |
---|
202 | IDNEXT(h) = this; |
---|
203 | h->id_i=iiS2I(s); |
---|
204 | if (init) |
---|
205 | { |
---|
206 | if ((t==IDEAL_CMD)||(t==MODUL_CMD)) |
---|
207 | IDFLAG(h) = Sy_bit(FLAG_STD); |
---|
208 | IDSTRING(h)=(char *)idrecDataInit(t); |
---|
209 | } |
---|
210 | // additional settings:-------------------------------------- |
---|
211 | #if 0 |
---|
212 | // this leads to a memory leak |
---|
213 | if (t == QRING_CMD) |
---|
214 | { |
---|
215 | // IDRING(h)=rCopy(currRing); |
---|
216 | /* QRING_CMD is ring dep => currRing !=NULL */ |
---|
217 | } |
---|
218 | else |
---|
219 | #endif |
---|
220 | if (t == PROC_CMD) |
---|
221 | { |
---|
222 | IDPROC(h)->language=LANG_NONE; |
---|
223 | } |
---|
224 | else if (t == PACKAGE_CMD) |
---|
225 | { |
---|
226 | IDPACKAGE(h)->language=LANG_NONE; |
---|
227 | IDPACKAGE(h)->loaded = FALSE; |
---|
228 | } |
---|
229 | // -------------------------------------------------------- |
---|
230 | return h; |
---|
231 | } |
---|
232 | |
---|
233 | char * idrec::String() |
---|
234 | { |
---|
235 | sleftv tmp; |
---|
236 | memset(&tmp,0,sizeof(sleftv)); |
---|
237 | tmp.rtyp=IDTYP(this); |
---|
238 | tmp.data=IDDATA(this); |
---|
239 | tmp.name=IDID(this); |
---|
240 | return tmp.String(); |
---|
241 | } |
---|
242 | |
---|
243 | idhdl enterid(const char * s, int lev, int t, idhdl* root, BOOLEAN init, BOOLEAN search) |
---|
244 | { |
---|
245 | idhdl h; |
---|
246 | s=omStrDup(s); |
---|
247 | // is it already defined in root ? |
---|
248 | if ((h=(*root)->get(s,lev))!=NULL) |
---|
249 | { |
---|
250 | if (IDLEV(h)==lev) |
---|
251 | { |
---|
252 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
253 | { |
---|
254 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
255 | && (strcmp(s,"Top")==0)) |
---|
256 | { |
---|
257 | goto errlabel; |
---|
258 | } |
---|
259 | if (BVERBOSE(V_REDEFINE)) |
---|
260 | Warn("redefining %s **",s); |
---|
261 | if (s==IDID(h)) IDID(h)=NULL; |
---|
262 | killhdl2(h,root,currRing); |
---|
263 | } |
---|
264 | else |
---|
265 | goto errlabel; |
---|
266 | } |
---|
267 | } |
---|
268 | // is it already defined in currRing->idroot ? |
---|
269 | else if (search && (currRing!=NULL)&&((*root) != currRing->idroot)) |
---|
270 | { |
---|
271 | if ((h=currRing->idroot->get(s,lev))!=NULL) |
---|
272 | { |
---|
273 | if (IDLEV(h)==lev) |
---|
274 | { |
---|
275 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
276 | { |
---|
277 | if (BVERBOSE(V_REDEFINE)) |
---|
278 | Warn("redefining %s **",s); |
---|
279 | IDID(h)=NULL; |
---|
280 | killhdl2(h,&currRing->idroot,currRing); |
---|
281 | } |
---|
282 | else |
---|
283 | goto errlabel; |
---|
284 | } |
---|
285 | } |
---|
286 | } |
---|
287 | // is it already defined in idroot ? |
---|
288 | else if (search && (*root != IDROOT)) |
---|
289 | { |
---|
290 | if ((h=IDROOT->get(s,lev))!=NULL) |
---|
291 | { |
---|
292 | if (IDLEV(h)==lev) |
---|
293 | { |
---|
294 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
295 | { |
---|
296 | if (BVERBOSE(V_REDEFINE)) |
---|
297 | Warn("redefining `%s` **",s); |
---|
298 | if (s==IDID(h)) IDID(h)=NULL; |
---|
299 | killhdl2(h,&IDROOT,NULL); |
---|
300 | } |
---|
301 | else |
---|
302 | goto errlabel; |
---|
303 | } |
---|
304 | } |
---|
305 | } |
---|
306 | *root = (*root)->set(s, lev, t, init); |
---|
307 | #ifndef NDEBUG |
---|
308 | checkall(); |
---|
309 | #endif |
---|
310 | return *root; |
---|
311 | |
---|
312 | errlabel: |
---|
313 | //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev); |
---|
314 | Werror("identifier `%s` in use",s); |
---|
315 | //listall(); |
---|
316 | omFree((ADDRESS)s); |
---|
317 | return NULL; |
---|
318 | } |
---|
319 | void killid(const char * id, idhdl * ih) |
---|
320 | { |
---|
321 | if (id!=NULL) |
---|
322 | { |
---|
323 | idhdl h = (*ih)->get(id,myynest); |
---|
324 | |
---|
325 | // id not found in global list, is it defined in current ring ? |
---|
326 | if (h==NULL) |
---|
327 | { |
---|
328 | if ((currRing!=NULL) && (*ih != (currRing->idroot))) |
---|
329 | { |
---|
330 | h = currRing->idroot->get(id,myynest); |
---|
331 | if (h!=NULL) |
---|
332 | { |
---|
333 | killhdl2(h,&(currRing->idroot),currRing); |
---|
334 | return; |
---|
335 | } |
---|
336 | } |
---|
337 | Werror("`%s` is not defined",id); |
---|
338 | return; |
---|
339 | } |
---|
340 | killhdl2(h,ih,currRing); |
---|
341 | } |
---|
342 | else |
---|
343 | Werror("kill what ?"); |
---|
344 | } |
---|
345 | |
---|
346 | void killhdl(idhdl h, package proot) |
---|
347 | { |
---|
348 | int t=IDTYP(h); |
---|
349 | if (((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD)) |
---|
350 | || ((t==LIST_CMD) && (lRingDependend((lists)IDDATA(h))))) |
---|
351 | killhdl2(h,&currRing->idroot,currRing); |
---|
352 | else |
---|
353 | { |
---|
354 | if(t==PACKAGE_CMD) |
---|
355 | { |
---|
356 | killhdl2(h,&(basePack->idroot),NULL); |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | idhdl s=proot->idroot; |
---|
361 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
362 | if (s!=NULL) |
---|
363 | killhdl2(h,&(proot->idroot),NULL); |
---|
364 | else if (basePack!=proot) |
---|
365 | { |
---|
366 | idhdl s=basePack->idroot; |
---|
367 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
368 | if (s!=NULL) |
---|
369 | killhdl2(h,&(basePack->idroot),currRing); |
---|
370 | else |
---|
371 | killhdl2(h,&(currRing->idroot),currRing); |
---|
372 | } |
---|
373 | } |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | void killhdl2(idhdl h, idhdl * ih, ring r) |
---|
378 | { |
---|
379 | //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h)); |
---|
380 | idhdl hh; |
---|
381 | |
---|
382 | if (h->attribute!=NULL) |
---|
383 | { |
---|
384 | at_KillAll(h,r); |
---|
385 | //h->attribute=NULL; |
---|
386 | } |
---|
387 | if ((IDTYP(h) == PACKAGE_CMD) && (strcmp(IDID(h),"Top")==0)) |
---|
388 | { |
---|
389 | WarnS("can not kill `Top`"); |
---|
390 | return; |
---|
391 | } |
---|
392 | // ring / qring -------------------------------------------------------- |
---|
393 | if ((IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)) |
---|
394 | { |
---|
395 | // any objects defined for this ring ? -> done by rKill |
---|
396 | rKill(h); |
---|
397 | } |
---|
398 | // package ------------------------------------------------------------- |
---|
399 | else if (IDTYP(h) == PACKAGE_CMD) |
---|
400 | { |
---|
401 | // any objects defined for this package ? |
---|
402 | if ((IDPACKAGE(h)->ref<=0) && (IDPACKAGE(h)->idroot!=NULL)) |
---|
403 | { |
---|
404 | if (currPack==IDPACKAGE(h)) |
---|
405 | { |
---|
406 | currPack=basePack; |
---|
407 | currPackHdl=NULL; |
---|
408 | } |
---|
409 | idhdl * hd = &IDRING(h)->idroot; |
---|
410 | idhdl hdh = IDNEXT(*hd); |
---|
411 | idhdl temp; |
---|
412 | while (hdh!=NULL) |
---|
413 | { |
---|
414 | temp = IDNEXT(hdh); |
---|
415 | killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL); |
---|
416 | hdh = temp; |
---|
417 | } |
---|
418 | killhdl2(*hd,hd,NULL); |
---|
419 | if (IDPACKAGE(h)->libname!=NULL) omFree((ADDRESS)(IDPACKAGE(h)->libname)); |
---|
420 | } |
---|
421 | paKill(IDPACKAGE(h)); |
---|
422 | if (currPackHdl==h) currPackHdl=packFindHdl(currPack); |
---|
423 | iiCheckPack(currPack); |
---|
424 | } |
---|
425 | // poly / vector ------------------------------------------------------- |
---|
426 | else if ((IDTYP(h) == POLY_CMD) || (IDTYP(h) == VECTOR_CMD)) |
---|
427 | { |
---|
428 | assume(r!=NULL); |
---|
429 | p_Delete(&IDPOLY(h),r); |
---|
430 | } |
---|
431 | // ideal / module/ matrix / map ---------------------------------------- |
---|
432 | else if ((IDTYP(h) == IDEAL_CMD) |
---|
433 | || (IDTYP(h) == MODUL_CMD) |
---|
434 | || (IDTYP(h) == MATRIX_CMD) |
---|
435 | || (IDTYP(h) == MAP_CMD)) |
---|
436 | { |
---|
437 | assume(r!=NULL); |
---|
438 | ideal iid = IDIDEAL(h); |
---|
439 | if (IDTYP(h) == MAP_CMD) |
---|
440 | { |
---|
441 | map im = IDMAP(h); |
---|
442 | omFree((ADDRESS)im->preimage); |
---|
443 | } |
---|
444 | id_Delete(&iid,r); |
---|
445 | } |
---|
446 | // string ------------------------------------------------------------- |
---|
447 | else if (IDTYP(h) == STRING_CMD) |
---|
448 | { |
---|
449 | omFree((ADDRESS)IDSTRING(h)); |
---|
450 | //IDSTRING(h)=NULL; |
---|
451 | } |
---|
452 | // proc --------------------------------------------------------------- |
---|
453 | else if (IDTYP(h) == PROC_CMD) |
---|
454 | { |
---|
455 | if (piKill(IDPROC(h))) return; |
---|
456 | } |
---|
457 | // number ------------------------------------------------------------- |
---|
458 | else if (IDTYP(h) == NUMBER_CMD) |
---|
459 | { |
---|
460 | assume(r!=NULL); |
---|
461 | n_Delete(&IDNUMBER(h),r); |
---|
462 | } |
---|
463 | // bigint ------------------------------------------------------------- |
---|
464 | else if (IDTYP(h) == BIGINT_CMD) |
---|
465 | { |
---|
466 | nlDelete(&IDNUMBER(h),NULL); |
---|
467 | } |
---|
468 | // intvec / intmat --------------------------------------------------- |
---|
469 | else if ((IDTYP(h) == INTVEC_CMD)||(IDTYP(h) == INTMAT_CMD)) |
---|
470 | { |
---|
471 | delete IDINTVEC(h); |
---|
472 | } |
---|
473 | // list ------------------------------------------------------------- |
---|
474 | else if (IDTYP(h)==LIST_CMD) |
---|
475 | { |
---|
476 | IDLIST(h)->Clean(r); |
---|
477 | //IDLIST(h)=NULL; |
---|
478 | } |
---|
479 | // link ------------------------------------------------------------- |
---|
480 | else if (IDTYP(h)==LINK_CMD) |
---|
481 | { |
---|
482 | slKill(IDLINK(h)); |
---|
483 | } |
---|
484 | else if(IDTYP(h)==RESOLUTION_CMD) |
---|
485 | { |
---|
486 | assume(r!=NULL); |
---|
487 | if (IDDATA(h)!=NULL) |
---|
488 | syKillComputation((syStrategy)IDDATA(h),r); |
---|
489 | } |
---|
490 | // blackbox ------------------------------------------------------------- |
---|
491 | else if (IDTYP(h)>MAX_TOK) |
---|
492 | { |
---|
493 | blackbox *bb=getBlackboxStuff(IDTYP(h)); |
---|
494 | if (bb!=NULL) bb->blackbox_destroy(bb,IDDATA(h)); |
---|
495 | IDDATA(h)=NULL; |
---|
496 | } |
---|
497 | #ifdef HAVE_FANS |
---|
498 | // fan ------------------------------------------------------------- |
---|
499 | else if (IDTYP(h) == FAN_CMD) |
---|
500 | { |
---|
501 | gfan::ZFan* zf = (gfan::ZFan*)IDDATA(h); |
---|
502 | delete zf; |
---|
503 | IDDATA(h) = NULL; |
---|
504 | } |
---|
505 | // cone ------------------------------------------------------------ |
---|
506 | else if (IDTYP(h) == CONE_CMD) |
---|
507 | { |
---|
508 | gfan::ZCone* zc = (gfan::ZCone*)IDDATA(h); |
---|
509 | delete zc; |
---|
510 | IDDATA(h) = NULL; |
---|
511 | } |
---|
512 | #endif /* HAVE_FANS */ |
---|
513 | #ifdef TEST |
---|
514 | else if ((IDTYP(h)!= INT_CMD) |
---|
515 | &&(IDTYP(h)!=DEF_CMD) |
---|
516 | &&(IDTYP(h)!=ALIAS_CMD) |
---|
517 | &&(IDTYP(h)!=NONE)) |
---|
518 | Warn("unknown type to kill: %s(%d)",Tok2Cmdname(IDTYP(h)),IDTYP(h)); |
---|
519 | #endif |
---|
520 | |
---|
521 | // general ------------------------------------------------------------- |
---|
522 | // now dechain it and delete idrec |
---|
523 | if (IDID(h)!=NULL) // OB: ????? |
---|
524 | omFree((ADDRESS)IDID(h)); |
---|
525 | IDID(h)=NULL; |
---|
526 | IDDATA(h)=NULL; |
---|
527 | if (h == (*ih)) |
---|
528 | { |
---|
529 | // h is at the beginning of the list |
---|
530 | *ih = IDNEXT(h) /* ==*ih */; |
---|
531 | } |
---|
532 | else if (ih!=NULL) |
---|
533 | { |
---|
534 | // h is somethere in the list: |
---|
535 | hh = *ih; |
---|
536 | loop |
---|
537 | { |
---|
538 | if (hh==NULL) |
---|
539 | { |
---|
540 | PrintS(">>?<< not found for kill\n"); |
---|
541 | return; |
---|
542 | } |
---|
543 | idhdl hhh = IDNEXT(hh); |
---|
544 | if (hhh == h) |
---|
545 | { |
---|
546 | IDNEXT(hh) = IDNEXT(hhh); |
---|
547 | break; |
---|
548 | } |
---|
549 | hh = hhh; |
---|
550 | } |
---|
551 | } |
---|
552 | omFreeBin((ADDRESS)h, idrec_bin); |
---|
553 | } |
---|
554 | |
---|
555 | idhdl ggetid(const char *n, BOOLEAN local, idhdl *packhdl) |
---|
556 | { |
---|
557 | idhdl h = IDROOT->get(n,myynest); |
---|
558 | idhdl h2=NULL; |
---|
559 | *packhdl = NULL; |
---|
560 | if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest))) |
---|
561 | { |
---|
562 | h2 = currRing->idroot->get(n,myynest); |
---|
563 | } |
---|
564 | if (h2==NULL) return h; |
---|
565 | return h2; |
---|
566 | } |
---|
567 | |
---|
568 | idhdl ggetid(const char *n) |
---|
569 | { |
---|
570 | idhdl h = IDROOT->get(n,myynest); |
---|
571 | if ((h!=NULL)&&(IDLEV(h)==myynest)) return h; |
---|
572 | idhdl h2=NULL; |
---|
573 | if (currRing!=NULL) |
---|
574 | { |
---|
575 | h2 = currRing->idroot->get(n,myynest); |
---|
576 | } |
---|
577 | if (h2!=NULL) return h2; |
---|
578 | if (h!=NULL) return h; |
---|
579 | if (basePack!=currPack) |
---|
580 | return basePack->idroot->get(n,myynest); |
---|
581 | return NULL; |
---|
582 | } |
---|
583 | |
---|
584 | void ipListFlag(idhdl h) |
---|
585 | { |
---|
586 | if (hasFlag(h,FLAG_STD)) PrintS(" (SB)"); |
---|
587 | #ifdef HAVE_PLURAL |
---|
588 | if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)"); |
---|
589 | #endif |
---|
590 | } |
---|
591 | |
---|
592 | lists ipNameList(idhdl root) |
---|
593 | { |
---|
594 | idhdl h=root; |
---|
595 | /* compute the length */ |
---|
596 | int l=0; |
---|
597 | while (h!=NULL) { l++; h=IDNEXT(h); } |
---|
598 | /* allocate list */ |
---|
599 | lists L=(lists)omAllocBin(slists_bin); |
---|
600 | L->Init(l); |
---|
601 | /* copy names */ |
---|
602 | h=root; |
---|
603 | l=0; |
---|
604 | while (h!=NULL) |
---|
605 | { |
---|
606 | /* list is initialized with 0 => no need to clear anything */ |
---|
607 | L->m[l].rtyp=STRING_CMD; |
---|
608 | L->m[l].data=omStrDup(IDID(h)); |
---|
609 | l++; |
---|
610 | h=IDNEXT(h); |
---|
611 | } |
---|
612 | return L; |
---|
613 | } |
---|
614 | |
---|
615 | /* |
---|
616 | * move 'tomove' from root1 list to root2 list |
---|
617 | */ |
---|
618 | static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2) |
---|
619 | { |
---|
620 | idhdl h; |
---|
621 | /* search 'tomove' in root2 : if found -> do nothing */ |
---|
622 | h=root2; |
---|
623 | while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h); |
---|
624 | if (h!=NULL) return FALSE; /*okay */ |
---|
625 | /* search predecessor of h in root1, remove 'tomove' */ |
---|
626 | h=root1; |
---|
627 | if (tomove==h) |
---|
628 | { |
---|
629 | root1=IDNEXT(h); |
---|
630 | } |
---|
631 | else |
---|
632 | { |
---|
633 | while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h); |
---|
634 | if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */ |
---|
635 | IDNEXT(h)=IDNEXT(tomove); |
---|
636 | } |
---|
637 | /* add to root2 list */ |
---|
638 | IDNEXT(tomove)=root2; |
---|
639 | root2=tomove; |
---|
640 | return FALSE; |
---|
641 | } |
---|
642 | |
---|
643 | void ipMoveId(idhdl tomove) |
---|
644 | { |
---|
645 | if ((currRing!=NULL)&&(tomove!=NULL)) |
---|
646 | { |
---|
647 | if (((QRING_CMD!=IDTYP(tomove)) && RingDependend(IDTYP(tomove))) |
---|
648 | || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove))))) |
---|
649 | { |
---|
650 | /*move 'tomove' to ring id's*/ |
---|
651 | if (ipSwapId(tomove,IDROOT,currRing->idroot)) |
---|
652 | ipSwapId(tomove,basePack->idroot,currRing->idroot); |
---|
653 | } |
---|
654 | else |
---|
655 | { |
---|
656 | /*move 'tomove' to global id's*/ |
---|
657 | ipSwapId(tomove,currRing->idroot,IDROOT); |
---|
658 | } |
---|
659 | } |
---|
660 | } |
---|
661 | |
---|
662 | const char * piProcinfo(procinfov pi, const char *request) |
---|
663 | { |
---|
664 | if(pi == NULL) return "empty proc"; |
---|
665 | else if (strcmp(request, "libname") == 0) return pi->libname; |
---|
666 | else if (strcmp(request, "procname") == 0) return pi->procname; |
---|
667 | else if (strcmp(request, "type") == 0) |
---|
668 | { |
---|
669 | switch (pi->language) |
---|
670 | { |
---|
671 | case LANG_SINGULAR: return "singular"; break; |
---|
672 | case LANG_C: return "object"; break; |
---|
673 | case LANG_NONE: return "none"; break; |
---|
674 | default: return "unknow language"; |
---|
675 | } |
---|
676 | } |
---|
677 | else if (strcmp(request, "ref") == 0) |
---|
678 | { |
---|
679 | char p[8]; |
---|
680 | sprintf(p, "%d", pi->ref); |
---|
681 | return omStrDup(p); // MEMORY-LEAK |
---|
682 | } |
---|
683 | return "??"; |
---|
684 | } |
---|
685 | |
---|
686 | void piCleanUp(procinfov pi) |
---|
687 | { |
---|
688 | (pi->ref)--; |
---|
689 | if (pi->ref <= 0) |
---|
690 | { |
---|
691 | if (pi->libname != NULL) // OB: ???? |
---|
692 | omFree((ADDRESS)pi->libname); |
---|
693 | if (pi->procname != NULL) // OB: ???? |
---|
694 | omFree((ADDRESS)pi->procname); |
---|
695 | |
---|
696 | if( pi->language == LANG_SINGULAR) |
---|
697 | { |
---|
698 | if (pi->data.s.body != NULL) // OB: ???? |
---|
699 | omFree((ADDRESS)pi->data.s.body); |
---|
700 | } |
---|
701 | if( pi->language == LANG_C) |
---|
702 | { |
---|
703 | } |
---|
704 | memset((void *) pi, 0, sizeof(procinfo)); |
---|
705 | pi->language=LANG_NONE; |
---|
706 | } |
---|
707 | } |
---|
708 | |
---|
709 | BOOLEAN piKill(procinfov pi) |
---|
710 | { |
---|
711 | Voice *p=currentVoice; |
---|
712 | while (p!=NULL) |
---|
713 | { |
---|
714 | if (p->pi==pi && pi->ref <= 1) |
---|
715 | { |
---|
716 | Warn("`%s` in use, can not be killed",pi->procname); |
---|
717 | return TRUE; |
---|
718 | } |
---|
719 | p=p->next; |
---|
720 | } |
---|
721 | piCleanUp(pi); |
---|
722 | if (pi->ref <= 0) |
---|
723 | omFreeBin((ADDRESS)pi, procinfo_bin); |
---|
724 | return FALSE; |
---|
725 | } |
---|
726 | |
---|
727 | void paCleanUp(package pack) |
---|
728 | { |
---|
729 | (pack->ref)--; |
---|
730 | if (pack->ref < 0) |
---|
731 | { |
---|
732 | #ifndef HAVE_STATIC |
---|
733 | if( pack->language == LANG_C) |
---|
734 | { |
---|
735 | Print("//dlclose(%s)\n",pack->libname); |
---|
736 | #ifdef HAVE_DYNAMIC_LOADING |
---|
737 | dynl_close (pack->handle); |
---|
738 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
739 | } |
---|
740 | #endif /* HAVE_STATIC */ |
---|
741 | omfree((ADDRESS)pack->libname); |
---|
742 | memset((void *) pack, 0, sizeof(sip_package)); |
---|
743 | pack->language=LANG_NONE; |
---|
744 | } |
---|
745 | } |
---|
746 | |
---|
747 | void proclevel::push(char *n) |
---|
748 | { |
---|
749 | //Print("push %s\n",n); |
---|
750 | proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel)); |
---|
751 | p->cRing=currRing; |
---|
752 | p->cRingHdl=currRingHdl; |
---|
753 | p->name=n; |
---|
754 | p->cPackHdl=currPackHdl; |
---|
755 | p->cPack=currPack; |
---|
756 | p->next=this; |
---|
757 | procstack=p; |
---|
758 | } |
---|
759 | void proclevel::pop() |
---|
760 | { |
---|
761 | //Print("pop %s\n",name); |
---|
762 | //if (currRing!=::currRing) PrintS("currRing wrong\n");; |
---|
763 | //::currRing=this->currRing; |
---|
764 | //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name); |
---|
765 | //::currRingHdl=this->currRingHdl; |
---|
766 | //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing))) |
---|
767 | // ::currRingHdl=rFindHdl(::currRing,NULL,NULL); |
---|
768 | //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot)); |
---|
769 | currPackHdl=this->cPackHdl; |
---|
770 | currPack=this->cPack; |
---|
771 | iiCheckPack(currPack); |
---|
772 | proclevel *p=this; |
---|
773 | procstack=next; |
---|
774 | omFreeSize(p,sizeof(proclevel)); |
---|
775 | } |
---|
776 | |
---|
777 | idhdl packFindHdl(package r) |
---|
778 | { |
---|
779 | idhdl h=basePack->idroot; |
---|
780 | while (h!=NULL) |
---|
781 | { |
---|
782 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
783 | && (IDPACKAGE(h)==r)) |
---|
784 | return h; |
---|
785 | h=IDNEXT(h); |
---|
786 | } |
---|
787 | return NULL; |
---|
788 | } |
---|