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, 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 sl)
 
static void iiCallLibProcBegin ()
 
static void iiCallLibProcEnd (idhdl save_ringhdl, ring save_ring)
 
void * iiCallLibProc1 (const char *n, void *arg, int arg_type, BOOLEAN &err)
 
void * iiCallLibProcM (const char *n, void **args, int *arg_types, BOOLEAN &err)
 args: NULL terminated arry 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) }
 
SModulFunc_t iiGetBuiltinModInit (const char *libname)
 
BOOLEAN iiTryLoadLib (leftv v, const char *id)
 
BOOLEAN iiLocateLib (const char *lib, char *where)
 
BOOLEAN iiLibCmd (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 745 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 1331 of file iplib.cc.

1332 {
1333  void* result = NULL;
1334 
1335  const char* bin_dir = feGetResource('b');
1336  if (!bin_dir) { return NULL; }
1337 
1338  char path_name[MAXPATHLEN];
1339  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1340 
1341  void* openlib = dynl_open(path_name);
1342  if(!openlib)
1343  {
1344  Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1345  return NULL;
1346  }
1347  result = dynl_sym(openlib, funcname);
1348  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1349 
1350  return result;
1351 }
#define MAXPATHLEN
Definition: omRet2Info.c:22
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:162
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
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
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189
return result
Definition: facAbsBiFact.cc:76
const char * dynl_error()
Definition: mod_raw.cc:178

◆ close_all_dyn_modules()

void close_all_dyn_modules ( )

Definition at line 1114 of file iplib.cc.

1114  {
1115  for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1116  it != dyn_modules->end();
1117  it++)
1118  {
1119  dynl_close(it->second);
1120  }
1121  delete dyn_modules;
1122  dyn_modules = NULL;
1123 }
int dynl_close(void *handle)
Definition: mod_raw.cc:173
#define NULL
Definition: omList.c:12
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition: iplib.cc:1098

◆ 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 }
#define yytext
Definition: libparse.cc:16
VAR int offset
Definition: libparse.cc:1093
int i
Definition: cfEzgcd.cc:125
VAR char * yylp_buffer_start
Definition: libparse.cc:1102

◆ iiAddCproc()

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

Definition at line 1006 of file iplib.cc.

1008 {
1009  procinfov pi;
1010  idhdl h;
1011 
1012  #ifndef SING_NDEBUG
1013  int dummy;
1014  if (IsCmd(procname,dummy))
1015  {
1016  Werror(">>%s< is a reserved name",procname);
1017  return 0;
1018  }
1019  #endif
1020 
1021  h=IDROOT->get(procname,0);
1022  if ((h!=NULL)
1023  && (IDTYP(h)==PROC_CMD))
1024  {
1025  pi = IDPROC(h);
1026  #if 0
1027  if ((pi->language == LANG_SINGULAR)
1028  &&(BVERBOSE(V_REDEFINE)))
1029  Warn("extend `%s`",procname);
1030  #endif
1031  }
1032  else
1033  {
1034  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1035  }
1036  if ( h!= NULL )
1037  {
1038  pi = IDPROC(h);
1039  if((pi->language == LANG_SINGULAR)
1040  ||(pi->language == LANG_NONE))
1041  {
1042  omfree(pi->libname);
1043  pi->libname = omStrDup(libname);
1044  omfree(pi->procname);
1045  pi->procname = omStrDup(procname);
1046  pi->language = LANG_C;
1047  pi->ref = 1;
1048  pi->is_static = pstatic;
1049  pi->data.o.function = func;
1050  }
1051  else if(pi->language == LANG_C)
1052  {
1053  if(pi->data.o.function == func)
1054  {
1055  pi->ref++;
1056  }
1057  else
1058  {
1059  omfree(pi->libname);
1060  pi->libname = omStrDup(libname);
1061  omfree(pi->procname);
1062  pi->procname = omStrDup(procname);
1063  pi->language = LANG_C;
1064  pi->ref = 1;
1065  pi->is_static = pstatic;
1066  pi->data.o.function = func;
1067  }
1068  }
1069  else
1070  Warn("internal error: unknown procedure type %d",pi->language);
1071  if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1072  return(1);
1073  }
1074  else
1075  {
1076  WarnS("iiAddCproc: failed.");
1077  }
1078  return(0);
1079 }
language_defs language
Definition: subexpr.h:59
#define IDROOT
Definition: ipid.h:18
#define TRUE
Definition: auxiliary.h:100
short ref
Definition: subexpr.h:60
#define WarnS
Definition: emacs.cc:78
Definition: idrec.h:34
char * procname
Definition: subexpr.h:57
Definition: subexpr.h:22
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
char * libname
Definition: subexpr.h:56
#define omfree(addr)
Definition: omAllocDecl.h:237
procinfodata data
Definition: subexpr.h:63
VAR package currPack
Definition: ipid.cc:57
#define BVERBOSE(a)
Definition: options.h:34
char is_static
Definition: subexpr.h:61
#define IDPROC(a)
Definition: ipid.h:135
#define pi
Definition: libparse.cc:1145
STATIC_VAR Poly * h
Definition: janet.cc:971
#define NULL
Definition: omList.c:12
#define V_REDEFINE
Definition: options.h:44
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:9007
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiAddCprocTop()

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

Definition at line 1081 of file iplib.cc.

