My Project
Macros | Functions | Variables
iplib.cc File Reference
#include "kernel/mod2.h"
#include "Singular/tok.h"
#include "misc/options.h"
#include "Singular/ipid.h"
#include "polys/monomials/ring.h"
#include "Singular/subexpr.h"
#include "Singular/ipshell.h"
#include "Singular/fevoices.h"
#include "Singular/lists.h"
#include <ctype.h>
#include "libparse.h"
#include "Singular/mod_lib.h"
#include <map>
#include <string>
#include <pthread.h>

Go to the source code of this file.

Macros

#define SI_MAX_NEST   500
 
#define MODULE_SUFFIX   so
 
#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)
 
#define SI_GET_BUILTIN_MOD_INIT0(name)   int SI_MOD_INIT0(name)(SModulFunctions*);
 
#define SI_GET_BUILTIN_MOD_INIT(name)   if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
 

Functions

BOOLEAN load_modules (const char *newlib, char *fullname, BOOLEAN autoexport)
 
int iiArithAddCmd (const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
 
void yylprestart (FILE *input_file)
 
int current_pos (int i=0)
 
void print_init ()
 
char mytolower (char c)
 
BOOLEAN iiGetLibStatus (const char *lib)
 
char * iiProcName (char *buf, char &ct, char *&e)
 
char * iiProcArgs (char *e, BOOLEAN withParenth)
 
char * iiGetLibProcBuffer (procinfo *pi, int part)
 
BOOLEAN iiAllStart (procinfov pi, const char *p, feBufferTypes t, int l)
 
BOOLEAN iiPStart (idhdl pn, leftv v)
 
static void iiShowLevRings ()
 
static void iiCheckNest ()
 
BOOLEAN iiMake_proc (idhdl pn, package pack, leftv args)
 
static void iiCallLibProcBegin ()
 
static void iiCallLibProcEnd (idhdl save_ringhdl, ring save_ring)
 
void * iiCallLibProc1 (const char *n, void *arg, int arg_type, BOOLEAN &err)
 
ideal ii_CallProcId2Id (const char *lib, const char *proc, ideal arg, const ring R)
 
int ii_CallProcId2Int (const char *lib, const char *proc, ideal arg, const ring R)
 
leftv ii_CallLibProcM (const char *n, void **args, int *arg_types, const ring R, BOOLEAN &err)
 args: NULL terminated array of arguments arg_types: 0 terminated array of corresponding types More...
 
BOOLEAN iiEStart (char *example, procinfo *pi)
 
 SI_FOREACH_BUILTIN (SI_GET_BUILTIN_MOD_INIT0) }
 
int flint_mod_init (SModulFunctions *psModulFunctions)
 
SModulFunc_t iiGetBuiltinModInit (const char *libname)
 
BOOLEAN iiTryLoadLib (leftv v, const char *id)
 
BOOLEAN iiLocateLib (const char *lib, char *where)
 
