My Project
Loading...
Searching...
No Matches
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 SINGULAR_PATH_LENGTH   512
 
#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 ()
 
static 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)
 
static 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 39 of file iplib.cc.

◆ MODULE_SUFFIX_STRING

#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)

Definition at line 42 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 799 of file iplib.cc.

◆ SI_MAX_NEST

#define SI_MAX_NEST   500

Definition at line 27 of file iplib.cc.

◆ SINGULAR_PATH_LENGTH

#define SINGULAR_PATH_LENGTH   512

Definition at line 21 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:148
#define DIR_SEPP
Definition: feResource.h:7
#define MODULE_SUFFIX_STRING
Definition: iplib.cc:42
const char * dynl_error()
Definition: mod_raw.cc:175
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:159
void * dynl_open(char *filename)
Definition: mod_raw.cc:142
#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 1171 of file iplib.cc.

1171 {
1172 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1173 it != dyn_modules->end();
1174 it++)
1175 {
1176 dynl_close(it->second);
1177 }
1178 delete dyn_modules;
1179 dyn_modules = NULL;
1180}
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition: iplib.cc:1155
int dynl_close(void *handle)
Definition: mod_raw.cc:170

◆ 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 1281 of file misc_ip.cc.

1282{
1283 package save=currPack;
1286 if (n_FlintQ!=n_unknown)
1287 {
1288 iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1290 }
1291#if __FLINT_RELEASE >= 20503
1292 iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1294#endif
1296 if (n_FlintZn!=n_unknown)
1297 {
1298 iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1300 }
1301 currPack=save;
1302 return MAX_TOK;
1303}
#define FALSE
Definition: auxiliary.h:96
@ n_unknown
Definition: coeffs.h:28
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:486
coeffs flintZnInitCfByName(char *s, n_coeffType n)
Definition: flintcf_Zn.cc:432
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:1063
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition: misc_ip.cc:1236
STATIC_VAR n_coeffType n_FlintQ
Definition: misc_ip.cc:1220
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition: misc_ip.cc:1222
STATIC_VAR n_coeffType n_FlintZn
Definition: misc_ip.cc:1219
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition: numbers.cc:636
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:595
@ 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 701 of file iplib.cc.

702{
703 idhdl h=ggetid(n);
704 if ((h==NULL)
705 || (IDTYP(h)!=PROC_CMD))
706 {
707 err=2;
708 return NULL;
709 }
710 // ring handling
711 idhdl save_ringhdl=currRingHdl;
712 ring save_ring=currRing;
715 // argument:
716 if (arg_types[0]!=0)
717 {
718 sleftv tmp;
719 leftv tt=&tmp;
720 int i=1;
721 tmp.Init();
722 tmp.data=args[0];
723 tmp.rtyp=arg_types[0];
724 while(arg_types[i]!=0)
725 {
727 tt=tt->next;
728 tt->rtyp=arg_types[i];
729 tt->data=args[i];
730 i++;
731 }
732 // call proc
733 err=iiMake_proc(h,currPack,&tmp);
734 }
735 else
736 // call proc
738 // clean up ring
739 iiCallLibProcEnd(save_ringhdl,save_ring);
740 // return
741 if (err==FALSE)
742 {
744 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
746 return h;
747 }
748 return NULL;
749}
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:581
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:606
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition: iplib.cc:504
INST_VAR sleftv iiRETURNEXPR
Definition: iplib.cc:474
static void iiCallLibProcBegin()
Definition: iplib.cc:589
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:57

◆ ii_CallProcId2Id()

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

Definition at line 661 of file iplib.cc.

662{
663 char *plib = iiConvName(lib);
664 idhdl h=ggetid(plib);
665 omFreeBinAddr(plib);
666 if (h==NULL)
667 {
669 if (bo) return NULL;
670 }
671 ring oldR=currRing;
673 BOOLEAN err;
674 ideal I=(ideal)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
675 rChangeCurrRing(oldR);
676 if (err) return NULL;
677 return I;
678}
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
char * iiConvName(const char *libname)
Definition: iplib.cc:1429
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:884
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition: iplib.cc:627
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258

◆ ii_CallProcId2Int()

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

Definition at line 680 of file iplib.cc.

