Skip to content

Commit 3c5db47

Browse files
authored
v1.1.0
* Added unit tests for Easyqueue API functions * Bugfixes related to placing enough to utilize the underlying linked list, emptying the queue, then attempting to place enough to utilize the underlying linked list again --------- Co-authored-by: null-default <>
1 parent 5336ca3 commit 3c5db47

File tree

4 files changed

+912
-43
lines changed

4 files changed

+912
-43
lines changed

CMakeLists.txt

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
cmake_minimum_required(VERSION 3.23.0)
22
project(easyqueue
3-
DESCRIPTION "A simple queue implementation intended to support flexible applicability with an easy-to-use interface."
4-
HOMEPAGE_URL "https://github.com/null-default/easyqueue"
5-
LANGUAGES C)
3+
DESCRIPTION "A simple queue implementation intended to support flexible applicability with an easy-to-use interface."
4+
HOMEPAGE_URL "https://github.com/null-default/easyqueue"
5+
LANGUAGES C)
66

77
# Semantic Versioning, for the API version.
88
set(EASYQUEUE_MAJOR_VERSION 1) # increment for incompatible API changes
9-
set(EASYQUEUE_MINOR_VERSION 0) # increment with new backwards-compatible functionality
9+
set(EASYQUEUE_MINOR_VERSION 1) # increment with new backwards-compatible functionality
1010
set(EASYQUEUE_PATCH_VERSION 0) # increment with backwards-compatible bugfixes
1111
set(EASYQUEUE_APIVERSION ${EASYQUEUE_MAJOR_VERSION}.${EASYQUEUE_MINOR_VERSION})
1212

1313
# Shared Object Versioning compatible with libtool's -version-info, for the ABI version.
1414
# Ref: https://autotools.io/libtool/version.html
1515
set(EASYQUEUE_CURRENT_VERSION 1) # increment whenever an interface has been added, removed, or changed
16-
set(EASYQUEUE_REVISION_VERSION 0) # always increment regardless of changes
16+
set(EASYQUEUE_REVISION_VERSION 1) # always increment regardless of changes
1717
set(EASYQUEUE_AGE_VERSION 0) # only increment if ABI changes are backwards-compatible
1818
math(EXPR EASYQUEUE_SOVERSION "${EASYQUEUE_CURRENT_VERSION} - ${EASYQUEUE_AGE_VERSION}")
1919
set(EASYQUEUE_VERSION ${EASYQUEUE_SOVERSION}.${EASYQUEUE_AGE_VERSION}.${EASYQUEUE_REVISION_VERSION})
2020

2121
# Define any boolean options that will tune the build.
2222
option(EASYQUEUE_BUILD_32 "Build 32-bit binaries instead of 64-bit." OFF)
23+
option(EASYQUEUE_BUILD_UNIT_TESTS "Build unit tests included in the repository. Unit tests use the Unity framework, which must be installed on the system." OFF)
2324

2425
# Allow the fixed-size buffer's capacity to be configured.
2526
set(EASYQUEUE_DEFAULT_FIXED_BUFFER_CAPACITY 32)
@@ -30,53 +31,61 @@ endif()
3031
# Build a shared object.
3132
add_library(${PROJECT_NAME} SHARED)
3233
target_compile_definitions(${PROJECT_NAME}
33-
PUBLIC EZQ_FIXED_BUFFER_CAPACITY=${EASYQUEUE_FIXED_BUFFER_CAPACITY})
34+
PUBLIC EZQ_FIXED_BUFFER_CAPACITY=${EASYQUEUE_FIXED_BUFFER_CAPACITY})
3435
set_target_properties(${PROJECT_NAME}
35-
PROPERTIES C_STANDARD 90
36-
C_STANDARD_REQUIRED ON
37-
C_EXTENSIONS OFF
38-
POSITION_INDEPENDENT_CODE ON)
36+
PROPERTIES
37+
C_STANDARD 90
38+
C_STANDARD_REQUIRED ON
39+
C_EXTENSIONS OFF
40+
POSITION_INDEPENDENT_CODE ON)
3941
target_compile_options(${PROJECT_NAME}
40-
PRIVATE -Wall -Werror -Wextra -Wpedantic)
42+
PRIVATE -Wall -Werror -Wextra -Wpedantic)
4143
target_sources(${PROJECT_NAME}
42-
PRIVATE src/easyqueue.c
43-
PUBLIC FILE_SET easyqueue_headers
44-
TYPE HEADERS
45-
BASE_DIRS include
46-
FILES include/easyqueue.h)
44+
PRIVATE src/easyqueue.c
45+
PUBLIC
46+
FILE_SET easyqueue_headers
47+
TYPE HEADERS
48+
BASE_DIRS include
49+
FILES include/easyqueue.h)
4750
target_link_options(${PROJECT_NAME} PRIVATE -nostdlib)
4851

