D processing a char* allocated by a C module
Carlos Smith
carlos-smith at sympatico.ca
Wed Jun 20 12:40:35 PDT 2007
Hi !
I have a C module, compiled with DMC.
Coming from this C module:
extern (C)
{
int ccleng; // strlen(cctext)
int pos;
char *cctext; // point into an input buffer
int yylex();
}
cctext is a pointer to a buffer allocated by yylex().
the buffer is small and can be freed or overwritten
by yylex();
In the D module, i do:
char[] dtext = toString(cclex);
and dtext get corrupted (not always).
I guess toString do not make a new copy of cctext,
just point to it.
How can i duplicate cctext, in D ? (strdup does not exist ?)
Will the D copy be garbage collected ?
Thanks
More information about the Digitalmars-d-learn
mailing list