BOOLEAN iiLibCmd (const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
 
static void iiCleanProcs (idhdl &root)
 
static void iiRunInit (package p)
 
BOOLEAN iiLoadLIB (FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
 
procinfoiiInitSingularProcinfo (procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
 
int iiAddCproc (const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
 
int iiAddCprocTop (const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
 
bool registered_dyn_module (char *fullname)
 
void register_dyn_module (char *fullname, void *handle)
 
void close_all_dyn_modules ()
 
BOOLEAN load_modules_aux (const char *newlib, char *fullname, BOOLEAN autoexport)
 
BOOLEAN load_builtin (const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
 
void module_help_main (const char *newlib, const char *help)
 
void module_help_proc (const char *newlib, const char *p, const char *help)
 
void * binary_module_function (const char *newlib, const char *funcname)
 
char mytoupper (char c)
 
char * iiConvName (const char *libname)
 

Variables

EXTERN_VAR int yylp_errno
 
EXTERN_VAR int yylplineno
 
const char * yylp_errlist []
 
VAR libstackv library_stack
 
VAR ring * iiLocalRing
 
INST_VAR sleftv iiRETURNEXPR
 
VAR int iiRETURNEXPR_len =0
 
THREAD_VAR std::map< std::string, void * > * dyn_modules
 

Macro Definition Documentation

◆ MODULE_SUFFIX

#define MODULE_SUFFIX   so

Definition at line 35 of file iplib.cc.

◆ MODULE_SUFFIX_STRING

#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)

Definition at line 38 of file iplib.cc.

◆ SI_GET_BUILTIN_MOD_INIT

#define SI_GET_BUILTIN_MOD_INIT (   name)    if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }

◆ SI_GET_BUILTIN_MOD_INIT0

#define SI_GET_BUILTIN_MOD_INIT0 (   name)    int SI_MOD_INIT0(name)(SModulFunctions*);

Definition at line 795 of file iplib.cc.

◆ SI_MAX_NEST

#define SI_MAX_NEST   500

Definition at line 23 of file iplib.cc.

Function Documentation

◆ binary_module_function()

void* binary_module_function ( const char *  newlib,
const char *  funcname 
)

Definition at line 1386 of file iplib.cc.

1387 {
1388  void* result = NULL;
1389 
1390  const char* bin_dir = feGetResource('b');
1391  if (!bin_dir) { return NULL; }
1392 
1393  char path_name[MAXPATHLEN];
1394  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1395 
1396  void* openlib = dynl_open(path_name);
1397  if(!openlib)
1398  {
1399  Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1400  return NULL;
1401  }
1402  result = dynl_sym(openlib, funcname);
1403  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1404 
1405  return result;
1406 }
return result
Definition: facAbsBiFact.cc:75
char * feGetResource(const char id, int warn)
Definition: feResource.cc:155
#define DIR_SEPP
Definition: feResource.h:7
#define MODULE_SUFFIX_STRING
Definition: iplib.cc:38
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:162
const char * dynl_error()
Definition: mod_raw.cc:178
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
#define NULL
Definition: omList.c:12
#define MAXPATHLEN
Definition: omRet2Info.c:22
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ close_all_dyn_modules()

void close_all_dyn_modules ( )

Definition at line 1167 of file iplib.cc.

1167  {
1168  for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1169  it != dyn_modules->end();
1170  it++)
1171  {
1172  dynl_close(it->second);
1173  }
1174  delete dyn_modules;
1175  dyn_modules = NULL;
1176 }
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition: iplib.cc:1151
int dynl_close(void *handle)
Definition: mod_raw.cc:173

◆ current_pos()

int current_pos ( int  i = 0)

Definition at line 3346 of file libparse.cc.

3347 {
3348  return(i+offset+(int)(yytext-yylp_buffer_start));
3349 }
int i
Definition: cfEzgcd.cc:132
VAR char * yylp_buffer_start
Definition: libparse.cc:1102
#define yytext
Definition: libparse.cc:16
VAR int offset
Definition: libparse.cc:1093

◆ flint_mod_init()

int flint_mod_init ( SModulFunctions psModulFunctions)

Definition at line 1269 of file misc_ip.cc.

1270 {
1271  package save=currPack;
1274  if (n_FlintQ!=n_unknown)
1275  {
1276  iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1278  }
1279 #if __FLINT_RELEASE >= 20503
1280  iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1282 #endif
1284  if (n_FlintZn!=n_unknown)
1285  {
1286  iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1288  }
1289  currPack=save;
1290  return MAX_TOK;
1291 }
#define FALSE
Definition: auxiliary.h:96
@ n_unknown
Definition: coeffs.h:29
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Q.cc:561
coeffs flintQInitCfByName(char *s, n_coeffType n)
Definition: flintcf_Q.cc:533
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
Definition: flintcf_Zn.cc:476
coeffs flintZnInitCfByName(char *s, n_coeffType n)
Definition: flintcf_Zn.cc:422
VAR package basePack
Definition: ipid.cc:58
VAR package currPack
Definition: ipid.cc:57
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1059
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition: misc_ip.cc:1224
STATIC_VAR n_coeffType n_FlintQ
Definition: misc_ip.cc:1208
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition: misc_ip.cc:1210
STATIC_VAR n_coeffType n_FlintZn
Definition: misc_ip.cc:1207
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition: numbers.cc:582
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:541
@ MAX_TOK
Definition: tok.h:218

◆ ii_CallLibProcM()

leftv ii_CallLibProcM ( const char *  n,
void **  args,
int *  arg_types,
const ring  R,
BOOLEAN err 
)

args: NULL terminated array of arguments arg_types: 0 terminated array of corresponding types

Definition at line 697 of file iplib.cc.

698 {
699  idhdl h=ggetid(n);
700  if ((h==NULL)
701  || (IDTYP(h)!=PROC_CMD))
702  {
703  err=2;
704  return NULL;
705  }
706  // ring handling
707  idhdl save_ringhdl=currRingHdl;
708  ring save_ring=currRing;
711  // argument:
712  if (arg_types[0]!=0)
713  {
714  sleftv tmp;
715  leftv tt=&tmp;
716  int i=1;
717  tmp.Init();
718  tmp.data=args[0];
719  tmp.rtyp=arg_types[0];
720  while(arg_types[i]!=0)
721  {
723  tt=tt->next;
724  tt->rtyp=arg_types[i];
725  tt->data=args[i];
726  i++;
727  }
728  // call proc
729  err=iiMake_proc(h,currPack,&tmp);
730  }
731  else
732  // call proc
733  err=iiMake_proc(h,currPack,NULL);
734  // clean up ring
735  iiCallLibProcEnd(save_ringhdl,save_ring);
736  // return
737  if (err==FALSE)
738  {
740  memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
741  iiRETURNEXPR.Init();
742  return h;
743  }
744  return NULL;
745 }
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int rtyp
Definition: subexpr.h:91
void Init()
Definition: subexpr.h:107
leftv next
Definition: subexpr.h:86
void * data
Definition: subexpr.h:88
@ PROC_CMD
Definition: grammar.cc:280
idhdl ggetid(const char *n)
Definition: ipid.cc:571
VAR idhdl currRingHdl
Definition: ipid.cc:59
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:145
#define IDTYP(a)
Definition: ipid.h:119
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition: iplib.cc:602
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition: iplib.cc:500
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:470
static void iiCallLibProcBegin()
Definition: iplib.cc:585
STATIC_VAR Poly * h
Definition: janet.cc:971
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
void rChangeCurrRing(ring r)
Definition: polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define R
Definition: sirandom.c:27
sleftv * leftv
Definition: structs.h:62

◆ ii_CallProcId2Id()

ideal ii_CallProcId2Id ( const char *  lib,
const char *  proc,
ideal  arg,
const ring  R 
)

Definition at line 657 of file iplib.cc.

658 {
659  char *plib = iiConvName(lib);
660  idhdl h=ggetid(plib);
661  omFree(plib);
662  if (h==NULL)
663  {
664  BOOLEAN bo=iiLibCmd(lib,TRUE,TRUE,FALSE);
665  if (bo) return NULL;
666  }
667  ring oldR=currRing;
669  BOOLEAN err;
670  ideal I=(ideal)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
671  rChangeCurrRing(oldR);
672  if (err) return NULL;
673  return I;
674 }
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:16
@ IDEAL_CMD
Definition: grammar.cc:284
ideal idCopy(ideal A)
Definition: ideals.h:60
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition: iplib.cc:623
char * iiConvName(const char *libname)
Definition: iplib.cc:1429
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:880
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ ii_CallProcId2Int()

int ii_CallProcId2Int ( const char *  lib,
const char *  proc,
ideal  arg,
const ring  R 
)

Definition at line 676 of file iplib.cc.

677 {
678  char *plib = iiConvName(lib);
679  idhdl h=ggetid(plib);
680  omFree(plib);
681  if (h==NULL)
682  {
683  BOOLEAN bo=iiLibCmd(lib,TRUE,TRUE,FALSE);
684  if (bo) return 0;
685  }
686  BOOLEAN err;
687  ring oldR=currRing;
689  int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
690  rChangeCurrRing(oldR);
691  if (err) return 0;
692  return I;
693 }

◆ iiAddCproc()

int iiAddCproc ( const char *  libname,
const char *  procname,
BOOLEAN  pstatic,
BOOLEAN(*)(leftv res, leftv v func 
)

Definition at line 1059 of file iplib.cc.

1061 {
1062  procinfov pi;
1063  idhdl h;
1064 
1065  #ifndef SING_NDEBUG
1066  int dummy;
1067  if (IsCmd(procname,dummy))
1068  {
1069  Werror(">>%s< is a reserved name",procname);
1070  return 0;
1071  }
1072  #endif
1073 
1074  h=IDROOT->get(procname,0);
1075  if ((h!=NULL)
1076  && (IDTYP(h)==PROC_CMD))
1077  {
1078  pi = IDPROC(h);
1079  #if 0
1080  if ((pi->language == LANG_SINGULAR)
1081  &&(BVERBOSE(V_REDEFINE)))
1082  Warn("extend `%s`",procname);
1083  #endif
1084  }
1085  else
1086  {
1087  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1088  }
1089  if ( h!= NULL )
1090  {
1091  pi = IDPROC(h);
1092  if((pi->language == LANG_SINGULAR)
1093  ||(pi->language == LANG_NONE))
1094  {
1095  omfree(pi->libname);
1096  pi->libname = omStrDup(libname);
1097  omfree(pi->procname);
1098  pi->procname = omStrDup(procname);
1099  pi->language = LANG_C;
1100  pi->ref = 1;
1101  pi->is_static = pstatic;
1102  pi->data.o.function = func;
1103  }
1104  else if(pi->language == LANG_C)
1105  {
1106  if(pi->data.o.function == func)
1107  {
1108  pi->ref++;
1109  }
1110  else
1111  {
1112  omfree(pi->libname);
1113  pi->libname = omStrDup(libname);
1114  omfree(pi->procname);
1115  pi->procname = omStrDup(procname);
1116  pi->language = LANG_C;
1117  pi->ref = 1;
1118  pi->is_static = pstatic;
1119  pi->data.o.function = func;
1120  }
1121  }
1122  else
1123  Warn("internal error: unknown procedure type %d",pi->language);
1124  if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1125  return(1);
1126  }
1127  else
1128  {
1129  WarnS("iiAddCproc: failed.");
1130  }
1131  return(0);
1132 }
#define Warn
Definition: emacs.cc:77
#define WarnS
Definition: emacs.cc:78
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:9447
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:278
#define IDPROC(a)
Definition: ipid.h:140
#define IDROOT
Definition: ipid.h:19
#define pi
Definition: libparse.cc:1145
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omfree(addr)
Definition: omAllocDecl.h:237
#define BVERBOSE(a)
Definition: options.h:34
#define V_REDEFINE
Definition: options.h:44
@ LANG_SINGULAR
Definition: subexpr.h:22
@ LANG_NONE
Definition: subexpr.h:22
@ LANG_MIX
Definition: subexpr.h:22
@ LANG_C
Definition: subexpr.h:22

◆ iiAddCprocTop()

int iiAddCprocTop ( const char *  libname,
const char *  procname,
BOOLEAN  pstatic,
BOOLEAN(*)(leftv res, leftv v func 
)

Definition at line 1134 of file iplib.cc.

1136 {
1137  int r=iiAddCproc(libname,procname,pstatic,func);
1138  package s=currPack;
1140  if (r) r=iiAddCproc(libname,procname,pstatic,func);
1141  currPack=s;
1142  return r;
1143 }
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ iiAllStart()

BOOLEAN iiAllStart ( procinfov  pi,
const char *  p,
feBufferTypes  t,
int  l 
)

Definition at line 294 of file iplib.cc.

295 {
296  int save_trace=traceit;
297  int restore_traceit=0;
298  if (traceit_stop
299  && (traceit & TRACE_SHOW_LINE))
300  {
302  traceit_stop=0;
303  restore_traceit=1;
304  }
305  // see below:
306  BITSET save1=si_opt_1;
307  BITSET save2=si_opt_2;
308  newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
309  pi, l );
310  BOOLEAN err=yyparse();
311 
312  if (sLastPrinted.rtyp!=0)
313  {
315  }
316 
317  if (restore_traceit) traceit=save_trace;
318 
319  // the access to optionStruct and verboseStruct do not work
320  // on x86_64-Linux for pic-code
321  if ((TEST_V_ALLWARN) &&
322  (t==BT_proc) &&
323  ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
324  (pi->libname!=NULL) && (pi->libname[0]!='\0'))
325  {
326  if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
327  Warn("option changed in proc %s from %s",pi->procname,pi->libname);
328  else
329  Warn("option changed in proc %s",pi->procname);
330  int i;
331  for (i=0; optionStruct[i].setval!=0; i++)
332  {
333  if ((optionStruct[i].setval & si_opt_1)
334  && (!(optionStruct[i].setval & save1)))
335  {
336  Print(" +%s",optionStruct[i].name);
337  }
338  if (!(optionStruct[i].setval & si_opt_1)
339  && ((optionStruct[i].setval & save1)))
340  {
341  Print(" -%s",optionStruct[i].name);
342  }
343  }
344  for (i=0; verboseStruct[i].setval!=0; i++)
345  {
346  if ((verboseStruct[i].setval & si_opt_2)
347  && (!(verboseStruct[i].setval & save2)))
348  {
349  Print(" +%s",verboseStruct[i].name);
350  }
351  if (!(verboseStruct[i].setval & si_opt_2)
352  && ((verboseStruct[i].setval & save2)))
353  {
354  Print(" -%s",verboseStruct[i].name);
355  }
356  }
357  PrintLn();
358  }
359  return err;
360 }
int l
Definition: cfEzgcd.cc:100
int p
Definition: cfModGcd.cc:4080
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
#define Print
Definition: emacs.cc:80
char name(const Variable &v)
Definition: factory.h:196
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:164
@ BT_proc
Definition: fevoices.h:20
int yyparse(void)
Definition: grammar.cc:2111
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:550
unsigned setval
Definition: ipid.h:153
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:519
VAR unsigned si_opt_2
Definition: options.c:6
VAR unsigned si_opt_1
Definition: options.c:5
#define TEST_V_ALLWARN
Definition: options.h:141
void PrintLn()
Definition: reporter.cc:310
#define TRACE_SHOW_LINE
Definition: reporter.h:33
EXTERN_VAR int traceit
Definition: reporter.h:24
EXTERN_VAR int traceit_stop
Definition: reporter.h:25
#define BITSET
Definition: structs.h:20
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46

◆ iiArithAddCmd()

int iiArithAddCmd ( const char *  szName,
short  nAlias,
short  nTokval,
short  nToktype,
short  nPos 
)

Definition at line 9792 of file iparith.cc.

9799 {
9800  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9801  // nTokval, nToktype, nPos);
9802  if(nPos>=0)
9803  {
9804  // no checks: we rely on a correct generated code in iparith.inc
9805  assume((unsigned)nPos < sArithBase.nCmdAllocated);
9806  assume(szName!=NULL);
9807  sArithBase.sCmds[nPos].name = omStrDup(szName);
9808  sArithBase.sCmds[nPos].alias = nAlias;
9809  sArithBase.sCmds[nPos].tokval = nTokval;
9810  sArithBase.sCmds[nPos].toktype = nToktype;
9811  sArithBase.nCmdUsed++;
9812  //if(nTokval>0) sArithBase.nLastIdentifier++;
9813  }
9814  else
9815  {
9816  if(szName==NULL) return -1;
9817  int nIndex = iiArithFindCmd(szName);
9818  if(nIndex>=0)
9819  {
9820  Print("'%s' already exists at %d\n", szName, nIndex);
9821  return -1;
9822  }
9823 
9825  {
9826  /* needs to create new slots */
9827  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9828  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9829  if(sArithBase.sCmds==NULL) return -1;
9831  }
9832  /* still free slots available */
9833  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9834  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9835  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9836  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9837  sArithBase.nCmdUsed++;
9838 
9839  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9840  (&_gentable_sort_cmds));
9843  {
9844  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9845  }
9846  //Print("L=%d\n", sArithBase.nLastIdentifier);
9847  }
9848  return 0;
9849 }
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:9625
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:9697
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:183
unsigned nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:190
STATIC_VAR SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:198
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:189
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:188
#define assume(x)
Definition: mod2.h:387
#define nSize(n)
Definition: numbers.h:39
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225

◆ iiCallLibProc1()

void* iiCallLibProc1 ( const char *  n,
void *  arg,
int  arg_type,
BOOLEAN err 
)

Definition at line 623 of file iplib.cc.

624 {
625  idhdl h=ggetid(n);
626  if ((h==NULL)
627  || (IDTYP(h)!=PROC_CMD))
628  {
629  err=2;
630  return NULL;
631  }
632  // ring handling
633  idhdl save_ringhdl=currRingHdl;
634  ring save_ring=currRing;
636  // argument:
637  sleftv tmp;
638  tmp.Init();
639  tmp.data=arg;
640  tmp.rtyp=arg_type;
641  // call proc
642  err=iiMake_proc(h,currPack,&tmp);
643  // clean up ring
644  iiCallLibProcEnd(save_ringhdl,save_ring);
645  // return
646  if (err==FALSE)
647  {
648  void*r=iiRETURNEXPR.data;
651  return r;
652  }
653  return NULL;
654 }

◆ iiCallLibProcBegin()

static void iiCallLibProcBegin ( )
static

Definition at line 585 of file iplib.cc.

586 {
587  idhdl tmp_ring=NULL;
588  if (currRing!=NULL)
589  {
591  {
592  // clean up things depending on currRingHdl:
594  sLastPrinted.Init();
595  }
596  // need to define a ring-hdl for currRingHdl
597  tmp_ring=enterid(" tmpRing",myynest,RING_CMD,&IDROOT,FALSE);
598  IDRING(tmp_ring)=rIncRefCnt(currRing);
599  rSetHdl(tmp_ring);
600  }
601 }
VAR int myynest
Definition: febase.cc:41
@ RING_CMD
Definition: grammar.cc:281
#define IDRING(a)
Definition: ipid.h:127
void rSetHdl(idhdl h)
Definition: ipshell.cc:5135
static ring rIncRefCnt(ring r)
Definition: ring.h:847

◆ iiCallLibProcEnd()

static void iiCallLibProcEnd ( idhdl  save_ringhdl,
ring  save_ring 
)
static

Definition at line 602 of file iplib.cc.

603 {
604  if ((currRing!=NULL)
605  &&(currRing!=save_ring))
606  {
608  idhdl hh=IDROOT;
609  idhdl prev=NULL;
610  while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
611  if (hh!=NULL)
612  {
613  if (prev==NULL) IDROOT=hh->next;
614  else prev->next=hh->next;
615  omFree((ADDRESS)IDID(hh));
617  }
618  }
619  currRingHdl=save_ringhdl;
620  currRing=save_ring;
621 }
void * ADDRESS
Definition: auxiliary.h:119
idhdl next
Definition: idrec.h:38
VAR omBin idrec_bin
Definition: ipid.cc:48
#define IDID(a)
Definition: ipid.h:122
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static void rDecRefCnt(ring r)
Definition: ring.h:848

◆ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 489 of file iplib.cc.

490 {
491  if (myynest >= iiRETURNEXPR_len-1)
492  {
494  iiRETURNEXPR_len*sizeof(ring),
495  (iiRETURNEXPR_len+16)*sizeof(ring));
496  memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
497  iiRETURNEXPR_len+=16;
498  }
499 }
VAR int iiRETURNEXPR_len
Definition: iplib.cc:471
VAR ring * iiLocalRing
Definition: iplib.cc:469
#define omreallocSize(addr, o_size, size)
Definition: omAllocDecl.h:231

◆ iiCleanProcs()

static void iiCleanProcs ( idhdl root)
static

Definition at line 924 of file iplib.cc.

925 {
926  idhdl prev=NULL;
927  loop
928  {
929  if (root==NULL) return;
930  if (IDTYP(root)==PROC_CMD)
931  {
932  procinfo *pi=(procinfo*)IDDATA(root);
933  if ((pi->language == LANG_SINGULAR)
934  && (pi->data.s.body_start == 0L))
935  {
936  // procinfo data incorrect:
937  // - no proc body can start at the beginning of the file
938  killhdl(root);
939  if (prev==NULL)
940  root=IDROOT;
941  else
942  {
943  root=prev;
944  prev=NULL;
945  }
946  continue;
947  }
948  }
949  prev=root;
950  root=IDNEXT(root);
951  }
952 }
void killhdl(idhdl h, package proot)
Definition: ipid.cc:406
#define IDNEXT(a)
Definition: ipid.h:118
#define IDDATA(a)
Definition: ipid.h:126
#define loop
Definition: structs.h:80

◆ iiConvName()

char* iiConvName ( const char *  libname)

Definition at line 1429 of file iplib.cc.

1430 {
1431  char *tmpname = omStrDup(libname);
1432  char *p = strrchr(tmpname, DIR_SEP);
1433  char *r;
1434  if(p==NULL) p = tmpname; else p++;
1435  // p is now the start of the file name (without path)
1436  r=p;
1437  while(isalnum(*r)||(*r=='_')) r++;
1438  // r point the the end of the main part of the filename
1439  *r = '\0';
1440  r = omStrDup(p);
1441  *r = mytoupper(*r);
1442  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1443  omFree((ADDRESS)tmpname);
1444 
1445  return(r);
1446 }
#define DIR_SEP
Definition: feResource.h:6
char mytoupper(char c)
Definition: iplib.cc:1410

◆ iiEStart()

BOOLEAN iiEStart ( char *  example,
procinfo pi 
)

Definition at line 750 of file iplib.cc.

751 {
752  BOOLEAN err;
753  int old_echo=si_echo;
754 
755  iiCheckNest();
756  procstack->push(example);
759  {
760  if (traceit&TRACE_SHOW_LINENO) printf("\n");
761  printf("entering example (level %d)\n",myynest);
762  }
763  myynest++;
764 
765  err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
766 
768  myynest--;
769  si_echo=old_echo;
771  {
772  if (traceit&TRACE_SHOW_LINENO) printf("\n");
773  printf("leaving -example- (level %d)\n",myynest);
774  }
775  if (iiLocalRing[myynest] != currRing)
776  {
777  if (iiLocalRing[myynest]!=NULL)
778  {
781  }
782  else
783  {
785  currRing=NULL;
786  }
787  }
788  procstack->pop();
789  return err;
790 }
void pop()
Definition: ipid.cc:805
void push(char *)
Definition: ipid.cc:795
VAR int si_echo
Definition: febase.cc:35
@ BT_example
Definition: fevoices.h:21
VAR proclevel * procstack
Definition: ipid.cc:52
static void iiCheckNest()
Definition: iplib.cc:489
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition: iplib.cc:294
void killlocals(int v)
Definition: ipshell.cc:384
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1632
#define TRACE_SHOW_LINENO
Definition: reporter.h:31
#define TRACE_SHOW_PROC
Definition: reporter.h:29

◆ iiGetBuiltinModInit()

SModulFunc_t iiGetBuiltinModInit ( const char *  libname)

Definition at line 803 of file iplib.cc.

804 {
805 #ifdef HAVE_FLINT
806  if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
807 #endif
808 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
810 # undef SI_GET_BUILTIN_MOD_INIT
811 
812  return NULL;
813 }
#define SI_GET_BUILTIN_MOD_INIT(name)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
#define SI_MOD_INIT0(name)
Definition: mod_lib.h:4

◆ iiGetLibProcBuffer()

char* iiGetLibProcBuffer ( procinfo pi,
int  part 
)

Definition at line 193 of file iplib.cc.

194 {
195  char buf[256], *s = NULL, *p;
196  long procbuflen;
197 
198  FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE );
199  if (fp==NULL)
200  {
201  return NULL;
202  }
203 
204  fseek(fp, pi->data.s.proc_start, SEEK_SET);
205  if(part==0)
206  { // load help string
207  int i, offset=0;
208  long head = pi->data.s.def_end - pi->data.s.proc_start;
209  procbuflen = pi->data.s.help_end - pi->data.s.help_start;
210  if (procbuflen<5)
211  {
212  fclose(fp);
213  return NULL; // help part does not exist
214  }
215  //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
216  // pi->data.s.proc_start, procbuflen);
217  s = (char *)omAlloc(procbuflen+head+3);
218  myfread(s, head, 1, fp);
219  s[head] = '\n';
220  fseek(fp, pi->data.s.help_start, SEEK_SET);
221  myfread(s+head+1, procbuflen, 1, fp);
222  fclose(fp);
223  s[procbuflen+head+1] = '\n';
224  s[procbuflen+head+2] = '\0';
225  offset=0;
226  for(i=0;i<=procbuflen+head+2; i++)
227  {
228  if(s[i]=='\\' &&
229  (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
230  {
231  i++;
232  offset++;
233  }
234  if(offset>0) s[i-offset] = s[i];
235  }
236  return(s);
237  }
238  else if(part==1)
239  { // load proc part - must exist
240  procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
241  char *ss=(char *)omAlloc(procbuflen+2);
242  //fgets(buf, sizeof(buf), fp);
243  myfread( ss, procbuflen, 1, fp);
244  char ct;
245  char *e;
246  s=iiProcName(ss,ct,e);
247  char *argstr=NULL;
248  *e=ct;
249  argstr=iiProcArgs(e,TRUE);
250 
251  assume(pi->data.s.body_end > pi->data.s.body_start);
252 
253  procbuflen = pi->data.s.body_end - pi->data.s.body_start;
254  pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
255  strlen(pi->libname) );
256  //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
257  // pi->data.s.body_start, procbuflen);
258  assume(pi->data.s.body != NULL);
259  fseek(fp, pi->data.s.body_start, SEEK_SET);
260  strcpy(pi->data.s.body,argstr);
261  myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
262  fclose( fp );
263  procbuflen+=strlen(argstr);
264  omFree(argstr);
265  omFree(ss);
266  pi->data.s.body[procbuflen] = '\0';
267  strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
268  strcat( pi->data.s.body+procbuflen+13,pi->libname);
269  s=(char *)strchr(pi->data.s.body,'{');
270  if (s!=NULL) *s=' ';
271  return NULL;
272  }
273  else if(part==2)
274  { // example
275  if ( pi->data.s.example_lineno == 0)
276  return NULL; // example part does not exist
277  // load example
278  fseek(fp, pi->data.s.example_start, SEEK_SET);
279  /*char *dummy=*/ (void) fgets(buf, sizeof(buf), fp); // skip line with "example"
280  procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
281  //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
282  // pi->data.s.example_start, procbuflen);
283  s = (char *)omAlloc(procbuflen+14);
284  myfread(s, procbuflen, 1, fp);
285  s[procbuflen] = '\0';
286  strcat(s+procbuflen-3, "\n;return();\n\n" );
287  p=(char *)strchr(s,'{');
288  if (p!=NULL) *p=' ';
289  return(s);
290  }
291  return NULL;
292 }
CanonicalForm head(const CanonicalForm &f)
CanonicalForm fp
Definition: cfModGcd.cc:4104
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: feFopen.cc:195
char * iiProcName(char *buf, char &ct, char *&e)
Definition: iplib.cc:96
char * iiProcArgs(char *e, BOOLEAN withParenth)
Definition: iplib.cc:110
STATIC_VAR int offset
Definition: janet.cc:29
#define SEEK_SET
Definition: mod2.h:113
#define omAlloc(size)
Definition: omAllocDecl.h:210
int status int void * buf
Definition: si_signals.h:59

◆ iiGetLibStatus()

BOOLEAN iiGetLibStatus ( const char *  lib)

Definition at line 73 of file iplib.cc.

74 {
75  idhdl hl;
76 
77  char *plib = iiConvName(lib);
78  hl = basePack->idroot->get(plib,0);
79  omFree(plib);
80  if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD))
81  {
82  return FALSE;
83  }
84  if ((IDPACKAGE(hl)->language!=LANG_C)&&(IDPACKAGE(hl)->libname!=NULL))
85  return (strcmp(lib,IDPACKAGE(hl)->libname)==0);
86  return FALSE;
87 }
#define IDPACKAGE(a)
Definition: ipid.h:139
@ PACKAGE_CMD
Definition: tok.h:149

◆ iiInitSingularProcinfo()

procinfo* iiInitSingularProcinfo ( procinfov  pi,
const char *  libname,
const char *  procname,
int  ,
long  pos,
BOOLEAN  pstatic 
)

Definition at line 1045 of file iplib.cc.

1047 {
1048  memset(pi,0,sizeof(*pi));
1049  pi->libname = omStrDup(libname);
1050  pi->procname = omStrDup(procname);
1051  pi->language = LANG_SINGULAR;
1052  pi->ref = 1;
1053  pi->is_static = pstatic;
1054  pi->data.s.proc_start = pos;
1055  return(pi);
1056 }

◆ iiLibCmd()

BOOLEAN iiLibCmd ( const char *  newlib,
BOOLEAN  autoexport,
BOOLEAN  tellerror,
BOOLEAN  force 
)

Definition at line 880 of file iplib.cc.

881 {
882  if (strcmp(newlib,"Singular")==0) return FALSE;
883  char libnamebuf[1024];
884  idhdl pl;
885  char *plib = iiConvName(newlib);
886  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
887  // int lines = 1;
888  BOOLEAN LoadResult = TRUE;
889 
890  if (fp==NULL)
891  {
892  return TRUE;
893  }
894  pl = basePack->idroot->get(plib,0);
895  if (pl==NULL)
896  {
897  pl = enterid( plib,0, PACKAGE_CMD,
898  &(basePack->idroot), TRUE );
899  IDPACKAGE(pl)->language = LANG_SINGULAR;
900  IDPACKAGE(pl)->libname=omStrDup(newlib);
901  }
902  else
903  {
904  if(IDTYP(pl)!=PACKAGE_CMD)
905  {
906  omFree(plib);
907  WarnS("not of type package.");
908  fclose(fp);
909  return TRUE;
910  }
911  if (!force)
912  {
913  omFree(plib);
914  return FALSE;
915  }
916  }
917  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
918 
919  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
920  omFree((ADDRESS)plib);
921  return LoadResult;
922 }
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:969
VAR char libnamebuf[1024]
Definition: libparse.cc:1098

◆ iiLoadLIB()

BOOLEAN iiLoadLIB ( FILE *  fp,
const char *  libnamebuf,
const char *  newlib,
idhdl  pl,
BOOLEAN  autoexport,
BOOLEAN  tellerror 
)

Definition at line 969 of file iplib.cc.

971 {
972  EXTERN_VAR FILE *yylpin;
973  libstackv ls_start = library_stack;
974  lib_style_types lib_style;
975 
976  yylpin = fp;
977  #if YYLPDEBUG > 1
978  print_init();
979  #endif
980  EXTERN_VAR int lpverbose;
982  else lpverbose=0;
983  // yylplex sets also text_buffer
984  if (text_buffer!=NULL) *text_buffer='\0';
985  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
986  if(yylp_errno)
987  {
988  Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
989  current_pos(0));
991  {
995  }
996  else
998  WerrorS("Cannot load library,... aborting.");
999  reinit_yylp();
1000  fclose( yylpin );
1002  return TRUE;
1003  }
1004  if (BVERBOSE(V_LOAD_LIB))
1005  Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1006  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
1007  {
1008  Warn( "library %s has old format. This format is still accepted,", newlib);
1009  WarnS( "but for functionality you may wish to change to the new");
1010  WarnS( "format. Please refer to the manual for further information.");
1011  }
1012  reinit_yylp();
1013  fclose( yylpin );
1014  fp = NULL;
1015  iiRunInit(IDPACKAGE(pl));
1016 
1017  {
1018  libstackv ls;
1019  for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1020  {
1021  if(ls->to_be_done)
1022  {
1023  ls->to_be_done=FALSE;
1024  iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
1025  ls = ls->pop(newlib);
1026  }
1027  }
1028 #if 0
1029  PrintS("--------------------\n");
1030  for(ls = library_stack; ls != NULL; ls = ls->next)
1031  {
1032  Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1033  ls->to_be_done ? "not loaded" : "loaded");
1034  }
1035  PrintS("--------------------\n");
1036 #endif
1037  }
1038 
1039  if(fp != NULL) fclose(fp);
1040  return FALSE;
1041 }
libstackv next
Definition: subexpr.h:164
libstackv pop(const char *p)
Definition: iplib.cc:1520
int cnt
Definition: subexpr.h:167
char * get()
Definition: subexpr.h:170
BOOLEAN to_be_done
Definition: subexpr.h:166
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define EXTERN_VAR
Definition: globaldefs.h:6
int current_pos(int i=0)
Definition: libparse.cc:3346
void print_init()
Definition: libparse.cc:3482
static void iiCleanProcs(idhdl &root)
Definition: iplib.cc:924
VAR libstackv library_stack
Definition: iplib.cc:64
const char * yylp_errlist[]
Definition: libparse.cc:1114
EXTERN_VAR int yylplineno
Definition: iplib.cc:61
static void iiRunInit(package p)
Definition: iplib.cc:953
EXTERN_VAR int yylp_errno
Definition: iplib.cc:60
void reinit_yylp()
Definition: libparse.cc:3376
VAR char * text_buffer
Definition: libparse.cc:1099
VAR int lpverbose
Definition: libparse.cc:1106
lib_style_types
Definition: libparse.h:9
@ OLD_LIBSTYLE
Definition: libparse.h:9
#define YYLP_BAD_CHAR
Definition: libparse.h:93
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
#define V_DEBUG_LIB
Definition: options.h:47
#define V_LOAD_LIB
Definition: options.h:46
void PrintS(const char *s)
Definition: reporter.cc:284