1083 {
1084  int r=iiAddCproc(libname,procname,pstatic,func);
1085  package s=currPack;
1087  if (r) r=iiAddCproc(libname,procname,pstatic,func);
1088  currPack=s;
1089  return r;
1090 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
VAR package currPack
Definition: ipid.cc:57
VAR package basePack
Definition: ipid.cc:58
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1006

◆ iiAllStart()

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

Definition at line 294 of file iplib.cc.

295 {
296  // see below:
297  BITSET save1=si_opt_1;
298  BITSET save2=si_opt_2;
299  newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
300  pi, l );
301  BOOLEAN err=yyparse();
302  if (sLastPrinted.rtyp!=0)
303  {
305  }
306  // the access to optionStruct and verboseStruct do not work
307  // on x86_64-Linux for pic-code
308  if ((TEST_V_ALLWARN) &&
309  (t==BT_proc) &&
310  ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
311  (pi->libname!=NULL) && (pi->libname[0]!='\0'))
312  {
313  if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
314  Warn("option changed in proc %s from %s",pi->procname,pi->libname);
315  else
316  Warn("option changed in proc %s",pi->procname);
317  int i;
318  for (i=0; optionStruct[i].setval!=0; i++)
319  {
320  if ((optionStruct[i].setval & si_opt_1)
321  && (!(optionStruct[i].setval & save1)))
322  {
323  Print(" +%s",optionStruct[i].name);
324  }
325  if (!(optionStruct[i].setval & si_opt_1)
326  && ((optionStruct[i].setval & save1)))
327  {
328  Print(" -%s",optionStruct[i].name);
329  }
330  }
331  for (i=0; verboseStruct[i].setval!=0; i++)
332  {
333  if ((verboseStruct[i].setval & si_opt_2)
334  && (!(verboseStruct[i].setval & save2)))
335  {
336  Print(" +%s",verboseStruct[i].name);
337  }
338  if (!(verboseStruct[i].setval & si_opt_2)
339  && ((verboseStruct[i].setval & save2)))
340  {
341  Print(" -%s",verboseStruct[i].name);
342  }
343  }
344  PrintLn();
345  }
346  return err;
347 }
VAR unsigned si_opt_2
Definition: options.c:6
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:521
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:80
VAR unsigned si_opt_1
Definition: options.c:5
unsigned setval
Definition: ipid.h:148
#define BITSET
Definition: structs.h:20
char * procname
Definition: subexpr.h:57
char * libname
Definition: subexpr.h:56
int i
Definition: cfEzgcd.cc:125
char name(const Variable &v)
Definition: factory.h:180
int yyparse(void)
Definition: grammar.cc:2111
#define NULL
Definition: omList.c:12
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46
int rtyp
Definition: subexpr.h:91
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:156
int p
Definition: cfModGcd.cc:4019
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:551
int BOOLEAN
Definition: auxiliary.h:87
#define TEST_V_ALLWARN
Definition: options.h:139
int l
Definition: cfEzgcd.cc:93
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiArithAddCmd()

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

Definition at line 9352 of file iparith.cc.

9359 {
9360  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9361  // nTokval, nToktype, nPos);
9362  if(nPos>=0)
9363  {
9364  // no checks: we rely on a correct generated code in iparith.inc
9365  assume((unsigned)nPos < sArithBase.nCmdAllocated);
9366  assume(szName!=NULL);
9367  sArithBase.sCmds[nPos].name = omStrDup(szName);
9368  sArithBase.sCmds[nPos].alias = nAlias;
9369  sArithBase.sCmds[nPos].tokval = nTokval;
9370  sArithBase.sCmds[nPos].toktype = nToktype;
9371  sArithBase.nCmdUsed++;
9372  //if(nTokval>0) sArithBase.nLastIdentifier++;
9373  }
9374  else
9375  {
9376  if(szName==NULL) return -1;
9377  int nIndex = iiArithFindCmd(szName);
9378  if(nIndex>=0)
9379  {
9380  Print("'%s' already exists at %d\n", szName, nIndex);
9381  return -1;
9382  }
9383 
9385  {
9386  /* needs to create new slots */
9387  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9388  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9389  if(sArithBase.sCmds==NULL) return -1;
9391  }
9392  /* still free slots available */
9393  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9394  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9395  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9396  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9397  sArithBase.nCmdUsed++;
9398 
9399  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9400  (&_gentable_sort_cmds));
9403  {
9404  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9405  }
9406  //Print("L=%d\n", sArithBase.nLastIdentifier);
9407  }
9408  return 0;
9409 }
STATIC_VAR SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:195
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:9185
#define Print
Definition: emacs.cc:80
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:186
#define assume(x)
Definition: mod2.h:390
unsigned nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:187
#define NULL
Definition: omList.c:12
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:185
#define nSize(n)
Definition: numbers.h:39
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:9257
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:180
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiCallLibProc1()

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

Definition at line 614 of file iplib.cc.

615 {
616  idhdl h=ggetid(n);
617  if ((h==NULL)
618  || (IDTYP(h)!=PROC_CMD))
619  {
620  err=2;
621  return NULL;
622  }
623  // ring handling
624  idhdl save_ringhdl=currRingHdl;
625  ring save_ring=currRing;
627  // argument:
628  sleftv tmp;
629  tmp.Init();
630  tmp.data=arg;
631  tmp.rtyp=arg_type;
632  // call proc
633  err=iiMake_proc(h,currPack,&tmp);
634  // clean up ring
635  iiCallLibProcEnd(save_ringhdl,save_ring);
636  // return
637  if (err==FALSE)
638  {
639  void*r=iiRETURNEXPR.data;
642  return r;
643  }
644  return NULL;
645 }
idhdl ggetid(const char *n)
Definition: ipid.cc:521
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define FALSE
Definition: auxiliary.h:96
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:456
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition: iplib.cc:589
void Init()
Definition: subexpr.h:107
Definition: idrec.h:34
void * data
Definition: subexpr.h:88
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define IDTYP(a)
Definition: ipid.h:114
VAR package currPack
Definition: ipid.cc:57
static void iiCallLibProcBegin()
Definition: iplib.cc:571
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
Definition: iplib.cc:486
STATIC_VAR Poly * h
Definition: janet.cc:971
#define NULL
Definition: omList.c:12
int rtyp
Definition: subexpr.h:91
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
VAR idhdl currRingHdl
Definition: ipid.cc:59

◆ iiCallLibProcBegin()

static void iiCallLibProcBegin ( )
static

Definition at line 571 of file iplib.cc.

572 {
573  idhdl tmp_ring=NULL;
574  if (currRing!=NULL)
575  {
577  {
578  // clean up things depending on currRingHdl:
580  sLastPrinted.Init();
581  // need to define a ring-hdl for currRingHdl
582  tmp_ring=enterid(" tmpRing",myynest,RING_CMD,&IDROOT,FALSE);
583  IDRING(tmp_ring)=currRing;
584  currRing->ref++;
585  rSetHdl(tmp_ring);
586  }
587  }
588 }
#define FALSE
Definition: auxiliary.h:96
#define IDROOT
Definition: ipid.h:18
void Init()
Definition: subexpr.h:107
Definition: idrec.h:34
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
#define NULL
Definition: omList.c:12
#define IDRING(a)
Definition: ipid.h:122
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46
VAR int myynest
Definition: febase.cc:41
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
void rSetHdl(idhdl h)
Definition: ipshell.cc:5086
VAR idhdl currRingHdl
Definition: ipid.cc:59

◆ iiCallLibProcEnd()

static void iiCallLibProcEnd ( idhdl  save_ringhdl,
ring  save_ring 
)
static

Definition at line 589 of file iplib.cc.

