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)
 
chariiProcName (char *buf, char &ct, char *&e)
 
chariiProcArgs (char *e, BOOLEAN withParenth)
 
chariiGetLibProcBuffer (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)
 
voidiiCallLibProc1 (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
 
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)
 
voidbinary_module_function (const char *newlib, const char *funcname)
 
static char mytoupper (char c)
 
chariiConvName (const char *libname)
 

Variables

EXTERN_VAR int yylp_errno
 
EXTERN_VAR int yylplineno
 
const charyylp_errlist []
 
VAR libstackv library_stack
 
VAR ringiiLocalRing
 
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 807 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 1395 of file iplib.cc.

1396{
1397 void* result = NULL;
1398
1399 const char* bin_dir = feGetResource('b');
1400 if (!bin_dir) { return NULL; }
1401
1402 char path_name[MAXPATHLEN];
1404
1405 void* openlib = dynl_open(path_name);
1406 if(!openlib)
1407 {
1408 Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1409 return NULL;
1410 }
1412 if (!result) Werror("%s: %s\n", funcname, dynl_error());
1413
1414 return result;
1415}
return result
char * feGetResource(const char id, int warn)
#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 1180 of file iplib.cc.

1180 {
1181 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1182 it != dyn_modules->end();
1183 it++)
1184 {
1185 dynl_close(it->second);
1186 }
1187 delete dyn_modules;
1188 dyn_modules = NULL;
1189}
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition iplib.cc:1164
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 1284 of file misc_ip.cc.

1285{
1286 package save=currPack;
1289 if (n_FlintQ!=n_unknown)
1290 {
1291 iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1293 }
1294#if __FLINT_RELEASE >= 20503
1295 iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1297#endif
1299 if (n_FlintZn!=n_unknown)
1300 {
1301 iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1303 }
1304 currPack=save;
1305 return MAX_TOK;
1306}
#define FALSE
Definition auxiliary.h:96
@ n_unknown
Definition coeffs.h:28
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition flintcf_Q.cc:635
coeffs flintQInitCfByName(char *s, n_coeffType n)
Definition flintcf_Q.cc:607
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
coeffs flintZnInitCfByName(char *s, n_coeffType n)
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:1072
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition misc_ip.cc:1239
STATIC_VAR n_coeffType n_FlintQ
Definition misc_ip.cc:1223
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition misc_ip.cc:1225
STATIC_VAR n_coeffType n_FlintZn
Definition misc_ip.cc:1222
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition numbers.cc:642
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition numbers.cc:601
@ MAX_TOK
Definition tok.h:220

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

710{
711 idhdl h=ggetid(n);
712 if ((h==NULL)
713 || (IDTYP(h)!=PROC_CMD))
714 {
715 err=2;
716 return NULL;
717 }
718 // ring handling
723 // argument:
724 if (arg_types[0]!=0)
725 {
726 sleftv tmp;
727 leftv tt=&tmp;
728 int i=1;
729 tmp.Init();
730 tmp.data=args[0];
731 tmp.rtyp=arg_types[0];
732 while(arg_types[i]!=0)
733 {
735 tt=tt->next;
736 tt->rtyp=arg_types[i];
737 tt->data=args[i];
738 i++;
739 }
740 // call proc
742 }
743 else
744 // call proc
746 // clean up ring
748 // return
749 if (err==FALSE)
750 {
752 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
754 return h;
755 }
756 return NULL;
757}
Definition idrec.h:35
Class used for (list of) interpreter objects.
Definition subexpr.h:83
void Init()
Definition subexpr.h:107
@ PROC_CMD
Definition grammar.cc:281
idhdl ggetid(const char *n)
Definition ipid.cc:583
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:614
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:512
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:482
static void iiCallLibProcBegin()
Definition iplib.cc:597
STATIC_VAR Poly * h
Definition janet.cc:971
#define omAllocBin(bin)
#define omAlloc0Bin(bin)
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 669 of file iplib.cc.

670{
671 char *plib = iiConvName(lib);
674 if (h==NULL)
675 {
677 if (bo) return NULL;
678 }
681 BOOLEAN err;
684 if (err) return NULL;
685 return I;
686}
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:285
ideal idCopy(ideal A)
Definition ideals.h:60
char * iiConvName(const char *libname)
Definition iplib.cc:1438
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:893
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition iplib.cc:635
#define omFreeBinAddr(addr)