◆ iiLocateLib()

BOOLEAN iiLocateLib ( const char *  lib,
char *  where 
)

Definition at line 866 of file iplib.cc.

867 {
868  char *plib = iiConvName(lib);
869  idhdl pl = basePack->idroot->get(plib,0);
870  if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
871  (IDPACKAGE(pl)->language == LANG_SINGULAR))
872  {
873  strncpy(where,IDPACKAGE(pl)->libname,127);
874  return TRUE;
875  }
876  else
877  return FALSE;;
878 }

◆ iiMake_proc()

BOOLEAN iiMake_proc ( idhdl  pn,
package  pack,
leftv  args 
)

Definition at line 500 of file iplib.cc.

501 {
502  int err;
503  procinfov pi = IDPROC(pn);
504  if(pi->is_static && myynest==0)
505  {
506  Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
507  pi->libname, pi->procname);
508  return TRUE;
509  }
510  iiCheckNest();
512  //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
513  iiRETURNEXPR.Init();
514  procstack->push(pi->procname);
516  || (pi->trace_flag&TRACE_SHOW_PROC))
517  {
519  Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
520  }
521 #ifdef RDEBUG
523 #endif
524  switch (pi->language)
525  {
526  default:
527  case LANG_NONE:
528  WerrorS("undefined proc");
529  err=TRUE;
530  break;
531 
532  case LANG_SINGULAR:
533  if ((pi->pack!=NULL)&&(currPack!=pi->pack))
534  {
535  currPack=pi->pack;
538  //Print("set pack=%s\n",IDID(currPackHdl));
539  }
540  else if ((pack!=NULL)&&(currPack!=pack))
541  {
542  currPack=pack;
545  //Print("set pack=%s\n",IDID(currPackHdl));
546  }
547  err=iiPStart(pn,args);
548  break;
549  case LANG_C:
551  err = (pi->data.o.function)(res, args);
552  memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
554  break;
555  }
557  || (pi->trace_flag&TRACE_SHOW_PROC))
558  {
560  Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
561  }
562  //const char *n="NULL";
563  //if (currRingHdl!=NULL) n=IDID(currRingHdl);
564  //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
565 #ifdef RDEBUG
567 #endif
568  if (err)
569  {
571  //iiRETURNEXPR.Init(); //done by CleanUp
572  }
573  if (iiCurrArgs!=NULL)
574  {
575  if (!err) Warn("too many arguments for %s",IDID(pn));
576  iiCurrArgs->CleanUp();
579  }
580  procstack->pop();
581  if (err)
582  return TRUE;
583  return FALSE;
584 }
CanonicalForm res
Definition: facAbsFact.cc:60
VAR idhdl currPackHdl
Definition: ipid.cc:55
idhdl packFindHdl(package r)
Definition: ipid.cc:823
static void iiShowLevRings()
Definition: iplib.cc:474
BOOLEAN iiPStart(idhdl pn, leftv v)
Definition: iplib.cc:367
void iiCheckPack(package &p)
Definition: ipshell.cc:1561
VAR leftv iiCurrArgs
Definition: ipshell.cc:78
#define TRACE_SHOW_RINGS
Definition: reporter.h:36