590 {
591  if ((currRing!=NULL)
592  &&(currRing!=save_ring))
593  {
594  currRing->ref--;
595  idhdl hh=IDROOT;
596  idhdl prev=NULL;
597  while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
598  if (hh!=NULL)
599  {
600  if (prev==NULL) IDROOT=hh->next;
601  else prev->next=hh->next;
602  omFree((ADDRESS)IDID(hh));
604  }
605  else
606  {
607  WarnS("internal: lost ring in iiCallLib");
608  }
609  }
610  currRingHdl=save_ringhdl;
611  currRing=save_ring;
612 }
#define IDID(a)
Definition: ipid.h:117
#define IDROOT
Definition: ipid.h:18
void * ADDRESS
Definition: auxiliary.h:135
#define WarnS
Definition: emacs.cc:78
Definition: idrec.h:34
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
VAR omBin idrec_bin
Definition: ipid.cc:48
#define omFree(addr)
Definition: omAllocDecl.h:261
idhdl next
Definition: idrec.h:38
#define NULL
Definition: omList.c:12
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
VAR idhdl currRingHdl
Definition: ipid.cc:59

◆ iiCallLibProcM()

void* iiCallLibProcM ( const char *  n,
void **  args,
int *  arg_types,
BOOLEAN err 
)

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

Definition at line 648 of file iplib.cc.

649 {
650  idhdl h=ggetid(n);
651  if ((h==NULL)
652  || (IDTYP(h)!=PROC_CMD))
653  {
654  err=2;
655  return NULL;
656  }
657  // ring handling
658  idhdl save_ringhdl=currRingHdl;
659  ring save_ring=currRing;
661  // argument:
662  if (arg_types[0]!=0)
663  {
664  sleftv tmp;
665  leftv tt=&tmp;
666  int i=1;
667  tmp.Init();
668  tmp.data=args[0];
669  tmp.rtyp=arg_types[0];
670  while(arg_types[i]!=0)
671  {
672  tt->next=(leftv)omAlloc0(sizeof(sleftv));
673  tt=tt->next;
674  tt->rtyp=arg_types[i];
675  tt->data=args[i];
676  i++;
677  }
678  // call proc
679  err=iiMake_proc(h,currPack,&tmp);
680  }
681  else
682  // call proc
683  err=iiMake_proc(h,currPack,NULL);
684  // clean up ring
685  iiCallLibProcEnd(save_ringhdl,save_ring);
686  // return
687  if (err==FALSE)
688  {
689  void*r=iiRETURNEXPR.data;
692  return r;
693  }
694  return NULL;
695 }
idhdl ggetid(const char *n)
Definition: ipid.cc:521
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define FALSE
Definition: auxiliary.h:96
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:456
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition: iplib.cc:589
void Init()
Definition: subexpr.h:107
sleftv * leftv
Definition: structs.h:62
Definition: idrec.h:34
void * data
Definition: subexpr.h:88
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define IDTYP(a)
Definition: ipid.h:114
int i
Definition: cfEzgcd.cc:125
VAR package currPack
Definition: ipid.cc:57
static void iiCallLibProcBegin()
Definition: iplib.cc:571
leftv next
Definition: subexpr.h:86
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
Definition: iplib.cc:486
STATIC_VAR Poly * h
Definition: janet.cc:971
#define NULL
Definition: omList.c:12
int rtyp
Definition: subexpr.h:91
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
VAR idhdl currRingHdl
Definition: ipid.cc:59
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 475 of file iplib.cc.

476 {
477  if (myynest >= iiRETURNEXPR_len-1)
478  {
480  iiRETURNEXPR_len*sizeof(ring),
481  (iiRETURNEXPR_len+16)*sizeof(ring));
482  memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
483  iiRETURNEXPR_len+=16;
484  }
485 }
VAR int iiRETURNEXPR_len
Definition: iplib.cc:457
#define omreallocSize(addr, o_size, size)
Definition: omAllocDecl.h:231
VAR ring * iiLocalRing
Definition: iplib.cc:455
VAR int myynest
Definition: febase.cc:41

◆ iiCleanProcs()

static void iiCleanProcs ( idhdl root)
static

Definition at line 871 of file iplib.cc.

872 {
873  idhdl prev=NULL;
874  loop
875  {
876  if (root==NULL) return;
877  if (IDTYP(root)==PROC_CMD)
878  {
879  procinfo *pi=(procinfo*)IDDATA(root);
880  if ((pi->language == LANG_SINGULAR)
881  && (pi->data.s.body_start == 0L))
882  {
883  // procinfo data incorrect:
884  // - no proc body can start at the beginning of the file
885  killhdl(root);
886  if (prev==NULL)
887  root=IDROOT;
888  else
889  {
890  root=prev;
891  prev=NULL;
892  }
893  continue;
894  }
895  }
896  prev=root;
897  root=IDNEXT(root);
898  }
899 }
#define IDNEXT(a)
Definition: ipid.h:113
language_defs language
Definition: subexpr.h:59
#define IDROOT
Definition: ipid.h:18
#define loop
Definition: structs.h:80
Definition: idrec.h:34
#define IDTYP(a)
Definition: ipid.h:114
procinfodata data
Definition: subexpr.h:63
#define pi
Definition: libparse.cc:1145
#define NULL
Definition: omList.c:12
void killhdl(idhdl h, package proot)
Definition: ipid.cc:384
#define IDDATA(a)
Definition: ipid.h:121

◆ iiConvName()

char* iiConvName ( const char *  libname)

Definition at line 1374 of file iplib.cc.

1375 {
1376  char *tmpname = omStrDup(libname);
1377  char *p = strrchr(tmpname, DIR_SEP);
1378  char *r;
1379  if(p==NULL) p = tmpname; else p++;
1380  // p is now the start of the file name (without path)
1381  r=p;
1382  while(isalnum(*r)||(*r=='_')) r++;
1383  // r point the the end of the main part of the filename
1384  *r = '\0';
1385  r = omStrDup(p);
1386  *r = mytoupper(*r);
1387  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1388  omFree((ADDRESS)tmpname);
1389 
1390  return(r);
1391 }
char mytoupper(char c)
Definition: iplib.cc:1355
void * ADDRESS
Definition: auxiliary.h:135
#define DIR_SEP
Definition: feResource.h:6
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:12
int p
Definition: cfModGcd.cc:4019
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiEStart()

BOOLEAN iiEStart ( char *  example,
procinfo pi 
)

Definition at line 700 of file iplib.cc.