◆ ii_CallProcId2Int()

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

Definition at line 688 of file iplib.cc.

689{
690 char *plib = iiConvName(lib);
693 if (h==NULL)
694 {
696 if (bo) return 0;
697 }
698 BOOLEAN err;
701 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
703 if (err) return 0;
704 return I;
705}

◆ iiAddCproc()

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

Definition at line 1072 of file iplib.cc.

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

1149{
1150 int r=iiAddCproc(libname,procname,pstatic,func);
1151 package s=currPack;
1153 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1154 currPack=s;
1155 return r;
1156}
const CanonicalForm int s
Definition facAbsFact.cc:51

◆ iiAllStart()

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

Definition at line 306 of file iplib.cc.

307{
309 int restore_traceit=0;
310 if (traceit_stop
312 {
313 traceit &=(~TRACE_SHOW_LINE);
314 traceit_stop=0;
316 }
317 // see below:
320 newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
321 pi, l );
322 BOOLEAN err=yyparse();
323
324 if (sLastPrinted.rtyp!=0)
325 {
327 }
328
330
331 // the access to optionStruct and verboseStruct do not work
332 // on x86_64-Linux for pic-code
333 if ((TEST_V_ALLWARN) &&
334 (t==BT_proc) &&
335 ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
336 (pi->libname!=NULL) && (pi->libname[0]!='\0'))
337 {
338 if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
339 Warn("option changed in proc %s from %s",pi->procname,pi->libname);
340 else
341 Warn("option changed in proc %s",pi->procname);
342 int i;
343 for (i=0; optionStruct[i].setval!=0; i++)
344 {
345 if ((optionStruct[i].setval & si_opt_1)
346 && (!(optionStruct[i].setval & save1)))
347 {
348 Print(" +%s",optionStruct[i].name);
349 }
350 if (!(optionStruct[i].setval & si_opt_1)
351 && ((optionStruct[i].setval & save1)))
352 {
353 Print(" -%s",optionStruct[i].name);
354 }
355 }
356 for (i=0; verboseStruct[i].setval!=0; i++)
357 {
358 if ((verboseStruct[i].setval & si_opt_2)
359 && (!(verboseStruct[i].setval & save2)))
360 {
361 Print(" +%s",verboseStruct[i].name);
362 }
363 if (!(verboseStruct[i].setval & si_opt_2)
364 && ((verboseStruct[i].setval & save2)))
365 {
366 Print(" -%s",verboseStruct[i].name);
367 }
368 }
369 PrintLn();
370 }
371 return err;
372}
int l
Definition cfEzgcd.cc:100
int p
Definition cfModGcd.cc:4086
int rtyp
Definition subexpr.h:91
void CleanUp(ring r=currRing)
Definition subexpr.cc:351
#define Print
Definition emacs.cc:80
char name(const Variable &v)
Definition factory.h:189
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:2149
const struct soptionStruct verboseStruct[]
Definition misc_ip.cc:538
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:142
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

◆ iiArithAddCmd()

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

Definition at line 10126 of file iparith.cc.

10133{
10134 //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
10135 // nTokval, nToktype, nPos);
10136 if(nPos>=0)
10137 {
10138 // no checks: we rely on a correct generated code in iparith.inc
10139 assume((unsigned)nPos < sArithBase.nCmdAllocated);
10140 assume(szName!=NULL);
10142 sArithBase.sCmds[nPos].alias = nAlias;
10143 sArithBase.sCmds[nPos].tokval = nTokval;
10144 sArithBase.sCmds[nPos].toktype = nToktype;
10146 //if(nTokval>0) sArithBase.nLastIdentifier++;
10147 }
10148 else
10149 {
10150 if(szName==NULL) return -1;
10152 if(nIndex>=0)
10153 {
10154 Print("'%s' already exists at %d\n", szName, nIndex);
10155 return -1;
10156 }
10157
10159 {
10160 /* needs to create new slots */
10161 unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
10163 if(sArithBase.sCmds==NULL) return -1;
10165 }
10166 /* still free slots available */
10172
10177 {
10178 if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
10179 }
10180 //Print("L=%d\n", sArithBase.nLastIdentifier);
10181 }
10182 return 0;
10183}
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition iparith.cc:9959
int iiArithFindCmd(const char *szName)
Definition iparith.cc:10031
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:387
#define nSize(n)
Definition numbers.h:39
#define omRealloc(addr, size)

