diff options
| author | Paul Eggert | 2025-01-26 22:15:48 -0800 |
|---|---|---|
| committer | Paul Eggert | 2025-01-26 23:05:50 -0800 |
| commit | f885806fdf1aa862ad55d124e9795794fed0b964 (patch) | |
| tree | ee01f12a59c4ef057dd6c780b5343ed12b7ff8c0 /src/alloc.c | |
| parent | bcfd4d21b0a62c5c15b919fa28673066c493775a (diff) | |
| download | emacs-f885806fdf1aa862ad55d124e9795794fed0b964.tar.gz emacs-f885806fdf1aa862ad55d124e9795794fed0b964.zip | |
Simplify make_formatted_string API
From a suggestion by Pip Cet.
* src/alloc.c (make_formatted_string): Omit first argument,
to simplify the calling convention. All callers changed.
* src/doprnt.c (doprnt): Also support %u. Update doc.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/alloc.c b/src/alloc.c index c4e2ff52015..2c0ccc9dd62 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2542,19 +2542,23 @@ make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes) | |||
| 2542 | return make_clear_multibyte_string (nchars, nbytes, false); | 2542 | return make_clear_multibyte_string (nchars, nbytes, false); |
| 2543 | } | 2543 | } |
| 2544 | 2544 | ||
| 2545 | /* Print arguments to BUF according to a FORMAT, then return | 2545 | /* Return a Lisp_String according to a doprnt-style FORMAT and args. */ |
| 2546 | a Lisp_String initialized with the data from BUF. */ | ||
| 2547 | 2546 | ||
| 2548 | Lisp_Object | 2547 | Lisp_Object |
| 2549 | make_formatted_string (char *buf, const char *format, ...) | 2548 | make_formatted_string (const char *format, ...) |
| 2550 | { | 2549 | { |
| 2550 | char buf[64]; | ||
| 2551 | char *cstr = buf; | ||
| 2552 | ptrdiff_t bufsize = sizeof buf; | ||
| 2551 | va_list ap; | 2553 | va_list ap; |
| 2552 | int length; | ||
| 2553 | 2554 | ||
| 2554 | va_start (ap, format); | 2555 | va_start (ap, format); |
| 2555 | length = vsprintf (buf, format, ap); | 2556 | ptrdiff_t length = evxprintf (&cstr, &bufsize, buf, -1, format, ap); |
| 2556 | va_end (ap); | 2557 | va_end (ap); |
| 2557 | return make_string (buf, length); | 2558 | Lisp_Object ret = make_string (cstr, length); |
| 2559 | if (cstr != buf) | ||
| 2560 | xfree (cstr); | ||
| 2561 | return ret; | ||
| 2558 | } | 2562 | } |
| 2559 | 2563 | ||
| 2560 | /* Pin a unibyte string in place so that it won't move during GC. */ | 2564 | /* Pin a unibyte string in place so that it won't move during GC. */ |