701 {
702  BOOLEAN err;
703  int old_echo=si_echo;
704 
705  iiCheckNest();
706  procstack->push(example);
709  {
710  if (traceit&TRACE_SHOW_LINENO) printf("\n");
711  printf("entering example (level %d)\n",myynest);
712  }
713  myynest++;
714 
715  err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
716 
718  myynest--;
719  si_echo=old_echo;
720  if (traceit&TRACE_SHOW_PROC)
721  {
722  if (traceit&TRACE_SHOW_LINENO) printf("\n");
723  printf("leaving -example- (level %d)\n",myynest);
724  }
725  if (iiLocalRing[myynest] != currRing)
726  {
727  if (iiLocalRing[myynest]!=NULL)
728  {
731  }
732  else
733  {
735  currRing=NULL;
736  }
737  }
738  procstack->pop();
739  return err;
740 }
#define TRACE_SHOW_LINENO
Definition: reporter.h:30
VAR proclevel * procstack
Definition: ipid.cc:52
EXTERN_VAR int traceit
Definition: reporter.h:24
static void iiCheckNest()
Definition: iplib.cc:475
VAR ring * iiLocalRing
Definition: iplib.cc:455
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void killlocals(int v)
Definition: ipshell.cc:381
procinfodata data
Definition: subexpr.h:63
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1610
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
Definition: iplib.cc:294
VAR int si_echo
Definition: febase.cc:35
#define NULL
Definition: omList.c:12
VAR int myynest
Definition: febase.cc:41
#define TRACE_SHOW_PROC
Definition: reporter.h:28
void rSetHdl(idhdl h)
Definition: ipshell.cc:5086
void push(char *)
Definition: ipid.cc:722
void pop()
Definition: ipid.cc:732
int BOOLEAN
Definition: auxiliary.h:87
VAR idhdl currRingHdl
Definition: ipid.cc:59

◆ iiGetBuiltinModInit()

SModulFunc_t iiGetBuiltinModInit ( const char *  libname)

Definition at line 752 of file iplib.cc.

753 {
754 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
756 # undef SI_GET_BUILTIN_MOD_INIT
757 
758  return NULL;
759 }
#define SI_GET_BUILTIN_MOD_INIT(name)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
#define NULL
Definition: omList.c:12

◆ 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 }
char * iiProcArgs(char *e, BOOLEAN withParenth)
Definition: iplib.cc:110
const CanonicalForm int s
Definition: facAbsFact.cc:55
CanonicalForm fp
Definition: cfModGcd.cc:4043
#define TRUE
Definition: auxiliary.h:100
#define omAlloc(size)
Definition: omAllocDecl.h:210
char * libname
Definition: subexpr.h:56
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:390
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: feFopen.cc:195
int status int void * buf
Definition: si_signals.h:59
procinfodata data
Definition: subexpr.h:63
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
int i
Definition: cfEzgcd.cc:125
char * iiProcName(char *buf, char &ct, char *&e)
Definition: iplib.cc:96
STATIC_VAR int offset
Definition: janet.cc:29
#define NULL
Definition: omList.c:12
CanonicalForm head(const CanonicalForm &f)
#define SEEK_SET
Definition: mod2.h:116
int p
Definition: cfModGcd.cc:4019

◆ 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 FALSE
Definition: auxiliary.h:96
Definition: idrec.h:34
Definition: subexpr.h:22
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
char * iiConvName(const char *libname)
Definition: iplib.cc:1374

◆ iiInitSingularProcinfo()

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

Definition at line 992 of file iplib.cc.

994 {
995  memset(pi,0,sizeof(*pi));
996  pi->libname = omStrDup(libname);
997  pi->procname = omStrDup(procname);
998  pi->language = LANG_SINGULAR;
999  pi->ref = 1;
1000  pi->is_static = pstatic;
1001  pi->data.s.proc_start = pos;
1002  return(pi);
1003 }
language_defs language
Definition: subexpr.h:59
short ref
Definition: subexpr.h:60
char * procname
Definition: subexpr.h:57
char * libname
Definition: subexpr.h:56
procinfodata data
Definition: subexpr.h:63
char is_static
Definition: subexpr.h:61
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiLibCmd()

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

Definition at line 827 of file iplib.cc.

828 {
829  char libnamebuf[1024];
830  // procinfov pi;
831  // idhdl h;
832  idhdl pl;
833  // idhdl hl;
834  // long pos = 0L;
835  char *plib = iiConvName(newlib);
836  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
837  // int lines = 1;
838  BOOLEAN LoadResult = TRUE;
839 
840  if (fp==NULL)
841  {
842  return TRUE;
843  }
844  pl = basePack->idroot->get(plib,0);
845  if (pl==NULL)
846  {
847  pl = enterid( plib,0, PACKAGE_CMD,
848  &(basePack->idroot), TRUE );
849  IDPACKAGE(pl)->language = LANG_SINGULAR;
850  IDPACKAGE(pl)->libname=omStrDup(newlib);
851  }
852  else
853  {
854  if(IDTYP(pl)!=PACKAGE_CMD)
855  {
856  WarnS("not of type package.");
857  fclose(fp);
858  return TRUE;
859  }
860  if (!force) return FALSE;
861  }
862  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
863  omFree((ADDRESS)newlib);
864 
865  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
866  omFree((ADDRESS)plib);
867 
868  return LoadResult;
869 }
CanonicalForm fp
Definition: cfModGcd.cc:4043
#define FALSE
Definition: auxiliary.h:96
#define TRUE
Definition: auxiliary.h:100
void * ADDRESS
Definition: auxiliary.h:135
#define WarnS
Definition: emacs.cc:78
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR char libnamebuf[1024]
Definition: libparse.cc:1098
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:916
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
int BOOLEAN
Definition: auxiliary.h:87
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ iiLoadLIB()

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

Definition at line 916 of file iplib.cc.

