NEURON
nrnpython.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef _WIN64
4 #define MS_WIN64
5 #define MS_WIN32
6 #define MS_WINDOWS
7 #endif
10 #include <../../nrnconf.h>
11 
12 #if defined(USE_PYTHON)
13 #undef _POSIX_C_SOURCE
14 #undef _XOPEN_SOURCE
15 #include "nrnwrap_Python.h"
16 
17 #include "nrn_export.hpp"
18 
19 #endif /*USE_PYTHON*/
20 
21 #include <string_view>
22 
23 #define PyString_FromString PyUnicode_FromString
24 #define PyInt_Check PyLong_Check
25 #define PyInt_CheckExact PyLong_CheckExact
26 #define PyInt_AS_LONG PyLong_AsLong
27 #define PyInt_AsLong PyLong_AsLong
28 #define PyInt_FromLong PyLong_FromLong
29 
30 static_assert(PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9),
31  "Python >= 3.9 required");
32 
33 extern PyObject* nrnpy_hoc_pop(const char* mes);
34 extern int nrnpy_numbercheck(PyObject*);
35 
36 #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ > __SIZEOF_LONG__
37 #define castptr2long (long) (long long)
38 #else
39 #define castptr2long (long)
40 #endif
41 
42 
43 /*
44 Because python types have so many methods, attempt to do all set and get
45 using a PyHocObject which has different amounts filled in as the information
46 is gathered with a view toward ultimately making a call to hoc_object_component.
47 That requires that array indices or function arguments are on the stack.
48 The major variant is that we may be at the top level. The function arg
49 case is easy since they all come as a tuple in the call method. The
50 array indices come sequentially with a series of calls to the
51 sequence method. A nice side effect of intermediate objects is the extra
52 efficiency of reuse that avoids symbol lookup. Sadly, the scalar case does
53 not give this since the value is set/get instead of returning the
54 intermediate.
55 */
56 namespace PyHoc {
57 enum ObjectType {
59  HocObject = 1,
60  HocFunction = 2, // function or TEMPLATE
61  HocArray = 3,
62  HocRefNum = 4,
63  HocRefStr = 5,
64  HocRefObj = 6,
68  HocArrayIncomplete = 10, // incomplete pointer to a hoc array (similar to HocArray)
69  HocRefPStr = 11,
70 };
72 } // namespace PyHoc
73 // Declare methods that are used in different translation units within one libnrnpythonX.Y
74 struct Object;
75 struct Section;
77 struct NPySecObj {
78  PyObject_HEAD
80  char* name_;
82 };
89 
90 struct Prop;
91 struct Symbol;
92 
95 extern "C" PyObject* nrn_hocobj_ptr(double*);
#define sec
Definition: md1redef.h:20
IteratorState
Definition: nrnpython.h:71
@ NextNotLast
Definition: nrnpython.h:71
@ Last
Definition: nrnpython.h:71
@ Begin
Definition: nrnpython.h:71
ObjectType
Definition: nrnpython.h:57
@ HocScalarPtr
Definition: nrnpython.h:67
@ HocRefObj
Definition: nrnpython.h:64
@ HocRefNum
Definition: nrnpython.h:62
@ HocForallSectionIterator
Definition: nrnpython.h:65
@ HocArrayIncomplete
Definition: nrnpython.h:68
@ HocRefStr
Definition: nrnpython.h:63
@ HocObject
Definition: nrnpython.h:59
@ HocArray
Definition: nrnpython.h:61
@ HocRefPStr
Definition: nrnpython.h:69
@ HocTopLevelInterpreter
Definition: nrnpython.h:58
@ HocSectionListIterator
Definition: nrnpython.h:66
@ HocFunction
Definition: nrnpython.h:60
_object PyObject
Definition: nrnpy.h:12
PyObject * hocobj_call_arg(int)
Definition: nrnpy_hoc.cpp:778
Object * nrnpy_pyobject_in_obj(PyObject *)
Definition: nrnpy_p2h.cpp:91
int nrn_is_hocobj_ptr(PyObject *, neuron::container::data_handle< double > &)
Definition: nrnpy_hoc.cpp:970
Object * nrnpy_po2ho(PyObject *)
Definition: nrnpy_hoc.cpp:592
bool nrn_chk_data_handle(const neuron::container::data_handle< double > &)
Definition: nrnpy_hoc.cpp:182
int nrnpy_numbercheck(PyObject *)
Definition: nrnpy_hoc.cpp:542
int nrn_pointer_assign(Prop *, Symbol *, PyObject *)
Definition: nrnpy_nrn.cpp:2308
PyObject * nrnpy_ho2po(Object *)
Definition: nrnpy_hoc.cpp:566
int nrnpy_ho_eq_po(Object *, PyObject *)
Definition: nrnpy_p2h.cpp:61
PyObject * nrnpy_hoc2pyobject(Object *ho)
Definition: nrnpy_p2h.cpp:77
neuron::container::generic_data_handle * nrnpy_setpointer_helper(PyObject *, PyObject *)
Definition: nrnpy_nrn.cpp:2626
PyObject * nrn_hocobj_handle(neuron::container::data_handle< double > d)
Definition: nrnpy_hoc.cpp:957
PyObject * nrn_hocobj_ptr(double *)
Definition: nrnpy_hoc.cpp:966
PyObject * nrnpy_hoc_pop(const char *mes)
Definition: nrnpy_hoc.cpp:620
NPySecObj * newpysechelp(Section *sec)
Definition: nrnpy_nrn.cpp:1043
PyObject_HEAD Section * sec_
Definition: nrnpython.h:79
char * name_
Definition: nrnpython.h:80
PyObject * cell_weakref_
Definition: nrnpython.h:81
Definition: hocdec.h:173
Definition: section.h:231
Definition: model.h:47
Non-template stable handle to a generic value.