◆ iiProcArgs()

char* iiProcArgs ( char *  e,
BOOLEAN  withParenth 
)

Definition at line 110 of file iplib.cc.

111 {
112  while ((*e==' ') || (*e=='\t') || (*e=='(')) e++;
113  if (*e<' ')
114  {
115  if (withParenth)
116  {
117  // no argument list, allow list #
118  return omStrDup("parameter list #;");
119  }
120  else
121  {
122  // empty list
123  return omStrDup("");
124  }
125  }
126  BOOLEAN in_args;
127  BOOLEAN args_found;
128  char *s;
129  char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc
130  int argstrlen=127;
131  *argstr='\0';
132  int par=0;
133  do
134  {
135  args_found=FALSE;
136  s=e; // set s to the starting point of the arg
137  // and search for the end
138  // skip leading spaces:
139  loop
140  {
141  if ((*s==' ')||(*s=='\t'))
142  s++;
143  else if ((*s=='\n')&&(*(s+1)==' '))
144  s+=2;
145  else // start of new arg or \0 or )
146  break;
147  }
148  e=s;
149  while ((*e!=',')
150  &&((par!=0) || (*e!=')'))
151  &&(*e!='\0'))
152  {
153  if (*e=='(') par++;
154  else if (*e==')') par--;
155  args_found=args_found || (*e>' ');
156  e++;
157  }
158  in_args=(*e==',');
159  if (args_found)
160  {
161  *e='\0';
162  // check for space:
163  if ((int)strlen(argstr)+12 /* parameter + ;*/ +(int)strlen(s)>= argstrlen)
164  {
165  argstrlen*=2;
166  char *a=(char *)omAlloc( argstrlen);
167  strcpy(a,argstr);
168  omFree((ADDRESS)argstr);
169  argstr=a;
170  }
171  // copy the result to argstr
172  if(strncmp(s,"alias ",6)!=0)
173  {
174  strcat(argstr,"parameter ");
175  }
176  strcat(argstr,s);
177  strcat(argstr,"; ");
178  e++; // e was pointing to ','
179  }
180  } while (in_args);
181  return argstr;
182 }

