Skip to content

Commit

Permalink
modlunit units.c space not allocated. (#792)
Browse files Browse the repository at this point in the history
* modlunit units.c space not allocated.

* modlunit ignores REPRESENTS syntax as it does not affect units.
  • Loading branch information
nrnhines committed Oct 26, 2020
1 parent 7254be1 commit ef5bc82
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
15 changes: 14 additions & 1 deletion src/modlunit/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ extern int Getc();
%}
D [0-9]
E [Ee][-+]?{D}+
%START O to_eocom to_par to_eoverb to_eol

%START O to_eocom to_par to_eoverb to_eol ontology
%%
<O>[a-zA-Z][a-zA-Z0-9_]*'+ { /*PRIME possibly high order*/
yylval.qp = putintoken(yytext, PRIME, 0);
return PRIME;
}

<O>REPRESENTS {
BEGIN ontology;
}

<ontology>\n {
BEGIN O;
}

<ontology>\[[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_]*\]|[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_]* { /*ONTOLOGY_ID*/
BEGIN O;
}

<O>[a-zA-Z][a-zA-Z0-9_]* { /*NAME*/
Symbol *s;

Expand Down
33 changes: 25 additions & 8 deletions src/modlunit/units.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,29 @@ void unit_stk_clean() {
usp = unit_stack - 1;
}

// allow the outside world to call either modl_units() or unit_init().
static void units_alloc() {
int i;
static int units_alloc_called = 0;
if (!units_alloc_called) {
units_alloc_called = 1;
#if NRN_DYNAMIC_UNITS
for (i=0; i < 2; ++i) {
dynam[i].table = (struct table*)calloc(NTAB, sizeof(struct table));
assert(dynam[i].table);
dynam[i].names = (char*)calloc(NTAB*10, sizeof(char));
assert(dynam[i].names);
switch_units(i);
}
#else
table = (struct table*)calloc(NTAB, sizeof(struct table));
assert(table);
names = (char*)calloc(NTAB*10, sizeof(char));
assert(names);
#endif
}
}

#if MODL||NMODL||HMODL||SIMSYS
extern void unit_init();

Expand All @@ -558,20 +581,13 @@ void modl_units() {
static int first=1;
unitonflag = 1;
if (first) {
units_alloc();
#if NRN_DYNAMIC_UNITS
for (i=0; i < 2; ++i) {
dynam[i].table = (struct table*)calloc(NTAB, sizeof(struct table));
assert(dynam[i].table);
dynam[i].names = (char*)calloc(NTAB*10, sizeof(char));
assert(dynam[i].names);
switch_units(i);
unit_init();
}
#else
table = (struct table*)calloc(NDIM, sizeof(struct table));
assert(table);
names = (char*)calloc(NTAB*10, sizeof(char));
assert(names);
unit_init();
#endif
first = 0;
Expand All @@ -584,6 +600,7 @@ void unit_init() {
char* s;
char buf[1024];
inpfile = (FILE*)0;
units_alloc();
UnitsOn = 1;
s = getenv("MODLUNIT");
if (s) {
Expand Down

0 comments on commit ef5bc82

Please sign in to comment.