4952
# Build a static archive.
5053
add_library(${PROJECT_NAME}_static STATIC)
5154
target_compile_definitions(${PROJECT_NAME}_static
52-
PUBLIC EZQ_FIXED_BUFFER_CAPACITY=${EASYQUEUE_FIXED_BUFFER_CAPACITY})
55+
PUBLIC EZQ_FIXED_BUFFER_CAPACITY=${EASYQUEUE_FIXED_BUFFER_CAPACITY})
5356
set_target_properties(${PROJECT_NAME}_static
54-
PROPERTIES C_STANDARD 90
55-
C_STANDARD_REQUIRED ON
56-
C_EXTENSIONS OFF
57-
POSITION_INDEPENDENT_CODE ON)
57+
PROPERTIES
58+
C_STANDARD 90
59+
C_STANDARD_REQUIRED ON
60+
C_EXTENSIONS OFF
61+
POSITION_INDEPENDENT_CODE ON)
5862
target_compile_options(${PROJECT_NAME}_static
59-
PRIVATE -Wall -Werror -Wextra -Wpedantic)
63+
PRIVATE -Wall -Werror -Wextra -Wpedantic)
6064
target_sources(${PROJECT_NAME}_static
61-
PRIVATE src/easyqueue.c
62-
PUBLIC FILE_SET easyqueue_headers
63-
TYPE HEADERS
64-
BASE_DIRS include
65-
FILES include/easyqueue.h)
65+
PRIVATE src/easyqueue.c
66+
PUBLIC
67+
FILE_SET easyqueue_headers
68+
TYPE HEADERS
69+
BASE_DIRS include
70+
FILES include/easyqueue.h)
6671

6772
# Set additional flags for 32-bit builds.
6873
if(EASYQUEUE_BUILD_32)
6974
set_target_properties(${PROJECT_NAME}
70-
PROPERTIES COMPILE_FLAGS "-m32"
71-
LINK_FLAGS "-m32")
75+
PROPERTIES
76+
COMPILE_FLAGS "-m32"
77+
LINK_FLAGS "-m32")
7278
target_compile_options(${PROJECT_NAME}
73-
PRIVATE -fno-stack-protector) # is this the best option..?
79+
PRIVATE
80+
-fno-stack-protector) # is this the best option..?
7481

7582
set_target_properties(${PROJECT_NAME}_static
76-
PROPERTIES COMPILE_FLAGS "-m32"
77-
LINK_FLAGS "-m32")
83+
PROPERTIES
84+
COMPILE_FLAGS "-m32"
85+
LINK_FLAGS "-m32")
7886
target_compile_options(${PROJECT_NAME}_static
79-
PRIVATE -fno-stack-protector)
87+
PRIVATE
88+
-fno-stack-protector)
8089
endif()
8190

8291
# Example executables that demonstrate usage of the library can be compiled if
@@ -85,9 +94,24 @@ if(EASYQUEUE_BUILD_EXAMPLES)
8594
add_subdirectory(examples)
8695
endif()
8796

97+
# If unit test building is specified, include CTest.
98+
# NOTE: 32-bit builds of unit tests are not currently supported.
99+
if(EASYQUEUE_BUILD_UNIT_TESTS)
100+
find_library(UNITY_TESTS
101+
NAMES unity)
102+
include(CTest)
103+
add_executable(easyqueue_unit_tests src/easyqueue.tests.c)
104+
target_link_libraries(easyqueue_unit_tests
105+
PRIVATE
106+
${PROJECT_NAME}_static
107+
${UNITY_TESTS})
108+
add_test(NAME easyqueue_unit_tests
109+
COMMAND easyqueue_unit_tests)
110+
endif()
111+
88112
# Set installation rules
89113
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static
90-
RUNTIME DESTINATION bin
91-
LIBRARY DESTINATION lib
92-
ARCHIVE DESTINATION lib
93-
FILE_SET easyqueue_headers)
114+
RUNTIME DESTINATION bin
115+
LIBRARY DESTINATION lib
116+
ARCHIVE DESTINATION lib
117+
FILE_SET easyqueue_headers)

src/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/easyqueue.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ ezq_destroy(
313313
estat = EZQ_STATUS_NULL_QUEUE;
314314
goto done;
315315
}
316+
if (p_queue->dynamic.count > 0 && NULL == p_queue->free_fn)
317+
{
318+
estat = EZQ_STATUS_NO_FREE_FN;
319+
goto done;
320+
}
316321

317322
ezq_destroy_unsafe(p_queue, item_cleanup_fn, p_args);
318323

@@ -441,9 +446,14 @@ ezq_list_pop(
441446
p_front = p_ll->p_head;
442447
p_ll->p_head = p_ll->p_head->p_next;
443448
--p_ll->count;
449+
if (0 == p_ll->count)
450+
{
451+
p_ll->p_tail = NULL;
452+
}
444453

445454
*pp_item = p_front->p_item;
446455
p_front->p_item = NULL;
456+
p_front->p_next = NULL;
447457

448458
if (NULL != free_fn)
449459
{
@@ -482,4 +492,9 @@ ezq_destroy_unsafe(
482492
item_cleanup_fn(p_item, p_args);
483493
}
484494
}
495+
496+
/* Clear the other fields of the queue. */
497+
p_queue->alloc_fn = NULL;
498+
p_queue->free_fn = NULL;
499+
p_queue->capacity = 0;
485500
} /* ezq_destroy_unsafe */

0 commit comments

Comments
 (0)