◆ iiProcName()

char* iiProcName ( char *  buf,
char &  ct,
char *&  e 
)

Definition at line 96 of file iplib.cc.

97 {
98  char *s=buf+5;
99  while (*s==' ') s++;
100  e=s+1;
101  while ((*e>' ') && (*e!='(')) e++;
102  ct=*e;
103  *e='\0';
104  return s;
105 }

◆ iiPStart()

BOOLEAN iiPStart ( idhdl  pn,
leftv  v 
)

Definition at line 367 of file iplib.cc.

368 {
369  procinfov pi=NULL;
370  int old_echo=si_echo;
371  BOOLEAN err=FALSE;
372  char save_flags=0;
373 
374  /* init febase ======================================== */
375  /* we do not enter this case if filename != NULL !! */
376  if (pn!=NULL)
377  {
378  pi = IDPROC(pn);
379  if(pi!=NULL)
380  {
381  save_flags=pi->trace_flag;
382  if( pi->data.s.body==NULL )
383  {
385  if (pi->data.s.body==NULL) return TRUE;
386  }
387 // omUpdateInfo();
388 // int m=om_Info.UsedBytes;
389 // Print("proc %s, mem=%d\n",IDID(pn),m);
390  }
391  }
392  else return TRUE;
393  /* generate argument list ======================================*/
394  //iiCurrArgs should be NULL here, as the assignment for the parameters
395  // of the prevouis call are already done befor calling another routine
396  if (v!=NULL)
397  {
399  memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
400  v->Init();
401  }
402  else
403  {
405  }
406  /* start interpreter ======================================*/
407  myynest++;
408  if (myynest > SI_MAX_NEST)
409  {
410  WerrorS("nesting too deep");
411  err=TRUE;
412  }
413  else
414  {
415  iiCurrProc=pn;
416  err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
418 
419  if (iiLocalRing[myynest-1] != currRing)
420  {
422  {
423  //idhdl hn;
424  const char *n;
425  const char *o;
426  idhdl nh=NULL, oh=NULL;
427  if (iiLocalRing[myynest-1]!=NULL)
429  if (oh!=NULL) o=oh->id;
430  else o="none";
431  if (currRing!=NULL)
432  nh=rFindHdl(currRing,NULL);
433  if (nh!=NULL) n=nh->id;
434  else n="none";
435  Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
437  err=TRUE;
438  }
440  }
441  if ((currRing==NULL)
442  && (currRingHdl!=NULL))
444  else
445  if ((currRing!=NULL) &&
447  ||(IDLEV(currRingHdl)>=myynest-1)))
448  {
451  }
452  //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
454 #ifndef SING_NDEBUG
455  checkall();
456 #endif
457  //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
458  }
459  myynest--;
460  si_echo=old_echo;
461  if (pi!=NULL)
462  pi->trace_flag=save_flags;
463 // omUpdateInfo();
464 // int m=om_Info.UsedBytes;
465 // Print("exit %s, mem=%d\n",IDID(pn),m);
466  return err;
467 }
const char * id
Definition: idrec.h:39
BOOLEAN RingDependend()
Definition: subexpr.cc:418
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
#define IDLEV(a)
Definition: ipid.h:121
#define SI_MAX_NEST
Definition: iplib.cc:23
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:193
VAR idhdl iiCurrProc
Definition: ipshell.cc:79

