diff --git a/src/core/buffer.c b/src/core/buffer.c index 1f964965..3a32dd1e 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -208,6 +208,16 @@ static Janet cfun_buffer_chars(int32_t argc, Janet *argv) { JanetBuffer *buffer = janet_getbuffer(argv, 0); for (i = 1; i < argc; i++) { JanetByteView view = janet_getbytes(argv, i); + if (janet_checktype(argv[i], JANET_BUFFER)) { + JanetBuffer *other = janet_getbuffer(argv, i); + if (buffer == other) { + JanetBuffer *tmp = janet_buffer(buffer->count); + janet_buffer_setcount(tmp, buffer->count); + memcpy(tmp->data, buffer->data, buffer->count); + view.bytes = tmp->data; + view.len = tmp->count; + } + } janet_buffer_push_bytes(buffer, view.bytes, view.len); } return argv[0]; diff --git a/test/suite3.janet b/test/suite3.janet index 00fce95d..c0707e4b 100644 --- a/test/suite3.janet +++ b/test/suite3.janet @@ -170,6 +170,15 @@ (assert (= 8 (length b3)) "buffer/push-word 3") (assert (= "\xFF\xFF\xFF\xFF\0\x11\0\0" (string b3)) "buffer/push-word 4") +# Buffer push string + +(def b4 (buffer/new-filled 10 0)) +(buffer/push-string b4 b4) +(assert (= "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" (string b4)) "buffer/push-buffer 1") +(def b5 @"123") +(buffer/push-string b5 "456" @"789") +(assert (= "123456789" (string b5)) "buffer/push-buffer 2") + # Peg (defn check-match