source: git/Singular/ipid.cc @ ad2c16

spielwiese
Last change on this file since ad2c16 was ad2c16, checked in by Hans Schoenemann <hannes@…>, 4 years ago
opt: reorder switch
  • 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 PACKAGE_CMD:
194    {
195      package pa=(package)omAlloc0Bin(sip_package_bin);
196      pa->language=LANG_NONE;
197      pa->loaded = FALSE;
198      return (void*)pa;
199    }
200    case PROC_CMD:
201    {
202      procinfov pi=(procinfov)omAlloc0Bin(procinfo_bin);
203      pi->ref=1;
204      pi->language=LANG_NONE;
205      return (void*)pi;
206    }
207    case RESOLUTION_CMD:
208      return  (void *)omAlloc0(sizeof(ssyStrategy));
209    //other types: without alloc. (int,script,poly,def,package,..)
210    case INT_CMD:
211    case DEF_CMD:
212    case POLY_CMD:
213    case VECTOR_CMD:
214    case RING_CMD:
215    case CRING_CMD:
216    case QRING_CMD:
217      return NULL;
218    default:
219      {
220        if (t>MAX_TOK)
221        {
222#ifdef BLACKBOX_DEVEL
223          Print("bb-type %d\n",t);
224#endif
225          blackbox *bb=getBlackboxStuff(t);
226          if (bb!=NULL)
227             return (void *)bb->blackbox_Init(bb);
228        }
229        else
230          Werror("unknown type in idrecDataInit:%d",t);
231        break;
232      }
233  }
234  return (void *)0L;
235}
236idhdl idrec::set(const char * s, int level, int t, BOOLEAN init)
237{
238  //printf("define %s, %x, level: %d, typ: %d\n", s,s,level,t);
239  idhdl h = (idrec *)omAlloc0Bin(idrec_bin);
240  IDID(h)   = s;
241  IDTYP(h)  = t;
242  IDLEV(h)  = level;
243  IDNEXT(h) = this;
244  BOOLEAN at_start=(this==IDROOT);
245  h->id_i=iiS2I(s);
246  if (t==BUCKET_CMD) WarnS("defining polyBucket");
247  if (init)
248  {
249    if ((t==IDEAL_CMD)||(t==MODUL_CMD))
250      IDFLAG(h) = Sy_bit(FLAG_STD);
251    IDSTRING(h)=(char *)idrecDataInit(t);
252    // additional settings:--------------------------------------
253#if 0
254    // this leads to a memory leak
255    if (t == QRING_CMD)
256    {
257      // IDRING(h)=rCopy(currRing);
258      /* QRING_CMD is ring dep => currRing !=NULL */
259    }
260#endif
261  }
262  // --------------------------------------------------------
263  if (at_start)
264    IDNEXT(h) = IDROOT;
265  return  h;
266}
267
268char * idrec::String(BOOLEAN typed)
269{
270  sleftv tmp;
271  memset(&tmp,0,sizeof(sleftv));
272  tmp.rtyp=IDTYP(this);
273  tmp.data=IDDATA(this);
274  tmp.name=IDID(this);
275  return tmp.String(NULL, typed);
276}
277
278idhdl enterid(const char * s, int lev, int t, idhdl* root, BOOLEAN init, BOOLEAN search)
279{
280  if (s==NULL) return NULL;
281  if (root==NULL) return NULL;
282  idhdl h;
283  s=omStrDup(s);
284  // idhdl *save_root=root;
285  if (t==PACKAGE_CMD)
286  {
287    if (root!=&(basePack->idroot))
288    {
289      root=&(basePack->idroot);
290    }
291  }
292  // is it already defined in root ?
293  if ((h=(*root)->get_level(s,lev))!=NULL)
294  {
295    if ((IDTYP(h) == t)||(t==DEF_CMD))
296    {
297      if (IDTYP(h)==PACKAGE_CMD)
298      {
299        if (strcmp(s,"Top")==0)
300        {
301          goto errlabel;
302        }
303        else return h;
304      }
305      else
306      {
307        if (BVERBOSE(V_REDEFINE))
308        {
309          const char *f=VoiceName();
310          if (strcmp(f,"STDIN")==0)
311            Warn("redefining %s (%s)",s,my_yylinebuf);
312          else
313            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
314        }
315        if (s==IDID(h)) IDID(h)=NULL;
316        killhdl2(h,root,currRing);
317      }
318    }
319    else
320      goto errlabel;
321  }
322  // is it already defined in currRing->idroot ?
323  else if (search && (currRing!=NULL)&&((*root) != currRing->idroot))
324  {
325    if ((h=currRing->idroot->get_level(s,lev))!=NULL)
326    {
327      if ((IDTYP(h) == t)||(t==DEF_CMD))
328      {
329        if (BVERBOSE(V_REDEFINE))
330        {
331          const char *f=VoiceName();
332          if (strcmp(f,"STDIN")==0)
333            Warn("redefining %s (%s)",s,my_yylinebuf);
334          else
335            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
336        }
337        if (s==IDID(h)) IDID(h)=NULL;
338        killhdl2(h,&currRing->idroot,currRing);
339      }
340      else
341        goto errlabel;
342    }
343  }
344  // is it already defined in idroot ?
345  else if (search && (*root != IDROOT))
346  {
347    if ((h=IDROOT->get_level(s,lev))!=NULL)
348    {
349      if ((IDTYP(h) == t)||(t==DEF_CMD))
350      {
351        if (BVERBOSE(V_REDEFINE))
352        {
353          const char *f=VoiceName();
354          if (strcmp(f,"STDIN")==0)
355            Warn("redefining %s (%s)",s,my_yylinebuf);
356          else
357            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
358        }
359        if (s==IDID(h)) IDID(h)=NULL;
360        killhdl2(h,&IDROOT,NULL);
361      }
362      else
363        goto errlabel;
364    }
365  }
366  *root = (*root)->set(s, lev, t, init);
367#ifndef SING_NDEBUG
368  checkall();
369#endif
370  return *root;
371
372  errlabel:
373    //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev);
374    Werror("identifier `%s` in use",s);
375    //listall();
376    omFree((ADDRESS)s);
377    return NULL;
378}
379void killid(const char * id, idhdl * ih)
380{
381  if (id!=NULL)
382  {
383    idhdl h = (*ih)->get(id,myynest);
384
385    // id not found in global list, is it defined in current ring ?
386    if (h==NULL)
387    {
388      if ((currRing!=NULL) && (*ih != (currRing->idroot)))
389      {
390        h = currRing->idroot->get(id,myynest);
391        if (h!=NULL)
392        {
393          killhdl2(h,&(currRing->idroot),currRing);
394          return;
395        }
396      }
397      Werror("`%s` is not defined",id);
398      return;
399    }
400    killhdl2(h,ih,currRing);
401  }
402  else
403    WerrorS("kill what ?");
404}
405
406void killhdl(idhdl h, package proot)
407{
408  int t=IDTYP(h);
409  if (((BEGIN_RING<t) && (t<END_RING))
410  || ((t==LIST_CMD) && (lRingDependend((lists)IDDATA(h)))))
411    killhdl2(h,&currRing->idroot,currRing);
412  else
413  {
414    if(t==PACKAGE_CMD)
415    {
416      killhdl2(h,&(basePack->idroot),NULL);
417    }
418    else
419    {
420      idhdl s=proot->idroot;
421      while ((s!=h) && (s!=NULL)) s=s->next;
422      if (s!=NULL)
423        killhdl2(h,&(proot->idroot),NULL);
424      else if (basePack!=proot)
425      {
426        idhdl s=basePack->idroot;
427        while ((s!=h) && (s!=NULL)) s=s->next;
428        if (s!=NULL)
429          killhdl2(h,&(basePack->idroot),currRing);
430        else
431          killhdl2(h,&(currRing->idroot),currRing);
432       }
433    }
434  }
435}
436
437void killhdl2(idhdl h, idhdl * ih, ring r)
438{
439  //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h));
440  idhdl hh;
441
442  if (TEST_V_ALLWARN
443  && (IDLEV(h)!=myynest)
444  &&(IDLEV(h)==0))
445  {
446    if (((*ih)==basePack->idroot)
447    || ((currRing!=NULL)&&((*ih)==currRing->idroot)))
448      Warn("kill global `%s` at line >>%s<<\n",IDID(h),my_yylinebuf);
449  }
450  if (h->attribute!=NULL)
451  {
452    if ((IDTYP(h)==RING_CMD)&&(IDRING(h)!=r))
453       h->attribute->killAll(IDRING(h));
454    else
455       h->attribute->killAll(r);
456    h->attribute=NULL;
457  }
458  if (IDTYP(h) == PACKAGE_CMD)
459  {
460    if (((IDPACKAGE(h)->language==LANG_C)&&(IDPACKAGE(h)->idroot!=NULL))
461    || (strcmp(IDID(h),"Top")==0))
462    {
463      Warn("cannot kill `%s`",IDID(h));
464      return;
465    }
466    // any objects defined for this package ?
467    if ((IDPACKAGE(h)->ref<=0)  &&  (IDPACKAGE(h)->idroot!=NULL))
468    {
469      if (currPack==IDPACKAGE(h))
470      {
471        currPack=basePack;
472        currPackHdl=NULL;
473      }
474      idhdl * hd = &IDRING(h)->idroot;
475      idhdl  hdh = IDNEXT(*hd);
476      idhdl  temp;
477      while (hdh!=NULL)
478      {
479        temp = IDNEXT(hdh);
480        killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL);
481        hdh = temp;
482      }
483      killhdl2(*hd,hd,NULL);
484      if (IDPACKAGE(h)->libname!=NULL) omFree((ADDRESS)(IDPACKAGE(h)->libname));
485    }
486    paKill(IDPACKAGE(h));
487    if (currPackHdl==h) currPackHdl=packFindHdl(currPack);
488    iiCheckPack(currPack);
489  }
490  else if (IDTYP(h)==RING_CMD)
491    rKill(h);
492  else if (IDDATA(h)!=NULL)
493    s_internalDelete(IDTYP(h),IDDATA(h),r);
494  //  general  -------------------------------------------------------------
495  // now dechain it and delete idrec
496  if (IDID(h)!=NULL) // OB: ?????
497    omFree((ADDRESS)IDID(h));
498  IDID(h)=NULL;
499  IDDATA(h)=NULL;
500  if (h == (*ih))
501  {
502    // h is at the beginning of the list
503    *ih = IDNEXT(h) /* ==*ih */;
504  }
505  else if (ih!=NULL)
506  {
507    // h is somethere in the list:
508    hh = *ih;
509    loop
510    {
511      if (hh==NULL)
512      {
513        PrintS(">>?<< not found for kill\n");
514        return;
515      }
516      idhdl hhh = IDNEXT(hh);
517      if (hhh == h)
518      {
519        IDNEXT(hh) = IDNEXT(hhh);
520        break;
521      }
522      hh = hhh;
523    }
524  }
525  omFreeBin((ADDRESS)h, idrec_bin);
526}
527
528#if 0
529idhdl ggetid(const char *n, BOOLEAN /*local*/, idhdl *packhdl)
530{
531  idhdl h = IDROOT->get(n,myynest);
532  idhdl h2=NULL;
533  *packhdl = NULL;
534  if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest)))
535  {
536    h2 = currRing->idroot->get(n,myynest);
537  }
538  if (h2==NULL) return h;
539  return h2;
540}
541#endif
542
543#if 0
544// debug version
545idhdl ggetid(const char *n)
546{
547  if (currRing!=NULL)
548  {
549    idhdl h2 = currRing->idroot->get(n,myynest);
550    idhdl h = IDROOT->get(n,myynest);
551    if ((h!=NULL)&&(h2!=NULL)&&(IDLEV(h)==IDLEV(h2)))
552    {
553      Warn("SHADOW %s(%s) vs %s(%s) in %s\n",IDID(h),Tok2Cmdname(IDTYP(h)),IDID(h2),Tok2Cmdname(IDTYP(h2)),my_yylinebuf);
554    }
555    if ((h2!=NULL)&&(IDLEV(h2)==myynest)) return h2;
556    if (h!=NULL) return h;
557    if (h2!=NULL) return h2;
558  }
559  else
560  {
561    idhdl h = IDROOT->get(n,myynest);
562    if (h!=NULL) return h;
563  }
564  if (basePack!=currPack)
565    return basePack->idroot->get(n,myynest);
566  return NULL;
567}
568#endif
569#if 1
570// try currRing before non-ring stuff
571idhdl ggetid(const char *n)
572{
573  if (currRing!=NULL)
574  {
575    idhdl h2 = currRing->idroot->get(n,myynest);
576    if ((h2!=NULL)&&(IDLEV(h2)==myynest)) return h2;
577    idhdl h = IDROOT->get(n,myynest);
578    if (h!=NULL) return h;
579    if (h2!=NULL) return h2;
580  }
581  else
582  {
583    idhdl h = IDROOT->get(n,myynest);
584    if (h!=NULL) return h;
585  }
586  if (basePack!=currPack)
587    return basePack->idroot->get(n,myynest);
588  return NULL;
589}
590#endif
591#if 0
592// try non-ring stuff before ring stuff
593idhdl ggetid(const char *n)
594{
595  idhdl h = IDROOT->get(n,myynest);
596  if ((h!=NULL)&&(IDLEV(h)==myynest)) return h;
597  if (currRing!=NULL)
598  {
599    idhdl h2 = currRing->idroot->get(n,myynest);
600    if (h2!=NULL) return h2;
601  }
602  if (h!=NULL) return h;
603  if (basePack!=currPack)
604    return basePack->idroot->get(n,myynest);
605  return NULL;
606}
607#endif
608
609void ipListFlag(idhdl h)
610{
611  if (hasFlag(h,FLAG_STD)) PrintS(" (SB)");
612#ifdef HAVE_PLURAL
613  if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)");
614#endif
615}
616
617lists ipNameList(idhdl root)
618{
619  idhdl h=root;
620  /* compute the length */
621  int l=0;
622  while (h!=NULL) { l++; h=IDNEXT(h); }
623  /* allocate list */
624  lists L=(lists)omAllocBin(slists_bin);
625  L->Init(l);
626  /* copy names */
627  h=root;
628  l=0;
629  while (h!=NULL)
630  {
631    /* list is initialized with 0 => no need to clear anything */
632    L->m[l].rtyp=STRING_CMD;
633    L->m[l].data=omStrDup(IDID(h));
634    l++;
635    h=IDNEXT(h);
636  }
637  return L;
638}
639
640lists ipNameListLev(idhdl root, int lev)
641{
642  idhdl h=root;
643  /* compute the length */
644  int l=0;
645  while (h!=NULL) { if (IDLEV(h)==lev) l++; h=IDNEXT(h); }
646  /* allocate list */
647  lists L=(lists)omAllocBin(slists_bin);
648  L->Init(l);
649  /* copy names */
650  h=root;
651  l=0;
652  while (h!=NULL)
653  {
654    if (IDLEV(h)==lev)
655    {
656      /* list is initialized with 0 => no need to clear anything */
657      L->m[l].rtyp=STRING_CMD;
658      L->m[l].data=omStrDup(IDID(h));
659      l++;
660    }
661    h=IDNEXT(h);
662  }
663  return L;
664}
665
666/*
667* move 'tomove' from root1 list to root2 list
668*/
669static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2)
670{
671  idhdl h;
672  /* search 'tomove' in root2 : if found -> do nothing */
673  h=root2;
674  while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h);
675  if (h!=NULL) return FALSE; /*okay */
676  /* search predecessor of h in root1, remove 'tomove' */
677  h=root1;
678  if (tomove==h)
679  {
680    root1=IDNEXT(h);
681  }
682  else
683  {
684    while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h);
685    if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */
686    IDNEXT(h)=IDNEXT(tomove);
687  }
688  /* add to root2 list */
689  IDNEXT(tomove)=root2;
690  root2=tomove;
691  return FALSE;
692}
693
694void  ipMoveId(idhdl tomove)
695{
696  if ((currRing!=NULL)&&(tomove!=NULL))
697  {
698    if (RingDependend(IDTYP(tomove))
699    || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove)))))
700    {
701      /*move 'tomove' to ring id's*/
702      if (ipSwapId(tomove,IDROOT,currRing->idroot))
703      ipSwapId(tomove,basePack->idroot,currRing->idroot);
704    }
705    else
706    {
707      /*move 'tomove' to global id's*/
708      ipSwapId(tomove,currRing->idroot,IDROOT);
709    }
710  }
711}
712
713const char * piProcinfo(procinfov pi, const char *request)
714{
715  if((pi == NULL)||(pi->language==LANG_NONE)) return "empty proc";
716  else if (strcmp(request, "libname")  == 0) return pi->libname;
717  else if (strcmp(request, "procname") == 0) return pi->procname;
718  else if (strcmp(request, "type")     == 0)
719  {
720    switch (pi->language)
721    {
722      case LANG_SINGULAR: return "singular"; break;
723      case LANG_C:        return "object";   break;
724      case LANG_NONE:     return "none";     break;
725      default:            return "unknown language";
726    }
727  }
728  else if (strcmp(request, "ref")      == 0)
729  {
730    char p[8];
731    sprintf(p, "%d", pi->ref);
732    return omStrDup(p);  // MEMORY-LEAK
733  }
734  return "??";
735}
736
737BOOLEAN piKill(procinfov pi)
738{
739  (pi->ref)--;
740  if (pi->ref == 0)
741  {
742    if (pi->language==LANG_SINGULAR)
743    {
744      Voice *p=currentVoice;
745      while (p!=NULL)
746      {
747        if (p->pi==pi && pi->ref <= 1)
748        {
749          Warn("`%s` in use, can not be killed",pi->procname);
750          return TRUE;
751        }
752        p=p->next;
753      }
754    }
755    if (pi->libname != NULL) // OB: ????
756      omFree((ADDRESS)pi->libname);
757    if (pi->procname != NULL) // OB: ????
758      omFree((ADDRESS)pi->procname);
759
760    if( pi->language == LANG_SINGULAR)
761    {
762      if (pi->data.s.body != NULL) // OB: ????
763        omFree((ADDRESS)pi->data.s.body);
764    }
765    if( pi->language == LANG_C)
766    {
767    }
768    memset((void *) pi, 0, sizeof(procinfo));
769    //pi->language=LANG_NONE;
770    omFreeBin((ADDRESS)pi,  procinfo_bin);
771  }
772  return FALSE;
773}
774
775void paCleanUp(package pack)
776{
777  (pack->ref)--;
778  if (pack->ref < 0)
779  {
780#ifndef HAVE_STATIC
781    if( pack->language == LANG_C)
782    {
783      Print("//dlclose(%s)\n",pack->libname);
784#ifdef HAVE_DYNAMIC_LOADING
785      dynl_close (pack->handle);
786#endif /* HAVE_DYNAMIC_LOADING */
787    }
788#endif /* HAVE_STATIC */
789    omFree((ADDRESS)pack->libname);
790    memset((void *) pack, 0, sizeof(sip_package));
791    pack->language=LANG_NONE;
792  }
793}
794
795void proclevel::push(char *n)
796{
797  //Print("push %s\n",n);
798  proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel));
799  p->name=n;
800  p->cPackHdl=currPackHdl;
801  p->cPack=currPack;
802  p->next=this;
803  procstack=p;
804}
805void proclevel::pop()
806{
807  //Print("pop %s\n",name);
808  //if (currRing!=::currRing) PrintS("currRing wrong\n");;
809  //::currRing=this->currRing;
810  //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name);
811  //::currRingHdl=this->currRingHdl;
812  //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing)))
813  //  ::currRingHdl=rFindHdl(::currRing,NULL,NULL);
814  //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot));
815  currPackHdl=this->cPackHdl;
816  currPack=this->cPack;
817  iiCheckPack(currPack);
818  proclevel *p=this;
819  procstack=next;
820  omFreeSize(p,sizeof(proclevel));
821}
822
823idhdl packFindHdl(package r)
824{
825  idhdl h=basePack->idroot;
826  while (h!=NULL)
827  {
828    if ((IDTYP(h)==PACKAGE_CMD)
829        && (IDPACKAGE(h)==r))
830      return h;
831    h=IDNEXT(h);
832  }
833  return NULL;
834}
835
836BOOLEAN iiAlias(leftv p)
837{
838  if (iiCurrArgs==NULL)
839  {
840    Werror("not enough arguments for proc %s",VoiceName());
841    p->CleanUp();
842    return TRUE;
843  }
844  leftv h=iiCurrArgs;
845  iiCurrArgs=h->next;
846  h->next=NULL;
847  if (h->rtyp!=IDHDL)
848  {
849    BOOLEAN res=iiAssign(p,h);
850    h->CleanUp();
851    omFreeBin((ADDRESS)h, sleftv_bin);
852    return res;
853  }
854  if ((h->Typ()!=p->Typ()) &&(p->Typ()!=DEF_CMD))
855  {
856    WerrorS("type mismatch");
857    return TRUE;
858  }
859  idhdl pp=(idhdl)p->data;
860  switch(pp->typ)
861  {
862      case CRING_CMD:
863        nKillChar((coeffs)pp);
864        break;
865      case DEF_CMD:
866      case INT_CMD:
867        break;
868      case INTVEC_CMD:
869      case INTMAT_CMD:
870         delete IDINTVEC(pp);
871         break;
872      case NUMBER_CMD:
873         nDelete(&IDNUMBER(pp));
874         break;
875      case BIGINT_CMD:
876         n_Delete(&IDNUMBER(pp),coeffs_BIGINT);
877         break;
878      case MAP_CMD:
879         {
880           map im = IDMAP(pp);
881           omFree((ADDRESS)im->preimage);
882         }
883         // continue as ideal:
884      case IDEAL_CMD:
885      case MODUL_CMD:
886      case MATRIX_CMD:
887          idDelete(&IDIDEAL(pp));
888         break;
889      case PROC_CMD:
890      case RESOLUTION_CMD:
891      case STRING_CMD:
892         omFree((ADDRESS)IDSTRING(pp));
893         break;
894      case LIST_CMD:
895         IDLIST(pp)->Clean();
896         break;
897      case LINK_CMD:
898         omFreeBin(IDLINK(pp),sip_link_bin);
899         break;
900       // case ring: cannot happen
901       default:
902         Werror("unknown type %d",p->Typ());
903         return TRUE;
904  }
905  pp->typ=ALIAS_CMD;
906  IDDATA(pp)=(char*)h->data;
907  int eff_typ=h->Typ();
908  if ((RingDependend(eff_typ))
909  || ((eff_typ==LIST_CMD) && (lRingDependend((lists)h->Data()))))
910  {
911    ipSwapId(pp,IDROOT,currRing->idroot);
912  }
913  h->CleanUp();
914  omFreeBin((ADDRESS)h, sleftv_bin);
915  return FALSE;
916}
917
Note: See TracBrowser for help on using the repository browser.