Skip to content

Commit dd46bbd

Browse files
authored
document private string and severity functions
1 parent 74912d1 commit dd46bbd

File tree

3 files changed

+194
-1
lines changed

3 files changed

+194
-1
lines changed

include/private/severity.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@
4040
int
4141
get_severity( int prival );
4242

43+
/**
44+
* Identifies whether the supplied severity is within the range of valid severities.
45+
*
46+
* A valid severity is any severity between 0 and 7 inclusive.
47+
*
48+
* **Thread Safety: MT-Safe**
49+
* This function is thread safe.
50+
*
51+
* **Async Signal Safety: AS-Safe**
52+
* This function is safe to call from signal handlers.
53+
*
54+
* **Async Cancel Safety: AC-Safe**
55+
* This function is safe to call from threads that may be asynchronously
56+
* cancelled.
57+
*
58+
* @param severity The severity to check the validity of.
59+
*
60+
* @return Non-zero if invalid; 0 if valid.
61+
*/
4362
int
4463
severity_is_invalid( int severity );
4564

include/private/strbuilder.h

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,53 @@ struct strbuilder {
2727
char *buffer_end;
2828
};
2929

30+
/**
31+
* Appends a character buffer.
32+
*
33+
* **Thread Safety: MT-Unsafe**
34+
* This function is not thread safe.
35+
*
36+
* **Async Signal Safety: AS-Unsafe heap**
37+
* This function is not safe to call from signal handlers due to the potential
38+
* use of memory management functions.
39+
*
40+
* **Async Cancel Safety: AC-Unsafe heap**
41+
* This function is not safe to call from threads that may be asynchronously
42+
* cancelled, due to the potential use of memory management functions.
43+
*
44+
* @param builder The strbuilder to append the characters to.
45+
*
46+
* @param buffer The character buffer to append to the string.
47+
* @param size The number of bytes to copy from the character buffer.
48+
*
49+
* @return The modified builder if no error is encountered. If an error is
50+
* encountered, then NULL is returned and an error code is set appropriately.
51+
*/
3052
struct strbuilder *
3153
strbuilder_append_buffer( struct strbuilder *builder,
3254
const char *buffer, size_t size );
3355

56+
/**
57+
* Appends a char value.
58+
*
59+
* **Thread Safety: MT-Unsafe**
60+
* This function is not thread safe.
61+
*
62+
* **Async Signal Safety: AS-Unsafe heap**
63+
* This function is not safe to call from signal handlers due to the potential
64+
* use of memory management functions.
65+
*
66+
* **Async Cancel Safety: AC-Unsafe heap**
67+
* This function is not safe to call from threads that may be asynchronously
68+
* cancelled, due to the potential use of memory management functions.
69+
*
70+
* @param builder The strbuilder to append the characters to.
71+
*
72+
* @param c The character to append to the string.
73+
*
74+
* @return The modified builder if no error is encountered. If an error is
75+
* encountered, then NULL is returned and an error code is set appropriately.
76+
*/
3477
struct strbuilder *
3578
strbuilder_append_char( struct strbuilder *builder, char c );
3679

@@ -39,7 +82,7 @@ strbuilder_append_char( struct strbuilder *builder, char c );
3982
* zero. If it is negative, a negative sign is NOT included in the sequence of
4083
* appended characters.
4184
*
42-
* **Thread Safety: MT-Safe**
85+
* **Thread Safety: MT-Unsafe**
4386
* This function is not thread safe.
4487
*
4588
* **Async Signal Safety: AS-Unsafe heap**
@@ -60,19 +103,109 @@ strbuilder_append_char( struct strbuilder *builder, char c );
60103
struct strbuilder *
61104
strbuilder_append_positive_int( struct strbuilder *builder, int i );
62105

106+
/**
107+
* Appends a string.
108+
*
109+
* **Thread Safety: MT-Unsafe**
110+
* This function is not thread safe.
111+
*
112+
* **Async Signal Safety: AS-Unsafe heap**
113+
* This function is not safe to call from signal handlers due to the potential
114+
* use of memory management functions.
115+
*
116+
* **Async Cancel Safety: AC-Unsafe heap**
117+
* This function is not safe to call from threads that may be asynchronously
118+
* cancelled, due to the potential use of memory management functions.
119+
*
120+
* @param builder The strbuilder to append the characters to.
121+
*
122+
* @param str The NULL terminated string to append to the buffer.
123+
*
124+
* @return The modified builder if no error is encountered. If an error is
125+
* encountered, then NULL is returned and an error code is set appropriately.
126+
*/
63127
struct strbuilder *
64128
strbuilder_append_string( struct strbuilder *builder,
65129
const char *str );
66130

