mirror of
https://github.com/tezc/sc.git
synced 2025-01-14 06:43:04 +08:00
sc_buf_shrink, sc_list del before add. (#62)
sc_buf_shrink, sc_list del before add.
This commit is contained in:
parent
8c5b16ecd2
commit
c0149e90d4
2
.github/workflows/.aarch64.yml
vendored
2
.github/workflows/.aarch64.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
name: Build on aarch64
|
name: Build on aarch64
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2.1.0
|
- uses: actions/checkout@v2.1.0
|
||||||
- uses: uraimo/run-on-arch-action@v2.0.8
|
- uses: uraimo/run-on-arch-action@v2.0.9
|
||||||
name: Build artifact
|
name: Build artifact
|
||||||
id: build
|
id: build
|
||||||
with:
|
with:
|
||||||
|
9
.github/workflows/.armv6.yml
vendored
9
.github/workflows/.armv6.yml
vendored
@ -13,12 +13,12 @@ jobs:
|
|||||||
name: Build on armv6
|
name: Build on armv6
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2.1.0
|
- uses: actions/checkout@v2.1.0
|
||||||
- uses: uraimo/run-on-arch-action@v2.0.8
|
- uses: uraimo/run-on-arch-action@v2.0.9
|
||||||
name: Build artifact
|
name: Build artifact
|
||||||
id: build
|
id: build
|
||||||
with:
|
with:
|
||||||
arch: armv6
|
arch: armv6
|
||||||
distro: buster
|
distro: alpine_latest
|
||||||
|
|
||||||
# Not required, but speeds up builds
|
# Not required, but speeds up builds
|
||||||
githubToken: ${{ github.token }}
|
githubToken: ${{ github.token }}
|
||||||
@ -28,8 +28,7 @@ jobs:
|
|||||||
|
|
||||||
# Produce a binary artifact and place it in the mounted volume
|
# Produce a binary artifact and place it in the mounted volume
|
||||||
run: |
|
run: |
|
||||||
apt-get update -q -y
|
apk update
|
||||||
apt-get install -q -y build-essential git gcc valgrind cmake
|
apk add git build-base gcc make valgrind cmake
|
||||||
uname -a;id;uname -m;lscpu | grep Endian
|
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
cmake .. && make -j && make check
|
cmake .. && make -j && make check
|
||||||
|
2
.github/workflows/.armv7.yml
vendored
2
.github/workflows/.armv7.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
name: Build on armv7
|
name: Build on armv7
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2.1.0
|
- uses: actions/checkout@v2.1.0
|
||||||
- uses: uraimo/run-on-arch-action@v2.0.8
|
- uses: uraimo/run-on-arch-action@v2.0.9
|
||||||
name: Build artifact
|
name: Build artifact
|
||||||
id: build
|
id: build
|
||||||
with:
|
with:
|
||||||
|
2
.github/workflows/.ppc64le.yml
vendored
2
.github/workflows/.ppc64le.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
name: Build on ppc64le
|
name: Build on ppc64le
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2.1.0
|
- uses: actions/checkout@v2.1.0
|
||||||
- uses: uraimo/run-on-arch-action@v2.0.8
|
- uses: uraimo/run-on-arch-action@v2.0.9
|
||||||
name: Build artifact
|
name: Build artifact
|
||||||
id: build
|
id: build
|
||||||
with:
|
with:
|
||||||
|
2
.github/workflows/.s390x.yml
vendored
2
.github/workflows/.s390x.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
name: Build on s390x
|
name: Build on s390x
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2.1.0
|
- uses: actions/checkout@v2.1.0
|
||||||
- uses: uraimo/run-on-arch-action@v2.0.8
|
- uses: uraimo/run-on-arch-action@v2.0.9
|
||||||
name: Build artifact
|
name: Build artifact
|
||||||
id: build
|
id: build
|
||||||
with:
|
with:
|
||||||
|
@ -47,7 +47,7 @@ if (SC_BUILD_TEST)
|
|||||||
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_HAVE_WRAP)
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_HAVE_WRAP)
|
||||||
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-builtin)
|
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-builtin)
|
||||||
target_link_options(${PROJECT_NAME}_test PRIVATE
|
target_link_options(${PROJECT_NAME}_test PRIVATE
|
||||||
-Wl,--wrap=vsnprintf,--wrap=malloc,--wrap=realloc,--wrap=strlen)
|
-Wl,--wrap=vsnprintf,--wrap=calloc,--wrap=realloc,--wrap=strlen)
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
@ -188,6 +188,7 @@ void test1()
|
|||||||
|
|
||||||
void test2()
|
void test2()
|
||||||
{
|
{
|
||||||
|
unsigned char tmp[32];
|
||||||
struct sc_buf buf;
|
struct sc_buf buf;
|
||||||
sc_buf_init(&buf, 100);
|
sc_buf_init(&buf, 100);
|
||||||
|
|
||||||
@ -248,22 +249,57 @@ void test2()
|
|||||||
sc_buf_set_32(&buf, 100);
|
sc_buf_set_32(&buf, 100);
|
||||||
sc_buf_set_64(&buf, 100);
|
sc_buf_set_64(&buf, 100);
|
||||||
sc_buf_set_data(&buf, 19, "d", 1);
|
sc_buf_set_data(&buf, 19, "d", 1);
|
||||||
sc_buf_peek_data(&buf, 10, NULL, 0);
|
sc_buf_peek_data(&buf, 10, tmp, 0);
|
||||||
assert(!sc_buf_valid(&buf));
|
assert(!sc_buf_valid(&buf));
|
||||||
sc_buf_term(&buf);
|
sc_buf_term(&buf);
|
||||||
|
|
||||||
|
sc_buf_init(&buf, 32);
|
||||||
|
sc_buf_put_64(&buf, 100);
|
||||||
|
sc_buf_put_64(&buf, 200);
|
||||||
|
sc_buf_put_64(&buf, 300);
|
||||||
|
sc_buf_put_64(&buf, 400);
|
||||||
|
sc_buf_get_64(&buf);
|
||||||
|
sc_buf_get_64(&buf);
|
||||||
|
sc_buf_shrink(&buf, 24);
|
||||||
|
assert(sc_buf_get_64(&buf) == 300);
|
||||||
|
assert(sc_buf_get_64(&buf) == 400);
|
||||||
|
assert(sc_buf_size(&buf) == 0);
|
||||||
|
sc_buf_term(&buf);
|
||||||
|
|
||||||
|
sc_buf_init(&buf, 4096);
|
||||||
|
sc_buf_shrink(&buf, 4096 * 2);
|
||||||
|
sc_buf_shrink(&buf, 128);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4000; i++) {
|
||||||
|
sc_buf_put_64(&buf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_buf_shrink(&buf, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3700; i++) {
|
||||||
|
sc_buf_get_64(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_buf_shrink(&buf, 4096);
|
||||||
|
|
||||||
|
for (int i = 0; i < 300; i++) {
|
||||||
|
assert(sc_buf_get_64(&buf) == (uint64_t) 3700 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_buf_term(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SC_HAVE_WRAP
|
#ifdef SC_HAVE_WRAP
|
||||||
|
|
||||||
bool fail_malloc = false;
|
bool fail_calloc = false;
|
||||||
void *__real_malloc(size_t n);
|
void *__real_calloc(size_t m, size_t n);
|
||||||
void *__wrap_malloc(size_t n)
|
void *__wrap_calloc(size_t m, size_t n)
|
||||||
{
|
{
|
||||||
if (fail_malloc) {
|
if (fail_calloc) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return __real_malloc(n);
|
return __real_calloc(m, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fail_realloc = false;
|
bool fail_realloc = false;
|
||||||
@ -309,22 +345,22 @@ void fail_test()
|
|||||||
unsigned char* p;
|
unsigned char* p;
|
||||||
struct sc_buf buf;
|
struct sc_buf buf;
|
||||||
|
|
||||||
fail_malloc = true;
|
fail_calloc = true;
|
||||||
assert(sc_buf_init(&buf, 100) == false);
|
assert(sc_buf_init(&buf, 100) == false);
|
||||||
fail_malloc = false;
|
fail_calloc = false;
|
||||||
|
|
||||||
assert(sc_buf_init(&buf, 0) == true);
|
assert(sc_buf_init(&buf, 0) == true);
|
||||||
sc_buf_put_32(&buf, 100);
|
sc_buf_put_32(&buf, 100);
|
||||||
assert(sc_buf_valid(&buf) == true);
|
assert(sc_buf_valid(&buf) == true);
|
||||||
sc_buf_term(&buf);
|
sc_buf_term(&buf);
|
||||||
|
|
||||||
fail_malloc = true;
|
fail_calloc = true;
|
||||||
fail_realloc = true;
|
fail_realloc = true;
|
||||||
assert(sc_buf_init(&buf, 0) == true);
|
assert(sc_buf_init(&buf, 0) == true);
|
||||||
sc_buf_put_32(&buf, 100);
|
sc_buf_put_32(&buf, 100);
|
||||||
assert(sc_buf_valid(&buf) == false);
|
assert(sc_buf_valid(&buf) == false);
|
||||||
sc_buf_term(&buf);
|
sc_buf_term(&buf);
|
||||||
fail_malloc = false;
|
fail_calloc = false;
|
||||||
fail_realloc = false;
|
fail_realloc = false;
|
||||||
|
|
||||||
sc_buf_init(&buf, 10);
|
sc_buf_init(&buf, 10);
|
||||||
@ -497,6 +533,15 @@ void fail_test()
|
|||||||
assert(sc_buf_valid(&buf) == true);
|
assert(sc_buf_valid(&buf) == true);
|
||||||
sc_buf_term(&buf);
|
sc_buf_term(&buf);
|
||||||
|
|
||||||
|
sc_buf_init(&buf, 4096 * 8);
|
||||||
|
fail_realloc = true;
|
||||||
|
assert(sc_buf_shrink(&buf, 4096) == false);
|
||||||
|
fail_realloc = false;
|
||||||
|
assert(sc_buf_shrink(&buf, 4096) == true);
|
||||||
|
assert(sc_buf_cap(&buf) == 4096);
|
||||||
|
sc_buf_term(&buf);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void fail_test()
|
void fail_test()
|
||||||
|
@ -40,7 +40,7 @@ bool sc_buf_init(struct sc_buf *buf, uint32_t cap)
|
|||||||
*buf = (struct sc_buf){0};
|
*buf = (struct sc_buf){0};
|
||||||
|
|
||||||
if (cap > 0) {
|
if (cap > 0) {
|
||||||
mem = sc_buf_malloc(cap);
|
mem = sc_buf_calloc(1, cap);
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -119,6 +119,30 @@ bool sc_buf_reserve(struct sc_buf *buf, uint32_t len)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sc_buf_shrink(struct sc_buf *buf, uint32_t len)
|
||||||
|
{
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
|
sc_buf_compact(buf);
|
||||||
|
|
||||||
|
if (len > buf->cap || buf->wpos >= len) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = ((len + 4095) / 4096) * 4096;
|
||||||
|
|
||||||
|
tmp = sc_buf_realloc(buf->mem, len);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
buf->error |= SC_BUF_OOM;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf->cap = len;
|
||||||
|
buf->mem = tmp;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool sc_buf_valid(struct sc_buf *buf)
|
bool sc_buf_valid(struct sc_buf *buf)
|
||||||
{
|
{
|
||||||
return buf->error == 0;
|
return buf->error == 0;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#ifdef SC_HAVE_CONFIG_H
|
#ifdef SC_HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#else
|
#else
|
||||||
#define sc_buf_malloc malloc
|
#define sc_buf_calloc calloc
|
||||||
#define sc_buf_realloc realloc
|
#define sc_buf_realloc realloc
|
||||||
#define sc_buf_free free
|
#define sc_buf_free free
|
||||||
#endif
|
#endif
|
||||||
@ -123,6 +123,8 @@ uint32_t sc_buf_cap(struct sc_buf *buf);
|
|||||||
*/
|
*/
|
||||||
bool sc_buf_reserve(struct sc_buf *buf, uint32_t len);
|
bool sc_buf_reserve(struct sc_buf *buf, uint32_t len);
|
||||||
|
|
||||||
|
|
||||||
|
bool sc_buf_shrink(struct sc_buf *buf, uint32_t len);
|
||||||
/**
|
/**
|
||||||
* @param buf buf
|
* @param buf buf
|
||||||
* @return 'true' if buffer is valid. Buffer becomes invalid on out of
|
* @return 'true' if buffer is valid. Buffer becomes invalid on out of
|
||||||
|
@ -33,8 +33,10 @@ int main()
|
|||||||
struct sc_list list;
|
struct sc_list list;
|
||||||
|
|
||||||
sc_list_init(&list);
|
sc_list_init(&list);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
|
sc_list_init(&users[i].next);
|
||||||
sc_list_add_tail(&list, &users[i].next);
|
sc_list_add_tail(&list, &users[i].next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,9 @@ int main()
|
|||||||
|
|
||||||
sc_list_init(&list);
|
sc_list_init(&list);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
|
sc_list_init(&users[i].next);
|
||||||
sc_list_add_tail(&list, &users[i].next);
|
sc_list_add_tail(&list, &users[i].next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "sc_list.h"
|
#include "sc_list.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct elem
|
struct elem
|
||||||
{
|
{
|
||||||
@ -14,6 +15,12 @@ static void test1(void)
|
|||||||
struct elem a, b, c, d, e, *elem;
|
struct elem a, b, c, d, e, *elem;
|
||||||
struct sc_list list, *item, *tmp;
|
struct sc_list list, *item, *tmp;
|
||||||
|
|
||||||
|
sc_list_init(&a.list);
|
||||||
|
sc_list_init(&b.list);
|
||||||
|
sc_list_init(&c.list);
|
||||||
|
sc_list_init(&d.list);
|
||||||
|
sc_list_init(&e.list);
|
||||||
|
|
||||||
a.id = 1;
|
a.id = 1;
|
||||||
b.id = 2;
|
b.id = 2;
|
||||||
c.id = 3;
|
c.id = 3;
|
||||||
@ -97,12 +104,41 @@ static void test1(void)
|
|||||||
sc_list_add_tail(&list, &a.list);
|
sc_list_add_tail(&list, &a.list);
|
||||||
sc_list_add_tail(&list, &b.list);
|
sc_list_add_tail(&list, &b.list);
|
||||||
sc_list_add_tail(&list, &c.list);
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &b.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
sc_list_add_tail(&list, &d.list);
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_head(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_head(&list, &e.list);
|
||||||
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
sc_list_add_head(&list, &e.list);
|
||||||
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
sc_list_add_head(&list, &e.list);
|
||||||
sc_list_add_tail(&list, &e.list);
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
|
||||||
assert(sc_list_head(&list) != NULL);
|
assert(sc_list_head(&list) != NULL);
|
||||||
assert(sc_list_tail(&list) != NULL);
|
assert(sc_list_tail(&list) != NULL);
|
||||||
assert(sc_list_is_empty(&list) == false);
|
assert(sc_list_is_empty(&list) == false);
|
||||||
|
assert(sc_list_count(&list) == 5);
|
||||||
|
|
||||||
|
sc_list_clear(&list);
|
||||||
|
|
||||||
|
sc_list_add_tail(&list, &a.list);
|
||||||
|
sc_list_add_tail(&list, &b.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &c.list);
|
||||||
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_tail(&list, &d.list);
|
||||||
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
sc_list_add_tail(&list, &e.list);
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
sc_list_foreach_safe (&list, tmp, item) {
|
sc_list_foreach_safe (&list, tmp, item) {
|
||||||
|
@ -32,8 +32,11 @@ void sc_list_init(struct sc_list *list)
|
|||||||
|
|
||||||
void sc_list_clear(struct sc_list *list)
|
void sc_list_clear(struct sc_list *list)
|
||||||
{
|
{
|
||||||
list->next = list;
|
struct sc_list *tmp, *elem;
|
||||||
list->prev = list;
|
|
||||||
|
sc_list_foreach_safe (list, tmp, elem) {
|
||||||
|
sc_list_del(NULL, elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sc_list_is_empty(struct sc_list *list)
|
bool sc_list_is_empty(struct sc_list *list)
|
||||||
@ -55,32 +58,21 @@ size_t sc_list_count(struct sc_list *list)
|
|||||||
|
|
||||||
struct sc_list *sc_list_head(struct sc_list *list)
|
struct sc_list *sc_list_head(struct sc_list *list)
|
||||||
{
|
{
|
||||||
struct sc_list *elem;
|
return list->next != list ? list->next : NULL;
|
||||||
|
|
||||||
elem = list->next;
|
|
||||||
if (elem == list) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return elem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sc_list *sc_list_tail(struct sc_list *list)
|
struct sc_list *sc_list_tail(struct sc_list *list)
|
||||||
{
|
{
|
||||||
struct sc_list *elem;
|
return list->prev != list ? list->prev : NULL;
|
||||||
|
|
||||||
elem = list->prev;
|
|
||||||
if (elem == list) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return elem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc_list_add_tail(struct sc_list *list, struct sc_list *elem)
|
void sc_list_add_tail(struct sc_list *list, struct sc_list *elem)
|
||||||
{
|
{
|
||||||
struct sc_list *prev;
|
struct sc_list *prev;
|
||||||
|
|
||||||
|
// Delete if exists to prevent adding same item twice
|
||||||
|
sc_list_del(list, elem);
|
||||||
|
|
||||||
prev = list->prev;
|
prev = list->prev;
|
||||||
list->prev = elem;
|
list->prev = elem;
|
||||||
elem->next = list;
|
elem->next = list;
|
||||||
@ -90,13 +82,12 @@ void sc_list_add_tail(struct sc_list *list, struct sc_list *elem)
|
|||||||
|
|
||||||
struct sc_list *sc_list_pop_tail(struct sc_list *list)
|
struct sc_list *sc_list_pop_tail(struct sc_list *list)
|
||||||
{
|
{
|
||||||
struct sc_list *tail;
|
struct sc_list *tail = list->prev;
|
||||||
|
|
||||||
if (sc_list_is_empty(list)) {
|
if (sc_list_is_empty(list)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tail = list->prev;
|
|
||||||
sc_list_del(list, list->prev);
|
sc_list_del(list, list->prev);
|
||||||
|
|
||||||
return tail;
|
return tail;
|
||||||
@ -104,18 +95,26 @@ struct sc_list *sc_list_pop_tail(struct sc_list *list)
|
|||||||
|
|
||||||
void sc_list_add_head(struct sc_list *list, struct sc_list *elem)
|
void sc_list_add_head(struct sc_list *list, struct sc_list *elem)
|
||||||
{
|
{
|
||||||
sc_list_add_before(list, list->next, elem);
|
struct sc_list *next;
|
||||||
|
|
||||||
|
// Delete if exists to prevent adding same item twice
|
||||||
|
sc_list_del(list, elem);
|
||||||
|
|
||||||
|
next = list->next;
|
||||||
|
list->next = elem;
|
||||||
|
elem->prev = list;
|
||||||
|
elem->next = next;
|
||||||
|
next->prev = elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sc_list *sc_list_pop_head(struct sc_list *list)
|
struct sc_list *sc_list_pop_head(struct sc_list *list)
|
||||||
{
|
{
|
||||||
struct sc_list *head;
|
struct sc_list *head = list->next;
|
||||||
|
|
||||||
if (sc_list_is_empty(list)) {
|
if (sc_list_is_empty(list)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
head = list->next;
|
|
||||||
sc_list_del(list, list->next);
|
sc_list_del(list, list->next);
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
@ -127,6 +126,9 @@ void sc_list_add_after(struct sc_list *list, struct sc_list *prev,
|
|||||||
(void) list;
|
(void) list;
|
||||||
struct sc_list *next;
|
struct sc_list *next;
|
||||||
|
|
||||||
|
// Delete if exists to prevent adding same item twice
|
||||||
|
sc_list_del(list, elem);
|
||||||
|
|
||||||
next = prev->next;
|
next = prev->next;
|
||||||
prev->next = elem;
|
prev->next = elem;
|
||||||
elem->next = next;
|
elem->next = next;
|
||||||
@ -140,6 +142,9 @@ void sc_list_add_before(struct sc_list *list, struct sc_list *next,
|
|||||||
(void) list;
|
(void) list;
|
||||||
struct sc_list *prev;
|
struct sc_list *prev;
|
||||||
|
|
||||||
|
// Delete if exists to prevent adding same item twice
|
||||||
|
sc_list_del(list, elem);
|
||||||
|
|
||||||
prev = next->prev;
|
prev = next->prev;
|
||||||
next->prev = elem;
|
next->prev = elem;
|
||||||
elem->next = next;
|
elem->next = next;
|
||||||
|
@ -150,7 +150,7 @@ void sc_list_del(struct sc_list *list, struct sc_list *elem);
|
|||||||
* struct sc_list *list; // List pointer, should already be initialized.
|
* struct sc_list *list; // List pointer, should already be initialized.
|
||||||
* struct sc_list *it; // Iterator
|
* struct sc_list *it; // Iterator
|
||||||
*
|
*
|
||||||
* sc_list_foreach(list, it) {
|
* sc_list_foreach (list, it) {
|
||||||
* container = sc_list_entry(it, struct container, others);
|
* container = sc_list_entry(it, struct container, others);
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@ -166,9 +166,10 @@ void sc_list_del(struct sc_list *list, struct sc_list *elem);
|
|||||||
*
|
*
|
||||||
* struct container *container; // User object
|
* struct container *container; // User object
|
||||||
* struct sc_list *list; // List pointer, should already be initialized.
|
* struct sc_list *list; // List pointer, should already be initialized.
|
||||||
|
* struct sc_list *tmp; // Variable for loop, user should not use this.
|
||||||
* struct sc_list *it; // Iterator
|
* struct sc_list *it; // Iterator
|
||||||
*
|
*
|
||||||
* sc_list_foreach(list, it) {
|
* sc_list_foreach_safe (list, it) {
|
||||||
* container = sc_list_entry(it, struct container, others);
|
* container = sc_list_entry(it, struct container, others);
|
||||||
* sc_list_del(list, &container->others);
|
* sc_list_del(list, &container->others);
|
||||||
* }
|
* }
|
||||||
@ -188,11 +189,10 @@ void sc_list_del(struct sc_list *list, struct sc_list *elem);
|
|||||||
* struct sc_list *list; // List pointer, should already be initialized.
|
* struct sc_list *list; // List pointer, should already be initialized.
|
||||||
* struct sc_list *it; // Iterator
|
* struct sc_list *it; // Iterator
|
||||||
*
|
*
|
||||||
* sc_list_foreach(list, it) {
|
* sc_list_foreach_r (list, it) {
|
||||||
* container = sc_list_entry(it, struct container, others);
|
* container = sc_list_entry(it, struct container, others);
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define sc_list_foreach_r(list, elem) \
|
#define sc_list_foreach_r(list, elem) \
|
||||||
for ((elem) = (list)->prev; (elem) != (list); (elem) = (elem)->prev)
|
for ((elem) = (list)->prev; (elem) != (list); (elem) = (elem)->prev)
|
||||||
|
|
||||||
@ -209,9 +209,10 @@ void sc_list_del(struct sc_list *list, struct sc_list *elem);
|
|||||||
*
|
*
|
||||||
* struct container *container; // User object
|
* struct container *container; // User object
|
||||||
* struct sc_list *list; // List pointer, should already be initialized.
|
* struct sc_list *list; // List pointer, should already be initialized.
|
||||||
|
* struct sc_list *tmp; // Variable for loop, user should not use this.
|
||||||
* struct sc_list *it; // Iterator
|
* struct sc_list *it; // Iterator
|
||||||
*
|
*
|
||||||
* sc_list_foreach(list, it) {
|
* sc_list_foreach_safe_r (list, tmp, it) {
|
||||||
* container = sc_list_entry(it, struct container, others);
|
* container = sc_list_entry(it, struct container, others);
|
||||||
* sc_list_del(list, &container->others);
|
* sc_list_del(list, &container->others);
|
||||||
* }
|
* }
|
||||||
|
@ -57,6 +57,7 @@ void test1()
|
|||||||
#ifdef SC_HAVE_WRAP
|
#ifdef SC_HAVE_WRAP
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
bool fail_open;
|
bool fail_open;
|
||||||
|
@ -52,7 +52,7 @@ void test2()
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
bool fail_signal;
|
bool fail_signal;
|
||||||
extern void (*__real_signal(int sig, void (*func)(int)))(int);
|
extern void (*__real_signal(int sig, void (*func)(int)))(int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user