From 3256bc3ac2eb4c85c23f36e680e648df59e14000 Mon Sep 17 00:00:00 2001 From: Michael Hines Date: Thu, 6 Aug 2026 19:53:11 -0400 Subject: [PATCH] Fix child.mod/childa.mod for NEURON 8.2 and 9 C++ MOD translation. Use NRN_VERSION_GTEQ(9,0,0) wrappers: accessors on 9+, direct Section child/sibling on older NEURON. Convert K&R definitions to prototypes and drop local zero-arg redeclarations of chk_access and hoc_parse_stmt that break under C++. --- child.mod | 20 +++++++++++++++----- childa.mod | 20 ++++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/child.mod b/child.mod index 96382e6..db3b79c 100644 --- a/child.mod +++ b/child.mod @@ -13,14 +13,24 @@ } VERBATIM - static subtree(sec, sym) Section* sec; Symbol* sym; { + /* NEURON >= 9: Section is incomplete in MOD translation units; use accessors. + NEURON < 9: full Section definition is available (section.h). */ + #if NRN_VERSION_GTEQ(9, 0, 0) + #define SEC_CHILD(s) _nrn_mechanism_get_child(s) + #define SEC_SIBLING(s) _nrn_mechanism_get_sibling(s) + #else + #define SEC_CHILD(s) ((s)->child) + #define SEC_SIBLING(s) ((s)->sibling) + #endif + + static void subtree(Section* sec, Symbol* sym) { Section* child; nrn_pushsec(sec); /* move these three (sec becomes child) */ hoc_run_stmt(sym); /* into the loop to do only the first level */ nrn_popsec(); - for (child = sec->child; child; child = child->sibling) { + for (child = SEC_CHILD(sec); child; child = SEC_SIBLING(child)) { subtree(child, sym); } } @@ -29,8 +39,8 @@ PROCEDURE subtree_traverse_all() { VERBATIM { - Section* chk_access(); - Symbol* hoc_parse_stmt(); + /* Do not redeclare chk_access / hoc_parse_stmt here: in C++ (NEURON 9+) + a local Symbol* hoc_parse_stmt(); is a zero-arg overload that hides the real API. */ Symlist* symlist = (Symlist*)0; subtree(chk_access(), hoc_parse_stmt(gargstr(1), &symlist)); /* if following not executed (ie hoc error in statement), @@ -38,4 +48,4 @@ hoc_free_list(&symlist); } ENDVERBATIM - } \ No newline at end of file + } diff --git a/childa.mod b/childa.mod index ca45638..d39c41c 100644 --- a/childa.mod +++ b/childa.mod @@ -13,12 +13,20 @@ NEURON { } VERBATIM -static subtree(sec, sym) Section* sec; Symbol* sym; { +/* NEURON >= 9: Section is incomplete in MOD translation units; use accessors. + NEURON < 9: full Section definition is available (section.h). */ +#if NRN_VERSION_GTEQ(9, 0, 0) +#define SEC_CHILD(s) _nrn_mechanism_get_child(s) +#define SEC_SIBLING(s) _nrn_mechanism_get_sibling(s) +#else +#define SEC_CHILD(s) ((s)->child) +#define SEC_SIBLING(s) ((s)->sibling) +#endif + +static void subtree(Section* sec, Symbol* sym) { Section* child; - - - for (child = sec->child; child; child = child->sibling) { + for (child = SEC_CHILD(sec); child; child = SEC_SIBLING(child)) { nrn_pushsec(child); /* move these three (sec becomes child) */ hoc_run_stmt(sym); /* into the loop to do only the first level */ nrn_popsec(); @@ -30,8 +38,8 @@ ENDVERBATIM PROCEDURE subtree_traverse() { VERBATIM { - Section* chk_access(); - Symbol* hoc_parse_stmt(); + /* Do not redeclare chk_access / hoc_parse_stmt here: in C++ (NEURON 9+) + a local Symbol* hoc_parse_stmt(); is a zero-arg overload that hides the real API. */ Symlist* symlist = (Symlist*)0; subtree(chk_access(), hoc_parse_stmt(gargstr(1), &symlist)); /* if following not executed (ie hoc error in statement),