681{
682 char *plib = iiConvName(lib);
683 idhdl h=ggetid(plib);
684 omFreeBinAddr(plib);
685 if (h==NULL)
686 {
688 if (bo) return 0;
689 }
690 BOOLEAN err;
691 ring oldR=currRing;
693 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
694 rChangeCurrRing(oldR);
695 if (err) return 0;
696 return I;
697}

◆ iiAddCproc()

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

Definition at line 1063 of file iplib.cc.

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

1140{
1141 int r=iiAddCproc(libname,procname,pstatic,func);
1142 package s=currPack;
1144 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1145 currPack=s;
1146 return r;
1147}
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ iiAllStart()

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

Definition at line 298 of file iplib.cc.

299{
300 int save_trace=traceit;
301 int restore_traceit=0;
302 if (traceit_stop
304 {
305 traceit &=(~TRACE_SHOW_LINE);
306 traceit_stop=0;
307 restore_traceit=1;
308 }
309 // see below:
310 BITSET save1=si_opt_1;
311 BITSET save2=si_opt_2;
312 newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
313 pi, l );
314 BOOLEAN err=yyparse();
315
316 if (sLastPrinted.rtyp!=0)
317 {
319 }
320
321 if (restore_traceit) traceit=save_trace;
322
323 // the access to optionStruct and verboseStruct do not work
324 // on x86_64-Linux for pic-code
325 if ((TEST_V_ALLWARN) &&
326 (t==BT_proc) &&
327 ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
328 (pi->libname!=NULL) && (pi->libname[0]!='\0'))
329 {
330 if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
331 Warn("option changed in proc %s from %s",pi->procname,pi->libname);
332 else
333 Warn("option changed in proc %s",pi->procname);
334 int i;
335 for (i=0; optionStruct[i].setval!=0; i++)
336 {
337 if ((optionStruct[i].setval & si_opt_1)
338 && (!(optionStruct[i].setval & save1)))
339 {
340 Print(" +%s",optionStruct[i].name);
341 }
342 if (!(optionStruct[i].setval & si_opt_1)
343 && ((optionStruct[i].setval & save1)))
344 {
345 Print(" -%s",optionStruct[i].name);
346 }
347 }
348 for (i=0; verboseStruct[i].setval!=0; i++)
349 {
350 if ((verboseStruct[i].setval & si_opt_2)
351 && (!(verboseStruct[i].setval & save2)))
352 {
353 Print(" +%s",verboseStruct[i].name);
354 }
355 if (!(verboseStruct[i].setval & si_opt_2)
356 && ((verboseStruct[i].setval & save2)))
357 {
358 Print(" -%s",verboseStruct[i].name);
359 }
360 }
361 PrintLn();
362 }
363 return err;
364}
int l
Definition: cfEzgcd.cc:100
int p
Definition: cfModGcd.cc:4078
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
#define Print
Definition: emacs.cc:80
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:166
@ BT_proc
Definition: fevoices.h:20
int yyparse(void)
Definition: grammar.cc:2111
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:538
unsigned setval
Definition: ipid.h:153
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:507
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:144
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:16
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46
int name
New type name for int.
Definition: templateForC.h:21

◆ iiArithAddCmd()

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

Definition at line 9868 of file iparith.cc.

9875{
9876 //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9877 // nTokval, nToktype, nPos);
9878 if(nPos>=0)
9879 {
9880 // no checks: we rely on a correct generated code in iparith.inc
9881 assume((unsigned)nPos < sArithBase.nCmdAllocated);
9882 assume(szName!=NULL);
9883 sArithBase.sCmds[nPos].name = omStrDup(szName);
9884 sArithBase.sCmds[nPos].alias = nAlias;
9885 sArithBase.sCmds[nPos].tokval = nTokval;
9886 sArithBase.sCmds[nPos].toktype = nToktype;
9888 //if(nTokval>0) sArithBase.nLastIdentifier++;
9889 }
9890 else
9891 {
9892 if(szName==NULL) return -1;
9893 int nIndex = iiArithFindCmd(szName);
9894 if(nIndex>=0)
9895 {
9896 Print("'%s' already exists at %d\n", szName, nIndex);
9897 return -1;
9898 }
9899
9901 {
9902 /* needs to create new slots */
9903 unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9905 if(sArithBase.sCmds==NULL) return -1;
9907 }
9908 /* still free slots available */
9910 sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9911 sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9912 sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9914
9915 qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9919 {
9920 if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9921 }
9922 //Print("L=%d\n", sArithBase.nLastIdentifier);
9923 }
9924 return 0;
9925}
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:9701
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:9773
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:186
unsigned nLastIdentifier
valid identifiers are slot 1..nLastIdentifier
Definition: iparith.cc:193
STATIC_VAR SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:201
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:192
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:191
#define assume(x)
Definition: mod2.h:389
#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 627 of file iplib.cc.

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