◆ iiCallLibProc1()

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

Definition at line 635 of file iplib.cc.

636{
637 idhdl h=ggetid(n);
638 if ((h==NULL)
639 || (IDTYP(h)!=PROC_CMD))
640 {
641 err=2;
642 return NULL;
643 }
644 // ring handling
648 // argument:
649 sleftv tmp;
650 tmp.Init();
651 tmp.data=arg;
652 tmp.rtyp=arg_type;
653 // call proc
655 // clean up ring
657 // return
658 if (err==FALSE)
659 {
660 void*r=iiRETURNEXPR.data;
663 return r;
664 }
665 return NULL;
666}
void * data
Definition subexpr.h:88

◆ iiCallLibProcBegin()

static void iiCallLibProcBegin ( )
static

Definition at line 597 of file iplib.cc.

598{
600 if (currRing!=NULL)
601 {
603 {
604 // clean up things depending on currRingHdl:
607 }
608 // need to define a ring-hdl for currRingHdl
612 }
613}
VAR int myynest
Definition febase.cc:41
@ RING_CMD
Definition grammar.cc:282
#define IDRING(a)
Definition ipid.h:127
void rSetHdl(idhdl h)
Definition ipshell.cc:5135
static ring rIncRefCnt(ring r)
Definition ring.h:846

◆ iiCallLibProcEnd()

static void iiCallLibProcEnd ( idhdl  save_ringhdl,
ring  save_ring 
)
static

Definition at line 614 of file iplib.cc.

615{
616 if ((currRing!=NULL)
617 &&(currRing!=save_ring))
618 {
621 idhdl prev=NULL;
622 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
623 if (hh!=NULL)
624 {
625 if (prev==NULL) IDROOT=hh->next;
626 else prev->next=hh->next;
629 }
630 }
633}
idhdl next
Definition idrec.h:38
VAR omBin idrec_bin
Definition ipid.cc:48
#define IDID(a)
Definition ipid.h:122
#define omFree(addr)
#define omFreeBin(addr, bin)
static void rDecRefCnt(ring r)
Definition ring.h:847

◆ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 501 of file iplib.cc.

502{
503 if (myynest >= iiRETURNEXPR_len-1)
504 {
506 iiRETURNEXPR_len*sizeof(ring),
507 (iiRETURNEXPR_len+16)*sizeof(ring));
508 memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
510 }
511}
VAR int iiRETURNEXPR_len
Definition iplib.cc:483
VAR ring * iiLocalRing
Definition iplib.cc:481
#define omreallocSize(addr, o_size, size)

◆ iiCleanProcs()

static void iiCleanProcs ( idhdl root)
static

Definition at line 937 of file iplib.cc.

938{
939 idhdl prev=NULL;
940 loop
941 {
942 if (root==NULL) return;
943 if (IDTYP(root)==PROC_CMD)
944 {
945 procinfo *pi=(procinfo*)IDDATA(root);
946 if ((pi->language == LANG_SINGULAR)
947 && (pi->data.s.body_start == 0L))
948 {
949 // procinfo data incorrect:
950 // - no proc body can start at the beginning of the file
951 killhdl(root);
952 if (prev==NULL)
953 root=IDROOT;
954 else
955 {
956 root=prev;
957 prev=NULL;
958 }
959 continue;
960 }
961 }
962 prev=root;
963 root=IDNEXT(root);
964 }
965}
void killhdl(idhdl h, package proot)
Definition ipid.cc:416
#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 1438 of file iplib.cc.

1439{
1440 char *tmpname = omStrDup(libname);
1441 char *p = strrchr(tmpname, DIR_SEP);
1442 char *r;
1443 if(p==NULL) p = tmpname; else p++;
1444 // p is now the start of the file name (without path)
1445 r=p;
1446 while(isalnum(*r)||(*r=='_')) r++;
1447 // r point the the end of the main part of the filename
1448 *r = '\0';
1449 r = omStrDup(p);
1450 *r = mytoupper(*r);
1451 // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1453
1454 return(r);
1455}
#define DIR_SEP
Definition feResource.h:6
static char mytoupper(char c)
Definition iplib.cc:1419

◆ iiEStart()