918 {
919  EXTERN_VAR FILE *yylpin;
920  libstackv ls_start = library_stack;
921  lib_style_types lib_style;
922 
923  yylpin = fp;
924  #if YYLPDEBUG > 1
925  print_init();
926  #endif
927  EXTERN_VAR int lpverbose;
928  if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1;
929  else lpverbose=0;
930  // yylplex sets also text_buffer
931  if (text_buffer!=NULL) *text_buffer='\0';
932  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
933  if(yylp_errno)
934  {
935  Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
936  current_pos(0));
938  {
942  }
943  else
945  WerrorS("Cannot load library,... aborting.");
946  reinit_yylp();
947  fclose( yylpin );
949  return TRUE;
950  }
951  if (BVERBOSE(V_LOAD_LIB))
952  Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
953  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
954  {
955  Warn( "library %s has old format. This format is still accepted,", newlib);
956  WarnS( "but for functionality you may wish to change to the new");
957  WarnS( "format. Please refer to the manual for further information.");
958  }
959  reinit_yylp();
960  fclose( yylpin );
961  fp = NULL;
962  iiRunInit(IDPACKAGE(pl));
963 
964  {
965  libstackv ls;
966  for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
967  {
968  if(ls->to_be_done)
969  {
970  ls->to_be_done=FALSE;
971  iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
972  ls = ls->pop(newlib);
973  }
974  }
975 #if 0
976  PrintS("--------------------\n");
977  for(ls = library_stack; ls != NULL; ls = ls->next)
978  {
979  Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
980  ls->to_be_done ? "not loaded" : "loaded");
981  }
982  PrintS("--------------------\n");
983 #endif
984  }
985 
986  if(fp != NULL) fclose(fp);
987  return FALSE;
988 }
int cnt
Definition: subexpr.h:166
#define Print
Definition: emacs.cc:80
CanonicalForm fp
Definition: cfModGcd.cc:4043
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
libstackv next
Definition: subexpr.h:163
#define FALSE
Definition: auxiliary.h:96
static void iiRunInit(package p)
Definition: iplib.cc:900
#define V_LOAD_LIB
Definition: options.h:46
#define EXTERN_VAR
Definition: globaldefs.h:6
EXTERN_VAR int yylplineno
Definition: iplib.cc:61
const char * yylp_errlist[]
Definition: libparse.cc:1114
#define IDROOT
Definition: ipid.h:18
BOOLEAN to_be_done
Definition: subexpr.h:165
#define TRUE
Definition: auxiliary.h:100
void print_init()
Definition: libparse.cc:3482
VAR int lpverbose
Definition: libparse.cc:1106
void * ADDRESS
Definition: auxiliary.h:135
void WerrorS(const char *s)
Definition: feFopen.cc:24
char * get()
Definition: subexpr.h:169
#define V_DEBUG_LIB
Definition: options.h:47
#define WarnS
Definition: emacs.cc:78
libstackv pop(const char *p)
Definition: iplib.cc:1465
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:827
#define IDPACKAGE(a)
Definition: ipid.h:134
#define YYLP_BAD_CHAR
Definition: libparse.h:93
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR libstackv library_stack
Definition: iplib.cc:64
VAR char libnamebuf[1024]
Definition: libparse.cc:1098
void PrintS(const char *s)
Definition: reporter.cc:284
#define BVERBOSE(a)
Definition: options.h:34
#define NULL
Definition: omList.c:12
int current_pos(int i=0)
Definition: libparse.cc:3346
lib_style_types
Definition: libparse.h:9
EXTERN_VAR int yylp_errno
Definition: iplib.cc:60
static void iiCleanProcs(idhdl &root)
Definition: iplib.cc:871
VAR char * text_buffer
Definition: libparse.cc:1099
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define Warn
Definition: emacs.cc:77
void reinit_yylp()
Definition: libparse.cc:3376

◆ iiLocateLib()

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

Definition at line 813 of file iplib.cc.

814 {
815  char *plib = iiConvName(lib);
816  idhdl pl = basePack->idroot->get(plib,0);
817  if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
818  (IDPACKAGE(pl)->language == LANG_SINGULAR))
819  {
820  strncpy(where,IDPACKAGE(pl)->libname,127);
821  return TRUE;
822  }
823  else
824  return FALSE;;
825 }
#define FALSE
Definition: auxiliary.h:96
#define TRUE
Definition: auxiliary.h:100
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
char * iiConvName(const char *libname)
Definition: iplib.cc:1374

◆ iiMake_proc()

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

Definition at line 486 of file iplib.cc.

487 {
488  int err;
489  procinfov pi = IDPROC(pn);
490  if(pi->is_static && myynest==0)
491  {
492  Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
493  pi->libname, pi->procname);
494  return TRUE;
495  }
496  iiCheckNest();
498  //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
499  iiRETURNEXPR.Init();
500  procstack->push(pi->procname);
502  || (pi->trace_flag&TRACE_SHOW_PROC))
503  {
505  Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
506  }
507 #ifdef RDEBUG
509 #endif
510  switch (pi->language)
511  {
512  default:
513  case LANG_NONE:
514  WerrorS("undefined proc");
515  err=TRUE;
516  break;
517 
518  case LANG_SINGULAR:
519  if ((pi->pack!=NULL)&&(currPack!=pi->pack))
520  {
521  currPack=pi->pack;
524  //Print("set pack=%s\n",IDID(currPackHdl));
525  }
526  else if ((pack!=NULL)&&(currPack!=pack))
527  {
528  currPack=pack;
531  //Print("set pack=%s\n",IDID(currPackHdl));
532  }
533  err=iiPStart(pn,sl);
534  break;
535  case LANG_C:
537  err = (pi->data.o.function)(res, sl);
538  memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
540  break;
541  }
542  if ((traceit&TRACE_SHOW_PROC)
543  || (pi->trace_flag&TRACE_SHOW_PROC))
544  {
545  if (traceit&TRACE_SHOW_LINENO) PrintLn();
546  Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
547  }
548  //const char *n="NULL";
549  //if (currRingHdl!=NULL) n=IDID(currRingHdl);
550  //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
551 #ifdef RDEBUG
552  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
553 #endif
554  if (err)
555  {
557  //iiRETURNEXPR.Init(); //done by CleanUp
558  }
559  if (iiCurrArgs!=NULL)
560  {
561  if (!err) Warn("too many arguments for %s",IDID(pn));
562  iiCurrArgs->CleanUp();
565  }
566  procstack->pop();
567  if (err)
568  return TRUE;
569  return FALSE;
570 }
#define TRACE_SHOW_LINENO
Definition: reporter.h:30
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define TRACE_SHOW_RINGS
Definition: reporter.h:35
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:80
package pack
Definition: subexpr.h:58
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:140
#define IDID(a)
Definition: ipid.h:117
#define FALSE
Definition: auxiliary.h:96
VAR proclevel * procstack
Definition: ipid.cc:52
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:456
language_defs language
Definition: subexpr.h:59
static void iiShowLevRings()
Definition: iplib.cc:460
#define TRUE
Definition: auxiliary.h:100
void Init()
Definition: subexpr.h:107
void * ADDRESS
Definition: auxiliary.h:135
sleftv * leftv
Definition: structs.h:62
void WerrorS(const char *s)
Definition: feFopen.cc:24
EXTERN_VAR int traceit
Definition: reporter.h:24
static void iiCheckNest()
Definition: iplib.cc:475
VAR ring * iiLocalRing
Definition: iplib.cc:455
BOOLEAN iiPStart(idhdl pn, leftv v)
Definition: iplib.cc:354
char * procname
Definition: subexpr.h:57
Definition: subexpr.h:22
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
char * libname
Definition: subexpr.h:56
CanonicalForm res
Definition: facAbsFact.cc:64
procinfodata data
Definition: subexpr.h:63
VAR package currPack
Definition: ipid.cc:57
VAR leftv iiCurrArgs
Definition: ipshell.cc:76
char is_static
Definition: subexpr.h:61
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define IDPROC(a)
Definition: ipid.h:135
#define pi
Definition: libparse.cc:1145
#define NULL
Definition: omList.c:12
VAR int myynest
Definition: febase.cc:41
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
VAR idhdl currPackHdl
Definition: ipid.cc:55
#define TRACE_SHOW_PROC
Definition: reporter.h:28
idhdl packFindHdl(package r)
Definition: ipid.cc:750
void iiCheckPack(package &p)
Definition: ipshell.cc:1539
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void push(char *)
Definition: ipid.cc:722
void pop()
Definition: ipid.cc:732
char trace_flag
Definition: subexpr.h:62
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define Warn
Definition: emacs.cc:77

