byte buffer: reorganize struct
The previous layout did lead to better code in small test cases,
however in most situations in Pike it is not benefitial. The new layout
makes checking the buffer space more expensive, but we only have to
update the destination pointer after writing data into the buffer.
byte_buffer: added APIs for set/get
This will be used for updating jmp instructions.
byte_buffer: added flags to control growth
The way the buffer growth (exponential or not) can now be controlled by
setting flags. Additionally there is a flag to toggle between standard
realloc and mexec_realloc. This will be used to allocate space for
generating machine code.
byte_buffer: fixed uninitialized variable
byte_buffer: added API for exact allocation size
In some situations we know almost for sure how much data we will write
into the buffer. In those situations we do not want to always allocate
power of 2 sized buffer. Instead, this new API allows growing the buffer
by exactly as many bytes as needed.
Some other small changes:
* added a bit of documentation.
* generate a fatal on size overflow only in debug mode.
buffer: added buffer_get_string
buffer_get_string returns a zero terminated string. This is used when
e.g. printing from a buffer to stderr.
buffer: do not include pike_error
Including pike_error.h from within buffer.h creates all kinds of
problems. Since we only use it with debug enabled, we can move that code
buffer: added _nothrow variants
This variant of buffer_ensure_space() will return 0 instead of
throwing an exception in OOM situation. It is sometimes easier to
handle this explicitly, than registering an exception handler.
buffer: avoid one copy when building string
New byte buffer
This new byte buffer implements a simple dynamic buffer. It aims to
* Provide a clean API.
* Convince the compiler to generate good code. In particular it tries
to avoid unnecessary loads and stores which are otherwise generated
due to the C aliasing rules. This is done using the STATIC_ASSUME(X)
macro, which declare !X as unreachable.
* Have the fast path (when the buffer has enough space) completely
inlined to allow the compiler to batch single byte writes to the
buffer into larger stores.