Skip to content

Commit

Permalink
Merge branch 'master' into redef_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeplf authored Sep 4, 2024
2 parents 0a4cc74 + 9373eef commit d8d62f1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
67 changes: 39 additions & 28 deletions src/nmodl/nocpout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,35 +428,10 @@ extern void nrn_promote(Prop*, int, int);\n\
defs_list,
"double get_loc_point_process(void*); return (get_loc_point_process(_vptr));\n}\n");
}
/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}
std::string hoc_setdata_arg = point_process ? "void*" : "";
Sprintf(buf, "static void _hoc_setdata(%s);\n", hoc_setdata_arg.c_str());
Lappendstr(defs_list, buf);

/* functions */
Lappendstr(defs_list, "/* connect user functions to hoc names */\n");
Expand Down Expand Up @@ -755,6 +730,42 @@ extern void nrn_promote(Prop*, int, int);\n\
}
}

/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
if (!artificial_cell) {
Lappendstr(defs_list,
"Node * _node = _nrn_mechanism_access_node(_prop);\n"
"v = _nrn_mechanism_access_voltage(_node);\n");
}
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}


/******** what normally goes into cabvars.h structures */

/*declaration of the range variables names to HOC */
Expand Down
5 changes: 5 additions & 0 deletions src/nrnoc/membfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ void Memb_func::invoke_initialize(neuron::model_sorted_token const& sorted_token
long& _nrn_mechanism_access_alloc_seq(Prop* prop) {
return prop->_alloc_seq;
}

Node* _nrn_mechanism_access_node(Prop* prop) {
return prop->node;
}

double& _nrn_mechanism_access_a(Node* node) {
return node->a();
}
Expand Down
1 change: 1 addition & 0 deletions src/nrnoc/membfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ namespace _get {
// See https://github.com/neuronsimulator/nrn/issues/2234 for context of how this might be done
// better in future...
[[nodiscard]] long& _nrn_mechanism_access_alloc_seq(Prop*);
[[nodiscard]] Node* _nrn_mechanism_access_node(Prop* prop);
[[nodiscard]] double& _nrn_mechanism_access_a(Node*);
[[nodiscard]] double& _nrn_mechanism_access_b(Node*);
[[nodiscard]] double& _nrn_mechanism_access_d(Node*);
Expand Down
7 changes: 5 additions & 2 deletions src/nrnoc/section.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,20 @@ struct Node {
#include "hocdec.h" /* Prop needs Datum and Datum needs Symbol */
#endif


#define PROP_PY_INDEX 10
struct Prop {
// Working assumption is that we can safely equate "Prop" with "instance
// of a mechanism" apart from a few special cases like CABLESECTION
Prop(short type)
: _type{type} {
Prop(Node* node, short type)
: node(node)
, _type{type} {
if (type != CABLESECTION) {
m_mech_handle = neuron::container::Mechanism::owning_handle{
neuron::model().mechanism_data(type)};
}
}
Node* node; /* The node this property belongs to. */
Prop* next; /* linked list of properties */
short _type; /* type of membrane, e.g. passive, HH, etc. */
int dparam_size; /* for notifying hoc_free_val_array */
Expand Down
2 changes: 1 addition & 1 deletion src/nrnoc/treeset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Prop* prop_alloc(Prop** pp, int type, Node* nd) {
nrn_alloc_node_ = nd; // this might be null
v_structure_change = 1;
current_prop_list = pp;
auto* p = new Prop{static_cast<short>(type)};
auto* p = new Prop{nd, static_cast<short>(type)};
p->next = *pp;
p->ob = nullptr;
p->_alloc_seq = -1;
Expand Down

0 comments on commit d8d62f1

Please sign in to comment.