source: git/Singular/ipid.cc @ 5de33f4

fieker-DuValspielwiese
Last change on this file since 5de33f4 was 56ffd98, checked in by Hans Schoenemann <hannes@…>, 5 years ago
chg: several versions of ggetid
  • Property mode set to 100644
File size: 20.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/*
6* ABSTRACT: identfier handling
7*/
8
9
10
11
12
13#include "kernel/mod2.h"
14
15#include "misc/options.h"
16#include "misc/intvec.h"
17
18#include "coeffs/numbers.h"
19#include "coeffs/bigintmat.h"
20
21#include "polys/matpol.h"
22#include "polys/monomials/ring.h"
23
24#include "kernel/polys.h"
25#include "kernel/ideals.h"
26#include "kernel/GBEngine/syz.h"
27
28#include "Singular/tok.h"
29#include "Singular/ipshell.h"
30#include "Singular/fevoices.h"
31#include "Singular/lists.h"
32#include "Singular/attrib.h"
33#include "Singular/links/silink.h"
34#include "Singular/ipid.h"
35#include "Singular/blackbox.h"
36#include "Singular/number2.h"
37
38#ifdef SINGULAR_4_2
39#include "Singular/number2.h"
40#endif
41#ifdef HAVE_DYNAMIC_LOADING
42#include "polys/mod_raw.h"
43#endif /* HAVE_DYNAMIC_LOADING */
44
45VAR omBin sip_command_bin = omGetSpecBin(sizeof(sip_command));
46VAR omBin sip_package_bin = omGetSpecBin(sizeof(sip_package));
47//omBin ip_package_bin = omGetSpecBin(sizeof(ip_package));
48VAR omBin idrec_bin = omGetSpecBin(sizeof(idrec));
49
50VAR coeffs coeffs_BIGINT;
51
52VAR proclevel *procstack=NULL;
53//idhdl idroot = NULL;
54
55VAR idhdl currPackHdl = NULL;
56VAR idhdl basePackHdl = NULL;
57VAR package currPack = NULL;
58VAR package basePack = NULL;
59VAR idhdl currRingHdl = NULL;
60
61void paCleanUp(package pack);
62
63/*0 implementation*/
64
65static inline long iiS2I(const char *s)
66{
67  long l;
68  strncpy((char*)&l,s,SIZEOF_LONG);
69  return l;
70}
71
72idhdl idrec::get(const char * s, int level)
73{
74  assume(s!=NULL);
75  assume((level>=0) && (level<=1000)); //not really, but if it isnt in that bounds..
76  idhdl h = this;
77  idhdl found=NULL;
78  int l;
79  const char *id_;
80  unsigned long i=iiS2I(s);
81  int less4=(i < (1L<<((SIZEOF_LONG-1)*8)));
82  while (h!=NULL)
83  {
84    omCheckAddr((ADDRESS)IDID(h));
85    l=IDLEV(h);
86    if ((l==0)||(l==level))
87    {
88      if (i==h->id_i)
89      {
90        id_=IDID(h);
91        if (less4 || (0 == strcmp(s+SIZEOF_LONG,id_+SIZEOF_LONG)))
92        {
93          if(l==level) return h;
94          found=h;
95        }
96      }
97    }
98    h = IDNEXT(h);
99  }
100  return found;
101}
102
103idhdl idrec::get_level(const char * s, int level)
104{
105  assume(s!=NULL);
106  assume((level>=0) && (level<=1000)); //not really, but if it isnt in that bounds..
107  idhdl h = this;
108  int l;
109  const char *id_;
110  unsigned long i=iiS2I(s);
111  int less4=(i < (1L<<((SIZEOF_LONG-1)*8)));
112  while (h!=NULL)
113  {
114    omCheckAddr((ADDRESS)IDID(h));
115    l=IDLEV(h);
116    if ((l==level)&&(i==h->id_i))
117    {
118      id_=IDID(h);
119      if (less4 || (0 == strcmp(s+SIZEOF_LONG,id_+SIZEOF_LONG)))
120      {
121        return h;
122      }
123    }
124    h = IDNEXT(h);
125  }
126  return NULL;
127}
128
129//idrec::~idrec()
130//{
131//  if (id!=NULL)
132//  {
133//    omFree((ADDRESS)id);
134//    id=NULL;
135//  }
136//  /* much more !! */
137//}
138
139void *idrecDataInit(int t)
140{
141  switch (t)
142  {
143    //the type with init routines:
144#ifdef SINGULAR_4_2
145    case CNUMBER_CMD:
146      return (void*)n2Init(0,NULL);
147    case CPOLY_CMD:
148      return (void*)p2Init(0,NULL);
149    case CMATRIX_CMD:
150#endif
151    case BIGINTMAT_CMD:
152      return (void *)new bigintmat();
153    case BUCKET_CMD:
154      if (currRing!=NULL)
155      return (void*)sBucketCreate(currRing);
156      else
157      {
158        WerrorS("need basering for polyBucket");
159        return NULL;
160      }
161    case INTVEC_CMD:
162    case INTMAT_CMD:
163      return (void *)new intvec();
164    case NUMBER_CMD:
165    {
166      if (currRing!=NULL) return (void *) nInit(0);
167      else                return NULL;
168    }
169    case BIGINT_CMD:
170      return (void *) n_Init(0, coeffs_BIGINT);
171    case IDEAL_CMD:
172    case MODUL_CMD:
173    case MATRIX_CMD:
174    case SMATRIX_CMD:
175      return (void*) idInit(1,1);
176    case MAP_CMD:
177    {
178      map m = (map)idInit(1,1);
179      m->preimage = omStrDup(IDID(currRingHdl));
180      return (void *)m;
181    }
182    case STRING_CMD:
183      return (void *)omAlloc0(1);
184    case LIST_CMD:
185    {
186      lists l=(lists)omAllocBin(slists_bin);
187      l->Init();
188      return (void*)l;
189    }
190    //the types with the standard init: set the struct to zero
191    case LINK_CMD:
192      return (void*) omAlloc0Bin(sip_link_bin);
193    case RING_CMD:
194      return NULL;
195    case PACKAGE_CMD:
196    {
197      package pa=(package)omAlloc0Bin(sip_package_bin);
198      pa->language=LANG_NONE;
199      pa->loaded = FALSE;
200      return (void*)pa;
201    }
202    case PROC_CMD:
203    {
204      procinfov pi=(procinfov)omAlloc0Bin(procinfo_bin);
205      pi->ref=1;
206      pi->language=LANG_NONE;
207      return (void*)pi;
208    }
209    case RESOLUTION_CMD:
210      return  (void *)omAlloc0(sizeof(ssyStrategy));
211    //other types: without init (int,script,poly,def,package)
212    case CRING_CMD:
213    case INT_CMD:
214    case DEF_CMD:
215    case POLY_CMD:
216    case VECTOR_CMD:
217    case QRING_CMD:
218       return (void*)0L;
219    default:
220      {
221        if (t>MAX_TOK)
222        {
223#ifdef BLACKBOX_DEVEL
224          Print("bb-type %d\n",t);
225#endif
226          blackbox *bb=getBlackboxStuff(t);
227          if (bb!=NULL)
228             return (void *)bb->blackbox_Init(bb);
229        }
230        else
231          Werror("unknown type in idrecDataInit:%d",t);
232        break;
233      }
234  }
235  return (void *)0L;
236}
237idhdl idrec::set(const char * s, int level, int t, BOOLEAN init)
238{
239  //printf("define %s, %x, level: %d, typ: %d\n", s,s,level,t);
240  idhdl h = (idrec *)omAlloc0Bin(idrec_bin);
241  IDID(h)   = s;
242  IDTYP(h)  = t;
243  IDLEV(h)  = level;
244  IDNEXT(h) = this;
245  BOOLEAN at_start=(this==IDROOT);
246  h->id_i=iiS2I(s);
247  if (t==BUCKET_CMD) WarnS("defining polyBucket");
248  if (init)
249  {
250    if ((t==IDEAL_CMD)||(t==MODUL_CMD))
251      IDFLAG(h) = Sy_bit(FLAG_STD);
252    IDSTRING(h)=(char *)idrecDataInit(t);
253    // additional settings:--------------------------------------
254#if 0
255    // this leads to a memory leak
256    if (t == QRING_CMD)
257    {
258      // IDRING(h)=rCopy(currRing);
259      /* QRING_CMD is ring dep => currRing !=NULL */
260    }
261#endif
262  }
263  // --------------------------------------------------------
264  if (at_start)
265    IDNEXT(h) = IDROOT;
266  return  h;
267}
268
269char * idrec::String(BOOLEAN typed)
270{
271  sleftv tmp;
272  memset(&tmp,0,sizeof(sleftv));
273  tmp.rtyp=IDTYP(this);
274  tmp.data=IDDATA(this);
275  tmp.name=IDID(this);
276  return tmp.String(NULL, typed);
277}
278
279idhdl enterid(const char * s, int lev, int t, idhdl* root, BOOLEAN init, BOOLEAN search)
280{
281  if (s==NULL) return NULL;
282  if (root==NULL) return NULL;
283  idhdl h;
284  s=omStrDup(s);
285  // idhdl *save_root=root;
286  if (t==PACKAGE_CMD)
287  {
288    if (root!=&(basePack->idroot))
289    {
290      root=&(basePack->idroot);
291    }
292  }
293  // is it already defined in root ?
294  if ((h=(*root)->get_level(s,lev))!=NULL)
295  {
296    if ((IDTYP(h) == t)||(t==DEF_CMD))
297    {
298      if (IDTYP(h)==PACKAGE_CMD)
299      {
300        if (strcmp(s,"Top")==0)
301        {
302          goto errlabel;
303        }
304        else return h;
305      }
306      else
307      {
308        if (BVERBOSE(V_REDEFINE))
309        {
310          const char *f=VoiceName();
311          if (strcmp(f,"STDIN")==0)
312            Warn("redefining %s (%s)",s,my_yylinebuf);
313          else
314            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
315        }
316        if (s==IDID(h)) IDID(h)=NULL;
317        killhdl2(h,root,currRing);
318      }
319    }
320    else
321      goto errlabel;
322  }
323  // is it already defined in currRing->idroot ?
324  else if (search && (currRing!=NULL)&&((*root) != currRing->idroot))
325  {
326    if ((h=currRing->idroot->get_level(s,lev))!=NULL)
327    {
328      if ((IDTYP(h) == t)||(t==DEF_CMD))
329      {
330        if (BVERBOSE(V_REDEFINE))
331        {
332          const char *f=VoiceName();
333          if (strcmp(f,"STDIN")==0)
334            Warn("redefining %s (%s)",s,my_yylinebuf);
335          else
336            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
337        }
338        if (s==IDID(h)) IDID(h)=NULL;
339        killhdl2(h,&currRing->idroot,currRing);
340      }
341      else
342        goto errlabel;
343    }
344  }
345  // is it already defined in idroot ?
346  else if (search && (*root != IDROOT))
347  {
348    if ((h=IDROOT->get_level(s,lev))!=NULL)
349    {
350      if ((IDTYP(h) == t)||(t==DEF_CMD))
351      {
352        if (BVERBOSE(V_REDEFINE))
353        {
354          const char *f=VoiceName();
355          if (strcmp(f,"STDIN")==0)
356            Warn("redefining %s (%s)",s,my_yylinebuf);
357          else
358            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
359        }
360        if (s==IDID(h)) IDID(h)=NULL;
361        killhdl2(h,&IDROOT,NULL);
362      }
363      else
364        goto errlabel;
365    }
366  }
367  *root = (*root)->set(s, lev, t, init);
368#ifndef SING_NDEBUG
369  checkall();
370#endif
371  return *root;
372
373  errlabel:
374    //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev);
375    Werror("identifier `%s` in use",s);
376    //listall();
377    omFree((ADDRESS)s);
378    return NULL;
379}
380void killid(const char * id, idhdl * ih)
381{
382  if (id!=NULL)
383  {
384    idhdl h = (*ih)->get(id,myynest);
385
386    // id not found in global list, is it defined in current ring ?
387    if (h==NULL)
388    {
389      if ((currRing!=NULL) && (*ih != (currRing->idroot)))
390      {
391        h = currRing->idroot->get(id,myynest);
392        if (h!=NULL)
393        {
394          killhdl2(h,&(currRing->idroot),currRing);
395          return;
396        }
397      }
398      Werror("`%s` is not defined",id);
399      return;
400    }
401    killhdl2(h,ih,currRing);
402  }
403  else
404    WerrorS("kill what ?");
405}
406
407void killhdl(idhdl h, package proot)
408{
409  int t=IDTYP(h);
410  if (((BEGIN_RING<t) && (t<END_RING))
411  || ((t==LIST_CMD) && (lRingDependend((lists)IDDATA(h)))))
412    killhdl2(h,&currRing->idroot,currRing);
413  else
414  {
415    if(t==PACKAGE_CMD)
416    {
417      killhdl2(h,&(basePack->idroot),NULL);
418    }
419    else
420    {
421      idhdl s=proot->idroot;
422      while ((s!=h) && (s!=NULL)) s=s->next;
423      if (s!=NULL)
424        killhdl2(h,&(proot->idroot),NULL);
425      else if (basePack!=proot)
426      {
427        idhdl s=basePack->idroot;
428        while ((s!=h) && (s!=NULL)) s=s->next;
429        if (s!=NULL)
430          killhdl2(h,&(basePack->idroot),currRing);
431        else
432          killhdl2(h,&(currRing->idroot),currRing);
433       }
434    }
435  }
436}
437
438void killhdl2(idhdl h, idhdl * ih, ring r)
439{
440  //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h));
441  idhdl hh;
442
443  if (TEST_V_ALLWARN
444  && (IDLEV(h)!=myynest)
445  &&(IDLEV(h)==0))
446  {
447    if (((*ih)==basePack->idroot)
448    || ((currRing!=NULL)&&((*ih)==currRing->idroot)))
449      Warn("kill global `%s` at line >>%s<<\n",IDID(h),my_yylinebuf);
450  }
451  if (h->attribute!=NULL)
452  {
453    if ((IDTYP(h)==RING_CMD)&&(IDRING(h)!=r))
454       h->attribute->killAll(IDRING(h));
455    else
456       h->attribute->killAll(r);
457    h->attribute=NULL;
458  }
459  if (IDTYP(h) == PACKAGE_CMD)
460  {
461    if (((IDPACKAGE(h)->language==LANG_C)&&(IDPACKAGE(h)->idroot!=NULL))
462    || (strcmp(IDID(h),"Top")==0))
463    {
464      Warn("cannot kill `%s`",IDID(h));
465      return;
466    }
467    // any objects defined for this package ?
468    if ((IDPACKAGE(h)->ref<=0)  &&  (IDPACKAGE(h)->idroot!=NULL))
469    {
470      if (currPack==IDPACKAGE(h))
471      {
472        currPack=basePack;
473        currPackHdl=NULL;
474      }
475      idhdl * hd = &IDRING(h)->idroot;
476      idhdl  hdh = IDNEXT(*hd);
477      idhdl  temp;
478      while (hdh!=NULL)
479      {
480        temp = IDNEXT(hdh);
481        killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL);
482        hdh = temp;
483      }
484      killhdl2(*hd,hd,NULL);
485      if (IDPACKAGE(h)->libname!=NULL) omFree((ADDRESS)(IDPACKAGE(h)->libname));
486    }
487    paKill(IDPACKAGE(h));
488    if (currPackHdl==h) currPackHdl=packFindHdl(currPack);
489    iiCheckPack(currPack);
490  }
491  else if (IDTYP(h)==RING_CMD)
492    rKill(h);
493  else if (IDDATA(h)!=NULL)
494    s_internalDelete(IDTYP(h),IDDATA(h),r);
495  //  general  -------------------------------------------------------------
496  // now dechain it and delete idrec
497  if (IDID(h)!=NULL) // OB: ?????
498    omFree((ADDRESS)IDID(h));
499  IDID(h)=NULL;
500  IDDATA(h)=NULL;
501  if (h == (*ih))
502  {
503    // h is at the beginning of the list
504    *ih = IDNEXT(h) /* ==*ih */;
505  }
506  else if (ih!=NULL)
507  {
508    // h is somethere in the list:
509    hh = *ih;
510    loop
511    {
512      if (hh==NULL)
513      {
514        PrintS(">>?<< not found for kill\n");
515        return;
516      }
517      idhdl hhh = IDNEXT(hh);
518      if (hhh == h)
519      {
520        IDNEXT(hh) = IDNEXT(hhh);
521        break;
522      }
523      hh = hhh;
524    }
525  }
526  omFreeBin((ADDRESS)h, idrec_bin);
527}
528
529#if 0
530idhdl ggetid(const char *n, BOOLEAN /*local*/, idhdl *packhdl)
531{
532  idhdl h = IDROOT->get(n,myynest);
533  idhdl h2=NULL;
534  *packhdl = NULL;
535  if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest)))
536  {
537    h2 = currRing->idroot->get(n,myynest);
538  }
539  if (h2==NULL) return h;
540  return h2;
541}
542#endif
543
544#if 0
545// debug version
546idhdl ggetid(const char *n)
547{
548  if (currRing!=NULL)
549  {
550    idhdl h2 = currRing->idroot->get(n,myynest);
551    idhdl h = IDROOT->get(n,myynest);
552    if ((h!=NULL)&&(h2!=NULL)&&(IDLEV(h)==IDLEV(h2)))
553    {
554      Warn("SHADOW %s(%s) vs %s(%s) in %s\n",IDID(h),Tok2Cmdname(IDTYP(h)),IDID(h2),Tok2Cmdname(IDTYP(h2)),my_yylinebuf);
555    }
556    if ((h2!=NULL)&&(IDLEV(h2)==myynest)) return h2;
557    if (h!=NULL) return h;
558    if (h2!=NULL) return h2;
559  }
560  else
561  {
562    idhdl h = IDROOT->get(n,myynest);
563    if (h!=NULL) return h;
564  }
565  if (basePack!=currPack)
566    return basePack->idroot->get(n,myynest);
567  return NULL;
568}
569#endif
570#if 1
571// try currRing before non-ring stuff
572idhdl ggetid(const char *n)
573{
574  if (currRing!=NULL)
575  {
576    idhdl h2 = currRing->idroot->get(n,myynest);
577    if ((h2!=NULL)&&(IDLEV(h2)==myynest)) return h2;
578    idhdl h = IDROOT->get(n,myynest);
579    if (h!=NULL) return h;
580    if (h2!=NULL) return h2;
581  }
582  else
583  {
584    idhdl h = IDROOT->get(n,myynest);
585    if (h!=NULL) return h;
586  }
587  if (basePack!=currPack)
588    return basePack->idroot->get(n,myynest);
589  return NULL;
590}
591#endif
592#if 0
593// try non-ring stuff before ring stuff
594idhdl ggetid(const char *n)
595{
596  idhdl h = IDROOT->get(n,myynest);
597  if ((h!=NULL)&&(IDLEV(h)==myynest)) return h;
598  if (currRing!=NULL)
599  {
600    idhdl h2 = currRing->idroot->get(n,myynest);
601    if (h2!=NULL) return h2;
602  }
603  if (h!=NULL) return h;
604  if (basePack!=currPack)
605    return basePack->idroot->get(n,myynest);
606  return NULL;
607}
608#endif
609
610void ipListFlag(idhdl h)
611{
612  if (hasFlag(h,FLAG_STD)) PrintS(" (SB)");
613#ifdef HAVE_PLURAL
614  if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)");
615#endif
616}
617
618lists ipNameList(idhdl root)
619{
620  idhdl h=root;
621  /* compute the length */
622  int l=0;
623  while (h!=NULL) { l++; h=IDNEXT(h); }
624  /* allocate list */
625  lists L=(lists)omAllocBin(slists_bin);
626  L->Init(l);
627  /* copy names */
628  h=root;
629  l=0;
630  while (h!=NULL)
631  {
632    /* list is initialized with 0 => no need to clear anything */
633    L->m[l].rtyp=STRING_CMD;
634    L->m[l].data=omStrDup(IDID(h));
635    l++;
636    h=IDNEXT(h);
637  }
638  return L;
639}
640
641lists ipNameListLev(idhdl root, int lev)
642{
643  idhdl h=root;
644  /* compute the length */
645  int l=0;
646  while (h!=NULL) { if (IDLEV(h)==lev) l++; h=IDNEXT(h); }
647  /* allocate list */
648  lists L=(lists)omAllocBin(slists_bin);
649  L->Init(l);
650  /* copy names */
651  h=root;
652  l=0;
653  while (h!=NULL)
654  {
655    if (IDLEV(h)==lev)
656    {
657      /* list is initialized with 0 => no need to clear anything */
658      L->m[l].rtyp=STRING_CMD;
659      L->m[l].data=omStrDup(IDID(h));
660      l++;
661    }
662    h=IDNEXT(h);
663  }
664  return L;
665}
666
667/*
668* move 'tomove' from root1 list to root2 list
669*/
670static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2)
671{
672  idhdl h;
673  /* search 'tomove' in root2 : if found -> do nothing */
674  h=root2;
675  while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h);
676  if (h!=NULL) return FALSE; /*okay */
677  /* search predecessor of h in root1, remove 'tomove' */
678  h=root1;
679  if (tomove==h)
680  {
681    root1=IDNEXT(h);
682  }
683  else
684  {
685    while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h);
686    if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */
687    IDNEXT(h)=IDNEXT(tomove);
688  }
689  /* add to root2 list */
690  IDNEXT(tomove)=root2;
691  root2=tomove;
692  return FALSE;
693}
694
695void  ipMoveId(idhdl tomove)
696{
697  if ((currRing!=NULL)&&(tomove!=NULL))
698  {
699    if (RingDependend(IDTYP(tomove))
700    || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove)))))
701    {
702      /*move 'tomove' to ring id's*/
703      if (ipSwapId(tomove,IDROOT,currRing->idroot))
704      ipSwapId(tomove,basePack->idroot,currRing->idroot);
705    }
706    else
707    {
708      /*move 'tomove' to global id's*/
709      ipSwapId(tomove,currRing->idroot,IDROOT);
710    }
711  }
712}
713
714const char * piProcinfo(procinfov pi, const char *request)
715{
716  if((pi == NULL)||(pi->language==LANG_NONE)) return "empty proc";
717  else if (strcmp(request, "libname")  == 0) return pi->libname;
718  else if (strcmp(request, "procname") == 0) return pi->procname;
719  else if (strcmp(request, "type")     == 0)
720  {
721    switch (pi->language)
722    {
723      case LANG_SINGULAR: return "singular"; break;
724      case LANG_C:        return "object";   break;
725      case LANG_NONE:     return "none";     break;
726      default:            return "unknown language";
727    }
728  }
729  else if (strcmp(request, "ref")      == 0)
730  {
731    char p[8];
732    sprintf(p, "%d", pi->ref);
733    return omStrDup(p);  // MEMORY-LEAK
734  }
735  return "??";
736}
737
738BOOLEAN piKill(procinfov pi)
739{
740  (pi->ref)--;
741  if (pi->ref == 0)
742  {
743    if (pi->language==LANG_SINGULAR)
744    {
745      Voice *p=currentVoice;
746      while (p!=NULL)
747      {
748        if (p->pi==pi && pi->ref <= 1)
749        {
750          Warn("`%s` in use, can not be killed",pi->procname);
751          return TRUE;
752        }
753        p=p->next;
754      }
755    }
756    if (pi->libname != NULL) // OB: ????
757      omFree((ADDRESS)pi->libname);
758    if (pi->procname != NULL) // OB: ????
759      omFree((ADDRESS)pi->procname);
760
761    if( pi->language == LANG_SINGULAR)
762    {
763      if (pi->data.s.body != NULL) // OB: ????
764        omFree((ADDRESS)pi->data.s.body);
765    }
766    if( pi->language == LANG_C)
767    {
768    }
769    memset((void *) pi, 0, sizeof(procinfo));
770    //pi->language=LANG_NONE;
771    omFreeBin((ADDRESS)pi,  procinfo_bin);
772  }
773  return FALSE;
774}
775
776void paCleanUp(package pack)
777{
778  (pack->ref)--;
779  if (pack->ref < 0)
780  {
781#ifndef HAVE_STATIC
782    if( pack->language == LANG_C)
783    {
784      Print("//dlclose(%s)\n",pack->libname);
785#ifdef HAVE_DYNAMIC_LOADING
786      dynl_close (pack->handle);
787#endif /* HAVE_DYNAMIC_LOADING */
788    }
789#endif /* HAVE_STATIC */
790    omFree((ADDRESS)pack->libname);
791    memset((void *) pack, 0, sizeof(sip_package));
792    pack->language=LANG_NONE;
793  }
794}
795
796void proclevel::push(char *n)
797{
798  //Print("push %s\n",n);
799  proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel));
800  p->name=n;
801  p->cPackHdl=currPackHdl;
802  p->cPack=currPack;
803  p->next=this;
804  procstack=p;
805}
806void proclevel::pop()
807{
808  //Print("pop %s\n",name);
809  //if (currRing!=::currRing) PrintS("currRing wrong\n");;
810  //::currRing=this->currRing;
811  //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name);
812  //::currRingHdl=this->currRingHdl;
813  //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing)))
814  //  ::currRingHdl=rFindHdl(::currRing,NULL,NULL);
815  //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot));
816  currPackHdl=this->cPackHdl;
817  currPack=this->cPack;
818  iiCheckPack(currPack);
819  proclevel *p=this;
820  procstack=next;
821  omFreeSize(p,sizeof(proclevel));
822}
823
824idhdl packFindHdl(package r)
825{
826  idhdl h=basePack->idroot;
827  while (h!=NULL)
828  {
829    if ((IDTYP(h)==PACKAGE_CMD)
830        && (IDPACKAGE(h)==r))
831      return h;
832    h=IDNEXT(h);
833  }
834  return NULL;
835}
836
837BOOLEAN iiAlias(leftv p)
838{
839  if (iiCurrArgs==NULL)
840  {
841    Werror("not enough arguments for proc %s",VoiceName());
842    p->CleanUp();
843    return TRUE;
844  }
845  leftv h=iiCurrArgs;
846  iiCurrArgs=h->next;
847  h->next=NULL;
848  if (h->rtyp!=IDHDL)
849  {
850    BOOLEAN res=iiAssign(p,h);
851    h->CleanUp();
852    omFreeBin((ADDRESS)h, sleftv_bin);
853    return res;
854  }
855  if ((h->Typ()!=p->Typ()) &&(p->Typ()!=DEF_CMD))
856  {
857    WerrorS("type mismatch");
858    return TRUE;
859  }
860  idhdl pp=(idhdl)p->data;
861  switch(pp->typ)
862  {
863      case CRING_CMD:
864        nKillChar((coeffs)pp);
865        break;
866      case DEF_CMD:
867      case INT_CMD:
868        break;
869      case INTVEC_CMD:
870      case INTMAT_CMD:
871         delete IDINTVEC(pp);
872         break;
873      case NUMBER_CMD:
874         nDelete(&IDNUMBER(pp));
875         break;
876      case BIGINT_CMD:
877         n_Delete(&IDNUMBER(pp),coeffs_BIGINT);
878         break;
879      case MAP_CMD:
880         {
881           map im = IDMAP(pp);
882           omFree((ADDRESS)im->preimage);
883         }
884         // continue as ideal:
885      case IDEAL_CMD:
886      case MODUL_CMD:
887      case MATRIX_CMD:
888          idDelete(&IDIDEAL(pp));
889         break;
890      case PROC_CMD:
891      case RESOLUTION_CMD:
892      case STRING_CMD:
893         omFree((ADDRESS)IDSTRING(pp));
894         break;
895      case LIST_CMD:
896         IDLIST(pp)->Clean();
897         break;
898      case LINK_CMD:
899         omFreeBin(IDLINK(pp),sip_link_bin);
900         break;
901       // case ring: cannot happen
902       default:
903         Werror("unknown type %d",p->Typ());
904         return TRUE;
905  }
906  pp->typ=ALIAS_CMD;
907  IDDATA(pp)=(char*)h->data;
908  int eff_typ=h->Typ();
909  if ((RingDependend(eff_typ))
910  || ((eff_typ==LIST_CMD) && (lRingDependend((lists)h->Data()))))
911  {
912    ipSwapId(pp,IDROOT,currRing->idroot);
913  }
914  h->CleanUp();
915  omFreeBin((ADDRESS)h, sleftv_bin);
916  return FALSE;
917}
918
Note: See TracBrowser for help on using the repository browser.