Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the C API higher level #2650

Open
wants to merge 78 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
aa0b950
initial partial API
ramcdougal May 14, 2023
05c9126
clang-format changes
ramcdougal May 14, 2023
6e98ba0
nrnpy_set_pr_etal should be extern C
ramcdougal May 14, 2023
8d4e8b5
nrn_call_function leaves results on stack
ramcdougal May 14, 2023
6f5016f
segments, properties
ramcdougal May 14, 2023
bac48bc
including hocdec.h to try to avoid Datum errors on some systems
ramcdougal May 14, 2023
9f92799
sectionlist and allsec hoc_Item getters
ramcdougal May 15, 2023
8cb0757
ran clang-format
ramcdougal May 15, 2023
aff2229
symbol and object introspection
ramcdougal May 15, 2023
4ca7f3c
minor comment edits
ramcdougal May 15, 2023
a005703
symbol table getting and interating
ramcdougal May 15, 2023
93d6ec3
object ref, push
ramcdougal May 15, 2023
fa6a234
Renamed files to avoid having two nrnapi.h files.
ramcdougal May 15, 2023
f9eb4e3
possible fix for no nrnmpi_stubs case
ramcdougal May 15, 2023
f4fcc7d
this really ought to fix the nrnmpi_stubs missing case
ramcdougal May 15, 2023
e6afbb0
neuronapi.cpp no longer uses its .h, that is now a header for 3rd par…
ramcdougal May 15, 2023
20758c8
switched to enum for stack types
ramcdougal May 15, 2023
61560a1
clang-format update
ramcdougal May 16, 2023
1d7d4a3
fixed lost extern C, removed unnecessary externs
ramcdougal May 16, 2023
2e89ba1
test: hh_sim
ramcdougal May 16, 2023
d493476
test: vclamp.cpp
ramcdougal May 16, 2023
1dc2079
fix for vclamp name
ramcdougal May 16, 2023
28842da
needed typedefs for C to be happy
ramcdougal May 16, 2023
31f9a29
test: sections.c
ramcdougal May 16, 2023
bdaaff2
clang-format
ramcdougal May 16, 2023
0a689c8
replaced hoc_Item with new synonym nrn_Item
ramcdougal May 18, 2023
e422638
removed inconsistency in typedef even though it was probably harmless
ramcdougal May 18, 2023
bd606d2
netcon example shows no need for dlsym
ramcdougal May 18, 2023
5631706
support for .so files in addition to .dylib
ramcdougal May 18, 2023
87028b3
removed an excess const
ramcdougal May 18, 2023
0c85738
Add Robert's API tests to CTest (#2365)
olupton Jun 25, 2023
71ab005
Merge branch 'master' into api
ramcdougal Jun 25, 2023
0b8fd3b
fix to header file name of api
ramcdougal Jun 25, 2023
7b48a89
hh_sim and sections work with handles
ramcdougal Jun 25, 2023
6e929b6
rename stack_types_t per @olupton
ramcdougal Jun 25, 2023
5ea5168
format
ramcdougal Jun 25, 2023
8e758c6
netcon works, standardization of names
ramcdougal Jun 25, 2023
963bd75
name adjustments to end with verb
ramcdougal Jun 25, 2023
9638da3
name fixes
ramcdougal Jun 25, 2023
0173e02
replace param_handle with param
ramcdougal Jun 25, 2023
244b2fd
working vclamp
ramcdougal Jun 27, 2023
3a1b3e3
unified API property functions
ramcdougal Jun 27, 2023
2fd9e34
getters use const args
ramcdougal Jun 27, 2023
30214f8
forgot to commit sections
ramcdougal Jun 27, 2023
4de562d
vector_capacity now on const obj
ramcdougal Jun 27, 2023
ba8a0a0
Merge branch 'master' into api
ramcdougal Sep 24, 2023
219df3b
Several improvements
ferdonline Sep 27, 2023
77ad3cf
Merge branch 'master' into api
ferdonline Dec 13, 2023
8f9eff0
Make tests link against nrniv_lib, no dlopen
ferdonline Dec 13, 2023
f662ba1
Address sonar lint reservations
ferdonline Dec 14, 2023
a328651
Make comparisons be part of the test and account for fp innacuraciesa
ferdonline Dec 15, 2023
000178d
Tests to find ref files
ferdonline Dec 16, 2023
ab1b152
api: Make tests resilient to accumulated errors
ferdonline Dec 18, 2023
2c3421b
Merge branch 'master' into api
ferdonline Dec 20, 2023
4bc12b0
Use in-test ref result, depending on NRN_ENABLE_CORENEURON
ferdonline Dec 22, 2023
89cafa6
Merge branch 'master' into api
pramodk Jan 3, 2024
75b1f37
Use free for allocated c strings
ferdonline Jan 3, 2024
a5fbaab
Dont alloc Section Item to heap as its not used.
ferdonline Jan 3, 2024
e0a593b
A higher level API for function calls
ferdonline Jan 4, 2024
648999e
Working version of the High Level API
ferdonline Jan 5, 2024
4c2c120
Cleanup
ferdonline Jan 6, 2024
509d520
Documentation and more cleanup
ferdonline Jan 7, 2024
1f6273c
Address intel compiler complain
ferdonline Jan 7, 2024
b6e4a95
Address intel compiler complain
ferdonline Jan 7, 2024
dd1569a
No more manual stack pop. Methods pop the right type and return `Result`
ferdonline Jan 9, 2024
d23f891
Creating catch unit tests for API
ferdonline Jan 10, 2024
37c4ecf
Make return value pop its own func. Investigate other internal funcs
ferdonline Jan 11, 2024
15f91ee
Free memb_func[].dparam_semantics
ferdonline Jan 16, 2024
c1f44bc
Switch dparam_semantics to unique_ptr (no raw!)
ferdonline Jan 18, 2024
b08dcd7
Memb_list to do its memory management
ferdonline Jan 21, 2024
3c31399
Memb_list to be aware of its potential "view" condition and not free
ferdonline Jan 22, 2024
4fc381a
Back pdata free
ferdonline Jan 22, 2024
de0ddf6
Merge branch 'master' into api
ferdonline Jan 22, 2024
6fcb352
nrn_init to better initialize mpi
ferdonline Jan 23, 2024
f6aaf6f
Addressed a number of warnings, inc avoidiing potential double free
ferdonline Jan 24, 2024
193003f
Addressed sonarcloud issues
ferdonline Jan 28, 2024
be7261e
Merge branch 'master' into api
ferdonline Jan 28, 2024
deb29fb
Merge branch 'api' into api-hl
ferdonline Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ endfunction()
set(NRN_RUN_FROM_BUILD_DIR_ENV "NEURONHOME=${PROJECT_BINARY_DIR}/share/nrn"
"NRNHOME=${PROJECT_BINARY_DIR}")
prepend_to_var(PATH "${PROJECT_BINARY_DIR}/bin")
prepend_to_var(LD_LIBRARY_PATH "${PROJECT_BINARY_DIR}/lib")
if(APPLE)
prepend_to_var(DYLD_LIBRARY_PATH "${PROJECT_BINARY_DIR}/lib")
else()
prepend_to_var(LD_LIBRARY_PATH "${PROJECT_BINARY_DIR}/lib")
endif()
if(NRN_ENABLE_CORENEURON)
list(APPEND NRN_RUN_FROM_BUILD_DIR_ENV "CORENRNHOME=${PROJECT_BINARY_DIR}")
endif()
Expand Down
2 changes: 2 additions & 0 deletions cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(STRUCTURED_HEADER_FILES_TO_INSTALL
set(HEADER_FILES_TO_INSTALL
nrniv/backtrace_utils.h
nrniv/bbsavestate.h
nrniv/neuronapi.h
nrnmpi/nrnmpidec.h
nrnoc/cabvars.h
nrnoc/md1redef.h
Expand Down Expand Up @@ -236,6 +237,7 @@ set(NRNIV_FILE_LIST
ndatclas.cpp
netpar.cpp
nonlinz.cpp
neuronapi.cpp
nrncore_write.cpp
nrncore_write/callbacks/nrncore_callbacks.cpp
nrncore_write/data/cell_group.cpp
Expand Down
23 changes: 23 additions & 0 deletions src/ivoc/ocjump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ bool OcJump::execute(const char* stmt, Object* ob) {
}
}

void OcJump::execute_throw_on_exception(Object* obj, Symbol* sym, int narg) {
saved_state before{};
try_catch_depth_increment tell_children_we_will_catch{};
try {
hoc_call_ob_proc(obj, sym, narg);
} catch (...) {
before.restore();
throw;
}
}

void OcJump::execute_throw_on_exception(Symbol* sym, int narg) {
// NOTE: return value is left on the stack
saved_state before{};
try_catch_depth_increment tell_children_we_will_catch{};
try {
hoc_pushx(hoc_call_func(sym, narg));
} catch (...) {
before.restore();
throw;
}
}

void* OcJump::fpycall(void* (*f)(void*, void*), void* a, void* b) {
saved_state before{};
try_catch_depth_increment tell_children_we_will_catch{};
Expand Down
5 changes: 4 additions & 1 deletion src/ivoc/ocjump.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ struct Object;
union Objectdata;
struct Symlist;

/** @brief How many NEURON try { ... } catch(...) { ... } blocks are in the call stack.
/** @brief How many NEURON try { ... } catch(...) { ... } blocks are in the call
* stack.
*
* Errors inside NEURON are triggered using hoc_execerror, which ultimately
* throws an exception. To replicate the old logic, we sometimes need to insert
Expand Down Expand Up @@ -40,4 +41,6 @@ struct OcJump {
static bool execute(Inst* p);
static bool execute(const char*, Object* ob = NULL);
static void* fpycall(void* (*) (void*, void*), void*, void*);
static void execute_throw_on_exception(Symbol* sym, int narg);
static void execute_throw_on_exception(Object* obj, Symbol* sym, int narg);
};
10 changes: 4 additions & 6 deletions src/neuron/container/soa_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ struct field_data<Tag, FieldImplementation::RuntimeVariable> {
*/
template <may_cause_reallocation might_reallocate, typename Callable>
Callable for_each_vector(Callable callable) {
for (auto i = 0; i < m_storage.size(); ++i) {
for (size_t i = 0; i < m_storage.size(); ++i) {
callable(m_tag, m_storage[i], i, m_array_dims[i]);
}
if constexpr (might_reallocate == may_cause_reallocation::Yes) {
Expand All @@ -479,7 +479,7 @@ struct field_data<Tag, FieldImplementation::RuntimeVariable> {
*/
template <typename Callable>
Callable for_each_vector(Callable callable) const {
for (auto i = 0; i < m_storage.size(); ++i) {
for (size_t i = 0; i < m_storage.size(); ++i) {
callable(m_tag, m_storage[i], i, m_array_dims[i]);
}

Expand All @@ -491,11 +491,11 @@ struct field_data<Tag, FieldImplementation::RuntimeVariable> {
[[nodiscard]] field_index translate_legacy_index(int legacy_index) const {
int total{};
auto const num_fields = m_tag.num_variables();
for (auto field = 0; field < num_fields; ++field) {
for (size_t field = 0; field < num_fields; ++field) {
auto const array_dim = m_array_dims[field];
if (legacy_index < total + array_dim) {
auto const array_index = legacy_index - total;
return {field, array_index};
return {static_cast<int>(field), array_index};
}
total += array_dim;
}
Expand Down Expand Up @@ -594,8 +594,6 @@ class AccumulateMemoryUsage {
std::vector<detail::index_column_tag::type> const& vec,
int field_index,
int array_dim) {
auto element_size = sizeof(detail::index_column_tag::type);

m_usage.stable_identifiers.size = vec.size() * (sizeof(vec[0]) + sizeof(size_t*));
m_usage.stable_identifiers.capacity = m_usage.stable_identifiers.size +
(vec.capacity() - vec.size()) * sizeof(vec[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/neuron/model_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Model {
*/
template <typename Callable>
void apply_to_mechanisms(Callable const& callable) {
for (auto type = 0; type < m_mech_data.size(); ++type) {
for (size_t type = 0; type < m_mech_data.size(); ++type) {
if (!m_mech_data[type]) {
continue;
}
Expand All @@ -45,7 +45,7 @@ struct Model {

template <typename Callable>
void apply_to_mechanisms(Callable const& callable) const {
for (auto type = 0; type < m_mech_data.size(); ++type) {
for (size_t type = 0; type < m_mech_data.size(); ++type) {
if (!m_mech_data[type]) {
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ set_property(
APPEND
PROPERTY COMPILE_DEFINITIONS OOP=1 HOC=1 INTERVIEWS=1)

set_property(
SOURCE neuronapi.cpp
APPEND
PROPERTY COMPILE_OPTIONS -Wall)

set_property(
SOURCE ${NRN_IVOC_SRC_FILES}
APPEND
Expand Down