Thanks for any tips...
strtest.mod (compile with nrnivmodl):
Code: Select all
NEURON {
SUFFIX nothing
}
PARAMETER {
}
ASSIGNED {
}
PROCEDURE strtest () {
VERBATIM
char **pname, str[100];
char** hoc_pgargstr();
pname = hoc_pgargstr(1);
sprintf(str,"goodbye");
printf("first pname is %s\n",*pname);
hoc_assign_str(pname,str);
printf("now pname is %s\n",*pname);
return;
ENDVERBATIM
}
Code: Select all
from neuron import h
print "------------------------------------------------"
print " STARTING TEST"
print "------------------------------------------------"
h("strdef tstr") // declare the string in hoc
print "first, from hoc:"
h("strtest(tstr)") // run the test in hoc -- works properly
print type(h.tstr) # <type 'str'>
print "next, from python:"
h.strtest(h.tstr) # run the same thing from python -> causes a crash
Code: Select all
hoc_assign_str(cpp, buf)
char** cpp, *buf;
{
char* s = *cpp;
*cpp = (char *)emalloc((unsigned)(strlen(buf) + 1));
Strcpy(*cpp, buf);
if (s) {
hoc_free_string(s); // this line causes the crash
}
}