NEURON
hoc.cpp File Reference
#include <../../nrnconf.h>
#include "hocstr.h"
#include "equation.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include "parse.hpp"
#include "hocparse.h"
#include "oc_ansi.h"
#include "ocjump.h"
#include "ocfunc.h"
#include "ocmisc.h"
#include "nrnmpi.h"
#include "nrnpy.h"
#include "nrnfilewrap.h"
#include "../nrniv/backtrace_utils.h"
#include "../utils/profile/profiler_interface.h"
#include <cfenv>
#include <condition_variable>
#include <filesystem>
#include <iostream>
#include <mutex>
#include <thread>
#include <utility>
#include "utils/logger.hpp"
#include <ctype.h>
#include <signal.h>

Go to the source code of this file.

Classes

struct  signal_handler_guard
 
struct  temporarily_change< T >
 

Macros

#define FEEXCEPT   (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)
 
#define READLINE   1
 
#define CHAR   char
 
#define TMPBUFSIZE   512
 
#define CBUFSIZE   512
 
#define EPS   hoc_epsilon
 
#define HAS_SIGPIPE   1
 
#define YYNEEDMORE   -3
 

Typedefs

using SignalType = void(int)
 

Functions

static void matherr1 (void)
 
void nrn_feenableexcept ()
 
void start_profile (int i)
 
void add_profile (int i)
 
void pr_profile (void)
 
char * readline (const char *prompt)
 
void rl_deprep_terminal (void)
 
void add_history (const char *)
 
static int follow (int expect, int ifyes, int ifno)
 
static int Getc (NrnFILEWrap *fp)
 
static void unGetc (int c, NrnFILEWrap *fp)
 
static int backslash (int c)
 
void nrn_exit (int i)
 
static void sigpipe_handler (int sig)
 
int getnb (void)
 
static char * optarray (char *buf)
 
int yylex (void)
 
void hoc_arayinstal (void)
 
int hoc_arayinfo_install (Symbol *sp, int nsub)
 
void hoc_freearay (Symbol *sp)
 
void hoc_free_arrayinfo (Arrayinfo *a)
 
void hoc_defnonly (const char *s)
 
void hoc_show_errmess_always (void)
 
void hoc_execerror_mes (const char *s, const char *t, int prnt)
 
void hoc_execerror (const char *s, const char *t)
 
void onintr (int)
 
void hoc_coredump_on_error (void)
 
void print_bt ()
 
void fpecatch (int)
 
 __attribute__ ((noreturn)) void sigsegvcatch(int)
 
int hoc_pid (void)
 
void hoc_main1_init (const char *pname, const char **envp)
 
HocStrhocstr_create (size_t size)
 
static CHARfgets_unlimited_nltrans (HocStr *s, NrnFILEWrap *f, int nltrans)
 
char * fgets_unlimited (HocStr *s, NrnFILEWrap *f)
 
void hocstr_delete (HocStr *hs)
 
void hocstr_resize (HocStr *hs, size_t n)
 
void hocstr_copy (HocStr *hs, const char *buf)
 
static int hoc_run1 ()
 
int hoc_main1 (int argc, const char **argv, const char **envp)
 
void hoc_final_exit (void)
 
void hoc_quit (void)
 
int hoc_moreinput ()
 
static void set_signals (void)
 
static void restore_signals (void)
 
static void nrn_inputbuf_getline (void)
 
void oc_save_input_info (const char **i1, int *i2, int *i3, NrnFILEWrap **i4)
 
void oc_restore_input_info (const char *i1, int i2, int i3, NrnFILEWrap *i4)
 
int hoc_oc (const char *buf)
 
int hoc_oc (const char *buf, std::ostream &os)
 
void hoc_warning (const char *s, const char *t)
 
int hoc_yyparse (void)
 
CHARhoc_fgets_unlimited (HocStr *bufstr, NrnFILEWrap *f)
 
int hoc_get_line (void)
 
void hoc_help (void)
 

Variables

int nrnignore
 
int nrn_global_argc
 
