libweston: route log scope printf through FILE

The old implementation malloc'd a temporary buffer to hold the formatted
string, flushed it out to subscribers, and freed the buffer. On every
single call.

Forwarding the formatted output to the input stream instead avoids the
malloc. It is flushed explicitly so that interleaving messages through
multiple scopes continues to work. Color-lcms module uses that.

Also fix reference to the non-existing function
weston_debug_stream_write().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2026-03-02 16:11:42 +02:00 committed by Pekka Paalanen
parent 664e882415
commit 60567e7bd6

View file

@ -935,7 +935,7 @@ weston_log_scope_stream(struct weston_log_scope *scope)
* Writes to formatted string to all subscribed clients' streams.
*
* The behavioral details for each stream are the same as for
* weston_debug_stream_write().
* weston_log_scope_write().
*
* \memberof weston_log_scope
*/
@ -943,20 +943,13 @@ WL_EXPORT int
weston_log_scope_vprintf(struct weston_log_scope *scope,
const char *fmt, va_list ap)
{
static const char oom[] = "Out of memory";
char *str;
int len = 0;
if (!weston_log_scope_is_enabled(scope))
return len;
len = vasprintf(&str, fmt, ap);
if (len >= 0) {
weston_log_scope_write(scope, str, len);
free(str);
} else {
weston_log_scope_write(scope, oom, sizeof oom - 1);
}
len = vfprintf(scope->input_stream, fmt, ap);
fflush(scope->input_stream);
return len;
}
@ -970,7 +963,7 @@ weston_log_scope_vprintf(struct weston_log_scope *scope,
* Writes to formatted string to all subscribed clients' streams.
*
* The behavioral details for each stream are the same as for
* weston_debug_stream_write().
* weston_log_scope_write().
*
* \memberof weston_log_scope
*/