◆ 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 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:135
#define loop
Definition: structs.h:80
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
int BOOLEAN
Definition: auxiliary.h:87
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ 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 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int status int void * buf
Definition: si_signals.h:59

◆ iiPStart()

BOOLEAN iiPStart ( idhdl  pn,
leftv  v 
)

Definition at line 354 of file iplib.cc.

355 {
356  procinfov pi=NULL;
357  int old_echo=si_echo;
358  BOOLEAN err=FALSE;
359  char save_flags=0;
360 
361  /* init febase ======================================== */
362  /* we do not enter this case if filename != NULL !! */
363  if (pn!=NULL)
364  {
365  pi = IDPROC(pn);
366  if(pi!=NULL)
367  {
368  save_flags=pi->trace_flag;
369  if( pi->data.s.body==NULL )
370  {
371  iiGetLibProcBuffer(pi);
372  if (pi->data.s.body==NULL) return TRUE;
373  }
374 // omUpdateInfo();
375 // int m=om_Info.UsedBytes;
376 // Print("proc %s, mem=%d\n",IDID(pn),m);
377  }
378  }
379  else return TRUE;
380  /* generate argument list ======================================*/
381  //iiCurrArgs should be NULL here, as the assignment for the parameters
382  // of the prevouis call are already done befor calling another routine
383  if (v!=NULL)
384  {
386  memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
387  memset(v,0,sizeof(sleftv));
388  }
389  else
390  {
392  }
393  iiCurrProc=pn;
394  /* start interpreter ======================================*/
395  myynest++;
396  if (myynest > SI_MAX_NEST)
397  {
398  WerrorS("nesting too deep");
399  err=TRUE;
400  }
401  else
402  {
403  err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
404 
405  if (iiLocalRing[myynest-1] != currRing)
406  {
408  {
409  //idhdl hn;
410  const char *n;
411  const char *o;
412  idhdl nh=NULL, oh=NULL;
413  if (iiLocalRing[myynest-1]!=NULL)
415  if (oh!=NULL) o=oh->id;
416  else o="none";
417  if (currRing!=NULL)
418  nh=rFindHdl(currRing,NULL);
419  if (nh!=NULL) n=nh->id;
420  else n="none";
421  Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
423  err=TRUE;
424  }
426  }
427  if ((currRing==NULL)
428  && (currRingHdl!=NULL))
430  else
431  if ((currRing!=NULL) &&
433  ||(IDLEV(currRingHdl)>=myynest-1)))
434  {
437  }
438  //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
440 #ifndef SING_NDEBUG
441  checkall();
442 #endif
443  //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
444  }
445  myynest--;
446  si_echo=old_echo;
447  if (pi!=NULL)
448  pi->trace_flag=save_flags;
449 // omUpdateInfo();
450 // int m=om_Info.UsedBytes;
451 // Print("exit %s, mem=%d\n",IDID(pn),m);
452  return err;
453 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:140
VAR idhdl iiCurrProc
Definition: ipshell.cc:77
#define FALSE
Definition: auxiliary.h:96
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:456
#define TRUE
Definition: auxiliary.h:100
sleftv * leftv
Definition: structs.h:62
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
#define SI_MAX_NEST
Definition: iplib.cc:23
VAR ring * iiLocalRing
Definition: iplib.cc:455
char * procname
Definition: subexpr.h:57
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
BOOLEAN RingDependend()
Definition: subexpr.cc:418
void killlocals(int v)
Definition: ipshell.cc:381
procinfodata data
Definition: subexpr.h:63
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1610
VAR leftv iiCurrArgs
Definition: ipshell.cc:76
#define IDLEV(a)
Definition: ipid.h:116
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
Definition: iplib.cc:294
#define IDPROC(a)
Definition: ipid.h:135
#define pi
Definition: libparse.cc:1145
VAR int si_echo
Definition: febase.cc:35
#define NULL
Definition: omList.c:12
#define IDRING(a)
Definition: ipid.h:122
VAR int myynest
Definition: febase.cc:41
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
const char * id
Definition: idrec.h:39
void rSetHdl(idhdl h)
Definition: ipshell.cc:5086
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:193
int BOOLEAN
Definition: auxiliary.h:87
VAR idhdl currRingHdl
Definition: ipid.cc:59
char trace_flag
Definition: subexpr.h:62
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ iiRunInit()

static void iiRunInit ( package  p)
static

Definition at line 900 of file iplib.cc.

901 {
902  idhdl h=p->idroot->get("mod_init",0);
903  if (h==NULL) return;
904  if (IDTYP(h)==PROC_CMD)
905  {
906  int save=yylineno;
907  myynest++;
908  // procinfo *pi=(procinfo*)IDDATA(h);
909  //PrintS("mod_init found\n");
910  iiMake_proc(h,p,NULL);
911  myynest--;
912  yylineno=save;
913  }
914 }
Definition: idrec.h:34
#define IDTYP(a)
Definition: ipid.h:114
VAR int yylineno
Definition: febase.cc:40
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
Definition: iplib.cc:486
STATIC_VAR Poly * h
Definition: janet.cc:971
#define NULL
Definition: omList.c:12
VAR int myynest
Definition: febase.cc:41
int p
Definition: cfModGcd.cc:4019

