Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.github: check for meson format correctness #145

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- uses: actions/checkout@v3
- name: configure
run: |
apk add --repository https://dl-cdn.alpinelinux.org/alpine/edge/testing muon
apk add clang16-extra-tools
meson setup /tmp/build \
-Dwerror=true \
Expand All @@ -29,7 +30,16 @@ jobs:
-Dfuse-old=disabled \
-Dtest=false \
-Ddoc=false
- name: format-check
- name: muon fmt
run: |
if ! find . \( -name meson.build -or -name meson_options.txt \) -print0 \
| xargs -0 muon fmt -q; then
find . \( -name meson.build -or -name meson_options.txt \) -print0 \
| xargs -0 muon fmt -i;
git diff
exit 1
fi
- name: clang-format
run: |
ninja -C /tmp/build clang-format-check
test:
Expand Down
2 changes: 1 addition & 1 deletion lib/data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ libsqsh_data_dependencies = [
cextras_dep,
]

libsqsh_data_c_args = [ '-Wconversion', '-Wsign-conversion']
libsqsh_data_c_args = ['-Wconversion', '-Wsign-conversion']

libsqsh_data = static_library(
'sqsh',
Expand Down
4 changes: 2 additions & 2 deletions lib/read/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ libsqsh_sources = files(
'table/id_table.c',
'table/table.c',
'table/xattr_table.c',
'tree/walker.c',
'tree/path_resolver.c',
'tree/walker.c',
'utils/error.c',
'utils/posix.c',
'utils/thread.c',
Expand Down Expand Up @@ -84,7 +84,7 @@ libsqsh = both_libraries(
'sqsh',
libsqsh_sources + libsqsh_headers_private,
install: not meson.is_subproject(),
link_with: [ libsqsh_data],
link_with: [libsqsh_data],
c_args: libsqsh_c_args,
dependencies: libsqsh_dependencies,
version: meson.project_version(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ac57719c53157f87416044008883cbb3029863409c69fc085609878b03f5bc5e
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/******************************************************************************
* *
* Copyright (c) 2023, Enno Boland <[email protected]> *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are *
* met: *
* *
* * Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
******************************************************************************/

/**
* @author Enno Boland ([email protected])
* @file threadpool.h
*/

#ifndef MEMORY_H

#define MEMORY_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>

/***************************************
* memory/rc.c
*/

struct CxRc {
atomic_uint count;
};

void cx_rc_init(struct CxRc *rc);
void cx_rc_retain(struct CxRc *rc);
bool cx_rc_release(struct CxRc *rc);

#ifdef __cplusplus
}
#endif
#endif // MEMORY_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if threads_dep.found()
concurrency_src = files('threadpool.c', 'future.c')
concurrency_src = files('future.c', 'threadpool.c')
else
concurrency_src = []
endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
memory_src = files('rc.c')
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* *
* Copyright (c) 2023, Enno Boland <[email protected]> *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are *
* met: *
* *
* * Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
******************************************************************************/

#include "../../include/cextras/memory.h"
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>

void
cx_rc_init(struct CxRc *rc) {
rc->count = 1;
}

void
cx_rc_retain(struct CxRc *rc) {
atomic_fetch_add(&rc->count, 1);
}

bool
cx_rc_release(struct CxRc *rc) {
return atomic_fetch_sub(&rc->count, 1) == 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ subdir('concurrency')

subdir('utils')

src = [concurrency_src, collection_src, utils_src]
subdir('memory')

src = [concurrency_src, collection_src, utils_src, memory_src]

cextras = static_library(
'cextras',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#define _GNU_SOURCE

#include <assert.h>
#include <cextras/memory.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdio.h>
#include <testlib.h>
#include <unistd.h>

struct MyStruct {
struct CxRc rc;
};

static void
test_simple(void) {
bool should_free;
struct MyStruct s = {0};
cx_rc_init(&s.rc);
assert(s.rc.count == 1);
cx_rc_retain(&s.rc);
assert(s.rc.count == 2);
should_free = cx_rc_release(&s.rc);
assert(should_free == false);
assert(s.rc.count == 1);
should_free = cx_rc_release(&s.rc);
assert(should_free == true);
assert(s.rc.count == 0);
}

DECLARE_TESTS
TEST(test_simple)
END_TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tests = [
'collection/rc_hash_map_test.c',
'collection/rc_map_test.c',
'utils/memory.c',
'memory/rc.c',
]

foreach test : tests
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions subprojects/cextras.wrap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[wrap-file]
directory = cextras-c3d6f8c344099fd87d186a634b382d70b7e797ab
directory = cextras-0fdb772e64ebdefe89b1e860ac821a24dd8a993d

source_url = https://github.com/Gottox/cextras/archive/c3d6f8c344099fd87d186a634b382d70b7e797ab.tar.gz
source_filename = cextras-c3d6f8c344099fd87d186a634b382d70b7e797ab.tar.gz
source_hash = 497d4a45a5fbf976c750e5ada3e74593d381be8bef125858cd2df7d1e8da1a9e
source_url = https://github.com/Gottox/cextras/archive/0fdb772e64ebdefe89b1e860ac821a24dd8a993d.tar.gz
source_filename = cextras-0fdb772e64ebdefe89b1e860ac821a24dd8a993d.tar.gz
source_hash = 2bcf6caae3b7a5cd6221d8784767f62c63bfc9159bb95ead00d9c1d0f7635dac

[provide]
cextras=cextras_dep
Expand Down