From efd572273a46aced899fc62620c9b9f7558c9f10 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 22 Nov 2024 10:20:36 +0100 Subject: [PATCH 1/2] Remove typedef from nrnpython --- src/nrnpython/grids.h | 53 ++++++++++++++----------------------- src/nrnpython/hoccontext.h | 4 +-- src/nrnpython/nrnpy_hoc.cpp | 4 +-- src/nrnpython/nrnpy_nrn.cpp | 40 ++++++++++++++-------------- src/nrnpython/rxd.cpp | 12 ++++----- src/nrnpython/rxd.h | 32 +++++++++++----------- 6 files changed, 66 insertions(+), 79 deletions(-) diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 0d43a3f1fe..75b82afe29 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -31,7 +31,7 @@ and Flux_pair structs and their respective functions #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) -typedef struct Hybrid_data { +struct Hybrid_data { long num_1d_indices; long* indices1d; long* num_3d_indices_per_1d_seg; @@ -39,12 +39,7 @@ typedef struct Hybrid_data { double* rates; double* volumes1d; double* volumes3d; -} Hybrid_data; - -typedef struct Flux_pair { - double* flux; // Value of flux - int grid_index; // Location in grid -} Flux; +}; struct Concentration_Pair { neuron::container::data_handle destination; /* memory loc to transfer concentration to @@ -58,19 +53,11 @@ struct Current_Triple { double scale_factor; }; -typedef void (*ReactionRate)(double**, - double**, - double**, - double*, - double*, - double*, - double*, - double**, - double); -typedef void (*ECSReactionRate)(double*, double*, double*, double*); -typedef struct Reaction { - struct Reaction* next; - ECSReactionRate reaction; +using ReactionRate = void (double**, double**, double**, double*, double*, double*, double*, double**, double); +using ECSReactionRate = void (double*, double*, double*, double*); +struct Reaction { + Reaction* next; + ECSReactionRate* reaction; unsigned int num_species_involved; unsigned int num_params_involved; double** species_states; @@ -78,18 +65,18 @@ typedef struct Reaction { unsigned int region_size; uint64_t* mc3d_indices_offsets; double** mc3d_mults; -} Reaction; +}; -typedef struct { +struct AdiLineData { double* copyFrom; long copyTo; -} AdiLineData; +}; -typedef struct { +struct BoundaryConditions { /*TODO: Support for mixed boundaries and by edge (maybe even by voxel)*/ unsigned char type; double value; -} BoundaryConditions; +}; class Grid_node { public: @@ -237,7 +224,7 @@ class ECS_Grid_node: public Grid_node { double* set_rxd_currents(int, int*, PyHocObject**); }; -typedef struct ECSAdiDirection { +struct ECSAdiDirection { void (*ecs_dg_adi_dir)(ECS_Grid_node*, const double, const int, @@ -248,16 +235,16 @@ typedef struct ECSAdiDirection { double* states_in; double* states_out; int line_size; -} ECSAdiDirection; +}; -typedef struct ECSAdiGridData { +struct ECSAdiGridData { int start, stop; double* state; ECS_Grid_node* g; int sizej; ECSAdiDirection* ecs_adi_dir; double* scratchpad; -} ECSAdiGridData; +}; class ICS_Grid_node: public Grid_node { public: @@ -335,7 +322,7 @@ class ICS_Grid_node: public Grid_node { double* set_rxd_currents(int, int*, PyHocObject**); }; -typedef struct ICSAdiDirection { +struct ICSAdiDirection { void (*ics_dg_adi_dir)(ICS_Grid_node* g, int, int, @@ -357,10 +344,10 @@ typedef struct ICSAdiDirection { double dc; double* dcgrid; double d; -} ICSAdiDirection; +}; -typedef struct ICSAdiGridData { +struct ICSAdiGridData { // Start and stop node indices for lines int line_start, line_stop; // Where to start in the ordered_nodes array @@ -374,7 +361,7 @@ typedef struct ICSAdiGridData { double* diag; double* u_diag; // double* deltas; -} ICSAdiGridData; +}; /***** GLOBALS *******************************************************************/ extern double* dt_ptr; // Universal ∆t diff --git a/src/nrnpython/hoccontext.h b/src/nrnpython/hoccontext.h index d6f79f4a46..85daea8fbe 100644 --- a/src/nrnpython/hoccontext.h +++ b/src/nrnpython/hoccontext.h @@ -17,11 +17,11 @@ extern Symlist* hoc_symlist; hc_restore_(hc_); \ } -typedef struct HocContext { +struct HocContext { Object* obj; Objectdata* obd; Symlist* sl; -} HocContext; +}; static HocContext* hc_save_and_set_to_top_(HocContext* hc) { hc->obj = hoc_thisobject; diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index e0932452f1..42cdcd7945 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -129,10 +129,10 @@ PyTypeObject* hocobject_type; static PyObject* hocobj_call(PyHocObject* self, PyObject* args, PyObject* kwrds); -typedef struct { +struct hocclass { PyTypeObject head; Symbol* sym; -} hocclass; +}; static int hocclass_init(hocclass* cls, PyObject* args, PyObject* kwds) { if (PyType_Type.tp_init((PyObject*) cls, args, kwds) < 0) { diff --git a/src/nrnpython/nrnpy_nrn.cpp b/src/nrnpython/nrnpy_nrn.cpp index f2b43f57d7..4989d578ab 100644 --- a/src/nrnpython/nrnpy_nrn.cpp +++ b/src/nrnpython/nrnpy_nrn.cpp @@ -44,25 +44,25 @@ extern int hocobj_pushargs(PyObject*, std::vector&); extern void hocobj_pushargs_free_strings(std::vector&); -typedef struct { +struct NPyAllSegOfSecIter { PyObject_HEAD NPySecObj* pysec_; int allseg_iter_; -} NPyAllSegOfSecIter; +}; -typedef struct { +struct NPySegOfSecIter { PyObject_HEAD NPySecObj* pysec_; int seg_iter_; -} NPySegOfSecIter; +}; -typedef struct { +struct NPySegObj { PyObject_HEAD NPySecObj* pysec_; double x_; -} NPySegObj; +}; -typedef struct { +struct NPyMechObj { PyObject_HEAD NPySegObj* pyseg_; Prop* prop_; @@ -70,43 +70,43 @@ typedef struct { // wrapper. neuron::container::non_owning_identifier_without_container prop_id_; int type_; -} NPyMechObj; +}; -typedef struct { +struct NPyMechOfSegIter { PyObject_HEAD NPyMechObj* pymech_; -} NPyMechOfSegIter; +}; -typedef struct { +struct NPyMechFunc { PyObject_HEAD NPyMechObj* pymech_; NPyDirectMechFunc* f_; -} NPyMechFunc; +}; -typedef struct { +struct NPyVarOfMechIter { PyObject_HEAD NPyMechObj* pymech_; Symbol* msym_; int i_; -} NPyVarOfMechIter; +}; -typedef struct { +struct NPyRVItr { PyObject_HEAD NPyMechObj* pymech_; int index_; -} NPyRVItr; +}; -typedef struct { +struct NPyRangeVar { PyObject_HEAD NPyMechObj* pymech_; Symbol* sym_; int isptr_; int attr_from_sec_; // so section.xraxial[0] = e assigns to all segments. -} NPyRangeVar; +}; -typedef struct { +struct NPyOpaquePointer { PyObject_HEAD -} NPyOpaquePointer; +}; PyTypeObject* psection_type; static PyTypeObject* pallseg_of_sec_iter_type; diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 8284a3d49f..5dfb4f949e 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -41,7 +41,7 @@ extern double* dt_ptr; extern double* t_ptr; -fptr _setup, _initialize, _setup_matrices, _setup_units; +fptr *_setup, *_initialize, *_setup_matrices, *_setup_units; extern NrnThread* nrn_threads; /*intracellular diffusion*/ @@ -474,20 +474,20 @@ static void mul(int nnonzero, } } -extern "C" NRN_EXPORT void set_setup(const fptr setup_fn) { +extern "C" NRN_EXPORT void set_setup(const fptr* setup_fn) { _setup = setup_fn; } -extern "C" NRN_EXPORT void set_initialize(const fptr initialize_fn) { +extern "C" NRN_EXPORT void set_initialize(const fptr* initialize_fn) { _initialize = initialize_fn; set_num_threads(NUM_THREADS); } -extern "C" NRN_EXPORT void set_setup_matrices(fptr setup_matrices) { +extern "C" NRN_EXPORT void set_setup_matrices(fptr* setup_matrices) { _setup_matrices = setup_matrices; } -extern "C" NRN_EXPORT void set_setup_units(fptr setup_units) { +extern "C" NRN_EXPORT void set_setup_units(fptr* setup_units) { _setup_units = setup_units; } @@ -861,7 +861,7 @@ extern "C" NRN_EXPORT void register_rate(int nspecies, int nmult, double* mult, PyHocObject** vptrs, - ReactionRate f) { + ReactionRate* f) { int i, j, k, idx, ecs_id, ecs_index, ecs_offset; unsigned char counted; Grid_node* g; diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 7371bca493..ec5c3afab5 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -7,39 +7,39 @@ #define SPECIES_ABSENT -1 #define PREFETCH 4 -typedef void (*fptr)(void); +using fptr = void (void); // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match // the one in ocptrvector.h -typedef struct { +struct ReactSet { Reaction* reaction; int idx; -} ReactSet; +}; -typedef struct { +struct ReactGridData { ReactSet* onset; ReactSet* offset; -} ReactGridData; +}; -typedef struct { +struct CurrentData { Grid_node* g; int onset, offset; double* val; -} CurrentData; +}; -typedef struct SpeciesIndexList { +struct SpeciesIndexList { int id; double atolscale; int* indices; int length; struct SpeciesIndexList* next; -} SpeciesIndexList; +}; -typedef struct ICSReactions { - ReactionRate reaction; +struct ICSReactions { + ReactionRate* reaction; int num_species; int num_regions; int num_params; @@ -63,23 +63,23 @@ typedef struct ICSReactions { int* mc_flux_idx; double** vptrs; struct ICSReactions* next; -} ICSReactions; +}; -typedef struct TaskList { +struct TaskList { void* (*task)(void*); void* args; void* result; struct TaskList* next; -} TaskList; +}; -typedef struct TaskQueue { +struct TaskQueue { std::condition_variable task_cond, waiting_cond; std::mutex task_mutex, waiting_mutex; std::vector exit; int length{}; struct TaskList* first; struct TaskList* last; -} TaskQueue; +}; extern "C" void set_num_threads(const int); void _fadvance(void); From 80cf5238a2e642b2c8a3aee7d598bc3858f42132 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 22 Nov 2024 10:50:47 +0100 Subject: [PATCH 2/2] format --- src/nrnpython/grids.h | 5 +++-- src/nrnpython/rxd.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 75b82afe29..ea5f467fdd 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -53,8 +53,9 @@ struct Current_Triple { double scale_factor; }; -using ReactionRate = void (double**, double**, double**, double*, double*, double*, double*, double**, double); -using ECSReactionRate = void (double*, double*, double*, double*); +using ReactionRate = + void(double**, double**, double**, double*, double*, double*, double*, double**, double); +using ECSReactionRate = void(double*, double*, double*, double*); struct Reaction { Reaction* next; ECSReactionRate* reaction; diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index ec5c3afab5..dcfb0353d3 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -7,7 +7,7 @@ #define SPECIES_ABSENT -1 #define PREFETCH 4 -using fptr = void (void); +using fptr = void(void); // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match // the one in ocptrvector.h