]> git.kaiwu.me - haproxy.git/commit
MINOR: sample: add smp_prepare_out() to prepare an output buffer
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Oct 2026 21:01:06 +0000 (23:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 10:08:46 +0000 (11:08 +0100)
commit4d8d922e262264878646c2d5e9c033f28ba6317e
tree1383ce17428ec19ce269b399479487d662facbf8
parent726d2ba132cc7e1019e051f96a8d7e1a5f15956d
MINOR: sample: add smp_prepare_out() to prepare an output buffer

Converters that transform their input without making it grow (case
conversion, character deletion etc) usually call smp_make_rw() then work
in place. When the input is read-only, which is the most common case,
smp_dup() first copies the whole input into a trash chunk, and the
converter then performs a second pass over it.

smp_prepare_out() avoids this copy: for a R/W sample of type STR or BIN,
it leaves the sample as-is, otherwise it replaces the sample's buffer with
a new trash chunk at least as large as the input (with the same truncation
rules as smp_dup()) and clears the "const" flag. The caller saves the
input's area pointer before the call, then reads from it and writes into
the sample's area. Since both may alias when the sample was R/W, the
caller must never write ahead of where it reads.
include/haproxy/sample.h
src/sample.c