On Wed, 23 Nov 2005, David Berry wrote:
> I've taken the liberty of committing some changes to dat_get0c in
> fortran_interface.c. I was having spurious memory corruption problems
> (which even managed to crash valgrind). I eventually tracked them down to
> the use of cnfCreim to allocate memory for the c string in dat_get0c
Thanks. The *big* problem is that HDS C interface does not return nul
terminated strings! I think at least datGet0C should do a cnfImprt before
returning the string.
I also think that datGet1C should do that as well. In fact, I was thinking
that datGet1C should be the routine to return a char** (and datPut1C
should provide it).
Does anyone have an opinion on the termination?
I'll be happy with:
* datGet0C always terminates
* datGetC terminate the last character in the string
* datGet1C terminates the last character but a (CNF?) routine
is made available for converting it to/from char**
> within fortran_interface.c. I've changed this to cnfCreat and also added a
> call to cnfExprt to export the C string to the F77 string.
Great. Sorry about that. I changed so much code that it's easy to miss
things.
>
> BTW, I see you use "free" within fortran_interface.c to free strings
> allocated by CNF functions. Shouldn't cnfFree be used rather than free?
>
Ah ha. This issue was raised by me a while back but garnered no comment.
cnfFree is incredibly inefficient for the cnfCr* routines since they are
not registered pointers. free() is much quicker. I was considering adding
a cnfTempFree routine that did just that but gave us control to tweak.
In fact, your not about HDS and malloc made me think about adding the
garbage collector again. It would make AST, CNF and HDS much faster since
they spend a lot of time doing tiny little mallocs. I'm toying with adding
a starMalloc/starFree macro/function in it's own little package. HDS and
CNF would then use that routine internally which could either use the ast
style safe malloc or the hairy garbage collector (and would have to have a
starmem_link command too).
--
Tim Jenness
JAC software
http://www.jach.hawaii.edu/~timj
|