[Ecls-list] ecl_read_from_cstring() and ecl_read_from_cstring_safe() don't work
Kamil Shakirov
kamils80 at gmail.com
Tue Aug 18 10:43:36 UTC 2009
On Tue, 2009-08-18 at 12:00 +0200, Juan Jose Garcia-Ripoll wrote:
> On Tue, Aug 18, 2009 at 11:25 AM, Kamil Shakirov<kamils80 at gmail.com> wrote:
> > In the latest ECL 9.8.x the function c_string_to_object(s) was replaced
> > with ecl_read_from_cstring(S) and ecl_read_from_cstring_safe(S, V)
> > macros.
>
> Yes, the intention is that there is the possibility to signal errors
> and not just ignore them.
>
> > I tested my app with the latest CVS HEAD and found that with the correct
> > input expression, ecl_read_from_cstring(S) returns a cl_object that
> > can't be evaluated with si_safe_eval() and ecl_read_from_cstring_safe(S,
> > V) always return V. c_string_to_object(S) works as expected in 9.7.x.
>
> I would say that is impossible because c_string_to_object is just an
> alias for ecl_read_from_string. From ecl/src/h/external.h
>
> #define ecl_read_from_cstring(s)
> si_string_to_object(1,make_constant_base_string(s))
> #define ecl_read_from_cstring_safe(s,v)
> si_string_to_object(2,make_constant_base_string(s),(v))
> #define c_string_to_object ecl_read_from_cstring
>
Yes, I first checked external.h before submitting this issue. After
c_string_to_object()/ecl_read_from_string() had failed I tried to use
ecl_read_from_cstring_safe() that also failed returning the second
parameter even if the input expression is correct.
I used this simple app to evaluate expressions:
/* ecl_test.c */
#include <ecl/ecl.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char line[256];
cl_object read_error, eval_error, form;
cl_boot(argc, argv);
read_error = cl_gensym(0);
eval_error = cl_gensym(0);
while(1) {
printf("\nREPL> ");
if(!fgets(line, sizeof(line), stdin)) {
break;
}
line[strlen(line)-1] = '\0';
form = ecl_read_from_cstring(line);
/* form = ecl_read_from_cstring_safe(line, read_error); */
if(form == read_error) {
printf("failed to read: %s\n", line);
}
else {
cl_object obj = cl_safe_eval(form, Cnil, eval_error);
if(obj == eval_error) {
printf("failed to evaluate: %s\n", line);
}
else {
cl_object out = cl_princ_to_string(1, obj);
printf("%s\n", (const char*)out->base_string.self);
}
}
}
cl_shutdown();
return 0;
}
> Could you print the output of ecl_read_from_cstring() ?
If I evaluate form with ecl_read_from_cstring() I get:
REPL> (list 1 2 3)
failed to evaluate: (list 1 2 3)
If I use ecl_read_from_cstring_safe() I get:
REPL> (list 1 2 3)
failed to read: (list 1 2 3)
In both cases it doesn't enter debugger.
> Does
> si_string_to_object get called when you use c_string_to_object() ?
Yes, it gets called by ecl_read_from_cstring() macro.
> Juanjo
>
--
--wbr.
More information about the ecl-devel
mailing list