My Project
Functions | Variables
tesths.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "factory/factory.h"
#include "kernel/oswrapper/feread.h"
#include "Singular/fevoices.h"
#include "kernel/oswrapper/timer.h"
#include "ipshell.h"
#include "cntrlc.h"
#include "links/silink.h"
#include "ipid.h"
#include "sdb.h"
#include "feOpt.h"
#include "misc/distrib.h"
#include "mmalloc.h"
#include "tok.h"
#include "resources/fegetopt.h"
#include "Singular/countedref.h"
#include "Singular/pyobject_setup.h"
#include <unistd.h>
#include <NTL/config.h>

Go to the source code of this file.

Functions

void siInit (char *)
 
int mmInit (void)
 
int main (int argc, char **argv)
 

Variables

EXTERN_VAR FILE * File_Log
 
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file tesths.cc.

64 {
65  mmInit();
66  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
67  omInitRet_2_Info(argv[0]);
69 
70 #ifdef PSINGULAR
71  global_argv0 = argv[0];
72 #endif
73  siInit(argv[0]);
74  init_signals();
75  #ifdef HAVE_NTL
76  #if NTL_MAJOR_VERSION>=10
77  #ifdef NTL_THREAD_BOOST
78  SetNumThreads(feOptValue(FE_OPT_CPUS));
79  #endif
80  #endif
81  #endif
82 
83  // parse command line options
84  int optc, option_index;
85  const char* errormsg;
86  while((optc = fe_getopt_long(argc, argv,
87  SHORT_OPTS_STRING, feOptSpec, &option_index))
88  != EOF)
89  {
90  if (optc == '?' || optc == 0)
91  {
92  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
93  exit(1);
94  }
95 
96  if (optc != LONG_OPTION_RETURN)
97  option_index = feGetOptIndex(optc);
98 
99  assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
100 
101  if (fe_optarg == NULL &&
102  (feOptSpec[option_index].type == feOptBool ||
103  feOptSpec[option_index].has_arg == optional_argument))
104  errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
105  else
106  errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
107 
108  if (errormsg)
109  {
110  if (fe_optarg == NULL)
111  fprintf(stderr, "Error: Option '--%s' %s\n",
112  feOptSpec[option_index].name, errormsg);
113  else
114  fprintf(stderr, "Error: Option '--%s=%s' %s\n",
115  feOptSpec[option_index].name, fe_optarg, errormsg);
116  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
117  exit(1);
118  }
119  if (optc == 'h') exit(0);
120  switch(option_index)
121  {
122  case FE_OPT_DUMP_VERSIONTUPLE:
123  exit(0);
124  break;
125  default: ;
126  }
127  }
128 
129  /* say hello */
130 
131  if (TEST_V_QUIET)
132  {
133  (printf)(
134 " SINGULAR /"
135 #ifndef MAKE_DISTRIBUTION
136 " Development"
137 #endif
138 "\n"
139 " A Computer Algebra System for Polynomial Computations / version %s\n"
140 " 0<\n"
141 " by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
142 "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\ Debian " DEB_PKG_VERSION "\n"
143 , VERSION, VERSION_DATE);
144  if (feOptValue(FE_OPT_NO_SHELL))
145  {
146  WarnS("running in restricted mode:"
147  " shell invocation and links are disallowed");
149  }
150  }
151  else
152  {
154  if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
155  dup2(1,2);
156  /* alternative:
157  * memcpy(stderr,stdout,sizeof(FILE));
158  */
159  }
160  if (feOptValue(FE_OPT_LOG)!=NULL)
161  {
162  int pid=getpid();
163  char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
164  sprintf(buf,"%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
165  File_Log=fopen(buf,"w");
166  }
167 
168 #ifdef SINGULAR_PYOBJECT_SETUP_H
169  pyobject_setup();
170 #endif
171 #ifdef SI_COUNTEDREF_AUTOLOAD
172  countedref_init();
173 #endif
174  errorreported = 0;
175 
176  // -- example for "static" modules ------
177  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
178  //module_help_main("huhu.so","Help for huhu\nhaha\n");
179  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
180  setjmp(si_start_jmpbuf);
181 
182  // Now, put things on the stack of stuff to do
183  // Last thing to do is to execute given scripts
184  if (fe_optind < argc)
185  {
186  int i = argc - 1;
187  FILE *fd;
188  while (i >= fe_optind)
189  {
190  if ((fd = feFopen(argv[i], "r")) == NULL)
191  {
192  Warn("Can not open %s", argv[i]);
193  }
194  else
195  {
196  fclose(fd);
197  newFile(argv[i]);
198  }
199  i--;
200  }
201  }
202  else
203  {
205  }
206 
207  // before scripts, we execute -c, if it was given
208  if (feOptValue(FE_OPT_EXECUTE) != NULL)
209  newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
210 
211  // first thing, however, is to load .singularrc from Singularpath
212  // and cwd/$HOME (in that order).
213  if (! feOptValue(FE_OPT_NO_RC))
214  {
215  char buf[MAXPATHLEN];
216  FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
217  if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
218  if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
219 
220  if (rc != NULL)
221  {
222  if (BVERBOSE(V_LOAD_LIB))
223  Print("// ** executing %s\n", buf);
224  fclose(rc);
225  newFile(buf);
226  }
227  }
228 
229  /* start shell */
231  {
233  char *linkname=(char*) feOptValue(FE_OPT_LINK);
234  if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
235  {
236  return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
237  //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
238  //exit(0);
239  }
240  else
241  {
242  Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
243  return 1;
244  }
245  }
246  setjmp(si_start_jmpbuf);
247  yyparse();
248  m2_end(0);
249  return 0;
250 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void On(int sw)
switches
int i
Definition: cfEzgcd.cc:132
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition: cf_defs.h:39
VAR jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:92
VAR BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:62
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
Definition: cntrlc.cc:527
void countedref_init()
Definition: countedref.h:458
#define Print
Definition: emacs.cc:80
#define Warn
Definition: emacs.cc:77
#define WarnS
Definition: emacs.cc:78
char name(const Variable &v)
Definition: factory.h:189
#define VERSION
Definition: factoryconf.h:277
VAR short errorreported
Definition: feFopen.cc:23
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
feOptIndex
Definition: feOptGen.h:15
@ FE_OPT_UNDEF
Definition: feOptGen.h:15
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:154
const char SHORT_OPTS_STRING[]
Definition: feOpt.cc:29
feOptIndex feGetOptIndex(const char *name)
Definition: feOpt.cc:104
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
EXTERN_VAR struct fe_option feOptSpec[]
Definition: feOpt.h:17
VAR char * feArgv0
Definition: feResource.cc:19
#define DIR_SEPP
Definition: feResource.h:7
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
Definition: fegetopt.c:664
char * fe_optarg
Definition: fegetopt.c:94
int fe_optind
Definition: fegetopt.c:109
@ feOptBool
Definition: fegetopt.h:77
#define optional_argument
Definition: fegetopt.h:101
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:32
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:455
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:166
VAR Voice * currentVoice
Definition: fevoices.cc:49
BOOLEAN newFile(char *fname)
Definition: fevoices.cc:129
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:677
@ BT_execute
Definition: fevoices.h:23
int yyparse(void)
Definition: grammar.cc:2111
#define assume(x)
Definition: mod2.h:389
void m2_end(int i)
Definition: misc_ip.cc:1097
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omInitGetBackTrace()
#define NULL
Definition: omList.c:12
#define MAXPATHLEN
Definition: omRet2Info.c:22
void * malloc(size_t size)
Definition: omalloc.c:85
#define BVERBOSE(a)
Definition: options.h:35
#define TEST_V_QUIET
Definition: options.h:135
#define V_LOAD_LIB
Definition: options.h:47
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
int status int void * buf
Definition: si_signals.h:59
int status int fd
Definition: si_signals.h:59
EXTERN_VAR FILE * File_Log
Definition: tesths.cc:42
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition: tesths.cc:43
void siInit(char *)
Definition: misc_ip.cc:1370
int mmInit(void)
Definition: tesths.cc:45
#define omInitRet_2_Info(argv0)
Definition: xalloc.h:274

◆ mmInit()

int mmInit ( void  )

Definition at line 45 of file tesths.cc.

46 {
47 #ifndef X_OMALLOC
48 #if defined(OMALLOC_USES_MALLOC)
49  /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
50  /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
51  /* do not rely on the default in Singular as libsingular may be different */
52  mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
53 #else
54  mp_set_memory_functions(malloc,reallocSize,freeSize);
55 #endif
56 #endif
57  return 1;
58 }
#define freeSize
Definition: omAllocFunc.c:15
#define reallocSize
Definition: omAllocFunc.c:17
void * omMallocFunc(size_t size)
void * omReallocSizeFunc(void *old_addr, size_t old_size, size_t new_size)
void omFreeSizeFunc(void *addr, size_t size)

◆ siInit()

void siInit ( char *  name)

Definition at line 1370 of file misc_ip.cc.

1371 {
1372 // memory initialization: -----------------------------------------------
1373  om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1374 #ifndef OM_NDEBUG
1375 #ifndef __OPTIMIZE__
1376  om_Opts.ErrorHook = dErrorBreak;
1377 #else
1378  om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1379 #endif
1380 #else
1381  om_Opts.Keep = 0; /* OM_NDEBUG */
1382 #endif
1383  omInitInfo();
1384 // factory
1385 #ifndef HAVE_NTL
1386  extern void initPT();
1387  initPT();
1388 #endif
1389 // options ---------------------------------------------------------------
1390  si_opt_1=0;
1391 // interpreter tables etc.: -----------------------------------------------
1392  memset(&sLastPrinted,0,sizeof(sleftv));
1394 
1395  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1396 
1397  basePack=(package)omAlloc0(sizeof(*basePack));
1399  idhdl h;
1400  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, FALSE);
1401  IDPACKAGE(h)=basePack;
1402  IDPACKAGE(h)->language = LANG_TOP;
1403  currPackHdl=h;
1404  basePackHdl=h;
1405 
1406  coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1407 
1408 #if 1
1409  // def HAVE_POLYEXTENSIONS
1410  if(TRUE)
1411  {
1412  n_coeffType type;
1413  #ifdef SINGULAR_4_2
1414  type = nRegister(n_polyExt, n2pInitChar);
1415  assume(type == n_polyExt);
1416  #endif
1417 
1418  type = nRegister(n_algExt, naInitChar);
1419  assume(type == n_algExt);
1420 
1421  type = nRegister(n_transExt, ntInitChar);
1422  assume(type == n_transExt);
1423 
1424  (void)type;
1425  }
1426 #endif
1427 
1428 // random generator: -----------------------------------------------
1429  int t=initTimer();
1430  if (t==0) t=1;
1431  initRTimer();
1432  siSeed=t;
1433  factoryseed(t);
1434  siRandomStart=t;
1435  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1436 
1437 // ressource table: ----------------------------------------------------
1438  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1439  // hack such that all shared' libs in the bindir are loaded correctly
1441 
1442 // singular links: --------------------------------------------------
1443  slStandardInit();
1444  myynest=0;
1445 // how many processes ? -----------------------------------------------------
1446  int cpus=2;
1447  int cpu_n;
1448  #ifdef _SC_NPROCESSORS_ONLN
1449  if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1450  #elif defined(_SC_NPROCESSORS_CONF)
1451  if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1452  #endif
1453  feSetOptValue(FE_OPT_CPUS, cpus);
1454 // how many threads ? -----------------------------------------------------
1455  feSetOptValue(FE_OPT_THREADS, cpus);
1456 
1457 // default coeffs
1458  {
1459  idhdl h;
1460  h=enterid("QQ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1461  IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1462  h=enterid("ZZ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1463  IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1464  nRegisterCfByName(nrnInitCfByName,n_Zn); // and n_Znm
1465  iiAddCproc("kernel","crossprod",FALSE,iiCrossProd);
1466  iiAddCproc("kernel","Float",FALSE,iiFloat);
1467  //h=enterid("RR",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1468  //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1469  //h=enterid("CC",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1470  //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1471  }
1472 // setting routines for PLURAL QRINGS:
1473 // allowing to use libpolys without libSingular(kStd)
1474 #ifdef HAVE_PLURAL
1475  nc_NF=k_NF;
1481 #endif
1482 // loading standard.lib -----------------------------------------------
1483  if (! feOptValue(FE_OPT_NO_STDLIB))
1484  {
1485  BITSET save1,save2;
1486  SI_SAVE_OPT(save1,save2);
1487  si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1488  iiLibCmd("standard.lib", TRUE,TRUE,TRUE);
1489  SI_RESTORE_OPT(save1,save2);
1490  }
1491  // interpreter error handling
1492  #ifndef __CYGWIN__
1493  factoryError=callWerrorS; // to honour later changes of variable WerrorS
1494  #endif
1495  errorreported = 0;
1496 }
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1388
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition: algext.cc:1642
void initPT()
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:189
VAR void(* factoryError)(const char *s)
Definition: cf_util.cc:80
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int rtyp
Definition: subexpr.h:91
VAR int siRandomStart
Definition: cntrlc.cc:93
n_coeffType
Definition: coeffs.h:27
@ n_polyExt
used to represent polys as coeffcients
Definition: coeffs.h:34
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:30
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition: coeffs.h:35
@ n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:38
@ n_Z
only used if HAVE_RINGS is defined
Definition: coeffs.h:43
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:413
void feInitResources(const char *argv0)
Definition: feResource.cc:163
VAR int myynest
Definition: febase.cc:41
void * value
Definition: fegetopt.h:93
EXTERN_VAR BBA_Proc gnc_gr_bba
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc gnc_gr_mora
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc sca_gr_bba
Definition: gb_hack.h:10
EXTERN_VAR NF_Proc nc_NF
Definition: gb_hack.h:9
EXTERN_VAR BBA_Proc sca_mora
Definition: gb_hack.h:10
EXTERN_VAR BBA_Proc sca_bba
Definition: gb_hack.h:10
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1283
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Definition: gr_kstd2.cc:1030
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:9740
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:279
VAR package basePack
Definition: ipid.cc:58
VAR package currPack
Definition: ipid.cc:57
VAR idhdl currPackHdl
Definition: ipid.cc:55
VAR idhdl basePackHdl
Definition: ipid.cc:56
VAR coeffs coeffs_BIGINT
Definition: ipid.cc:50
#define IDDATA(a)
Definition: ipid.h:126
#define IDROOT
Definition: ipid.h:19
#define IDPACKAGE(a)
Definition: ipid.h:139
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1063
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:884
STATIC_VAR Poly * h
Definition: janet.cc:971
ideal k_sca_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger's algorithm.
Definition: sca.cc:368
ideal k_sca_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Mora's algorithm.
Definition: sca.cc:885
ideal k_sca_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
Modified Plural's Buchberger's algorithmus.
Definition: sca.cc:95
poly k_NF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce, const ring _currRing)
NOTE: this is just a wrapper which sets currRing for the actual kNF call.
Definition: kstd1.cc:3396
static BOOLEAN iiCrossProd(leftv res, leftv args)
Definition: misc_ip.cc:1335
void omSingOutOfMemoryFunc()
Definition: misc_ip.cc:1208
static BOOLEAN iiFloat(leftv res, leftv pnn)
Definition: misc_ip.cc:1306
static void callWerrorS(const char *s)
Definition: misc_ip.cc:1369
void dErrorBreak(void)
Definition: dError.cc:140
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition: numbers.cc:636
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:595
#define omAlloc0(size)
Definition: omAllocDecl.h:211
omOpts_t om_Opts
Definition: omOpts.c:13
VAR unsigned si_opt_2
Definition: options.c:6
VAR unsigned si_opt_1
Definition: options.c:5
#define SI_SAVE_OPT(A, B)
Definition: options.h:20
#define Sy_bit(x)
Definition: options.h:31
#define SI_RESTORE_OPT(A, B)
Definition: options.h:23
coeffs nrnInitCfByName(char *s, n_coeffType)
Definition: rmodulon.cc:35
VAR int siSeed
Definition: sirandom.c:30
ip_package * package
Definition: structs.h:43
#define BITSET
Definition: structs.h:16
INST_VAR sleftv sLastPrinted
Definition: subexpr.cc:46
@ LANG_TOP
Definition: subexpr.h:22
int initTimer()
Definition: timer.cc:67
void initRTimer()
Definition: timer.cc:156
@ CRING_CMD
Definition: tok.h:56
@ PACKAGE_CMD
Definition: tok.h:149
#define NONE
Definition: tok.h:221
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2636
#define omInitInfo()
Definition: xalloc.h:228

Variable Documentation

◆ FE_OPT_NO_SHELL_FLAG

EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG

Definition at line 43 of file tesths.cc.

◆ File_Log

EXTERN_VAR FILE* File_Log

Definition at line 42 of file tesths.cc.