BOOLEAN iiEStart ( char example,
procinfo pi 
)

Definition at line 762 of file iplib.cc.

763{
764 BOOLEAN err;
765 int old_echo=si_echo;
766
767 iiCheckNest();
768 procstack->push(example);
771 {
773 printf("entering example (level %d)\n",myynest);
774 }
775 myynest++;
776
777 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
778
780 myynest--;
783 {
785 printf("leaving -example- (level %d)\n",myynest);
786 }
788 {
790 {
793 }
794 else
795 {
798 }
799 }
800 procstack->pop();
801 return err;
802}
void pop()
Definition ipid.cc:815
void push(char *)
Definition ipid.cc:805
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:501
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition iplib.cc:306
void killlocals(int v)
Definition ipshell.cc:386
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1702
#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 815 of file iplib.cc.

816{
817#ifdef HAVE_FLINT
818 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
819#endif
820# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
822# undef SI_GET_BUILTIN_MOD_INIT
823
824 return NULL;
825}
#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 int res=fseek(fp, pi->data.s.proc_start, SEEK_SET);
209 if (res==1) return NULL;
210 if(part==0)
211 { // load help string
212 int i, offset=0;
213 long head = pi->data.s.def_end - pi->data.s.proc_start;
214 procbuflen = pi->data.s.help_end - pi->data.s.help_start;
215 if (procbuflen<5)
216 {
217 fclose(fp);
218 return NULL; // help part does not exist
219 }
220 //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
221 // pi->data.s.proc_start, procbuflen);
222 s = (char *)omAlloc(procbuflen+head+3);
223 res=myfread(s, head, 1, fp);
224 if (res<=0) /* error*/ { omFree(s); return NULL; }
225 s[head] = '\n';
226 int res=fseek(fp, pi->data.s.help_start, SEEK_SET);
227 if (res==-1) /*error*/ { omFree(s); return NULL; }
228 res=myfread(s+head+1, procbuflen, 1, fp);
229 if (res<=0) /* error*/ { omFree(s); return NULL; }
230 fclose(fp);
231 s[procbuflen+head+1] = '\n';
232 s[procbuflen+head+2] = '\0';
233 offset=0;
234 for(i=0;i<=procbuflen+head+2; i++)
235 {
236 if(s[i]=='\\' &&
237 (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
238 {
239 i++;
240 offset++;
241 }
242 if(offset>0) s[i-offset] = s[i];
243 }
244 return(s);
245 }
246 else if(part==1)
247 { // load proc part - must exist
248 procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
249 char *ss=(char *)omAlloc(procbuflen+2);
250 //fgets(buf, sizeof(buf), fp);
251 myfread( ss, procbuflen, 1, fp);
252 char ct;
253 char *e;
254 s=iiProcName(ss,ct,e);
255 char *argstr=NULL;
256 *e=ct;
258
259 assume(pi->data.s.body_end > pi->data.s.body_start);
260
261 procbuflen = pi->data.s.body_end - pi->data.s.body_start;
262 pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
263 strlen(pi->libname) );
264 //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
265 // pi->data.s.body_start, procbuflen);
266 assume(pi->data.s.body != NULL);
267 fseek(fp, pi->data.s.body_start, SEEK_SET);
268 strcpy(pi->data.s.body,argstr);
269 myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
270 fclose( fp );
272 omFree(argstr);
273 omFree(ss);
274 pi->data.s.body[procbuflen] = '\0';
275 strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
276 strcat( pi->data.s.body+procbuflen+13,pi->libname);
277 s=(char *)strchr(pi->data.s.body,'{');
278 if (s!=NULL) *s=' ';
279 return NULL;
280 }
281 else if(part==2)
282 { // example
283 if ( pi->data.s.example_lineno == 0)
284 return NULL; // example part does not exist
285 // load example
286 fseek(fp, pi->data.s.example_start, SEEK_SET);
287 char* res=fgets(buf, sizeof(buf), fp); // skip line with "example"
288 if (res==NULL) /*error or eof*/
289 {
290 return omStrDup("");
291 }
292 procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
293 //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
294 // pi->data.s.example_start, procbuflen);
295 s = (char *)omAlloc(procbuflen+14);
296 myfread(s, procbuflen, 1, fp);
297 s[procbuflen] = '\0';
298 strcat(s+procbuflen-3, "\n;return();\n\n" );
299 p=(char *)strchr(s,'{');
300 if (p!=NULL) *p=' ';
301 return(s);
302 }
303 return NULL;
304}
CanonicalForm head(const CanonicalForm &f)
CanonicalForm fp
Definition cfModGcd.cc:4110
CanonicalForm res
Definition facAbsFact.cc:60
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:113
#define omAlloc(size)
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);
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:150