131+
/**
132+
* Frees all memory associated with any string builders that have been created.
133+
* Releases memory associated with the cache and also any buffers within each
134+
* item in the cache (via the teardown function).
135+
*
136+
* **Thread Safety: MT-Unsafe**
137+
* This function is not thread safe.
138+
*
139+
* **Async Signal Safety: AS-Unsafe heap**
140+
* This function is not safe to call from signal handlers due to the potential
141+
* use of memory management functions.
142+
*
143+
* **Async Cancel Safety: AC-Unsafe heap**
144+
* This function is not safe to call from threads that may be asynchronously
145+
* cancelled, due to the potential use of memory management functions.
146+
*/
67147
void
68148
strbuilder_free_all( void );
69149

150+
/**
151+
* Gets the buffer output from the string builder, returning the length of the
152+
* buffer in the supplied length parameter.
153+
*
154+
* **Thread Safety: MT-Unsafe**
155+
* This function is not thread safe.
156+
*
157+
* **Async Signal Safety: AS-Unsafe**
158+
* Mostly AS-Safe but there is an opportunity for tearing which could result
159+
* in a nonsensical length.
160+
*
161+
* **Async Cancel Safety: AC-Safe**
162+
*
163+
* @param builder The strbuilder to append the characters to.
164+
* @param length A pointer to a variable that will be set to the length
165+
* of the string. Must not be NULL.
166+
*
167+
* @return A pointer to the complete buffer.
168+
*/
70169
char *
71170
strbuilder_get_buffer( struct strbuilder *builder, size_t *length );
72171

172+
/**
173+
* Destroys a specific string builder but does not free the associated memory.
174+
*
175+
* **Thread Safety: MT-Safe**
176+
* This function is thread safe.
177+
*
178+
* **Async Signal Safety: AS-Unsafe lock heap**
179+
* This function is not safe to call from signal handlers due to the use of a
180+
* non-reentrant lock and possibly memory management functions.
181+
*
182+
* **Async Cancel Safety: AC-Unsafe lock heap**
183+
* This function is not safe to call from threads that may be asynchronously
184+
* cancelled due to the use of a lock that could be left locked and the possible
185+
* use of memory management functions.
186+
*
187+
* @param builder The strbuilder to destroy.
188+
*/
73189
void
74190
strbuilder_destroy( const struct strbuilder *builder );
75191

192+
/**
193+
* Creates a string builder.
194+
*
195+
* **Thread Safety: MT-Unsafe**
196+
* This function is not thread safe.
197+
*
198+
* **Async Signal Safety: AS-Unsafe lock heap**
199+
* This function is not safe to call from signal handlers due to the use of a
200+
* non-reentrant lock and possibly memory management functions.
201+
*
202+
* **Async Cancel Safety: AC-Unsafe lock heap**
203+
* This function is not safe to call from threads that may be asynchronously
204+
* cancelled due to the use of a lock that could be left locked and the possible
205+
* use of memory management functions.
206+
*
207+
* @return The new string builder.
208+
*/
76209
struct strbuilder *
77210
strbuilder_new( void );
78211

@@ -89,6 +222,22 @@ strbuilder_new( void );
89222
struct strbuilder *
90223
strbuilder_reset( struct strbuilder *builder );
91224

225+
/**
226+
* Converts a string builder to a NULL terminated string.
227+
*
228+
* **Thread Safety: MT-Unsafe**
229+
* This function is not thread safe.
230+
*
231+
* **Async Signal Safety: AS-Unsafe heap**
232+
* This function is not safe to call from signal handlers due to the potential
233+
* use of memory management functions.
234+
*
235+
* **Async Cancel Safety: AC-Unsafe heap**
236+
* This function is not safe to call from threads that may be asynchronously
237+
* cancelled, due to the potential use of memory management functions.
238+
*
239+
* @return The new string builder.
240+
*/
92241
char *
93242
strbuilder_to_string( const struct strbuilder *builder );
94243

include/private/strhelper.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@
5353
char *
5454
copy_cstring( const char *str );
5555

56+
/**
57+
* Creates a duplicate of the given C-string returning the length in the
58+
* supplied length parameter.
59+
*
60+
* Allocates a new buffer and copies the contents of `str` into it,
61+
* including the terminating NULL byte. The returned string must be freed
62+
* with the corresponding deallocator when no longer needed.
63+
*
64+
* **Thread Safety: MT-Safe**
65+
* Uses heap allocation but maintains no shared global state; safe when
66+
* used concurrently in multiple threads.
67+
*
68+
* **Async Signal Safety: AS-Unsafe (heap)**
69+
* Not safe to call from signal handlers because it may invoke memory
70+
* allocation routines that are not reentrant.
71+
*
72+
* **Async Cancel Safety: AC-Unsafe (heap)**
73+
* May leave heap state inconsistent if a thread is asynchronously
74+
* cancelled during allocation.
75+
*
76+
* @param str The NULL-terminated source string to copy. Must not be NULL.
77+
* @param length A pointer to a variable that will be set to the length
78+
* of the string. Must not be NULL.
79+
* @return A newly allocated copy of `str`, or `NULL` if allocation fails.
80+
*/
5681
char *
5782
copy_cstring_with_length( const char *str, size_t *length );
5883

0 commit comments

Comments
 (0)