6 #include <InterViews/session.h> 25 #if DARWIN || defined(__linux__) 26 extern const char* path_prefix_to_libnrniv();
36 #if NRNPYTHON_DYNAMICLOAD 37 int nrnpy_site_problem;
45 static int augmented = 0;
48 int err = PyRun_SimpleString(
"import sys");
50 #if defined(__linux__) || defined(DARWIN) 52 std::string lib = std::string(path_prefix_to_libnrniv());
53 #else // not defined(__linux__) || defined(DARWIN) 55 #endif //not defined(__linux__) || defined(DARWIN) 56 if (
isDirExist(lib + std::string(
"python/neuron"))) {
57 std::string cmd = std::string(
"sys.path.append('") + lib +
"python')";
58 err = PyRun_SimpleString(cmd.c_str());
61 err = PyRun_SimpleString(
"sys.path.insert(0, '')");
72 char* cmd =
new char[strlen(fname) + 40];
73 sprintf(cmd,
"exec(open(\"%s\").read(), globals())", fname);
74 int err = PyRun_SimpleString(cmd);
82 #else // MINGW not defined 85 int const code = PyRun_AnyFile(fp, fname);
89 std::cerr <<
"Could not open " << fname << std::endl;
92 #endif // MINGW not defined 99 for (
int i = 0;
i <
argc; ++
i) {
110 wcargv = (
wchar_t**)PyMem_Malloc(
sizeof(
wchar_t*) *
argc);
112 fprintf(stderr,
"out of memory\n");
115 for (
int i = 0;
i <
argc; ++
i) {
118 fprintf(stderr,
"out of memory\n");
125 size_t sz = mbstowcs(
NULL, s, 0);
126 wchar_t* ws =
new wchar_t[sz + 1];
127 int count = mbstowcs(ws, s, sz + 1);
144 if (b == 1 && !started) {
152 char * _p_pyhome =
getenv(
"PYTHONHOME");
153 if (_p_pyhome ==
NULL) {
160 #if NRNPYTHON_DYNAMICLOAD 162 nrnpy_site_problem = 0;
173 if (b == 0 && started) {
174 PyGILState_STATE gilsav = PyGILState_Ensure();
180 if (b == 2 && started) {
190 bool python_error_encountered{
false};
193 if (strcmp(arg,
"-c") == 0 && i + 1 < nrn_global_argc) {
195 python_error_encountered =
true;
198 }
else if (strlen(arg) > 3 && strcmp(arg + strlen(arg) - 3,
".py") == 0) {
200 python_error_encountered =
true;
209 PyRun_InteractiveLoop(
hoc_fin,
"stdin");
211 return python_error_encountered;
223 retval = PyRun_SimpleString(
gargstr(1)) == 0;
231 hoc_cbufstr->
buf[0] =
'\0';
236 size_t n = strlen(hoc_cbufstr->
buf) + 1;
238 char*
p =
static_cast<char*
>(PyMem_RawMalloc(n));
242 strcpy(p, hoc_cbufstr->
buf);
244 }
else if (r == EOF) {
245 char*
p =
static_cast<char*
>(PyMem_RawMalloc(2));
#define HocContextRestore
void nrnpy_augment_path()
char * neuronhome_forward()
int(* p_nrnpy_pyrun)(const char *)
int nrnpy_pyrun(const char *)
Execute a Python script.
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
bool isDirExist(const std::string &path)
static PyObject *(* nrnpy_reg_[])()
int nrnpython_start(int)
Start the Python interpreter.
static void copy_argv_wcargv(int argc, char **argv)
int const size_t const size_t n
static const char * fname(const char *name)
char * getenv(const char *s)
fprintf(stderr, "Don't know the location of params at %p\, pp)
static char * nrnpython_getline(FILE *, FILE *, const char *)
static void del_wcargv(int argc)
static wchar_t * mywstrdup(char *s)
const char * hoc_promptstr