◆ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 460 of file iplib.cc.

461 {
462  int i;
463  for (i=0;i<=myynest;i++)
464  {
465  Print("lev %d:",i);
466  if (iiLocalRing[i]==NULL) PrintS("NULL");
467  else Print("%lx",(long)iiLocalRing[i]);
468  PrintLn();
469  }
470  if (currRing==NULL) PrintS("curr:NULL\n");
471  else Print ("curr:%lx\n",(long)currRing);
472 }
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:80
VAR ring * iiLocalRing
Definition: iplib.cc:455
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284
#define NULL
Definition: omList.c:12
VAR int myynest
Definition: febase.cc:41

◆ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv  v,
const char *  id 
)

Definition at line 765 of file iplib.cc.

766 {
767  BOOLEAN LoadResult = TRUE;
768  char libnamebuf[1024];
769  char *libname = (char *)omAlloc(strlen(id)+5);
770  const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
771  int i = 0;
772  // FILE *fp;
773  // package pack;
774  // idhdl packhdl;
775  lib_types LT;
776  for(i=0; suffix[i] != NULL; i++)
777  {
778  sprintf(libname, "%s%s", id, suffix[i]);
779  *libname = mytolower(*libname);
780  if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
781  {
782  char *s=omStrDup(libname);
783  #ifdef HAVE_DYNAMIC_LOADING
784  char libnamebuf[1024];
785  #endif
786 
787  if (LT==LT_SINGULAR)
788  LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE);
789  #ifdef HAVE_DYNAMIC_LOADING
790  else if ((LT==LT_ELF) || (LT==LT_HPUX))
791  LoadResult = load_modules(s,libnamebuf,FALSE);
792  #endif
793  else if (LT==LT_BUILTIN)
794  {
795  LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
796  }
797  if(!LoadResult )
798  {
799  v->name = iiConvName(libname);
800  break;
801  }
802  }
803  }
804  omFree(libname);
805  return LoadResult;
806 }
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1240
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:96
Definition: mod_raw.h:16
#define TRUE
Definition: auxiliary.h:100
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:22
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:827
const char * name
Definition: subexpr.h:87
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR char libnamebuf[1024]
Definition: libparse.cc:1098
int i
Definition: cfEzgcd.cc:125
lib_types
Definition: mod_raw.h:16
char mytolower(char c)
Definition: iplib.cc:1361
#define NULL
Definition: omList.c:12
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:752
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
int BOOLEAN
Definition: auxiliary.h:87
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1231
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ load_builtin()

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

Definition at line 1240 of file iplib.cc.

1241 {
1242  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1243  BOOLEAN(*func)(leftv res, leftv v));
1244 /*
1245  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1246  BOOLEAN pstatic,
1247  BOOLEAN(*func)(leftv res, leftv v)));
1248 */
1249  // SModulFunc_t fktn;
1250  idhdl pl;
1251  char *plib = iiConvName(newlib);
1252  // BOOLEAN RET=TRUE;
1253  // int token;
1254 
1255  pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1256  if ((pl!=NULL)
1257  &&(IDTYP(pl)==PACKAGE_CMD))
1258  {
1259  if(IDPACKAGE(pl)->language==LANG_C)
1260  {
1261  if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1262  omFree(plib);
1263  return FALSE;
1264  }
1265  }
1266  else
1267  {
1268  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1269  IDPACKAGE(pl)->libname=omStrDup(newlib);
1270  }
1271  IDPACKAGE(pl)->language = LANG_C;
1272 
1273  IDPACKAGE(pl)->handle=(void *)NULL;
1274  SModulFunctions sModulFunctions;
1275 
1276  package s=currPack;
1277  currPack=IDPACKAGE(pl);
1278  if( init!= NULL)
1279  {
1280  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1281  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1282  else sModulFunctions.iiAddCproc = iiAddCproc;
1283  (*init)(&sModulFunctions);
1284  }
1285  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1286  currPack->loaded=1;
1287  currPack=s;
1288 
1289  return FALSE;
1290 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1081
const CanonicalForm int s
Definition: facAbsFact.cc:55
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define Print
Definition: emacs.cc:80
#define FALSE
Definition: auxiliary.h:96
#define V_LOAD_LIB
Definition: options.h:46
#define IDROOT
Definition: ipid.h:18
#define TRUE
Definition: auxiliary.h:100
Definition: idrec.h:34
Definition: subexpr.h:22
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
CanonicalForm res
Definition: facAbsFact.cc:64
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR package currPack
Definition: ipid.cc:57
#define BVERBOSE(a)
Definition: options.h:34
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:69
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1006
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
int BOOLEAN
Definition: auxiliary.h:87
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: ipid.h:71
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: iparith.cc:9352

◆ load_modules()

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

Definition at line 1231 of file iplib.cc.

1231  {
1232  GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1233  pthread_mutex_lock(&mutex);
1234  BOOLEAN r = load_modules_aux(newlib, fullname, autoexport);
1235  pthread_mutex_unlock(&mutex);
1236  return r;
1237 }
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1124
#define GLOBAL_VAR
Definition: globaldefs.h:11
int BOOLEAN
Definition: auxiliary.h:87

◆ load_modules_aux()

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

Definition at line 1124 of file iplib.cc.