◆ iiCallLibProcBegin()

static void iiCallLibProcBegin ( )
static

Definition at line 589 of file iplib.cc.

590{
591 idhdl tmp_ring=NULL;
592 if (currRing!=NULL)
593 {
595 {
596 // clean up things depending on currRingHdl:
599 }
600 // need to define a ring-hdl for currRingHdl
601 tmp_ring=enterid(" tmpRing",myynest,RING_CMD,&IDROOT,FALSE);
602 IDRING(tmp_ring)=rIncRefCnt(currRing);
603 rSetHdl(tmp_ring);
604 }
605}
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:5126
static ring rIncRefCnt(ring r)
Definition: ring.h:837

◆ iiCallLibProcEnd()

static void iiCallLibProcEnd ( idhdl  save_ringhdl,
ring  save_ring 
)
static

Definition at line 606 of file iplib.cc.

607{
608 if ((currRing!=NULL)
609 &&(currRing!=save_ring))
610 {
612 idhdl hh=IDROOT;
613 idhdl prev=NULL;
614 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
615 if (hh!=NULL)
616 {
617 if (prev==NULL) IDROOT=hh->next;
618 else prev->next=hh->next;
619 omFree((ADDRESS)IDID(hh));
621 }
622 }
623 currRingHdl=save_ringhdl;
624 currRing=save_ring;
625}
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 omFree(addr)
Definition: omAllocDecl.h:261
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static void rDecRefCnt(ring r)
Definition: ring.h:838

◆ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 493 of file iplib.cc.

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

◆ iiCleanProcs()

static void iiCleanProcs ( idhdl root)
static

Definition at line 928 of file iplib.cc.

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

◆ 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
static char mytoupper(char c)
Definition: iplib.cc:1410

◆ iiEStart()

BOOLEAN iiEStart ( char *  example,
procinfo pi 
)

Definition at line 754 of file iplib.cc.

755{
756 BOOLEAN err;
757 int old_echo=si_echo;
758
759 iiCheckNest();
760 procstack->push(example);
763 {
764 if (traceit&TRACE_SHOW_LINENO) printf("\n");
765 printf("entering example (level %d)\n",myynest);
766 }
767 myynest++;
768
769 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
770
772 myynest--;
773 si_echo=old_echo;
775 {
776 if (traceit&TRACE_SHOW_LINENO) printf("\n");
777 printf("leaving -example- (level %d)\n",myynest);
778 }
780 {
782 {
785 }
786 else
787 {
790 }
791 }
792 procstack->pop();
793 return err;
794}
void pop()
Definition: ipid.cc:813
void push(char *)
Definition: ipid.cc:803
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:493
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition: iplib.cc:298
void killlocals(int v)
Definition: ipshell.cc:386
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1701
#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 807 of file iplib.cc.

808{
809#ifdef HAVE_FLINT
810 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
811#endif
812# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
814# undef SI_GET_BUILTIN_MOD_INIT
815
816 return NULL;
817}
#define SI_GET_BUILTIN_MOD_INIT(name)
#define SI_MOD_INIT0(name)
Definition: mod_lib.h:4
#define SI_FOREACH_BUILTIN(add)
Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro.
Definition: mod_lib.h:17

◆ iiGetLibProcBuffer()

char * iiGetLibProcBuffer ( procinfo pi,
int  part 
)

Definition at line 197 of file iplib.cc.

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

78{
79 idhdl hl;
80
81 char *plib = iiConvName(lib);
82 hl = basePack->idroot->get(plib,0);
83 omFreeBinAddr(plib);
84 if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD))
85 {
86 return FALSE;
87 }
88 if ((IDPACKAGE(hl)->language!=LANG_C)&&(IDPACKAGE(hl)->libname!=NULL))
89 return (strcmp(lib,IDPACKAGE(hl)->libname)==0);
90 return FALSE;
91}
#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 1049 of file iplib.cc.

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

