Permalink
Browse files

Fix a few more small issues with encodings and assertions. Build gets…

… significantly further
  • Loading branch information...
Whiteknight committed Jun 2, 2012
1 parent f77b281 commit de4b0429d3b452c1718009e8ea60c16581cbdbdb
Showing with 13 additions and 13 deletions.
  1. +1 −1 src/io/api.c
  2. +4 −4 src/io/io_private.h
  3. +8 −8 src/io/utilities.c
View
@@ -641,7 +641,7 @@ Parrot_io_readall_s(PARROT_INTERP, ARGMOD(PMC *handle))
IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
IO_BUFFER * const read_buffer = IO_GET_READ_BUFFER(interp, handle);
size_t total_size = vtable->total_size(interp, handle);
- STR_VTABLE * const encoding = vtable->get_encoding(interp, handle);
+ STR_VTABLE * const encoding = io_get_encoding(interp, handle, vtable, PIO_F_READ);
STRING * const s = io_get_new_empty_string(interp, encoding, -1, total_size);
io_read_chars_append_string(interp, s, handle, vtable, read_buffer, total_size);
return s;
View
@@ -121,6 +121,8 @@ struct _ParrotIOData {
#define IO_VTABLE_UNIMPLEMENTED(i, v, s) Parrot_ex_throw_from_c_args((i), NULL, EXCEPTION_PIO_ERROR, "Method '%s' not implemented for type %s", s, v->name)
+#define IO_STRING_BUFFER_MINSIZE 32
+
/* HEADERIZER BEGIN: src/io/utilities.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
@@ -181,13 +183,12 @@ STRING * io_read_encoded_string(PARROT_INTERP,
ARGMOD(PMC *handle),
ARGIN(IO_VTABLE *vtable),
ARGMOD(IO_BUFFER *buffer),
- ARGIN(STR_VTABLE *encoding),
+ ARGIN_NULLOK(STR_VTABLE *encoding),
size_t char_length)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
__attribute__nonnull__(4)
- __attribute__nonnull__(5)
FUNC_MODIFIES(*handle)
FUNC_MODIFIES(*buffer);
@@ -258,8 +259,7 @@ STRING * io_verify_string_encoding(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle) \
, PARROT_ASSERT_ARG(vtable) \
- , PARROT_ASSERT_ARG(buffer) \
- , PARROT_ASSERT_ARG(encoding))
+ , PARROT_ASSERT_ARG(buffer))
#define ASSERT_ARGS_io_readline_encoded_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(handle) \
View
@@ -119,13 +119,11 @@ io_get_new_empty_string(PARROT_INTERP, ARGIN_NULLOK(STR_VTABLE *encoding),
byte_length = (byte_length + encoding->bytes_per_unit - 1) &
~(encoding->bytes_per_unit - 1);
- if (byte_length == 0)
- result = Parrot_str_new_noinit(interp, 0);
- else {
- /* Allocate 3 bytes more for partial multi-byte characters */
- result = Parrot_str_new_noinit(interp, byte_length + 3);
- }
+ if (byte_length < IO_STRING_BUFFER_MINSIZE)
+ byte_length = IO_STRING_BUFFER_MINSIZE;
+ /* Allocate 3 bytes more for partial multi-byte characters */
+ result = Parrot_str_new_noinit(interp, byte_length + 3);
result->encoding = encoding;
return result;
}
@@ -200,7 +198,7 @@ PARROT_WARN_UNUSED_RESULT
STRING *
io_read_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
ARGIN(IO_VTABLE *vtable), ARGMOD(IO_BUFFER *buffer),
- ARGIN(STR_VTABLE *encoding), size_t char_length)
+ ARGIN_NULLOK(STR_VTABLE *encoding), size_t char_length)
{
ASSERT_ARGS(io_read_encoded_string)
STRING * const s = Parrot_gc_new_string_header(interp, 0);
@@ -209,9 +207,10 @@ io_read_encoded_string(PARROT_INTERP, ARGMOD(PMC *handle),
if (encoding == NULL)
encoding = io_get_encoding(interp, handle, vtable, PIO_F_READ);
-
s->encoding = encoding;
+ PARROT_ASSERT(s->encoding);
+
while (1) {
Parrot_String_Bounds bounds;
size_t bytes_to_read = io_buffer_find_num_characters(interp, buffer,
@@ -253,6 +252,7 @@ io_read_chars_append_string(PARROT_INTERP, ARGMOD(STRING * s),
ARGMOD(IO_BUFFER *buffer), size_t byte_length)
{
const size_t alloc_size = s->bufused + byte_length;
+ PARROT_ASSERT(s->encoding);
if (alloc_size > s->_buflen) {
if (s->strstart)

0 comments on commit de4b042

Please sign in to comment.