◆ iiRunInit()

static void iiRunInit ( package  p)
static

Definition at line 953 of file iplib.cc.

954 {
955  idhdl h=p->idroot->get("mod_init",0);
956  if (h==NULL) return;
957  if (IDTYP(h)==PROC_CMD)
958  {
959  int save=yylineno;
960  myynest++;
961  // procinfo *pi=(procinfo*)IDDATA(h);
962  //PrintS("mod_init found\n");
963  iiMake_proc(h,p,NULL);
964  myynest--;
965  yylineno=save;
966  }
967 }
VAR int yylineno
Definition: febase.cc:40

◆ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 474 of file iplib.cc.

475 {
476  int i;
477  for (i=0;i<=myynest;i++)
478  {
479  Print("lev %d:",i);
480  if (iiLocalRing[i]==NULL) PrintS("NULL");
481  else Print("%lx",(long)iiLocalRing[i]);
482  PrintLn();
483  }
484  if (currRing==NULL) PrintS("curr:NULL\n");
485  else Print ("curr:%lx\n",(long)currRing);
486 }

◆ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv  v,
const char *  id 
)

Definition at line 819 of file iplib.cc.

820 {
821  BOOLEAN LoadResult = TRUE;
822  char libnamebuf[1024];
823  char *libname = (char *)omAlloc(strlen(id)+5);
824  const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
825  int i = 0;
826  // FILE *fp;
827  // package pack;
828  // idhdl packhdl;
829  lib_types LT;
830  for(i=0; suffix[i] != NULL; i++)
831  {
832  sprintf(libname, "%s%s", id, suffix[i]);
833  *libname = mytolower(*libname);
834  if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
835  {
836  #ifdef HAVE_DYNAMIC_LOADING
837  char libnamebuf[1024];
838  #endif
839 
840  if (LT==LT_SINGULAR)
841  LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
842  #ifdef HAVE_DYNAMIC_LOADING
843  else if ((LT==LT_ELF) || (LT==LT_HPUX))
844  LoadResult = load_modules(libname,libnamebuf,FALSE);
845  #endif
846  else if (LT==LT_BUILTIN)
847  {
848  LoadResult=load_builtin(libname,FALSE, iiGetBuiltinModInit(libname));
849  }
850  if(!LoadResult )
851  {
852  v->name = iiConvName(libname);
853  break;
854  }
855  }
856  }
857  omFree(libname);
858  return LoadResult;
859 }
char name() const
Definition: variable.cc:122
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1284
char mytolower(char c)
Definition: iplib.cc:1416
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1294
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:803
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:27
lib_types
Definition: mod_raw.h:16
@ LT_HPUX
Definition: mod_raw.h:16
@ LT_SINGULAR
Definition: mod_raw.h:16
@ LT_BUILTIN
Definition: mod_raw.h:16
@ LT_ELF
Definition: mod_raw.h:16
@ LT_NOTFOUND
Definition: mod_raw.h:16

