Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - gp - gp.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21348-d75f58f) Lines: 210 342 61.4 %
Date: 2017-11-20 06:21:05 Functions: 21 31 67.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /**                                                               **/
      16             : /**                        PARI CALCULATOR                        **/
      17             : /**                                                               **/
      18             : /*******************************************************************/
      19             : #ifdef _WIN32
      20             : #  include "../systems/mingw/pwinver.h"
      21             : #  include <windows.h>
      22             : #  include "../systems/mingw/mingw.h"
      23             : #endif
      24             : #include "pari.h"
      25             : #include "paripriv.h"
      26             : #include "gp.h"
      27             : 
      28             : static jmp_buf *env;
      29             : static pari_stack s_env;
      30             : void (*cb_gp_output)(GEN z) = NULL;
      31             : void (*cb_pari_end_output)(void) = NULL;
      32             : 
      33             : static void
      34           0 : gp_ask_confirm(const char *s)
      35             : {
      36           0 :   err_printf(s);
      37           0 :   err_printf(". OK ? (^C if not)\n");
      38           0 :   pari_hit_return();
      39           0 : }
      40             : 
      41             : /* numerr < 0: from SIGINT */
      42             : static void
      43         277 : gp_err_recover(long numerr)
      44             : {
      45         277 :   longjmp(env[s_env.n-1], numerr);
      46             : }
      47             : /* numerr < 0: from SIGINT */
      48             : static void
      49        8147 : gp_pre_recover(long numerr)
      50             : {
      51        8147 :   if (numerr>=0)
      52             :   {
      53        8147 :     out_puts(pariErr, "\n"); pariErr->flush();
      54             :   }
      55        8147 :   longjmp(env[s_env.n-1], numerr);
      56             : }
      57             : 
      58             : static void
      59       83534 : reset_ctrlc(void)
      60             : {
      61             : #if defined(_WIN32) || defined(__CYGWIN32__)
      62             :   win32ctrlc = 0;
      63             : #endif
      64       83534 : }
      65             : 
      66             : static int
      67       51465 : is_silent(char *s) { return s[strlen(s) - 1] == ';'; }
      68             : 
      69             : static int stdin_isatty = 0;
      70             : static int
      71        1635 : is_interactive(void)
      72        1635 : { return pari_infile == stdin && stdin_isatty; }
      73             : 
      74             : /*******************************************************************/
      75             : /**                                                               **/
      76             : /**                        INITIALIZATION                         **/
      77             : /**                                                               **/
      78             : /*******************************************************************/
      79             : static void
      80           0 : print_shortversion(void)
      81             : {
      82           0 :   const ulong mask = (1UL<<PARI_VERSION_SHIFT) - 1;
      83           0 :   ulong n = paricfg_version_code, major, minor, patch;
      84             : 
      85           0 :   patch = n & mask; n >>= PARI_VERSION_SHIFT;
      86           0 :   minor = n & mask; n >>= PARI_VERSION_SHIFT;
      87           0 :   major = n;
      88           0 :   printf("%lu.%lu.%lu\n", major,minor,patch); exit(0);
      89             : }
      90             : 
      91             : static void
      92           0 : usage(char *s)
      93             : {
      94           0 :   printf("### Usage: %s [options] [GP files]\n", s);
      95           0 :   printf("Available options:\n");
      96           0 :   printf("  [-f,--fast]\t\tFast start: do not read .gprc\n");
      97           0 :   printf("  [-q,--quiet]\t\tQuiet mode: do not print banner and history numbers\n");
      98           0 :   printf("  [-s stacksize]\tStart with the PARI stack of given size (in bytes)\n");
      99           0 :   printf("  [--default key=val]\tExecute default(key,val) on startup\n");
     100           0 :   printf("  [--emacs]\t\tRun as if in Emacs shell\n");
     101           0 :   printf("  [--help]\t\tPrint this message\n");
     102           0 :   printf("  [--test]\t\tTest mode. No history, wrap long lines (bench only)\n");
     103           0 :   printf("  [--texmacs]\t\tRun as if using TeXmacs frontend\n");
     104           0 :   printf("  [--version]\t\tOutput version info and exit\n");
     105           0 :   printf("  [--version-short]\tOutput version number and exit\n\n");
     106           0 :   exit(0);
     107             : }
     108             : 
     109             : static void
     110           0 : gp_head(void)
     111             : {
     112           0 :   pari_print_version();
     113           0 :   pari_putc('\n');
     114           0 :   pari_center("Copyright (C) 2000-2017 The PARI Group");
     115           0 :   pari_putc('\n');
     116           0 :   print_text("PARI/GP is free software, covered by the GNU General Public \
     117             : License, and comes WITHOUT ANY WARRANTY WHATSOEVER.");
     118           0 :   pari_puts("\nType ? for help, \\q to quit.\n");
     119           0 :   print_text("Type ?15 for how to get moral (and possibly technical) support.");
     120           0 :   if (pari_mainstack->vsize)
     121           0 :     pari_printf("\nparisizemax = %lu, primelimit = %lu",
     122           0 :                 pari_mainstack->vsize,GP_DATA->primelimit);
     123             :   else
     124           0 :     pari_printf("\nparisize = %lu, primelimit = %lu",
     125           0 :                 pari_mainstack->rsize,GP_DATA->primelimit);
     126           0 :   if (pari_mt_nbthreads > 1)
     127           0 :     pari_printf(", nbthreads = %lu", pari_mt_nbthreads);
     128           0 :   pari_putc('\n');
     129           0 : }
     130             : 
     131             : static char *
     132           0 : read_arg(long *nread, char *t, long argc, char **argv)
     133             : {
     134           0 :   long i = *nread;
     135           0 :   if (isdigit((int)*t)) return t;
     136           0 :   if (*t || i==argc) usage(argv[0]);
     137           0 :   *nread = i+1; return argv[i];
     138             : }
     139             : 
     140             : static char *
     141           0 : read_arg_equal(long *nread, char *t, long argc, char **argv)
     142             : {
     143           0 :   long i = *nread;
     144           0 :   if (*t=='=' && isdigit((int)t[1])) return t+1;
     145           0 :   if (*t || i==argc) usage(argv[0]);
     146           0 :   *nread = i+1; return argv[i];
     147             : }
     148             : 
     149             : static void
     150           2 : init_trivial_stack(void)
     151             : {
     152           2 :   const size_t s = 2048;
     153           2 :   pari_mainstack->size = s;
     154           2 :   pari_mainstack->bot = (pari_sp)pari_malloc(s);
     155           2 :   avma = pari_mainstack->top = pari_mainstack->bot + s;
     156           2 : }
     157             : 
     158             : static void
     159           2 : free_trivial_stack(void)
     160             : {
     161           2 :   free((void*)pari_mainstack->bot);
     162           2 : }
     163             : 
     164             : typedef struct { char *key, *val; } pair_t;
     165             : /* If ab of the form key=val, record pair in new stack entry
     166             :  * P[n].key must be freed by caller to avoid memory leak */
     167             : static void
     168           0 : record_default(pari_stack *s_P, char *ab)
     169             : {
     170           0 :   pair_t *P = (pair_t*)*pari_stack_base(s_P);
     171             :   char *k, *v;
     172             :   long n;
     173           0 :   ab = pari_strdup(ab);
     174           0 :   parse_key_val(ab, &k, &v);
     175           0 :   n = pari_stack_new(s_P);
     176           0 :   P[n].key = k;
     177           0 :   P[n].val = v;
     178           0 : }
     179             : static void
     180        1538 : read_opt(pari_stack *p_A, long argc, char **argv)
     181             : {
     182             :   pair_t *P;
     183             :   pari_stack s_P; /* key / value to record default() settings */
     184        1538 :   char *b = NULL, *p = NULL, *s = NULL;
     185        1538 :   ulong f = GP_DATA->flags;
     186        1538 :   long i = 1, initrc = 1;
     187             : 
     188             :   (void)&p; (void)&b; (void)&s; /* -Wall gcc-2.95 */
     189             : 
     190        1538 :   pari_stack_init(&s_P,sizeof(*P),(void**)&P);
     191        1538 :   pari_stack_alloc(&s_P, 64);
     192        1538 :   pari_outfile = stderr;
     193        6148 :   while (i < argc)
     194             :   {
     195        3074 :     char *t = argv[i];
     196             : 
     197        3074 :     if (*t++ != '-') break;
     198        3074 :     i++;
     199             : START:
     200        3074 :     switch(*t++)
     201             :     {
     202           0 :       case 'p': p = read_arg(&i,t,argc,argv); break;
     203           0 :       case 's': s = read_arg(&i,t,argc,argv); break;
     204             :       case 'e':
     205           0 :         f |= gpd_EMACS; if (*t) goto START;
     206           0 :         break;
     207             :       case 'q':
     208        1536 :         f |= gpd_QUIET; if (*t) goto START;
     209        1536 :         break;
     210             :       case 't':
     211           0 :         f |= gpd_TEST; if (*t) goto START;
     212           0 :         break;
     213             :       case 'f':
     214          33 :         initrc = 0; if (*t) goto START;
     215          33 :         break;
     216             :       case 'D':
     217           0 :         if (*t || i == argc) usage(argv[0]);
     218           0 :         record_default(&s_P, argv[i++]);
     219           0 :         break;
     220             :       case '-':
     221        1505 :         if (strcmp(t, "version-short") == 0) { print_shortversion(); exit(0); }
     222        1505 :         if (strcmp(t, "version") == 0) {
     223           2 :           init_trivial_stack(); pari_print_version();
     224           2 :           free_trivial_stack(); exit(0);
     225             :         }
     226        1503 :         if (strcmp(t, "default") == 0) {
     227           0 :           if (i == argc) usage(argv[0]);
     228           0 :           record_default(&s_P, argv[i++]);
     229           0 :           break;
     230             :         }
     231        1503 :         if (strcmp(t, "texmacs") == 0) { f |= gpd_TEXMACS; break; }
     232        1503 :         if (strcmp(t, "emacs") == 0) { f |= gpd_EMACS; break; }
     233        1503 :         if (strcmp(t, "test") == 0) { f |= gpd_TEST; initrc = 0; break; }
     234           0 :         if (strcmp(t, "quiet") == 0) { f |= gpd_QUIET; break; }
     235           0 :         if (strcmp(t, "fast") == 0) { initrc = 0; break; }
     236           0 :         if (strncmp(t, "primelimit",10) == 0) {p = read_arg_equal(&i,t+10,argc,argv); break; }
     237           0 :         if (strncmp(t, "stacksize",9) == 0) {s = read_arg_equal(&i,t+9,argc,argv); break; }
     238             :        /* fall through */
     239             :       default:
     240           0 :         usage(argv[0]);
     241             :     }
     242             :   }
     243        1536 :   if (f & gpd_TEST) stdin_isatty = 0;
     244        1536 :   GP_DATA->flags = f;
     245             : #ifdef READLINE
     246        1536 :   GP_DATA->use_readline = stdin_isatty;
     247             : #endif
     248        1536 :   if (!is_interactive()) GP_DATA->breakloop = 0;
     249        1536 :   if (initrc) gp_initrc(p_A);
     250        1536 :   for ( ; i < argc; i++) pari_stack_pushp(p_A, pari_strdup(argv[i]));
     251             : 
     252             :   /* override the values from gprc */
     253        1536 :   if (p) (void)sd_primelimit(p, d_INITRC);
     254        1536 :   if (s) (void)sd_parisize(s, d_INITRC);
     255        1536 :   for (i = 0; i < s_P.n; i++) {
     256           0 :     setdefault(P[i].key, P[i].val, d_INITRC);
     257           0 :     free((void*)P[i].key);
     258             :   }
     259        1536 :   pari_stack_delete(&s_P);
     260        1536 :   pari_outfile = stdout;
     261        1536 : }
     262             : 
     263             : /*******************************************************************/
     264             : /**                                                               **/
     265             : /**                            TEST MODE                          **/
     266             : /**                                                               **/
     267             : /*******************************************************************/
     268             : static int
     269      156059 : test_is_interactive(void) { return 0; }
     270             : 
     271             : static void
     272       34662 : test_output(GEN z) { init_linewrap(76); gen_output(z); }
     273             : void
     274        1503 : init_test(void)
     275             : {
     276        1503 :   disable_color = 1;
     277        1503 :   init_linewrap(76);
     278        1503 :   pari_errfile = stdout;
     279        1503 :   cb_gp_output = test_output;
     280        1503 :   cb_pari_is_interactive = test_is_interactive;
     281        1503 : }
     282             : 
     283             : /*******************************************************************/
     284             : /**                                                               **/
     285             : /**                   FORMAT GP OUTPUT                            **/
     286             : /**                                                               **/
     287             : /*******************************************************************/
     288             :     /* REGULAR */
     289             : static void
     290           0 : normal_output(GEN z, long n)
     291             : {
     292           0 :   long l = 0;
     293             :   char *s;
     294             :   /* history number */
     295           0 :   if (n)
     296             :   {
     297             :     char buf[64];
     298           0 :     if (!(GP_DATA->flags & gpd_QUIET))
     299             :     {
     300           0 :       term_color(c_HIST);
     301           0 :       sprintf(buf, "%%%ld = ", n);
     302           0 :       pari_puts(buf);
     303           0 :       l = strlen(buf);
     304             :     }
     305             :   }
     306             :   /* output */
     307           0 :   term_color(c_OUTPUT);
     308           0 :   s = GENtostr(z);
     309           0 :   if (GP_DATA->lim_lines)
     310           0 :     lim_lines_output(s, l, GP_DATA->lim_lines);
     311             :   else
     312           0 :     pari_puts(s);
     313           0 :   pari_free(s);
     314           0 :   term_color(c_NONE); pari_putc('\n');
     315           0 : }
     316             : 
     317             : static void
     318       34662 : gp_output(GEN z)
     319             : {
     320       34662 :   if (cb_gp_output) { cb_gp_output(z); return; }
     321           0 :   if (GP_DATA->fmt->prettyp == f_PRETTY)
     322           0 :   { if (tex2mail_output(z, GP_DATA->hist->total)) return; }
     323           0 :   normal_output(z, GP_DATA->hist->total);
     324           0 :   pari_flush();
     325             : }
     326             : 
     327             : static GEN
     328        1536 : gp_main_loop(long ismain)
     329             : {
     330        1536 :   VOLATILE GEN z = gnil;
     331        1536 :   VOLATILE long t = 0;
     332        1536 :   VOLATILE pari_sp av = avma;
     333             :   filtre_t F;
     334        1536 :   Buffer *b = filtered_buffer(&F);
     335             :   struct gp_context rec;
     336             :   long er;
     337        1536 :   if ((er = setjmp(env[s_env.n-1])))
     338             :   { /* recover: jump from error [ > 0 ] or allocatemem [ -1 ] */
     339        8403 :     if (er > 0) { /* true error */
     340        8140 :       if (!(GP_DATA->recover)) exit(1);
     341        8140 :       gp_context_restore(&rec);
     342             :       /* true error not from main instance, let caller sort it out */
     343        8140 :       if (!ismain) { kill_buffers_upto_including(b); return NULL; }
     344             :     } else { /* allocatemem */
     345         263 :       filestate_restore(rec.file);
     346         263 :       gp_context_save(&rec);
     347             :     }
     348        8403 :     avma = av = pari_mainstack->top;
     349        8403 :     parivstack_reset();
     350        8403 :     kill_buffers_upto(b);
     351        8403 :     pari_alarm(0);
     352             :   }
     353             :   for(;;)
     354             :   {
     355       84909 :     gp_context_save(&rec);
     356       84909 :     if (! gp_read_line(&F, NULL))
     357             :     {
     358        1536 :       if (popinfile()) gp_quit(0);
     359           0 :       if (ismain) continue;
     360           0 :       pop_buffer(); return z;
     361             :     }
     362       83373 :     if (ismain)
     363             :     {
     364       83373 :       reset_ctrlc();
     365       83373 :       timer_start(GP_DATA->T);
     366       83373 :       pari_set_last_newline(1);
     367             :     }
     368       83373 :     if (gp_meta(b->buf,ismain)) continue;
     369       70442 :     z = pari_compile_str(b->buf);
     370       70414 :     z = closure_evalres(z);
     371       62039 :     if (!ismain) continue;
     372       62039 :     pari_alarm(0);
     373             : 
     374       62039 :     if (!pari_last_was_newline()) pari_putc('\n');
     375             : 
     376       62039 :     t = timer_delay(GP_DATA->T);
     377       62039 :     if (t && GP_DATA->chrono)
     378             :     {
     379           0 :       pari_puts("time = ");
     380           0 :       pari_puts(gp_format_time(t));
     381             :     }
     382       62039 :     if (GP_DATA->simplify) z = simplify_shallow(z);
     383       62039 :     pari_add_hist(z, t);
     384       62039 :     if (z != gnil && ! is_silent(b->buf) ) gp_output(z);
     385       62039 :     avma = av;
     386       62039 :     parivstack_reset();
     387       74970 :   }
     388             : }
     389             : 
     390             : /* as gp_read_file, before running the main gp instance */
     391             : static void
     392           0 : read_main(const char *s)
     393             : {
     394             :   GEN z;
     395           0 :   if (setjmp(env[s_env.n-1]))
     396           0 :     z = NULL;
     397             :   else {
     398           0 :     FILE *f = switchin(s);
     399           0 :     if (file_is_binary(f)) {
     400           0 :       z = readbin(s,f, NULL);
     401           0 :       popinfile();
     402             :     }
     403           0 :     else z = gp_main_loop(0);
     404             :   }
     405           0 :   if (!z) err_printf("... skipping file '%s'\n", s);
     406           0 :   avma = pari_mainstack->top;
     407           0 : }
     408             : 
     409             : static const char *
     410          63 : break_loop_prompt(long n)
     411             : {
     412          63 :   const char *s = (n==1)? "break> ": stack_sprintf("break[%ld]> ", n);
     413          63 :   return gp_format_prompt(s);
     414             : }
     415             : 
     416             : static long frame_level=0, dbg_level = 0;
     417             : 
     418             : static int
     419          63 : break_loop(int numerr)
     420             : {
     421             :   filtre_t F;
     422             :   Buffer *b;
     423          63 :   int sigint = numerr<0, go_on = sigint;
     424             :   struct gp_context rec1, rec2;
     425             :   const char *prompt, *msg;
     426          63 :   long nenv, oldframe_level = frame_level;
     427             :   pari_sp av;
     428             : 
     429          63 :   if (numerr == e_SYNTAX) return 0;
     430          63 :   if (numerr == e_STACK) { evalstate_clone(); avma = pari_mainstack->top; }
     431          63 :   gp_context_save(&rec1);
     432             : 
     433          63 :   b = filtered_buffer(&F);
     434          63 :   nenv=pari_stack_new(&s_env);
     435          63 :   prompt = break_loop_prompt(s_env.n-1);
     436          63 :   iferr_env = NULL;
     437          63 :   dbg_level = 0;
     438          63 :   frame_level = closure_context(oldframe_level, dbg_level);
     439          63 :   pari_infile = newfile(stdin, "stdin", mf_IN)->file;
     440          63 :   term_color(c_ERR); pari_putc('\n');
     441          63 :   if (sigint)
     442           7 :     msg = "Break loop: <Return> to continue; 'break' to go back to GP prompt";
     443             :   else
     444          56 :     msg = "Break loop: type 'break' to go back to GP prompt";
     445          63 :   print_errcontext(pariOut, msg, NULL, NULL);
     446          63 :   term_color(c_NONE);
     447          63 :   av = avma;
     448             :   for(;;)
     449             :   {
     450             :     GEN x;
     451             :     long er, br_status;
     452         147 :     avma = av;
     453         147 :     gp_context_save(&rec2);
     454         147 :     if ((er=setjmp(env[nenv])))
     455             :     {
     456          28 :       if (er < 0)
     457             :       {
     458           7 :         s_env.n = 1;
     459           7 :         frame_level = oldframe_level;
     460           7 :         longjmp(env[s_env.n-1], er);
     461             :       }
     462          21 :       gp_context_restore(&rec2);
     463          21 :       iferr_env = NULL;
     464          21 :       closure_err(dbg_level);
     465          21 :       compilestate_restore(&rec1.eval.comp);
     466          21 :       (void) closure_context(oldframe_level, dbg_level);
     467          21 :       pari_infile = newfile(stdin, "stdin", mf_IN)->file;
     468             :     }
     469         168 :     term_color(c_NONE);
     470         168 :     if (!gp_read_line(&F, prompt))
     471           0 :       br_status = br_BREAK; /* EOF */
     472             :     else
     473             :     {
     474             :       /* Empty input ? Continue if entry on sigint (exit debugger frame) */
     475         168 :       if (! *(b->buf) && sigint) break;
     476         161 :       reset_ctrlc();
     477         161 :       if (gp_meta(b->buf,0)) continue;
     478         161 :       x = pari_compile_str(b->buf);
     479         161 :       x = closure_evalbrk(x, &br_status);
     480             :     }
     481         133 :     switch (br_status)
     482             :     {
     483             :       case br_NEXT: case br_MULTINEXT:
     484           0 :         popinfile(); /* exit frame. Don't exit debugger if s_env.n > 2 */
     485          49 :         go_on = 0; goto BR_EXIT;
     486             :       case br_BREAK: case br_RETURN:
     487          49 :         killallfiles(); /* completely exit the debugger */
     488          49 :         go_on = 0; goto BR_EXIT;
     489             :     }
     490          84 :     if (x!=gnil && !is_silent(b->buf)) { term_color(c_OUTPUT); gen_output(x); }
     491          84 :   }
     492             : BR_EXIT:
     493          56 :   s_env.n=nenv;
     494          56 :   frame_level = oldframe_level;
     495          56 :   gp_context_restore(&rec1);
     496          56 :   pop_buffer(); return go_on;
     497             : }
     498             : 
     499             : #ifdef __CYGWIN32__
     500             : void
     501             : cyg_environment(int argc, char ** argv)
     502             : {
     503             :   char *ti_dirs = getenv("TERMINFO_DIRS");
     504             :   char *argv0, *p;
     505             :   char *newdir;
     506             :   long n;
     507             : 
     508             :   if (!argc || !argv) return;
     509             :   argv0 = *argv;
     510             :   if (!argv0 || !*argv0) return;
     511             :   p = strrchr(argv0, '/');
     512             :   if (!p)
     513             :     p = argv0 = "";
     514             :   else
     515             :     p++;
     516             :   n = p - argv0;
     517             :   if (ti_dirs)
     518             :   {
     519             :     n += 14 + strlen(ti_dirs) + 1 + 8 + 1;
     520             :     newdir = malloc(n);
     521             :     if (!newdir) return;
     522             :     snprintf(newdir, n-8, "TERMINFO_DIRS=%s:%s", ti_dirs, argv0);
     523             :   }
     524             :   else
     525             :   {
     526             :     n += 14 + 8 + 1;
     527             :     newdir = malloc(n);
     528             :     if (!newdir) return;
     529             :     snprintf(newdir, n-8, "TERMINFO_DIRS=%s", argv0);
     530             :   }
     531             :   strcpy(newdir+n-9,"terminfo");
     532             :   putenv(newdir);
     533             : }
     534             : #endif
     535             : 
     536             : int
     537        1538 : main(int argc, char **argv)
     538             : {
     539             :   char **A;
     540             :   pari_stack s_A;
     541             : 
     542        1538 :   GP_DATA = default_gp_data();
     543        1538 :   pari_stack_init(&s_env, sizeof(*env), (void**)&env);
     544        1538 :   (void)pari_stack_new(&s_env);
     545             : 
     546        1538 :   if (setjmp(env[s_env.n-1]))
     547             :   {
     548           0 :     puts("### Errors on startup, exiting...\n\n");
     549           0 :     exit(1);
     550             :   }
     551             : #ifdef __CYGWIN32__
     552             :   cyg_environment(argc, argv);
     553             : #endif
     554        1538 :   stdin_isatty = pari_stdin_isatty();
     555        1538 :   pari_init_defaults();
     556        1538 :   pari_library_path = DL_DFLT_NAME;
     557        1538 :   pari_stack_init(&s_A,sizeof(*A),(void**)&A);
     558        1538 :   pari_init_opts(1000000 * sizeof(long), 0, INIT_SIGm | INIT_noPRIMEm | INIT_noIMTm);
     559        1538 :   cb_pari_err_recover = gp_err_recover;
     560        1538 :   cb_pari_pre_recover = gp_pre_recover;
     561        1538 :   cb_pari_break_loop = break_loop;
     562        1538 :   cb_pari_is_interactive = is_interactive;
     563             : 
     564        1538 :   read_opt(&s_A, argc,argv);
     565        1536 :   pari_init_primes(GP_DATA->primelimit);
     566             : #ifdef SIGALRM
     567        1536 :   (void)os_signal(SIGALRM,gp_alarm_handler);
     568             : #endif
     569        1536 :   pari_add_module(functions_gp);
     570             : 
     571        1536 :   pari_set_plot_engine(gp_get_plot);
     572        1536 :   cb_pari_quit = gp_quit;
     573        1536 :   cb_pari_whatnow = whatnow;
     574        1536 :   cb_pari_sigint = gp_sigint_fun;
     575        1536 :   cb_pari_handle_exception = gp_handle_exception;
     576        1536 :   cb_pari_ask_confirm = gp_ask_confirm;
     577        1536 :   pari_init_paths();
     578        1536 :   pari_mt_init(); /* MPI: will not return on slaves (pari_MPI_rank = 0) */
     579             : #ifdef _WIN32
     580             :   if (stdin_isatty) win32_set_codepage();
     581             : #endif
     582             : #ifdef READLINE
     583        1536 :   init_readline();
     584             : #endif
     585        1536 :   if (GP_DATA->flags & gpd_EMACS) init_emacs();
     586        1536 :   if (GP_DATA->flags & gpd_TEXMACS) init_texmacs();
     587             : 
     588        1536 :   timer_start(GP_DATA->T);
     589        1536 :   if (!(GP_DATA->flags & gpd_QUIET)) gp_head();
     590        1536 :   if (GP_DATA->flags & gpd_TEST) init_test();
     591        1536 :   if (s_A.n)
     592             :   {
     593           0 :     FILE *l = pari_logfile;
     594             :     long i;
     595           0 :     pari_logfile = NULL;
     596           0 :     for (i = 0; i < s_A.n; pari_free(A[i]),i++) read_main(A[i]);
     597             :     /* Reading one of the input files above can set pari_logfile.
     598             :      * Don't restore in that case. */
     599           0 :     if (!pari_logfile) pari_logfile = l;
     600             :   }
     601        1536 :   pari_stack_delete(&s_A);
     602        1536 :   (void)gp_main_loop(1);
     603           0 :   gp_quit(0);
     604             :   return 0; /* LCOV_EXCL_LINE */
     605             : }
     606             : 
     607             : void
     608           7 : pari_breakpoint(void)
     609             : {
     610           7 :   if (!pari_last_was_newline()) pari_putc('\n');
     611           7 :   closure_err(0);
     612          14 :   if (cb_pari_break_loop && cb_pari_break_loop(-1)) return;
     613           0 :   cb_pari_err_recover(e_MISC);
     614             : }
     615             : 
     616             : void
     617           0 : dbg_down(long k)
     618             : {
     619           0 :   if (k<0) k=0;
     620           0 :   dbg_level -= k;
     621           0 :   if (dbg_level<0) dbg_level=0;
     622           0 :   gp_err_recover(e_NONE);
     623           0 : }
     624             : 
     625             : GEN
     626           7 : dbg_err(void) { GEN E = pari_err_last(); return E? gcopy(E):gnil; }
     627             : 
     628             : void
     629          14 : dbg_up(long k)
     630             : {
     631          14 :   if (k<0) k=0;
     632          14 :   dbg_level += k;
     633          14 :   if (dbg_level>frame_level) dbg_level=frame_level;
     634          14 :   gp_err_recover(e_NONE);
     635           0 : }
     636             : 
     637             : void
     638        1536 : gp_quit(long code)
     639             : {
     640        1536 :   pari_kill_plot_engine();
     641        1536 :   pari_close();
     642        1536 :   kill_buffers_upto(NULL);
     643        1536 :   if (!(GP_DATA->flags & gpd_QUIET)) pari_puts("Goodbye!\n");
     644        1536 :   if (cb_pari_end_output) cb_pari_end_output();
     645        1536 :   exit(code);
     646             : }
     647             : 
     648             : void
     649          35 : whatnow0(char *s) { whatnow(pariOut, s,0); }
     650             : 
     651             : #include "gp_init.h"

Generated by: LCOV version 1.11