◆ iiInitSingularProcinfo()

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

Definition at line 1058 of file iplib.cc.

1060{
1061 memset(pi,0,sizeof(*pi));
1062 pi->libname = omStrDup(libname);
1063 pi->procname = omStrDup(procname);
1064 pi->language = LANG_SINGULAR;
1065 pi->ref = 1;
1066 pi->is_static = pstatic;
1067 pi->data.s.proc_start = pos;
1068 return(pi);
1069}

◆ iiLibCmd()

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

Definition at line 893 of file iplib.cc.

894{
895 if (strcmp(newlib,"Singular")==0) return FALSE;
896 char libnamebuf[1024];
897 idhdl pl;
898 char *plib = iiConvName(newlib);
900 // int lines = 1;
902
903 if (fp==NULL)
904 {
905 return TRUE;
906 }
907 pl = basePack->idroot->get(plib,0);
908 if (pl==NULL)
909 {
910 pl = enterid( plib,0, PACKAGE_CMD,
911 &(basePack->idroot), TRUE );
912 IDPACKAGE(pl)->language = LANG_SINGULAR;
913 IDPACKAGE(pl)->libname=omStrDup(newlib);
914 }
915 else
916 {
917 if(IDTYP(pl)!=PACKAGE_CMD)
918 {
920 WarnS("not of type package.");
921 fclose(fp);
922 return TRUE;
923 }
924 if (!force)
925 {
927 return FALSE;
928 }
929 }
931
932 if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
934 return LoadResult;
935}
idhdl get(const char *s, int lev)
Definition ipid.cc:72
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition iplib.cc:982
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 982 of file iplib.cc.

984{
988
989 yylpin = fp;
990 #if YYLPDEBUG > 1
991 print_init();
992 #endif
995 else lpverbose=0;
996 // yylplex sets also text_buffer
997 if (text_buffer!=NULL) *text_buffer='\0';
999 if(yylp_errno)
1000 {
1001 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
1002 current_pos(0));
1004 {
1008 }
1009 else
1011 WerrorS("Cannot load library,... aborting.");
1012 reinit_yylp();
1013 fclose( yylpin );
1015 return TRUE;
1016 }
1017 if (BVERBOSE(V_LOAD_LIB))
1018 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1020 {
1021 Warn( "library %s has old format. This format is still accepted,", newlib);
1022 WarnS( "but for functionality you may wish to change to the new");
1023 WarnS( "format. Please refer to the manual for further information.");
1024 }
1025 reinit_yylp();
1026 fclose( yylpin );
1027 fp = NULL;
1028 iiRunInit(IDPACKAGE(pl));
1029
1030 {
1031 libstackv ls;
1032 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1033 {
1034 if(ls->to_be_done)
1035 {
1036 ls->to_be_done=FALSE;
1038 ls = ls->pop(newlib);
1039 }
1040 }
1041#if 0
1042 PrintS("--------------------\n");
1043 for(ls = library_stack; ls != NULL; ls = ls->next)
1044 {
1045 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1046 ls->to_be_done ? "not loaded" : "loaded");
1047 }
1048 PrintS("--------------------\n");
1049#endif
1050 }
1051
1052 if(fp != NULL) fclose(fp);
1053 return FALSE;
1054}
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:937
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:966
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 879 of file iplib.cc.

880{
881 char *plib = iiConvName(lib);
882 idhdl pl = basePack->idroot->get(plib,0);
883 if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
884 (IDPACKAGE(pl)->language == LANG_SINGULAR))
885 {
886 strncpy(where,IDPACKAGE(pl)->libname,127);
887 return TRUE;
888 }
889 else
890 return FALSE;;
891}

◆ iiMake_proc()

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

Definition at line 512 of file iplib.cc.

