+2025-02-09 Bruno Haible <bruno@clisp.org>
+
+ string-buffer, string-buffer-reversed: Allow for better static analysis.
+ * lib/string-buffer.h (sb_appendvf, sb_appendf, sb_xappendvf,
+ sb_xappendf): Don't declare if SB_NO_APPENDF is defined.
+ (sb_xdupfree_c): Declare a non-NULL return value if SB_NO_APPENDF is
+ defined.
+ * lib/string-buffer-reversed.h (sbr_prependvf, sbr_prependf,
+ sbr_xprependvf, sbr_xprependf): Don't declare if SBR_NO_PREPENDF is
+ defined.
+ (sbr_xdupfree_c): Declare a non-NULL return value if SBR_NO_PREPENDF is
+ defined.
+
2025-02-09 Bruno Haible <bruno@clisp.org>
xstring-desc: Allow for better static analysis.
/* Written by Bruno Haible <bruno@clisp.org>, 2025. */
+/* Before including this file, you may define:
+ SBR_NO_PREPENDF Provides for more efficient code, assuming that
+ sbr_prependvf and sbr_prependf will not be called
+ and that 'struct string_buffer_reversed' instances
+ are not used across different compilation units.
+ */
+
#ifndef _STRING_BUFFER_REVERSED_H
#define _STRING_BUFFER_REVERSED_H
extern int sbr_prepend_c (struct string_buffer_reversed *buffer,
const char *str);
+#ifndef SBR_NO_PREPENDF
+
/* Prepends the result of the printf-compatible FORMATSTRING with the argument
list LIST to BUFFER.
Returns 0, or -1 with errno set in case of error.
#endif
;
+#endif
+
/* Frees the memory held by BUFFER. */
extern void sbr_free (struct string_buffer_reversed *buffer)
_GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
extern void sbr_xprepend_c (struct string_buffer_reversed *buffer,
const char *str);
+# ifndef SBR_NO_PREPENDF
+
/* Prepends the result of the printf-compatible FORMATSTRING with the argument
list LIST to BUFFER.
Returns 0, or -1 in case of error other than out-of-memory error.
#endif
;
+# endif
+
/* Returns the contents of BUFFER and frees all other memory held by BUFFER.
Returns (0, NULL) if there was an error earlier.
It is the responsibility of the caller to sd_free() the result. */
It is the responsibility of the caller to free() the result. */
extern char * sbr_xdupfree_c (struct string_buffer_reversed *buffer)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
+# ifdef SBR_NO_PREPENDF
+ _GL_ATTRIBUTE_RETURNS_NONNULL /* because buffer->error is always false */
+# endif
_GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
#endif /* GNULIB_XSTRING_BUFFER_REVERSED */
/* Written by Bruno Haible <bruno@clisp.org>, 2021. */
+/* Before including this file, you may define:
+ SB_NO_APPENDF Provides for more efficient code, assuming that
+ sb_appendvf and sb_appendf will not be called and
+ that 'struct string_buffer' instances are not used
+ across different compilation units.
+ */
+
#ifndef _STRING_BUFFER_H
#define _STRING_BUFFER_H
Returns 0, or -1 in case of out-of-memory error. */
extern int sb_append_c (struct string_buffer *buffer, const char *str);
+#ifndef SB_NO_APPENDF
+
/* Appends the result of the printf-compatible FORMATSTRING with the argument
list LIST to BUFFER.
Returns 0, or -1 with errno set in case of error.
#endif
;
+#endif
+
/* Frees the memory held by BUFFER. */
extern void sb_free (struct string_buffer *buffer)
_GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
/* Appends the contents of the C string STR to BUFFER. */
extern void sb_xappend_c (struct string_buffer *buffer, const char *str);
+# ifndef SB_NO_APPENDF
+
/* Appends the result of the printf-compatible FORMATSTRING with the argument
list LIST to BUFFER.
Returns 0, or -1 in case of error other than out-of-memory error.
#endif
;
+# endif
+
/* Ensures the contents of BUFFER is followed by a NUL byte (without
incrementing the length of the contents).
Then returns a read-only view of the current contents of BUFFER,
It is the responsibility of the caller to free() the result. */
extern char * sb_xdupfree_c (struct string_buffer *buffer)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
+# ifdef SB_NO_APPENDF
+ _GL_ATTRIBUTE_RETURNS_NONNULL /* because buffer->error is always false */
+# endif
_GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
#endif /* GNULIB_XSTRING_BUFFER */