Skip to content

Commit 17d23c8

Browse files
committed
read_from_chars module/op confusion, re issue #909
1 parent b8d79ef commit 17d23c8

File tree

4 files changed

+10
-42
lines changed

4 files changed

+10
-42
lines changed

library/builtins.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
:- help(predicate_property(+callable,+term), [iso(true)]).
1919

20+
read_from_chars(Cs, T) :-
21+
read_term_from_chars(Cs, T, []).
22+
23+
:- help(read_from_chars(+chars,?term), [iso(false)]).
24+
2025
predicate_property(P, A) :-
2126
nonvar(P), atom(A), !,
2227
must_be(P, callable, predicate_property/2, _),

library/charsio.pl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
char_type/2,
33
get_line_to_chars/3,
44
get_single_char/1,
5-
get_n_chars/3,
6-
read_from_chars/2
5+
get_n_chars/3
76
]).
87

98
get_single_char(C) :-
@@ -22,11 +21,6 @@
2221
Cs0 = Cs
2322
).
2423

25-
read_from_chars(Cs, T) :-
26-
read_term_from_chars(Cs, T, []).
27-
28-
:- help(read_from_chars(+chars,?term), [iso(false)]).
29-
3024
fabricate_var_name(VarType, VarName, N) :-
3125
char_code('A', AC),
3226
LN is N mod 26 + AC,

src/bif_streams.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,20 +4186,13 @@ static bool bif_sys_read_term_from_chars_4(query *q)
41864186
return throw_error(q, p_chars, p_chars_ctx, "type_error", "character");
41874187
}
41884188

4189-
str->p = parser_create(q->st.m);
4190-
str->p->flags = q->st.m->flags;
4191-
str->p->fp = str->fp;
4192-
parser_reset(str->p);
4193-
str->p->srcptr = src;
4194-
41954189
if (!src || !*src) {
4196-
parser_destroy(str->p);
41974190
cell tmp;
41984191
make_atom(&tmp, g_eof_s);
41994192
return unify(q, p_term, p_term_ctx, &tmp, q->st.cur_ctx);
42004193
}
42014194

4202-
bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, NULL);
4195+
bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, src);
42034196

42044197
if (ok != true) {
42054198
if (!is_string(p_chars))
@@ -4232,8 +4225,6 @@ static bool bif_sys_read_term_from_chars_4(query *q)
42324225
make_atom(&tmp, g_nil_s);
42334226
}
42344227

4235-
parser_destroy(str->p);
4236-
42374228
if (!is_string(p_chars))
42384229
free(src);
42394230

@@ -4281,21 +4272,6 @@ static bool bif_read_term_from_chars_3(query *q)
42814272
return throw_error(q, p_chars, p_chars_ctx, "type_error", "character");
42824273
}
42834274

4284-
str->p = parser_create(q->st.m);
4285-
str->p->flags = q->st.m->flags;
4286-
str->p->fp = str->fp;
4287-
parser_reset(str->p);
4288-
char *save_src = src;
4289-
str->p->srcptr = src;
4290-
4291-
if (!src || !*src) {
4292-
parser_destroy(str->p);
4293-
free(save_src);
4294-
cell tmp;
4295-
make_atom(&tmp, g_eof_s);
4296-
return unify(q, p_term, p_term_ctx, &tmp, q->st.cur_ctx);
4297-
}
4298-
42994275
const char *end_ptr = src + strlen(src) - 1;
43004276

43014277
while (isspace(*end_ptr) && (end_ptr != src))
@@ -4304,14 +4280,8 @@ static bool bif_read_term_from_chars_3(query *q)
43044280
if (src[strlen(src)-1] != '.')
43054281
strcat(src, ".");
43064282

4307-
bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, NULL);
4308-
parser_reset(str->p);
4309-
parser_destroy(str->p);
4310-
free(save_src);
4311-
4312-
if (ok != true)
4313-
return false;
4314-
4283+
bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, src);
4284+
free(src);
43154285
return ok;
43164286
}
43174287

@@ -4349,7 +4319,6 @@ static bool bif_read_term_from_atom_3(query *q)
43494319
strcat(src, ".");
43504320

43514321
bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, src);
4352-
parser_destroy(str->p);
43534322
free(src);
43544323
return ok;
43554324
}

tests/issues/test905.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Warning: Initialization goal exception: error(existence_error(procedure,read_from_chars/2),read_from_chars/2).
1+
Warning: Initialization goal exception: error(syntax_error(read_term),read_term_from_chars/3).

0 commit comments

Comments
 (0)