◆ load_builtin()

BOOLEAN load_builtin ( const char *  newlib,
BOOLEAN  autoexport,
SModulFunc_t  init 
)

Definition at line 1294 of file iplib.cc.

1295 {
1296  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1297  BOOLEAN(*func)(leftv res, leftv v));
1298 /*
1299  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1300  BOOLEAN pstatic,
1301  BOOLEAN(*func)(leftv res, leftv v)));
1302 */
1303  // SModulFunc_t fktn;
1304  idhdl pl;
1305  char *plib = iiConvName(newlib);
1306  // BOOLEAN RET=TRUE;
1307  // int token;
1308 
1309  pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1310  if ((pl!=NULL)
1311  &&(IDTYP(pl)==PACKAGE_CMD))
1312  {
1313  if(IDPACKAGE(pl)->language==LANG_C)
1314  {
1315  if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1316  omFree(plib);
1317  return FALSE;
1318  }
1319  }
1320  else
1321  {
1322  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1323  IDPACKAGE(pl)->libname=omStrDup(newlib);
1324  }
1325  omFree(plib);
1326  IDPACKAGE(pl)->language = LANG_C;
1327 
1328  IDPACKAGE(pl)->handle=(void *)NULL;
1329  SModulFunctions sModulFunctions;
1330 
1331  package s=currPack;
1332  currPack=IDPACKAGE(pl);
1333  if( init!= NULL)
1334  {
1335  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1336  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1337  else sModulFunctions.iiAddCproc = iiAddCproc;
1338  (*init)(&sModulFunctions);
1339  }
1340  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1341  currPack->loaded=1;
1342  currPack=s;
1343 
1344  return FALSE;
1345 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1134
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: iparith.cc:9792
void init()
Definition: lintree.cc:864
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: ipid.h:72
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:70

◆ load_modules()

BOOLEAN load_modules ( const char *  newlib,
char *  fullname,
BOOLEAN  autoexport 
)

Definition at line 1284 of file iplib.cc.

1285 {
1286  GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1287  pthread_mutex_lock(&mutex);
1288  BOOLEAN r = load_modules_aux(newlib, fullname, autoexport);
1289  pthread_mutex_unlock(&mutex);
1290  return r;
1291 }
#define GLOBAL_VAR
Definition: globaldefs.h:11
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1177