513{
514 int err;
516 if(pi->is_static && myynest==0)
517 {
518 Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
519 pi->libname, pi->procname);
520 return TRUE;
521 }
522 iiCheckNest();
524 //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
526 procstack->push(pi->procname);
528 || (pi->trace_flag&TRACE_SHOW_PROC))
529 {
531 Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
532 }
533#ifdef RDEBUG
535#endif
536 switch (pi->language)
537 {
538 default:
539 case LANG_NONE:
540 WerrorS("undefined proc");
541 err=TRUE;
542 break;
543
544 case LANG_SINGULAR:
545 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
546 {
547 currPack=pi->pack;
550 //Print("set pack=%s\n",IDID(currPackHdl));
551 }
552 else if ((pack!=NULL)&&(currPack!=pack))
553 {
554 currPack=pack;
557 //Print("set pack=%s\n",IDID(currPackHdl));
558 }
559 err=iiPStart(pn,args);
560 break;
561 case LANG_C:
563 err = (pi->data.o.function)(res, args);
566 break;
567 }
569 || (pi->trace_flag&TRACE_SHOW_PROC))
570 {
572 Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
573 }
574 //const char *n="NULL";
575 //if (currRingHdl!=NULL) n=IDID(currRingHdl);
576 //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
577#ifdef RDEBUG
579#endif
580 if (err)
581 {
583 //iiRETURNEXPR.Init(); //done by CleanUp
584 }
585 if (iiCurrArgs!=NULL)
586 {
587 if (!err) Warn("too many arguments for %s",IDID(pn));
591 }
592 procstack->pop();
593 if (err)
594 return TRUE;
595 return FALSE;
596}
VAR idhdl currPackHdl
Definition ipid.cc:55
idhdl packFindHdl(package r)
Definition ipid.cc:833
static void iiShowLevRings()
Definition iplib.cc:486
BOOLEAN iiPStart(idhdl pn, leftv v)
Definition iplib.cc:379
void iiCheckPack(package &p)
Definition ipshell.cc:1631
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 }
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 {
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);
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 379 of file iplib.cc.

380{
382 int old_echo=si_echo;
383 BOOLEAN err=FALSE;
384 char save_flags=0;
385
386 /* init febase ======================================== */
387 /* we do not enter this case if filename != NULL !! */
388 if (pn!=NULL)
389 {
390 pi = IDPROC(pn);
391 if(pi!=NULL)
392 {
393 save_flags=pi->trace_flag;
394 if( pi->data.s.body==NULL )
395 {
397 if (pi->data.s.body==NULL) return TRUE;
398 }
399// omUpdateInfo();
400// int m=om_Info.UsedBytes;
401// Print("proc %s, mem=%d\n",IDID(pn),m);
402 }
403 }
404 else return TRUE;
405 /* generate argument list ======================================*/
406 //iiCurrArgs should be NULL here, as the assignment for the parameters
407 // of the prevouis call are already done befor calling another routine
408 if (v!=NULL)
409 {
411 memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
412 v->Init();
413 }
414 else
415 {
417 }
418 /* start interpreter ======================================*/
419 myynest++;
420 if (myynest > SI_MAX_NEST)
421 {
422 WerrorS("nesting too deep");
423 err=TRUE;
424 }
425 else
426 {
428 err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
430
431 if (iiLocalRing[myynest-1] != currRing)
432 {
434 {
435 //idhdl hn;
436 const char *n;
437 const char *o;
439 if (iiLocalRing[myynest-1]!=NULL)
441 if (oh!=NULL) o=oh->id;
442 else o="none";
443 if (currRing!=NULL)
445 if (nh!=NULL) n=nh->id;
446 else n="none";
447 Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
449 err=TRUE;
450 }
452 }
453 if ((currRing==NULL)
454 && (currRingHdl!=NULL))
456 else
457 if ((currRing!=NULL) &&
459 ||(IDLEV(currRingHdl)>=myynest-1)))
460 {
463 }
464 //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
466#ifndef SING_NDEBUG
467 checkall();
468#endif
469 //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
470 }
471 myynest--;
473 if (pi!=NULL)
474 pi->trace_flag=save_flags;
475// omUpdateInfo();
476// int m=om_Info.UsedBytes;
477// Print("exit %s, mem=%d\n",IDID(pn),m);
478 return err;
479}
BOOLEAN RingDependend()
Definition subexpr.cc:421
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 966 of file iplib.cc.

