NEURON
nrnpy.h
Go to the documentation of this file.
1 #pragma once
2 #include <string_view>
3 #include <vector>
4 /**
5  * Declarations of global symbols in NEURON that have to be populated with python-version-specific
6  * values when dynamic Python is enabled. These are set by the nrnpython_reg_real function, and
7  * defined in nrnpy.cpp.
8  */
9 struct Object;
10 // PyObject is a typedef, so we can't forward-declare it as a type. This pattern is common enough in
11 // the wild that we hope Python won't dare change it.
12 struct _object;
13 typedef _object PyObject;
14 struct _ts;
15 typedef _ts PyThreadState;
16 struct Section;
17 struct Symbol;
18 namespace neuron::python {
19 /**
20  * @brief Collection of pointers to functions with python-version-specific implementations.
21  *
22  * When dynamic Python is enabled, these are filled in from a python-version-specific
23  * libnrnpythonX.Y library and then called from python-version-agnostic code inside NEURON.
24  */
25 struct impl_ptrs {
26  Object* (*callable_with_args)(Object*, int narg){};
27  double (*call_func)(Object*, int, int*){};
28  std::vector<char> (*call_picklef)(const std::vector<char>&, int narg){};
30  void (*cmdtool)(Object*, int type, double x, double y, int kd){};
31  int (*guigetstr)(Object*, char**){};
32  double (*guigetval)(Object*){};
33  Object** (*gui_helper)(const char* name, Object* obj){};
34  Object** (*gui_helper3)(const char* name, Object* obj, int handle_strptr){};
35  char** (*gui_helper3_str)(const char*, Object*, int){};
36  void (*guisetval)(Object*, double){};
37  int (*hoccommand_exec)(Object*){};
38  int (*hoccommand_exec_strret)(Object*, char*, int){};
39  void (*hoc_nrnpython)(){};
40  PyObject* (*ho2po)(Object*){};
41  void (*hpoasgn)(Object*, int){};
42  void (*interpreter_set_path)(std::string_view){};
43  int (*interpreter_start)(int){};
44  Object* (*mpi_alltoall_type)(int, int){};
45  double (*object_to_double)(Object*){};
46  void* (*opaque_obj2pyobj)(Object*){};
47  Object* (*pickle2po)(const std::vector<char>&){};
48  Object* (*po2ho)(PyObject*){};
49  std::vector<char> (*po2pickle)(Object*){};
50  double (*praxis_efun)(Object* pycallable, Object* hvec){};
51  int (*pysame)(Object* o1, Object* o2){};
52  void (*py2n_component)(Object*, Symbol*, int, int){};
54  PyThreadState* (*save_thread)(){};
55  // Such a common pattern it gets a wrapper
56  Object** try_gui_helper(const char* name, Object* obj) const {
57  if (gui_helper) {
58  return gui_helper(name, obj);
59  } else {
60  return nullptr;
61  }
62  }
63 };
64 /**
65  * @brief Collection of pointers to functions with python-version-specific implementations.
66  *
67  * This is defined in nrnpy.cpp.
68  */
69 extern impl_ptrs methods;
70 } // namespace neuron::python
71 extern Symbol* nrnpy_pyobj_sym_;
static int narg()
Definition: ivocvect.cpp:121
const char * name
Definition: init.cpp:16
impl_ptrs methods
Collection of pointers to functions with python-version-specific implementations.
Definition: nrnpy.cpp:21
short type
Definition: cabvars.h:10
Symbol * nrnpy_pyobj_sym_
Definition: hoc_oop.cpp:25
_ts PyThreadState
Definition: nrnpy.h:14
_object PyObject
Definition: nrnpy.h:12
Definition: hocdec.h:173
Definition: model.h:47
Collection of pointers to functions with python-version-specific implementations.
Definition: nrnpy.h:25
Object ** try_gui_helper(const char *name, Object *obj) const
Definition: nrnpy.h:56
void(* cmdtool)(Object *, int type, double x, double y, int kd)
Definition: nrnpy.h:30
int(* guigetstr)(Object *, char **)
Definition: nrnpy.h:31
std::vector< char >(* call_picklef)(const std::vector< char > &, int narg)
Definition: nrnpy.h:28
void(* hpoasgn)(Object *, int)
Definition: nrnpy.h:41
double(* object_to_double)(Object *)
Definition: nrnpy.h:45
std::vector< char >(* po2pickle)(Object *)
Definition: nrnpy.h:49
void(* restore_thread)(PyThreadState *)
Definition: nrnpy.h:53
int(* hoccommand_exec_strret)(Object *, char *, int)
Definition: nrnpy.h:38
Object **(* gui_helper)(const char *name, Object *obj)
Definition: nrnpy.h:33
double(* guigetval)(Object *)
Definition: nrnpy.h:32
void(* py2n_component)(Object *, Symbol *, int, int)
Definition: nrnpy.h:52
double(* call_func)(Object *, int, int *)
Definition: nrnpy.h:27
void(* interpreter_set_path)(std::string_view)
Definition: nrnpy.h:42
void(* guisetval)(Object *, double)
Definition: nrnpy.h:36
int(* pysame)(Object *o1, Object *o2)
Definition: nrnpy.h:51
double(* praxis_efun)(Object *pycallable, Object *hvec)
Definition: nrnpy.h:50
int(* hoccommand_exec)(Object *)
Definition: nrnpy.h:37
void(* call_python_with_section)(Object *, Section *)
Definition: nrnpy.h:29
int(* interpreter_start)(int)
Definition: nrnpy.h:43
void(* hoc_nrnpython)()
Definition: nrnpy.h:39