Fixing custom ports built without utf8 support.

This commit is contained in:
Alex Shinn 2014-05-08 06:47:33 -04:00
parent a595badee5
commit 22e2a08563
2 changed files with 5 additions and 3 deletions

View file

@ -880,6 +880,7 @@ SEXP_API sexp sexp_make_unsigned_integer(sexp ctx, sexp_luint_t x);
#define sexp_string_size(x) (sexp_field(x, string, SEXP_STRING, length))
#if SEXP_USE_PACKED_STRINGS
#define sexp_string_data(x) (sexp_field(x, string, SEXP_STRING, data))
#define sexp_string_bytes(x) (x)
#else
#define sexp_string_bytes(x) (sexp_field(x, string, SEXP_STRING, bytes))
#define sexp_string_offset(x) (sexp_field(x, string, SEXP_STRING, offset))

7
sexp.c
View file

@ -1451,15 +1451,16 @@ int sexp_buffered_read_char (sexp ctx, sexp p) {
} else if (sexp_port_customp(p)) {
sexp_gc_preserve2(ctx, tmp, origbytes);
tmp = sexp_list2(ctx, SEXP_ZERO, sexp_make_fixnum(SEXP_PORT_BUFFER_SIZE));
origbytes = sexp_port_binaryp(p) ? sexp_string_bytes(sexp_port_buffer(p)) : sexp_port_buffer(p);
origbytes = sexp_port_binaryp(p) && !SEXP_USE_PACKED_STRINGS ? sexp_string_bytes(sexp_port_buffer(p)) : sexp_port_buffer(p);
tmp = sexp_cons(ctx, origbytes, tmp);
tmp = sexp_apply(ctx, sexp_port_reader(p), tmp);
if (sexp_fixnump(tmp) && sexp_unbox_fixnum(tmp) > 0) {
sexp_port_offset(p) = 0;
sexp_port_size(p) = sexp_unbox_fixnum(tmp);
if (!sexp_port_binaryp(p) && origbytes != sexp_string_bytes(sexp_port_buffer(p))) {
if (!sexp_port_binaryp(p) && !SEXP_USE_PACKED_STRINGS
&& origbytes != sexp_string_bytes(sexp_port_buffer(p))) {
/* handle resize */
memcpy(sexp_port_buf(p), sexp_bytes_data(sexp_string_bytes(sexp_port_buffer(p))), sexp_port_size(p));
memcpy(sexp_port_buf(p), sexp_string_data(sexp_port_buffer(p)), sexp_port_size(p));
}
res = ((sexp_port_offset(p) < sexp_port_size(p))
? ((unsigned char*)sexp_port_buf(p))[sexp_port_offset(p)++] : EOF);