◆ iiLibCmd()

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

Definition at line 884 of file iplib.cc.

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

975{
976 EXTERN_VAR FILE *yylpin;
977 libstackv ls_start = library_stack;
978 lib_style_types lib_style;
979
980 yylpin = fp;
981 #if YYLPDEBUG > 1
982 print_init();
983 #endif
986 else lpverbose=0;
987 // yylplex sets also text_buffer
988 if (text_buffer!=NULL) *text_buffer='\0';
989 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
990 if(yylp_errno)
991 {
992 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
993 current_pos(0));
995 {
999 }
1000 else
1002 WerrorS("Cannot load library,... aborting.");
1003 reinit_yylp();
1004 fclose( yylpin );
1006 return TRUE;
1007 }
1008 if (BVERBOSE(V_LOAD_LIB))
1009 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1010 if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
1011 {
1012 Warn( "library %s has old format. This format is still accepted,", newlib);
1013 WarnS( "but for functionality you may wish to change to the new");
1014 WarnS( "format. Please refer to the manual for further information.");
1015 }
1016 reinit_yylp();
1017 fclose( yylpin );
1018 fp = NULL;
1019 iiRunInit(IDPACKAGE(pl));
1020
1021 {
1022 libstackv ls;
1023 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1024 {
1025 if(ls->to_be_done)
1026 {
1027 ls->to_be_done=FALSE;
1028 iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
1029 ls = ls->pop(newlib);
1030 }
1031 }
1032#if 0
1033 PrintS("--------------------\n");
1034 for(ls = library_stack; ls != NULL; ls = ls->next)
1035 {
1036 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1037 ls->to_be_done ? "not loaded" : "loaded");
1038 }
1039 PrintS("--------------------\n");
1040#endif
1041 }
1042
1043 if(fp != NULL) fclose(fp);
1044 return FALSE;
1045}
char * get()
Definition: subexpr.h:170
libstackv next
Definition: subexpr.h:164
libstackv pop(const char *p)
Definition: iplib.cc:1520
int cnt
Definition: subexpr.h:167
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:928
VAR libstackv library_stack
Definition: iplib.cc:68
const char * yylp_errlist[]
Definition: libparse.cc:1114
EXTERN_VAR int yylplineno
Definition: iplib.cc:65
static void iiRunInit(package p)
Definition: iplib.cc:957
EXTERN_VAR int yylp_errno
Definition: iplib.cc:64
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:48
#define V_LOAD_LIB
Definition: options.h:47
void PrintS(const char *s)
Definition: reporter.cc:284

◆ iiLocateLib()

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

Definition at line 870 of file iplib.cc.

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

◆ iiMake_proc()

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

Definition at line 504 of file iplib.cc.

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

◆ iiProcArgs()

char * iiProcArgs ( char *  e,
BOOLEAN  withParenth 
)

Definition at line 114 of file iplib.cc.

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

◆ iiProcName()

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

Definition at line 100 of file iplib.cc.

101{
102 char *s=buf+5;
103 while (*s==' ') s++;
104 e=s+1;
105 while ((*e>' ') && (*e!='(')) e++;
106 ct=*e;
107 *e='\0';
108 return s;
109}

◆ iiPStart()

BOOLEAN iiPStart ( idhdl  pn,
leftv  v 
)

Definition at line 371 of file iplib.cc.

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

◆ iiRunInit()

static void iiRunInit ( package  p)
static

Definition at line 957 of file iplib.cc.

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

◆ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 478 of file iplib.cc.

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

◆ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv  v,
const char *  id 
)

Definition at line 823 of file iplib.cc.

