SIZE flushed;
ION_CHECK(ion_writer_flush(obj->writer, &flushed));
- if (obj->type == BUFFER_WRITER) {
- smart_str_0(&obj->buffer.str);
- }
RETURN_LONG(flushed);
}
static ZEND_METHOD(ion_Writer_Writer, finish)
SIZE flushed;
ION_CHECK(ion_writer_finish(obj->writer, &flushed));
- if (obj->type == BUFFER_WRITER) {
- smart_str_0(&obj->buffer.str);
- }
RETURN_LONG(flushed);
}
static ZEND_METHOD(ion_Writer_Writer, writeOne)
ZEND_PARSE_PARAMETERS_NONE();
+ smart_str_0(&obj->buffer.str.s);
RETVAL_STR_COPY(obj->buffer.str.s);
}
static ZEND_METHOD(ion_Writer_Buffer_Writer, resetBuffer)
union {
struct {
smart_str str;
+ struct _ion_user_stream *usr;
} buffer;
struct {
ION_STRING buf;
LOCAL void php_ion_writer_buffer_init(php_ion_writer *obj)
{
- smart_str_alloc(&obj->buffer.str, 0, 0);
- smart_str_0(&obj->buffer.str);
+ smart_str_alloc(&obj->buffer.str, 0, false);
+ if (obj->buffer.usr) {
+ obj->buffer.usr->curr = (BYTE *) &obj->buffer.str.s->val[obj->buffer.str.s->len];
+ obj->buffer.usr->limit = obj->buffer.usr->curr + obj->buffer.str.a - obj->buffer.str.s->len;
+ }
}
LOCAL void php_ion_writer_buffer_reset(php_ion_writer *obj)
{
smart_str_free(&obj->buffer.str);
memset(&obj->buffer.str, 0, sizeof(obj->buffer.str));
- smart_str_alloc(&obj->buffer.str, 0, 0);
- smart_str_0(&obj->buffer.str);
+ php_ion_writer_buffer_init(obj);
}
LOCAL void php_ion_writer_buffer_grow(php_ion_writer *obj)
smart_str_alloc(&obj->buffer.str, obj->buffer.str.a << 1, 0);
memcpy(obj->buffer.str.s->val, keep->val, keep->len + 1);
obj->buffer.str.s->len = keep->len;
- smart_str_0(&obj->buffer.str);
zend_string_release(keep);
} else {
smart_str_erealloc(&obj->buffer.str, obj->buffer.str.a << 1);
LOCAL iERR php_ion_writer_buffer_handler(struct _ion_user_stream *user)
{
php_ion_writer *writer = (php_ion_writer *) user->handler_state;
+ writer->buffer.usr = user;
if (user->curr) {
- writer->buffer.str.s->len += user->curr - (BYTE *) &writer->buffer.str.s->val[writer->buffer.str.s->len];
- smart_str_0(&writer->buffer.str);
+ writer->buffer.str.s->len = user->curr - (BYTE *) writer->buffer.str.s->val;
if (user->limit == user->curr) {
php_ion_writer_buffer_grow(writer);
}
}
user->curr = (BYTE *) &writer->buffer.str.s->val[writer->buffer.str.s->len];
user->limit = user->curr + writer->buffer.str.a - writer->buffer.str.s->len;
-
+
return IERR_OK;
}