◆ load_modules_aux()

BOOLEAN load_modules_aux ( const char *  newlib,
char *  fullname,
BOOLEAN  autoexport 
)

Definition at line 1177 of file iplib.cc.

1178 {
1179 #ifdef HAVE_STATIC
1180  WerrorS("mod_init: static version can not load modules");
1181  return TRUE;
1182 #else
1183 /*
1184  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1185  BOOLEAN pstatic,
1186  BOOLEAN(*func)(leftv res, leftv v)));
1187 */
1188  SModulFunc_t fktn;
1189  idhdl pl;
1190  char *plib = iiConvName(newlib);
1191  BOOLEAN RET=TRUE;
1192  int token;
1193  char FullName[256];
1194 
1195  memset(FullName,0,sizeof(FullName));
1196 
1197  if( *fullname != '/' && *fullname != '.' )
1198  sprintf(FullName, "./%s", newlib);
1199  else strncpy(FullName, fullname,255);
1200 
1201 
1202  if(IsCmd(plib, token))
1203  {
1204  Werror("'%s' is resered identifier\n", plib);
1205  goto load_modules_end;
1206  }
1207  pl = basePack->idroot->get(plib,0); /* packages only in top level
1208  (see enterid) */
1209  if ((pl!=NULL)
1210  &&(IDTYP(pl)==PACKAGE_CMD))
1211  {
1212  if(IDPACKAGE(pl)->language==LANG_C)
1213  {
1214  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1215  omFree(plib);
1216  return FALSE;
1217  }
1218  else if(IDPACKAGE(pl)->language==LANG_MIX)
1219  {
1220  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1221  omFree(plib);
1222  return FALSE;
1223  }
1224  }
1225  else
1226  {
1227  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1228  omFree(plib); /* enterid copied plib*/
1229  IDPACKAGE(pl)->libname=omStrDup(newlib);
1230  }
1231  IDPACKAGE(pl)->language = LANG_C;
1232  if (dynl_check_opened(FullName))
1233  {
1234  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1235  return FALSE;
1236  }
1237  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1238  {
1239  Werror("dynl_open failed:%s", dynl_error());
1240  Werror("%s not found", newlib);
1241  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1242  goto load_modules_end;
1243  }
1244  else
1245  {
1246  SModulFunctions sModulFunctions;
1247 
1248  package s=currPack;
1249  currPack=IDPACKAGE(pl);
1250  fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1251  if( fktn!= NULL)
1252  {
1253  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1254  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1255  else sModulFunctions.iiAddCproc = iiAddCproc;
1256  int ver=(*fktn)(&sModulFunctions);
1257  if (ver==MAX_TOK)
1258  {
1259  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1260  }
1261  else
1262  {
1263  Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1264  }
1265  currPack->loaded=1;
1266  currPack=s; /* reset currPack to previous */
1267  register_dyn_module(fullname, IDPACKAGE(pl)->handle);
1268  RET=FALSE;
1269  }
1270  else
1271  {
1272  Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1273  errorreported=0;
1274  if(IDPACKAGE(pl)->idroot==NULL)
1275  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1276  }
1277  }
1278 
1279  load_modules_end:
1280  return RET;
1281 #endif /*STATIC */
1282 }
VAR short errorreported
Definition: feFopen.cc:23
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition: ipid.cc:437
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:81
void register_dyn_module(char *fullname, void *handle)
Definition: iplib.cc:1160
int dynl_check_opened(char *filename)
Definition: mod_raw.cc:138

◆ module_help_main()

void module_help_main ( const char *  newlib,
const char *  help 
)

Definition at line 1347 of file iplib.cc.

1348 {
1349  char *plib = iiConvName(newlib);
1350  idhdl pl = basePack->idroot->get(plib,0);
1351  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1352  Werror(">>%s<< is not a package (trying to add package help)",plib);
1353  else
1354  {
1355  package s=currPack;
1356  currPack=IDPACKAGE(pl);
1357  idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1358  IDSTRING(h)=omStrDup(help);
1359  currPack=s;
1360  }
1361 }
#define IDSTRING(a)
Definition: ipid.h:136
#define help
Definition: libparse.cc:1230
@ STRING_CMD
Definition: tok.h:185

◆ module_help_proc()

void module_help_proc ( const char *  newlib,
const char *  p,
const char *  help 
)

Definition at line 1362 of file iplib.cc.

1363 {
1364  char *plib = iiConvName(newlib);
1365  idhdl pl = basePack->idroot->get(plib,0);
1366  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1367  Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1368  else
1369  {
1370  package s=currPack;
1371  currPack=IDPACKAGE(pl);
1372  char buff[256];
1373  buff[255]='\0';
1374  strncpy(buff,p,255);
1375  strncat(buff,"_help",255-strlen(p));
1376  idhdl h=enterid(buff,0,STRING_CMD,&IDROOT,FALSE);
1377  IDSTRING(h)=omStrDup(help);
1378  currPack=s;
1379  }
1380 }

◆ mytolower()

char mytolower ( char  c)

Definition at line 1416 of file iplib.cc.

1417 {
1418  if(c>=65 && c<=(65+26)) c+=32;
1419  return(c);
1420 }

◆ mytoupper()

char mytoupper ( char  c)

Definition at line 1410 of file iplib.cc.

1411 {
1412  if(c>=97 && c<=(97+26)) c-=32;
1413  return(c);
1414 }

◆ print_init()

void print_init ( )

Definition at line 3482 of file libparse.cc.

3483 {
3484  printf("Init=%d\n", yy_init);
3485 }
STATIC_VAR int yy_init
Definition: libparse.cc:240

◆ register_dyn_module()

void register_dyn_module ( char *  fullname,
void *  handle 
)

Definition at line 1160 of file iplib.cc.

1160  {
1161  std::string fname = fullname;
1162  if (dyn_modules == NULL)
1163  dyn_modules = new std::map<std::string, void *>();
1164  dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1165 }
#define string
Definition: libparse.cc:1252

◆ registered_dyn_module()

bool registered_dyn_module ( char *  fullname)

Definition at line 1153 of file iplib.cc.

1153  {
1154  if (dyn_modules == NULL)
1155  return false;
1156  std::string fname = fullname;
1157  return dyn_modules->count(fname) != 0;
1158 }

◆ SI_FOREACH_BUILTIN()

SI_FOREACH_BUILTIN ( SI_GET_BUILTIN_MOD_INIT0  )

◆ yylprestart()

void yylprestart ( FILE *  input_file)

Variable Documentation

◆ dyn_modules

THREAD_VAR std::map<std::string, void *>* dyn_modules

Definition at line 1151 of file iplib.cc.

◆ iiLocalRing

VAR ring* iiLocalRing

Definition at line 469 of file iplib.cc.

◆ iiRETURNEXPR

INST_VAR sleftv iiRETURNEXPR

Definition at line 470 of file iplib.cc.

◆ iiRETURNEXPR_len

VAR int iiRETURNEXPR_len =0

Definition at line 471 of file iplib.cc.

◆ library_stack

VAR libstackv library_stack

Definition at line 64 of file iplib.cc.

◆ yylp_errlist

const char* yylp_errlist[]
extern

Definition at line 1114 of file libparse.cc.

◆ yylp_errno

EXTERN_VAR int yylp_errno

Definition at line 60 of file iplib.cc.

◆ yylplineno

EXTERN_VAR int yylplineno

Definition at line 61 of file iplib.cc.