char ** nrn_global_argv
 
int nrn_inpython_
 
int(* p_nrnpy_pyrun )(const char *fname)
 
int nrn_mpiabort_on_error_ {1}
 
int nrn_feenableexcept_ = 0
 
int nrn_nobanner_
 
int hoc_pipeflag
 
int hoc_usegui
 
HocStrhoc_tmpbuf
 
HocStrhoc_cbufstr
 
const char * hoc_promptstr
 
static CHARhoc_cbuf
 
CHARhoc_ctp
 
int hoc_ictp
 
char * neuron_home
 
int hoc_print_first_instance
 
NrnFILEWraphoc_fin
 
const char * progname
 
int hoc_lineno
 
int hoc_intset
 
int hoc_indef
 
const char * infile
 
size_t hoc_xopen_file_size_
 
char * hoc_xopen_file_
 
const char ** gargv
 
int gargc
 
static int c = '\n'
 
static int eos
 
static int debug_message_
 
int hoc_execerror_messages
 
int nrn_try_catch_nest_depth {0}
 How many NEURON try { ... More...
 
int yystart
 
static int coredump
 
int nrn_istty_
 
int hoc_main1_inited_
 
static SignalTypesignals [4]
 
static const char * nrn_inputbufptr
 
int hoc_in_yyparse = 0
 
int hoc_interviews = 0
 

Macro Definition Documentation

◆ CBUFSIZE

#define CBUFSIZE   512

Definition at line 136 of file hoc.cpp.

◆ CHAR

#define CHAR   char

Definition at line 126 of file hoc.cpp.

◆ EPS

#define EPS   hoc_epsilon

Definition at line 147 of file hoc.cpp.

◆ FEEXCEPT

#define FEEXCEPT   (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)

Definition at line 63 of file hoc.cpp.

◆ HAS_SIGPIPE

#define HAS_SIGPIPE   1

Definition at line 194 of file hoc.cpp.

◆ READLINE

#define READLINE   1

Definition at line 108 of file hoc.cpp.

◆ TMPBUFSIZE

#define TMPBUFSIZE   512

Definition at line 135 of file hoc.cpp.

◆ YYNEEDMORE

#define YYNEEDMORE   -3

Definition at line 219 of file hoc.cpp.

Typedef Documentation

◆ SignalType

using SignalType = void(int)

Definition at line 1156 of file hoc.cpp.

Function Documentation

◆ __attribute__()

__attribute__ ( (noreturn)  )

Definition at line 749 of file hoc.cpp.

◆ add_history()

void add_history ( const char *  )

◆ add_profile()

void add_profile ( int  i)

Definition at line 100 of file hoc.cpp.

◆ backslash()

static int backslash ( int  c)
static

Definition at line 488 of file hoc.cpp.

◆ fgets_unlimited()

char* fgets_unlimited ( HocStr s,
NrnFILEWrap f 
)

Definition at line 838 of file hoc.cpp.

◆ fgets_unlimited_nltrans()

static CHAR * fgets_unlimited_nltrans ( HocStr s,
NrnFILEWrap f,
int  nltrans 
)
static

Definition at line 1571 of file hoc.cpp.

◆ follow()

static int follow ( int  expect,
int  ifyes,
int  ifno 
)
static

Definition at line 498 of file hoc.cpp.

◆ fpecatch()

void fpecatch ( int  )

Definition at line 734 of file hoc.cpp.

◆ Getc()

static int Getc ( NrnFILEWrap fp)
static

Definition at line 1398 of file hoc.cpp.

◆ getnb()

int getnb ( void  )

Definition at line 204 of file hoc.cpp.

◆ hoc_arayinstal()

void hoc_arayinstal ( void  )

Definition at line 508 of file hoc.cpp.

◆ hoc_coredump_on_error()

void hoc_coredump_on_error ( void  )

Definition at line 674 of file hoc.cpp.

◆ hoc_defnonly()

void hoc_defnonly ( const char *  s)

Definition at line 590 of file hoc.cpp.

◆ hoc_fgets_unlimited()

CHAR* hoc_fgets_unlimited ( HocStr bufstr,
NrnFILEWrap f 
)

Definition at line 1567 of file hoc.cpp.

◆ hoc_help()

void hoc_help ( void  )

Definition at line 1723 of file hoc.cpp.

◆ hoc_main1_init()

void hoc_main1_init ( const char *  pname,
const char **  envp 
)

Definition at line 783 of file hoc.cpp.

◆ hoc_moreinput()

int hoc_moreinput ( )

Definition at line 1022 of file hoc.cpp.

◆ hoc_quit()

void hoc_quit ( void  )

Definition at line 975 of file hoc.cpp.

◆ hoc_run1()

static int hoc_run1 ( )
static

Definition at line 1204 of file hoc.cpp.

◆ hoc_show_errmess_always()

void hoc_show_errmess_always ( void  )

Definition at line 599 of file hoc.cpp.

◆ hoc_yyparse()

int hoc_yyparse ( void  )

Definition at line 1429 of file hoc.cpp.

◆ hocstr_copy()

void hocstr_copy ( HocStr hs,
const char *  buf 
)

Definition at line 855 of file hoc.cpp.

◆ hocstr_create()

HocStr* hocstr_create ( size_t  size)

Definition at line 828 of file hoc.cpp.

◆ hocstr_delete()

void hocstr_delete ( HocStr hs)

Definition at line 842 of file hoc.cpp.

◆ hocstr_resize()

void hocstr_resize ( HocStr hs,
size_t  n 
)

Definition at line 847 of file hoc.cpp.

◆ matherr1()

static void matherr1 ( void  )
static

Definition at line 64 of file hoc.cpp.

◆ nrn_feenableexcept()

void nrn_feenableexcept ( void  )

Definition at line 84 of file hoc.cpp.

◆ nrn_inputbuf_getline()

static void nrn_inputbuf_getline ( void  )
static

Definition at line 1283 of file hoc.cpp.

◆ oc_restore_input_info()

void oc_restore_input_info ( const char *  i1,
int  i2,
int  i3,
NrnFILEWrap i4 
)

Definition at line 1307 of file hoc.cpp.

◆ oc_save_input_info()

void oc_save_input_info ( const char **  i1,
int *  i2,
int *  i3,
NrnFILEWrap **  i4 
)

Definition at line 1301 of file hoc.cpp.

◆ onintr()

void onintr ( int  )

Definition at line 663 of file hoc.cpp.

◆ optarray()

static char* optarray ( char *  buf)
static

Definition at line 230 of file hoc.cpp.

◆ pr_profile()

void pr_profile ( void  )

Definition at line 101 of file hoc.cpp.

◆ print_bt()

void print_bt ( )

Definition at line 680 of file hoc.cpp.

◆ readline()

char* readline ( const char *  prompt)

◆ restore_signals()

static void restore_signals ( void  )
static

Definition at line 1168 of file hoc.cpp.

◆ rl_deprep_terminal()

void rl_deprep_terminal ( void  )

◆ set_signals()

static void set_signals ( void  )
static

Definition at line 1159 of file hoc.cpp.

◆ sigpipe_handler()

static void sigpipe_handler ( int  sig)
static

Definition at line 198 of file hoc.cpp.

◆ start_profile()

void start_profile ( int  i)

Definition at line 99 of file hoc.cpp.

◆ unGetc()

static void unGetc ( int  c,
NrnFILEWrap fp 
)
static

Definition at line 1420 of file hoc.cpp.

◆ yylex()

int yylex ( void  )

Definition at line 251 of file hoc.cpp.

Variable Documentation

◆ c

int c = '\n'
static

Definition at line 169 of file hoc.cpp.

◆ coredump

int coredump
static

Definition at line 672 of file hoc.cpp.

◆ debug_message_

int debug_message_
static

Definition at line 598 of file hoc.cpp.

◆ eos

int eos
static

Definition at line 228 of file hoc.cpp.

◆ gargc

int gargc

Definition at line 168 of file hoc.cpp.

◆ gargv

const char** gargv

Definition at line 167 of file hoc.cpp.

◆ hoc_cbuf

CHAR* hoc_cbuf
static

Definition at line 140 of file hoc.cpp.

◆ hoc_cbufstr

HocStr* hoc_cbufstr

Definition at line 138 of file hoc.cpp.

◆ hoc_ctp

CHAR* hoc_ctp

Definition at line 141 of file hoc.cpp.

◆ hoc_execerror_messages

int hoc_execerror_messages

Definition at line 607 of file hoc.cpp.

◆ hoc_fin

NrnFILEWrap* hoc_fin

Definition at line 152 of file hoc.cpp.

◆ hoc_ictp

int hoc_ictp

Definition at line 142 of file hoc.cpp.

◆ hoc_in_yyparse

int hoc_in_yyparse = 0

Definition at line 1427 of file hoc.cpp.

◆ hoc_indef

int hoc_indef

Definition at line 163 of file hoc.cpp.

◆ hoc_interviews

int hoc_interviews = 0

Definition at line 1476 of file hoc.cpp.

◆ hoc_intset

int hoc_intset

Definition at line 162 of file hoc.cpp.

◆ hoc_lineno

int hoc_lineno

Definition at line 156 of file hoc.cpp.

◆ hoc_main1_inited_

int hoc_main1_inited_

Definition at line 780 of file hoc.cpp.

◆ hoc_pipeflag

int hoc_pipeflag

Definition at line 120 of file hoc.cpp.

◆ hoc_print_first_instance

int hoc_print_first_instance
extern

Definition at line 39 of file hoc_oop.cpp.

◆ hoc_promptstr

const char* hoc_promptstr

Definition at line 139 of file hoc.cpp.

◆ hoc_tmpbuf

HocStr* hoc_tmpbuf

Definition at line 137 of file hoc.cpp.

◆ hoc_usegui

int hoc_usegui

Definition at line 121 of file hoc.cpp.

◆ hoc_xopen_file_

char* hoc_xopen_file_
extern

Definition at line 159 of file fileio.cpp.

◆ hoc_xopen_file_size_

size_t hoc_xopen_file_size_
extern

Definition at line 158 of file fileio.cpp.

◆ infile

const char* infile

Definition at line 164 of file hoc.cpp.

◆ neuron_home

char* neuron_home
extern

Definition at line 227 of file hoc_init.cpp.

◆ nrn_feenableexcept_

int nrn_feenableexcept_ = 0

Definition at line 82 of file hoc.cpp.

◆ nrn_global_argc

int nrn_global_argc

Definition at line 45 of file hoc.cpp.

◆ nrn_global_argv

char** nrn_global_argv

Definition at line 46 of file hoc.cpp.

◆ nrn_inputbufptr

const char* nrn_inputbufptr
static

Definition at line 1282 of file hoc.cpp.

◆ nrn_istty_

int nrn_istty_

Definition at line 778 of file hoc.cpp.

◆ nrn_nobanner_

int nrn_nobanner_

Definition at line 119 of file hoc.cpp.

◆ nrn_try_catch_nest_depth

int nrn_try_catch_nest_depth {0}

How many NEURON try { ...

} catch(...) { ... } blocks are in the call stack.

Errors inside NEURON are triggered using hoc_execerror, which ultimately throws an exception. To replicate the old logic, we sometimes need to insert a try/catch block only if there is no try/catch block less deeply nested on the call stack. This global variable tracks how many such blocks are currently present on the stack.

Definition at line 608 of file hoc.cpp.

◆ p_nrnpy_pyrun

int(* p_nrnpy_pyrun) (const char *fname) ( const char *  fname)

Definition at line 53 of file hoc.cpp.

◆ progname

const char* progname

Definition at line 155 of file hoc.cpp.

◆ signals

SignalType* signals[4]
static

Definition at line 1157 of file hoc.cpp.

◆ yystart

int yystart

Definition at line 609 of file hoc.cpp.