Skip to content

Commit

Permalink
Fix http_get/3
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Sep 18, 2024
1 parent 84d5fc8 commit 80f6c2f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ Non-standard predicates
cpu_time/1 # cpu_time(-Var) elapsed CPU time in secs as float

current_key/1
string_concat/3 # string_concat(+string,+string,?string)
string_length/2
sleep/1 # sleep time in secs
split/4 # split(+string,+sep,?left,?right)
Expand Down
4 changes: 2 additions & 2 deletions library/http.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
getline(S, Line),
hex_chars(Len, Line),
Len > 0,
!,
bread(S, Len, Tmp2),
getline(S, _),
append(Tmp, Tmp2, Tmp3),
!,
string_concat(Tmp, Tmp2, Tmp3),
read_chunks(S, Tmp3, Data).
read_chunks(_, Data, Data).

Expand Down
18 changes: 18 additions & 0 deletions src/bif_predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -5448,6 +5448,23 @@ static bool bif_call_nth_2(query *q)
return true;
}

static bool bif_string_concat_3(query *q)
{
GET_FIRST_ARG(p1,atom);
GET_NEXT_ARG(p2,atom);
GET_NEXT_ARG(p3,atom_or_var);
SB(pr);
SB_strcpy(pr, C_STR(q, p1));
SB_strcat(pr, C_STR(q, p2));
const char *src = SB_cstr(pr);
cell tmp;
make_string(&tmp, src);
SB_free(pr);
int ok = unify(q, p3, p3_ctx, &tmp, q->st.curr_frame);
unshare_cell(&tmp);
return ok;
}

static bool bif_string_length_2(query *q)
{
GET_FIRST_ARG(p1,atom_or_list_or_nil);
Expand Down Expand Up @@ -6661,6 +6678,7 @@ builtins g_other_bifs[] =
{"limit", 2, bif_limit_2, "+integer,:callable", false, false, BLAH},
{"offset", 2, bif_offset_2, "+integer,+callable", false, false, BLAH},
{"unifiable", 3, bif_sys_unifiable_3, "+term,+term,-list", false, false, BLAH},
{"string_concat", 3, bif_string_concat_3, "+string,+string,?string", false, false, BLAH},
{"string_length", 2, bif_string_length_2, "+string,?integer", false, false, BLAH},
{"crypto_n_random_bytes", 2, bif_crypto_n_random_bytes_2, "+integer,-codes", false, false, BLAH},
{"cyclic_term", 1, bif_cyclic_term_1, "+term", false, false, BLAH},
Expand Down

0 comments on commit 80f6c2f

Please sign in to comment.