From: Luc Moulinier on
Hello !

I've dined a structure with an element of type:
int **SeqT

When I reallocate it with 'realloc" :
for (i=0;i<nseq;i++) {
BiotextPtr->SeqT[i] = (int *)realloc((char *)BiotextPtr->SeqT[i],
(lgs+1)*sizeof(int));
}

it works , but with :
BiotextPtr->SeqT[i] = (int *)Tcl_Realloc((char *)BiotextPtr-
>SeqT[i],(lgs+1)*sizeof(int));

the program crashes with an allocation error ....

Did I miss something ?

Thanks for helping me !

Luc
From: Uwe Klein on
Luc Moulinier wrote:
> Hello !
>
> I've dined a structure with an element of type:
> int **SeqT
>
> When I reallocate it with 'realloc" :
> for (i=0;i<nseq;i++) {
> BiotextPtr->SeqT[i] = (int *)realloc((char *)BiotextPtr->SeqT[i],
> (lgs+1)*sizeof(int));
> }
>
> it works , but with :
> BiotextPtr->SeqT[i] = (int *)Tcl_Realloc((char *)BiotextPtr-
>
>>SeqT[i],(lgs+1)*sizeof(int));
>
>
> the program crashes with an allocation error ....
>
> Did I miss something ?
>
> Thanks for helping me !
>
> Luc
<manpage Tcl_Realloc>
Tcl_AttemptRealloc will not cause the Tcl interpreter to panic if the
memory allocation fails. If the allocation fails, these functions will
return NULL. Note that on some platforms, attempting to allocate a
block of memory will also cause these functions to return NULL.
</>

do you get that "interpreter panic" as an error?

would imho indicate that the (re)alloc failed,
test your realloc loop for a NULL return ? maybe it fails too ?

uwe

From: Luc Moulinier on
Thanks for your help !

The interpreter does not have the time to panic ! It crashes saying :
alloc: invalid block: 0x10000160: 0 0
Abort (core dumped)

As you suggested, I tried to check if Tcl_AttemptRealloc returns a
NULL, but again , it crashes before reutrning.

The strangest thing is that if you just change the Tcl_Realloc into
"realloc", the programs goes fine with the right allocation,
everything's perfect ...

luc
From: Tim Baker on
"Luc Moulinier" wrote:
> Hello !
>
> I've dined a structure with an element of type:
> int **SeqT
>
> When I reallocate it with 'realloc" :
> for (i=0;i<nseq;i++) {
> BiotextPtr->SeqT[i] = (int *)realloc((char *)BiotextPtr->SeqT[i],
> (lgs+1)*sizeof(int));
> }
>
> it works , but with :
> BiotextPtr->SeqT[i] = (int *)Tcl_Realloc((char *)BiotextPtr-
>>SeqT[i],(lgs+1)*sizeof(int));
>
> the program crashes with an allocation error ....
>
> Did I miss something ?
>
> Thanks for helping me !
>
> Luc


Make sure you aren't mixing different memory allocators.
If you use alloc() then use realloc().
If you use Tcl_Alloc() then use Tcl_Realloc().

-- Tim Baker
From: APN on
On Jul 9, 11:29 pm, "Tim Baker" <tnbak...(a)shaw.ca> wrote:
> "Luc Moulinier" wrote:
> > Hello !
>
> > I've dined a structure with an element of type:
> > int **SeqT
>
> > When I reallocate it with 'realloc" :
> >  for (i=0;i<nseq;i++) {
> >    BiotextPtr->SeqT[i]   = (int *)realloc((char *)BiotextPtr->SeqT[i],
> > (lgs+1)*sizeof(int));
> >  }
>
> > it works , but with :
> >    BiotextPtr->SeqT[i]   = (int *)Tcl_Realloc((char *)BiotextPtr-
> >>SeqT[i],(lgs+1)*sizeof(int));
>
> > the program crashes with an allocation error ....
>
> > Did I miss something ?
>
> > Thanks for helping me !
>
> > Luc
>
> Make sure you aren't mixing different memory allocators.
> If you use alloc() then use realloc().
> If you use Tcl_Alloc() then use Tcl_Realloc().
>
> -- Tim Baker

Also, make sure, at least on Windows that you have built with a
consistent C runtime (ie. don't mix the debug and release C runtime
libraries)

/Ashok