824{
825 BOOLEAN LoadResult = TRUE;
826 char libnamebuf[1024];
827 char *libname = (char *)omAlloc(strlen(id)+5);
828 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
829 int i = 0;
830 // FILE *fp;
831 // package pack;
832 // idhdl packhdl;
833 lib_types LT;
834 for(i=0; suffix[i] != NULL; i++)
835 {
836 sprintf(libname, "%s%s", id, suffix[i]);
837 *libname = mytolower(*libname);
838 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
839 {
840 #ifdef HAVE_DYNAMIC_LOADING
841 char libnamebuf[1024];
842 #endif
843
844 if (LT==LT_SINGULAR)
845 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
846 #ifdef HAVE_DYNAMIC_LOADING
847 else if ((LT==LT_ELF) || (LT==LT_HPUX))
848 LoadResult = load_modules(libname,libnamebuf,FALSE);
849 #endif
850 else if (LT==LT_BUILTIN)
851 {
852 LoadResult=load_builtin(libname,FALSE, iiGetBuiltinModInit(libname));
853 }
854 if(!LoadResult )
855 {
856 v->name = iiConvName(libname);
857 break;
858 }
859 }
860 }
861 omFree(libname);
862 return LoadResult;
863}
char name() const
Definition: variable.cc:122
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:1284
static 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:807
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 omFreeBinAddr(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 omFreeBinAddr(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 iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition: iparith.cc:9868
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1138
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:1181

◆ load_modules_aux()

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

Definition at line 1181 of file iplib.cc.

1182{
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 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1194 char *FullName=(char*)omAlloc0(l);
1195
1196 if( *fullname != '/' && *fullname != '.' )
1197 sprintf(FullName, "./%s", newlib);
1198 else strncpy(FullName, fullname,l);
1199
1200
1201 if(IsCmd(plib, token))
1202 {
1203 Werror("'%s' is resered identifier\n", plib);
1204 goto load_modules_end;
1205 }
1206 pl = basePack->idroot->get(plib,0); /* packages only in top level
1207 (see enterid) */
1208 if ((pl!=NULL)
1209 &&(IDTYP(pl)==PACKAGE_CMD))
1210 {
1211 if(IDPACKAGE(pl)->language==LANG_C)
1212 {
1213 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1214 omFreeBinAddr(plib);
1215 return FALSE;
1216 }
1217 else if(IDPACKAGE(pl)->language==LANG_MIX)
1218 {
1219 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1220 omFreeBinAddr(plib);
1221 return FALSE;
1222 }
1223 }
1224 else
1225 {
1226 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1227 omFreeBinAddr(plib); /* enterid copied plib*/
1228 IDPACKAGE(pl)->libname=omStrDup(newlib);
1229 }
1230 IDPACKAGE(pl)->language = LANG_C;
1231 if (dynl_check_opened(FullName))
1232 {
1233 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1234 omFreeSize(FullName,l);
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 omFreeSize(FullName,l);
1281 return RET;
1282}
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
VAR short errorreported
Definition: feFopen.cc:23
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition: ipid.cc:445
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:81
void register_dyn_module(char *fullname, void *handle)
Definition: iplib.cc:1164
int dynl_check_opened(char *filename)
Definition: mod_raw.cc:135
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ 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);
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[SINGULAR_PATH_LENGTH];
1373 buff[SINGULAR_PATH_LENGTH-1]='\0';
1374 strncpy(buff,p,SINGULAR_PATH_LENGTH-1);
1375 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1378 currPack=s;
1379 }
1380}

◆ mytolower()

static char mytolower ( char  c)
static

Definition at line 1416 of file iplib.cc.

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

◆ mytoupper()

static char mytoupper ( char  c)
static

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

1164 {
1165 std::string fname = fullname;
1166 if (dyn_modules == NULL)
1167 dyn_modules = new std::map<std::string, void *>();
1168 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1169}

◆ registered_dyn_module()

bool registered_dyn_module ( char *  fullname)

Definition at line 1157 of file iplib.cc.

1157 {
1158 if (dyn_modules == NULL)
1159 return false;
1160 std::string fname = fullname;
1161 return dyn_modules->count(fname) != 0;
1162}

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

◆ iiLocalRing

VAR ring* iiLocalRing

Definition at line 473 of file iplib.cc.

◆ iiRETURNEXPR

INST_VAR sleftv iiRETURNEXPR

Definition at line 474 of file iplib.cc.

◆ iiRETURNEXPR_len

VAR int iiRETURNEXPR_len =0

Definition at line 475 of file iplib.cc.

◆ library_stack

VAR libstackv library_stack

Definition at line 68 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 64 of file iplib.cc.

◆ yylplineno

EXTERN_VAR int yylplineno

Definition at line 65 of file iplib.cc.