967{
968 idhdl h=p->idroot->get("mod_init",0);
969 if (h==NULL) return;
970 if (IDTYP(h)==PROC_CMD)
971 {
972 int save=yylineno;
973 myynest++;
974 // procinfo *pi=(procinfo*)IDDATA(h);
975 //PrintS("mod_init found\n");
977 myynest--;
979 }
980}
VAR int yylineno
Definition febase.cc:40

◆ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 486 of file iplib.cc.

487{
488 int i;
489 for (i=0;i<=myynest;i++)
490 {
491 Print("lev %d:",i);
492 if (iiLocalRing[i]==NULL) PrintS("NULL");
493 else Print("%lx",(long)iiLocalRing[i]);
494 PrintLn();
495 }
496 if (currRing==NULL) PrintS("curr:NULL\n");
497 else Print ("curr:%lx\n",(long)currRing);
498}

◆ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv  v,
const char id 
)

Definition at line 831 of file iplib.cc.

832{
834 char libnamebuf[1024];
835 size_t len=strlen(id)+5;
836 char *libname = (char *)omAlloc(len);
837 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
838 int i = 0;
839 // FILE *fp;
840 // package pack;
841 // idhdl packhdl;
843 for(i=0; suffix[i] != NULL; i++)
844 {
845 snprintf(libname,len, "%s%s", id, suffix[i]);
846 *libname = mytolower(*libname);
847 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
848 {
849 #ifdef HAVE_DYNAMIC_LOADING
850 char libnamebuf[1024];
851 #endif
852
853 if (LT==LT_SINGULAR)
854 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
855 #ifdef HAVE_DYNAMIC_LOADING
856 else if ((LT==LT_ELF) || (LT==LT_HPUX))
858 #endif
859 else if (LT==LT_BUILTIN)
860 {
862 }
863 if(!LoadResult )
864 {
865 v->name = iiConvName(libname);
866 break;
867 }
868 }
869 }
870 omFree(libname);
871 return LoadResult;
872}
char name() const
Definition variable.cc:122
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1293
static char mytolower(char c)
Definition iplib.cc:1425
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition iplib.cc:1303
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition iplib.cc:815
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 1303 of file iplib.cc.

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

◆ load_modules()

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

Definition at line 1293 of file iplib.cc.

1294{
1296 pthread_mutex_lock(&mutex);
1298 pthread_mutex_unlock(&mutex);
1299 return r;
1300}
#define GLOBAL_VAR
Definition globaldefs.h:11
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1190

◆ load_modules_aux()

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

Definition at line 1190 of file iplib.cc.

1191{
1192/*
1193 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1194 BOOLEAN pstatic,
1195 BOOLEAN(*func)(leftv res, leftv v)));
1196*/
1198 idhdl pl;
1199 char *plib = iiConvName(newlib);
1201 int token;
1202 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1203 char *FullName=(char*)omAlloc0(l);
1204
1205 if( *fullname != '/' && *fullname != '.' )
1206 snprintf(FullName,l, "./%s", newlib);
1207 else strncpy(FullName, fullname,l);
1208
1209
1210 if(IsCmd(plib, token))
1211 {
1212 Werror("'%s' is resered identifier\n", plib);
1213 goto load_modules_end;
1214 }
1215 pl = basePack->idroot->get(plib,0); /* packages only in top level
1216 (see enterid) */
1217 if ((pl!=NULL)
1218 &&(IDTYP(pl)==PACKAGE_CMD))
1219 {
1220 if(IDPACKAGE(pl)->language==LANG_C)
1221 {
1222 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1224 return FALSE;
1225 }
1226 else if(IDPACKAGE(pl)->language==LANG_MIX)
1227 {
1228 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1230 return FALSE;
1231 }
1232 }
1233 else
1234 {
1235 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1236 omFreeBinAddr(plib); /* enterid copied plib*/
1237 IDPACKAGE(pl)->libname=omStrDup(newlib);
1238 }
1239 IDPACKAGE(pl)->language = LANG_C;
1241 {
1242 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1244 return FALSE;
1245 }
1246 if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1247 {
1248 Werror("dynl_open failed:%s", dynl_error());
1249 Werror("%s not found", newlib);
1250 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1251 goto load_modules_end;
1252 }
1253 else
1254 {
1256
1257 package s=currPack;
1258 currPack=IDPACKAGE(pl);
1259 fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1260 if( fktn!= NULL)
1261 {
1262 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1263 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1264 else sModulFunctions.iiAddCproc = iiAddCproc;
1265 int ver=(*fktn)(&sModulFunctions);
1266 if (ver==MAX_TOK)
1267 {
1268 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1269 }
1270 else
1271 {
1272 Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1273 }
1274 currPack->loaded=1;
1275 currPack=s; /* reset currPack to previous */
1277 RET=FALSE;
1278 }
1279 else
1280 {
1281 Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1282 errorreported=0;
1283 if(IDPACKAGE(pl)->idroot==NULL)
1284 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1285 }
1286 }
1287
1290 return RET;
1291}
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:447
int(* SModulFunc_t)(SModulFunctions *)
Definition ipid.h:81
void register_dyn_module(char *fullname, void *handle)
Definition iplib.cc:1173
int dynl_check_opened(char *filename)
Definition mod_raw.cc:135
#define omFreeSize(addr, size)
#define omAlloc0(size)