1125 {
1126 #ifdef HAVE_STATIC
1127  WerrorS("mod_init: static version can not load modules");
1128  return TRUE;
1129 #else
1130 /*
1131  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1132  BOOLEAN pstatic,
1133  BOOLEAN(*func)(leftv res, leftv v)));
1134 */
1135  SModulFunc_t fktn;
1136  idhdl pl;
1137  char *plib = iiConvName(newlib);
1138  BOOLEAN RET=TRUE;
1139  int token;
1140  char FullName[256];
1141 
1142  memset(FullName,0,256);
1143 
1144  if( *fullname != '/' && *fullname != '.' )
1145  sprintf(FullName, "./%s", newlib);
1146  else strncpy(FullName, fullname,255);
1147 
1148 
1149  if(IsCmd(plib, token))
1150  {
1151  Werror("'%s' is resered identifier\n", plib);
1152  goto load_modules_end;
1153  }
1154  pl = basePack->idroot->get(plib,0); /* packages only in top level
1155  (see enterid) */
1156  if ((pl!=NULL)
1157  &&(IDTYP(pl)==PACKAGE_CMD))
1158  {
1159  if(IDPACKAGE(pl)->language==LANG_C)
1160  {
1161  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1162  omFree(plib);
1163  return FALSE;
1164  }
1165  else if(IDPACKAGE(pl)->language==LANG_MIX)
1166  {
1167  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1168  omFree(plib);
1169  return FALSE;
1170  }
1171  }
1172  else
1173  {
1174  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1175  omFree(plib); /* enterid copied plib*/
1176  IDPACKAGE(pl)->libname=omStrDup(newlib);
1177  }
1178  IDPACKAGE(pl)->language = LANG_C;
1179  if (dynl_check_opened(FullName))
1180  {
1181  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1182  return FALSE;
1183  }
1184  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1185  {
1186  Werror("dynl_open failed:%s", dynl_error());
1187  Werror("%s not found", newlib);
1188  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1189  goto load_modules_end;
1190  }
1191  else
1192  {
1193  SModulFunctions sModulFunctions;
1194 
1195  package s=currPack;
1196  currPack=IDPACKAGE(pl);
1197  fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1198  if( fktn!= NULL)
1199  {
1200  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1201  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1202  else sModulFunctions.iiAddCproc = iiAddCproc;
1203  int ver=(*fktn)(&sModulFunctions);
1204  if (ver==MAX_TOK)
1205  {
1206  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1207  }
1208  else
1209  {
1210  Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1211  }
1212  currPack->loaded=1;
1213  currPack=s; /* reset currPack to previous */
1214  register_dyn_module(fullname, IDPACKAGE(pl)->handle);
1215  RET=FALSE;
1216  }
1217  else
1218  {
1219  Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1220  errorreported=0;
1221  if(IDPACKAGE(pl)->idroot==NULL)
1222  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1223  }
1224  }
1225 
1226  load_modules_end:
1227  return RET;
1228 #endif /*STATIC */
1229 }
VAR short errorreported
Definition: feFopen.cc:23
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1081
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:80
#define FALSE
Definition: auxiliary.h:96
#define V_LOAD_LIB
Definition: options.h:46
Definition: tok.h:217
#define IDROOT
Definition: ipid.h:18
#define TRUE
Definition: auxiliary.h:100
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:162
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
int dynl_check_opened(char *filename)
Definition: mod_raw.cc:138
Definition: subexpr.h:22
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition: ipid.cc:415
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR package currPack
Definition: ipid.cc:57
void register_dyn_module(char *fullname, void *handle)
Definition: iplib.cc:1107
#define BVERBOSE(a)
Definition: options.h:34
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:80
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:69
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1006
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
int BOOLEAN
Definition: auxiliary.h:87
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: ipid.h:71
void Werror(const char *fmt,...)
Definition: reporter.cc:189
const char * dynl_error()
Definition: mod_raw.cc:178
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:9007
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: iparith.cc:9352

◆ module_help_main()

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

Definition at line 1292 of file iplib.cc.

1293 {
1294  char *plib = iiConvName(newlib);
1295  idhdl pl = basePack->idroot->get(plib,0);
1296  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1297  Werror(">>%s<< is not a package (trying to add package help)",plib);
1298  else
1299  {
1300  package s=currPack;
1301  currPack=IDPACKAGE(pl);
1302  idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1303  IDSTRING(h)=omStrDup(help);
1304  currPack=s;
1305  }
1306 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:96
#define IDROOT
Definition: ipid.h:18
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
#define IDSTRING(a)
Definition: ipid.h:131
VAR package currPack
Definition: ipid.cc:57
#define help
Definition: libparse.cc:1230
STATIC_VAR Poly * h
Definition: janet.cc:971
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ module_help_proc()

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

Definition at line 1307 of file iplib.cc.

1308 {
1309  char *plib = iiConvName(newlib);
1310  idhdl pl = basePack->idroot->get(plib,0);
1311  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1312  Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1313  else
1314  {
1315  package s=currPack;
1316  currPack=IDPACKAGE(pl);
1317  char buff[256];
1318  buff[255]='\0';
1319  strncpy(buff,p,255);
1320  strncat(buff,"_help",255-strlen(p));
1321  idhdl h=enterid(buff,0,STRING_CMD,&IDROOT,FALSE);
1322  IDSTRING(h)=omStrDup(help);
1323  currPack=s;
1324  }
1325 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:96
#define IDROOT
Definition: ipid.h:18
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:134
#define IDTYP(a)
Definition: ipid.h:114
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
#define IDSTRING(a)
Definition: ipid.h:131
VAR package currPack
Definition: ipid.cc:57
#define help
Definition: libparse.cc:1230
STATIC_VAR Poly * h
Definition: janet.cc:971
VAR package basePack
Definition: ipid.cc:58
#define NULL
Definition: omList.c:12
int p
Definition: cfModGcd.cc:4019
char * iiConvName(const char *libname)
Definition: iplib.cc:1374
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ mytolower()

char mytolower ( char  c)

Definition at line 1361 of file iplib.cc.

1362 {
1363  if(c>=65 && c<=(65+26)) c+=32;
1364  return(c);
1365 }

◆ mytoupper()

char mytoupper ( char  c)

Definition at line 1355 of file iplib.cc.

1356 {
1357  if(c>=97 && c<=(97+26)) c-=32;
1358  return(c);
1359 }

◆ 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 1107 of file iplib.cc.

1107  {
1108  std::string fname = fullname;
1109  if (dyn_modules == NULL)
1110  dyn_modules = new std::map<std::string, void *>();
1111  dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1112 }
#define string
Definition: libparse.cc:1252
#define NULL
Definition: omList.c:12
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition: iplib.cc:1098

◆ registered_dyn_module()

bool registered_dyn_module ( char *  fullname)

Definition at line 1100 of file iplib.cc.

1100  {
1101  if (dyn_modules == NULL)
1102  return false;
1103  std::string fname = fullname;
1104  return dyn_modules->count(fname) != 0;
1105 }
#define string
Definition: libparse.cc:1252
#define NULL
Definition: omList.c:12
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition: iplib.cc:1098

◆ 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 1098 of file iplib.cc.

◆ iiLocalRing

VAR ring* iiLocalRing

Definition at line 455 of file iplib.cc.

◆ iiRETURNEXPR

INST_VAR sleftv iiRETURNEXPR

Definition at line 456 of file iplib.cc.

◆ iiRETURNEXPR_len

VAR int iiRETURNEXPR_len =0

Definition at line 457 of file iplib.cc.

◆ library_stack

VAR libstackv library_stack

Definition at line 64 of file iplib.cc.

◆ yylp_errlist

const char* yylp_errlist[]

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.