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 to exceed 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.12.0 lcov report (development 23346-507fdfd83) Lines: 286 341 83.9 %
Date: 2018-12-13 05:42:04 Functions: 26 31 83.9 %
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         305 : gp_err_recover(long numerr)
      44             : {
      45         305 :   longjmp(env[s_env.n-1], numerr);
      46             : }
      47             : /* numerr < 0: from SIGINT */
      48             : static void
      49        9115 : gp_pre_recover(long numerr)
      50             : {
      51        9115 :   if (numerr>=0)
      52             :   {
      53        9115 :     out_puts(pariErr, "\n"); pariErr->flush();
      54             :   }
      55        9115 :   longjmp(env[s_env.n-1], numerr);
      56             : }
      57             : 
      58             : static void
      59       95544 : reset_ctrlc(void)
      60             : {
      61             : #if defined(_WIN32) || defined(__CYGWIN32__)
      62             :   win32ctrlc = 0;
      63             : #endif
      64       95544 : }
      65             : 
      66             : static int
      67       59753 : is_silent(char *s) { return s[strlen(s) - 1] == ';'; }
      68             : 
      69             : static int stdin_isatty = 0;
      70             : static int
      71        1602 : is_interactive(void)
      72        1602 : { return pari_infile == stdin && stdin_isatty; }
      73             : 
      74             : /*******************************************************************/
      75             : /**                                                               **/
      76             : /**                        INITIALIZATION                         **/
      77             : /**                                                               **/
      78             : /*******************************************************************/
      79             : static void
      80           2 : print_shortversion(void)
      81             : {
      82           2 :   const ulong mask = (1UL<<PARI_VERSION_SHIFT) - 1;
      83           2 :   ulong n = paricfg_version_code, major, minor, patch;
      84             : 
      85           2 :   patch = n & mask; n >>= PARI_VERSION_SHIFT;
      86           2 :   minor = n & mask; n >>= PARI_VERSION_SHIFT;
      87           2 :   major = n;
      88           2 :   printf("%lu.%lu.%lu\n", major,minor,patch); exit(0);
      89             : }
      90             : 
      91             : static void
      92           2 : usage(char *s)
      93             : {
      94           2 :   printf("### Usage: %s [options] [GP files]\n", s);
      95           2 :   printf("Available options:\n");
      96           2 :   printf("  [-f,--fast]\t\tFast start: do not read .gprc\n");
      97           2 :   printf("  [-q,--quiet]\t\tQuiet mode: do not print banner and history numbers\n");
      98           2 :   printf("  [-s stacksize]\tStart with the PARI stack of given size (in bytes)\n");
      99           2 :   printf("  [--default key=val]\tExecute default(key,val) on startup\n");
     100           2 :   printf("  [--emacs]\t\tRun as if in Emacs shell\n");
     101           2 :   printf("  [--help]\t\tPrint this message\n");
     102           2 :   printf("  [--test]\t\tTest mode. No history, wrap long lines (bench only)\n");
     103           2 :   printf("  [--texmacs]\t\tRun as if using TeXmacs frontend\n");
     104           2 :   printf("  [--version]\t\tOutput version info and exit\n");
     105           2 :   printf("  [--version-short]\tOutput version number and exit\n\n");
     106           2 :   exit(0);
     107             : }
     108             : 
     109             : static void
     110           2 : gp_head(void)
     111             : {
     112           2 :   pari_print_version();
     113           2 :   pari_putc('\n');
     114           2 :   pari_center("Copyright (C) 2000-2018 The PARI Group");
     115           2 :   pari_putc('\n');
     116           2 :   print_text("PARI/GP is free software, covered by the GNU General Public \
     117             : License, and comes WITHOUT ANY WARRANTY WHATSOEVER.");
     118           2 :   pari_puts("\nType ? for help, \\q to quit.\n");
     119           2 :   pari_printf("Type ?%d for how to get moral"
     120             :               " (and possibly technical) support.\n", pari_community());
     121           2 :   if (pari_mainstack->vsize)
     122           0 :     pari_printf("\nparisizemax = %lu, primelimit = %lu",
     123           0 :                 pari_mainstack->vsize,GP_DATA->primelimit);
     124             :   else
     125           4 :     pari_printf("\nparisize = %lu, primelimit = %lu",
     126           4 :                 pari_mainstack->rsize,GP_DATA->primelimit);
     127           2 :   if (pari_mt_nbthreads > 1)
     128           0 :     pari_printf(", nbthreads = %lu", pari_mt_nbthreads);
     129           2 :   pari_putc('\n');
     130           2 : }
     131             : 
     132             : static char *
     133           0 : read_arg(long *nread, char *t, long argc, char **argv)
     134             : {
     135           0 :   long i = *nread;
     136           0 :   if (isdigit((int)*t)) return t;
     137           0 :   if (*t || i==argc) usage(argv[0]);
     138           0 :   *nread = i+1; return argv[i];
     139             : }
     140             : 
     141             : static char *
     142           0 : read_arg_equal(long *nread, char *t, long argc, char **argv)
     143             : {
     144           0 :   long i = *nread;
     145           0 :   if (*t=='=' && isdigit((int)t[1])) return t+1;
     146           0 :   if (*t || i==argc) usage(argv[0]);
     147           0 :   *nread = i+1; return argv[i];
     148             : }
     149             : 
     150             : static void
     151           4 : init_trivial_stack(void)
     152             : {
     153           4 :   const size_t s = 2048;
     154           4 :   pari_mainstack->size = s;
     155           4 :   pari_mainstack->bot = (pari_sp)pari_malloc(s);
     156           4 :   avma = pari_mainstack->top = pari_mainstack->bot + s;
     157           4 : }
     158             : 
     159             : static void
     160           4 : free_trivial_stack(void)
     161             : {
     162           4 :   free((void*)pari_mainstack->bot);
     163           4 : }
     164             : 
     165             : typedef struct { char *key, *val; } pair_t;
     166             : /* If ab of the form key=val, record pair in new stack entry
     167             :  * P[n].key must be freed by caller to avoid memory leak */
     168             : static void
     169           6 : record_default(pari_stack *s_P, char *ab)
     170             : {
     171           6 :   pair_t *P = (pair_t*)*pari_stack_base(s_P);
     172             :   char *k, *v;
     173             :   long n;
     174           6 :   ab = pari_strdup(ab);
     175           6 :   parse_key_val(ab, &k, &v);
     176           6 :   n = pari_stack_new(s_P);
     177           6 :   P[n].key = k;
     178           6 :   P[n].val = v;
     179           6 : }
     180             : static void
     181        1559 : read_opt(pari_stack *p_A, long argc, char **argv)
     182             : {
     183             :   pair_t *P;
     184             :   pari_stack s_P; /* key / value to record default() settings */
     185        1559 :   char *b = NULL, *p = NULL, *s = NULL;
     186        1559 :   ulong f = GP_DATA->flags;
     187        1559 :   long i = 1, initrc = 1;
     188             : 
     189             :   (void)&p; (void)&b; (void)&s; /* -Wall gcc-2.95 */
     190             : 
     191        1559 :   pari_stack_init(&s_P,sizeof(*P),(void**)&P);
     192        1559 :   pari_stack_alloc(&s_P, 64);
     193        1559 :   pari_outfile = stderr;
     194        6218 :   while (i < argc)
     195             :   {
     196        3108 :     char *t = argv[i];
     197             : 
     198        3108 :     if (*t++ != '-') break;
     199        3108 :     i++;
     200             : START:
     201        3108 :     switch(*t++)
     202             :     {
     203           0 :       case 'p': p = read_arg(&i,t,argc,argv); break;
     204           0 :       case 's': s = read_arg(&i,t,argc,argv); break;
     205             :       case 'e':
     206           0 :         f |= gpd_EMACS; if (*t) goto START;
     207           0 :         break;
     208             :       case 'q':
     209        1545 :         f |= gpd_QUIET; if (*t) goto START;
     210        1545 :         break;
     211             :       case 't':
     212           0 :         f |= gpd_TEST; if (*t) goto START;
     213           0 :         break;
     214             :       case 'f':
     215          13 :         initrc = 0; if (*t) goto START;
     216          13 :         break;
     217             :       case 'D':
     218           4 :         if (*t || i == argc) usage(argv[0]);
     219           4 :         record_default(&s_P, argv[i++]);
     220           4 :         break;
     221             :       case '-':
     222        1546 :         if (strcmp(t, "version-short") == 0) { print_shortversion(); exit(0); }
     223        1544 :         if (strcmp(t, "version") == 0) {
     224           4 :           init_trivial_stack(); pari_print_version();
     225           4 :           free_trivial_stack(); exit(0);
     226             :         }
     227        1540 :         if (strcmp(t, "default") == 0) {
     228           2 :           if (i == argc) usage(argv[0]);
     229           2 :           record_default(&s_P, argv[i++]);
     230           2 :           break;
     231             :         }
     232        1538 :         if (strcmp(t, "texmacs") == 0) { f |= gpd_TEXMACS; break; }
     233        1538 :         if (strcmp(t, "emacs") == 0) { f |= gpd_EMACS; break; }
     234        1538 :         if (strcmp(t, "test") == 0) { f |= gpd_TEST; initrc = 0; break; }
     235           6 :         if (strcmp(t, "quiet") == 0) { f |= gpd_QUIET; break; }
     236           4 :         if (strcmp(t, "fast") == 0) { initrc = 0; break; }
     237           2 :         if (strncmp(t, "primelimit",10) == 0) {p = read_arg_equal(&i,t+10,argc,argv); break; }
     238           2 :         if (strncmp(t, "stacksize",9) == 0) {s = read_arg_equal(&i,t+9,argc,argv); break; }
     239             :        /* fall through */
     240             :       default:
     241           2 :         usage(argv[0]);
     242             :     }
     243             :   }
     244        1551 :   if (f & gpd_TEST) stdin_isatty = 0;
     245        1551 :   GP_DATA->flags = f;
     246             : #ifdef READLINE
     247        1551 :   GP_DATA->use_readline = stdin_isatty;
     248             : #endif
     249        1551 :   if (!is_interactive()) GP_DATA->breakloop = 0;
     250        1551 :   if (initrc) gp_initrc(p_A);
     251        1551 :   for ( ; i < argc; i++) pari_stack_pushp(p_A, pari_strdup(argv[i]));
     252             : 
     253             :   /* override the values from gprc */
     254        1551 :   if (p) (void)sd_primelimit(p, d_INITRC);
     255        1551 :   if (s) (void)sd_parisize(s, d_INITRC);
     256        1555 :   for (i = 0; i < s_P.n; i++) {
     257           6 :     setdefault(P[i].key, P[i].val, d_INITRC);
     258           4 :     free((void*)P[i].key);
     259             :   }
     260        1549 :   pari_stack_delete(&s_P);
     261        1549 :   pari_outfile = stdout;
     262        1549 : }
     263             : 
     264             : /*******************************************************************/
     265             : /**                                                               **/
     266             : /**                            TEST MODE                          **/
     267             : /**                                                               **/
     268             : /*******************************************************************/
     269             : static int
     270      178558 : test_is_interactive(void) { return 0; }
     271             : 
     272             : static void
     273       40502 : test_output(GEN z) { init_linewrap(76); gen_output(z); }
     274             : void
     275        1532 : init_test(void)
     276             : {
     277        1532 :   disable_color = 1;
     278        1532 :   init_linewrap(76);
     279        1532 :   pari_errfile = stdout;
     280        1532 :   cb_gp_output = test_output;
     281        1532 :   cb_pari_is_interactive = test_is_interactive;
     282        1532 : }
     283             : 
     284             : /*******************************************************************/
     285             : /**                                                               **/
     286             : /**                   FORMAT GP OUTPUT                            **/
     287             : /**                                                               **/
     288             : /*******************************************************************/
     289             :     /* REGULAR */
     290             : static void
     291           4 : normal_output(GEN z, long n)
     292             : {
     293           4 :   long l = 0;
     294             :   char *s;
     295             :   /* history number */
     296           4 :   if (n)
     297             :   {
     298             :     char buf[64];
     299           4 :     if (!(GP_DATA->flags & gpd_QUIET))
     300             :     {
     301           2 :       term_color(c_HIST);
     302           2 :       sprintf(buf, "%%%ld = ", n);
     303           2 :       pari_puts(buf);
     304           2 :       l = strlen(buf);
     305             :     }
     306             :   }
     307             :   /* output */
     308           4 :   term_color(c_OUTPUT);
     309           4 :   s = GENtostr(z);
     310           4 :   if (GP_DATA->lim_lines)
     311           2 :     lim_lines_output(s, l, GP_DATA->lim_lines);
     312             :   else
     313           2 :     pari_puts(s);
     314           4 :   pari_free(s);
     315           4 :   term_color(c_NONE); pari_putc('\n');
     316           4 : }
     317             : 
     318             : static void
     319       40506 : gp_output(GEN z)
     320             : {
     321       40506 :   if (cb_gp_output) { cb_gp_output(z); return; }
     322           4 :   if (GP_DATA->fmt->prettyp == f_PRETTY)
     323           0 :   { if (tex2mail_output(z, GP_DATA->hist->total)) return; }
     324           4 :   normal_output(z, GP_DATA->hist->total);
     325           4 :   pari_flush();
     326             : }
     327             : 
     328             : static GEN
     329        1549 : gp_main_loop(long ismain)
     330             : {
     331        1549 :   VOLATILE GEN z = gnil;
     332        1549 :   VOLATILE long t = 0;
     333        1549 :   VOLATILE pari_sp av = avma;
     334             :   filtre_t F;
     335        1549 :   Buffer *b = filtered_buffer(&F);
     336             :   struct gp_context rec;
     337             :   long er;
     338        1549 :   if ((er = setjmp(env[s_env.n-1])))
     339             :   { /* recover: jump from error [ > 0 ] or allocatemem [ -1 ] */
     340        9397 :     if (er > 0) { /* true error */
     341        9106 :       if (!(GP_DATA->recover)) exit(1);
     342        9106 :       gp_context_restore(&rec);
     343             :       /* true error not from main instance, let caller sort it out */
     344        9106 :       if (!ismain) { kill_buffers_upto_including(b); return NULL; }
     345             :     } else { /* allocatemem */
     346         291 :       tmp_restore(rec.file.file);
     347         291 :       gp_context_save(&rec);
     348             :     }
     349        9397 :     set_avma(av = pari_mainstack->top);
     350        9397 :     parivstack_reset();
     351        9397 :     kill_buffers_upto(b);
     352        9397 :     pari_alarm(0);
     353             :   }
     354             :   for(;;)
     355             :   {
     356      182918 :     gp_context_save(&rec);
     357       96932 :     if (! gp_read_line(&F, NULL))
     358             :     {
     359        1549 :       if (popinfile()) gp_quit(0);
     360           0 :       if (ismain) continue;
     361           0 :       pop_buffer(); return z;
     362             :     }
     363       95383 :     if (ismain)
     364             :     {
     365       95383 :       reset_ctrlc();
     366       95383 :       timer_start(GP_DATA->T);
     367       95383 :       pari_set_last_newline(1);
     368             :     }
     369       95383 :     if (gp_meta(b->buf,ismain)) continue;
     370       80857 :     z = pari_compile_str(b->buf);
     371       80801 :     z = closure_evalres(z);
     372       71460 :     if (!ismain) continue;
     373             : 
     374       71460 :     t = timer_delay(GP_DATA->T);
     375       71460 :     if (!pari_last_was_newline()) pari_putc('\n');
     376       71460 :     pari_alarm(0);
     377       71460 :     if (t && GP_DATA->chrono)
     378             :     {
     379           0 :       pari_puts("time = ");
     380           0 :       pari_puts(gp_format_time(t));
     381             :     }
     382       71460 :     if (GP_DATA->simplify) z = simplify_shallow(z);
     383       71460 :     pari_add_hist(z, t);
     384       71460 :     if (z != gnil && ! is_silent(b->buf) ) gp_output(z);
     385       71460 :     set_avma(av);
     386       71460 :     parivstack_reset();
     387             :   }
     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 :   set_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(); set_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          84 :   {
     450             :     GEN x;
     451             :     long er, br_status;
     452         147 :     set_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             :   }
     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        1559 : main(int argc, char **argv)
     538             : {
     539             :   char **A;
     540             :   pari_stack s_A;
     541             : 
     542        1559 :   GP_DATA = default_gp_data();
     543        1559 :   pari_stack_init(&s_env, sizeof(*env), (void**)&env);
     544        1559 :   (void)pari_stack_new(&s_env);
     545             : 
     546        1559 :   if (setjmp(env[s_env.n-1]))
     547             :   {
     548           2 :     puts("### Errors on startup, exiting...\n\n");
     549           2 :     exit(1);
     550             :   }
     551             : #ifdef __CYGWIN32__
     552             :   cyg_environment(argc, argv);
     553             : #endif
     554        1559 :   stdin_isatty = pari_stdin_isatty();
     555        1559 :   pari_init_defaults();
     556        1559 :   pari_library_path = DL_DFLT_NAME;
     557        1559 :   pari_stack_init(&s_A,sizeof(*A),(void**)&A);
     558        1559 :   pari_init_opts(1000000 * sizeof(long), 0, INIT_SIGm | INIT_noPRIMEm | INIT_noIMTm);
     559        1559 :   cb_pari_err_recover = gp_err_recover;
     560        1559 :   cb_pari_pre_recover = gp_pre_recover;
     561        1559 :   cb_pari_break_loop = break_loop;
     562        1559 :   cb_pari_is_interactive = is_interactive;
     563             : 
     564        1559 :   read_opt(&s_A, argc,argv);
     565        1549 :   pari_init_primes(GP_DATA->primelimit);
     566             : #ifdef SIGALRM
     567        1549 :   (void)os_signal(SIGALRM,gp_alarm_handler);
     568             : #endif
     569        1549 :   pari_add_module(functions_gp);
     570             : 
     571        1549 :   pari_set_plot_engine(gp_get_plot);
     572        1549 :   cb_pari_quit = gp_quit;
     573        1549 :   cb_pari_whatnow = whatnow;
     574        1549 :   cb_pari_sigint = gp_sigint_fun;
     575        1549 :   cb_pari_handle_exception = gp_handle_exception;
     576        1549 :   cb_pari_ask_confirm = gp_ask_confirm;
     577        1549 :   pari_init_paths();
     578        1549 :   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        1549 :   init_readline();
     584             : #endif
     585        1549 :   if (GP_DATA->flags & gpd_EMACS) init_emacs();
     586        1549 :   if (GP_DATA->flags & gpd_TEXMACS) init_texmacs();
     587             : 
     588        1549 :   timer_start(GP_DATA->T);
     589        1549 :   if (!(GP_DATA->flags & gpd_QUIET)) gp_head();
     590        1549 :   if (GP_DATA->flags & gpd_TEST) init_test();
     591        1549 :   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        1549 :   pari_stack_delete(&s_A);
     602        1549 :   (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           7 :   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        1549 : gp_quit(long code)
     639             : {
     640        1549 :   pari_kill_plot_engine();
     641        1549 :   pari_close();
     642        1549 :   kill_buffers_upto(NULL);
     643        1549 :   if (!(GP_DATA->flags & gpd_QUIET)) pari_puts("Goodbye!\n");
     644        1549 :   if (cb_pari_end_output) cb_pari_end_output();
     645        1549 :   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.13