◆ module_help_main()

void module_help_main ( const char newlib,
const char help 
)

Definition at line 1356 of file iplib.cc.

1357{
1358 char *plib = iiConvName(newlib);
1359 idhdl pl = basePack->idroot->get(plib,0);
1360 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1361 Werror(">>%s<< is not a package (trying to add package help)",plib);
1362 else
1363 {
1364 package s=currPack;
1365 currPack=IDPACKAGE(pl);
1366 idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1368 currPack=s;
1369 }
1370}
#define IDSTRING(a)
Definition ipid.h:136
#define help
Definition libparse.cc:1230
@ STRING_CMD
Definition tok.h:187

◆ module_help_proc()

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

Definition at line 1371 of file iplib.cc.

1372{
1373 char *plib = iiConvName(newlib);
1374 idhdl pl = basePack->idroot->get(plib,0);
1375 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1376 Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1377 else
1378 {
1379 package s=currPack;
1380 currPack=IDPACKAGE(pl);
1381 char buff[SINGULAR_PATH_LENGTH];
1382 buff[SINGULAR_PATH_LENGTH-1]='\0';
1384 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1387 currPack=s;
1388 }
1389}

◆ mytolower()

static char mytolower ( char  c)
static

Definition at line 1425 of file iplib.cc.

1426{
1427 if(c>=65 && c<=(65+26)) c+=32;
1428 return(c);
1429}

◆ mytoupper()

static char mytoupper ( char  c)
static

Definition at line 1419 of file iplib.cc.

1420{
1421 if(c>=97 && c<=(97+26)) c-=32;
1422 return(c);
1423}

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

1173 {
1174 std::string fname = fullname;
1175 if (dyn_modules == NULL)
1176 dyn_modules = new std::map<std::string, void *>();
1177 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1178}

◆ registered_dyn_module()

bool registered_dyn_module ( char fullname)

Definition at line 1166 of file iplib.cc.

1166 {
1167 if (dyn_modules == NULL)
1168 return false;
1169 std::string fname = fullname;
1170 return dyn_modules->count(fname) != 0;
1171}

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

◆ iiLocalRing

VAR ring* iiLocalRing

Definition at line 481 of file iplib.cc.

◆ iiRETURNEXPR

INST_VAR sleftv iiRETURNEXPR

Definition at line 482 of file iplib.cc.

◆ iiRETURNEXPR_len

VAR int iiRETURNEXPR_len =0

Definition at line 483 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.

1114 {
1115 "",
1116 "missing close bracket ')' for proc definition in line %d.", /* 1 */
1117 "missing close bracket ')' for procbody in line %d.", /* 2 */
1118 "missing close bracket ']' for procbody in line %d.", /* 3 */
1119 "too many ')' closed brackets in line %d.", /* 4 */
1120 "too many ']' closed brackets in line %d.", /* 5 */
1121 "missing close bracket ')' for example in line %d.", /* 6 */
1122 "missing close bracket ']' for example in line %d.", /* 7 */
1123 "cannot assign character '%c' in line %d to any group.", /* 8 */
1124 "there must be a quote missing somewhere before line %d.", /* 9 */
1125 "missing close bracket '}' at end of library in line %d.", /* 10 */
1126 "missing close bracket ')' at end of library in line %d.", /* 11 */
1127 "missing close bracket ']' at end of library in line %d.", /* 12 */
1128 NULL
1129};

◆ 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.