[core] __attribute_returns_nonnull__

personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent c9f1b612f1
commit 5c0c4936b4
  1. 4
      src/array.h
  2. 1
      src/buffer.c
  3. 7
      src/buffer.h
  4. 5
      src/chunk.c
  5. 14
      src/chunk.h
  6. 9
      src/first.h
  7. 1
      src/status_counter.h

@ -53,9 +53,11 @@ typedef struct {
data_integer *data_integer_init(void);
__attribute_returns_nonnull__
array *array_init(void);
__attribute_cold__
__attribute_returns_nonnull__
array *array_init_array(const array *a);
void array_free(array *a);
@ -92,8 +94,10 @@ data_unset *array_get_element_klen(const array *a, const char *key, size_t klen)
__attribute_cold__
data_unset *array_extract_element_klen(array *a, const char *key, size_t klen); /* removes found entry from array */
__attribute_returns_nonnull__
int * array_get_int_ptr(array *a, const char *k, size_t klen);
__attribute_returns_nonnull__
buffer * array_get_buf_ptr(array *a, const char *k, size_t klen);
void array_insert_value(array *a, const char *v, size_t vlen);

@ -105,6 +105,7 @@ char* buffer_string_prepare_copy(buffer *b, size_t size) {
__attribute_cold__
__attribute_noinline__
__attribute_returns_nonnull__
static char* buffer_string_prepare_append_resize(buffer *b, size_t size) {
force_assert(NULL != b);
if (buffer_string_is_empty(b)) {

@ -25,8 +25,13 @@ typedef struct {
} buffer;
/* create new buffer; either empty or copy given data */
__attribute_returns_nonnull__
buffer* buffer_init(void);
__attribute_returns_nonnull__
buffer* buffer_init_buffer(const buffer *src); /* src can be NULL */
__attribute_returns_nonnull__
buffer* buffer_init_string(const char *str); /* str can be NULL */
void buffer_free(buffer *b); /* b can be NULL */
@ -41,6 +46,7 @@ void buffer_move(buffer *b, buffer *src);
* sets b to an empty string, and may drop old content.
* @return b->ptr
*/
__attribute_returns_nonnull__
char* buffer_string_prepare_copy(buffer *b, size_t size);
/* allocate buffer large enough to be able to append a string of given size
@ -49,6 +55,7 @@ char* buffer_string_prepare_copy(buffer *b, size_t size);
* "used" data is preserved; if not empty buffer must contain a
* zero terminated string.
*/
__attribute_returns_nonnull__
char* buffer_string_prepare_append(buffer *b, size_t size);
/* use after prepare_(copy,append) when you have written data to the buffer

@ -68,6 +68,7 @@ chunkqueue *chunkqueue_init(void) {
return cq;
}
__attribute_returns_nonnull__
static chunk *chunk_init(size_t sz) {
chunk *c;
@ -152,6 +153,7 @@ void chunk_buffer_release(buffer *b) {
}
}
__attribute_returns_nonnull__
static chunk * chunk_acquire(size_t sz) {
if (sz <= chunk_buf_sz) {
if (chunks) {
@ -251,18 +253,21 @@ static void chunkqueue_append_chunk(chunkqueue *cq, chunk *c) {
cq->last = c;
}
__attribute_returns_nonnull__
static chunk * chunkqueue_prepend_mem_chunk(chunkqueue *cq, size_t sz) {
chunk *c = chunk_acquire(sz);
chunkqueue_prepend_chunk(cq, c);
return c;
}
__attribute_returns_nonnull__
static chunk * chunkqueue_append_mem_chunk(chunkqueue *cq, size_t sz) {
chunk *c = chunk_acquire(sz);
chunkqueue_append_chunk(cq, c);
return c;
}
__attribute_returns_nonnull__
static chunk * chunkqueue_append_file_chunk(chunkqueue *cq, buffer *fn, off_t offset, off_t len) {
chunk *c = chunk_acquire(buffer_string_length(fn)+1);
chunkqueue_append_chunk(cq, c);

@ -47,13 +47,17 @@ typedef struct {
unsigned int tempdir_idx;
} chunkqueue;
__attribute_returns_nonnull__
buffer * chunk_buffer_acquire(void);
void chunk_buffer_release(buffer *b);
void chunkqueue_chunk_pool_clear(void);
void chunkqueue_chunk_pool_free(void);
__attribute_returns_nonnull__
chunkqueue *chunkqueue_init(void);
void chunkqueue_set_chunk_size (size_t sz);
void chunkqueue_set_tempdirs_default_reset (void);
void chunkqueue_set_tempdirs_default (array *tempdirs, off_t upload_temp_file_size);
@ -65,11 +69,20 @@ void chunkqueue_append_mem_min(chunkqueue *cq, const char * mem, size_t len); /*
void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */
void chunkqueue_append_chunkqueue(chunkqueue *cq, chunkqueue *src);
__attribute_returns_nonnull__
buffer * chunkqueue_prepend_buffer_open_sz(chunkqueue *cq, size_t sz);
__attribute_returns_nonnull__
buffer * chunkqueue_prepend_buffer_open(chunkqueue *cq);
void chunkqueue_prepend_buffer_commit(chunkqueue *cq);
__attribute_returns_nonnull__
buffer * chunkqueue_append_buffer_open_sz(chunkqueue *cq, size_t sz);
__attribute_returns_nonnull__
buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
void chunkqueue_append_buffer_commit(chunkqueue *cq);
struct server; /*(declaration)*/
@ -83,6 +96,7 @@ int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const
* even if nothing was read.
* pass 0 in len for mem at least half of chunk_buf_sz
*/
__attribute_returns_nonnull__
char * chunkqueue_get_memory(chunkqueue *cq, size_t *len);
/* commit len bytes of mem obtained from chunkqueue_get_memory() */
void chunkqueue_use_memory(chunkqueue *cq, size_t len);

@ -138,5 +138,14 @@
#endif
#endif
#ifndef __attribute_returns_nonnull__
#if __has_attribute(returns_nonnull) \
|| __GNUC_PREREQ(4,9)
#define __attribute_returns_nonnull__ __attribute__((__returns_nonnull__))
#else
#define __attribute_returns_nonnull__
#endif
#endif
#endif

@ -18,6 +18,7 @@ void status_counter_set(server *srv, const char *s, size_t len, int val);
#include "base.h" /* (srv->status) */
#include "array.h"
__attribute_returns_nonnull__
static inline
int *status_counter_get_counter(server *srv, const char *s, size_t len) {
return array_get_int_ptr(srv->status, s, len);

Loading…
Cancel
Save