Commit 21141429 authored by Thomas Haller's avatar Thomas Haller

Squashed 'shared/c-stdaux/' content from commit 11930d2592

git-subtree-dir: shared/c-stdaux
git-subtree-split: 11930d259212605a15430523472ef54e0c7654ee
parents
#!/bin/bash
set -e
rm -Rf "./ci-build"
mkdir "./ci-build"
cd "./ci-build"
${CHERRY_LIB_MESONSETUP} . "${CHERRY_LIB_SRCDIR}"
${CHERRY_LIB_NINJABUILD}
${CHERRY_LIB_MESONTEST}
(( ! CHERRY_LIB_VALGRIND )) || ${CHERRY_LIB_MESONTEST} "--wrapper=${CHERRY_LIB_VALGRINDWRAP}"
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[*.{c,h}]
indent_style = space
indent_size = 8
os: linux
dist: trusty
language: c
services:
- docker
before_install:
- curl -O -L "https://raw.githubusercontent.com/cherry-pick/cherry-images/v1/scripts/vmrun"
- curl -O -L "https://raw.githubusercontent.com/cherry-pick/cherry-ci/v1/scripts/cherryci"
- chmod +x "./vmrun" "./cherryci"
jobs:
include:
- stage: test
script:
- ./vmrun -- ../src/cherryci -d ../src/.cherryci -s c-util -m
- script:
- ./vmrun -T armv7hl -- ../src/cherryci -d ../src/.cherryci -s c-util
- script:
- ./vmrun -T i686 -- ../src/cherryci -d ../src/.cherryci -s c-util
LICENSE:
This project is dual-licensed under both the Apache License, Version
2.0, and the GNU Lesser General Public License, Version 2.1+.
AUTHORS-ASL:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
AUTHORS-LGPL:
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
COPYRIGHT: (ordered alphabetically)
Copyright (C) 2018-2019 Red Hat, Inc.
AUTHORS: (ordered alphabetically)
David Rheinsberg <david.rheinsberg@gmail.com>
Thomas Haller <thaller@redhat.com>
Tom Gundersen <teg@jklm.no>
# c-stdaux - Auxiliary macros and functions for the C standard library
## CHANGES WITH 1:
* Initial release of c-stdaux.
* TBD
Contributions from: TBD
- TBD, YYYY-MM-DD
c-stdaux
========
Auxiliary macros and functions for the C standard library
The c-stdaux project contains support-macros and auxiliary functions around the
functionality of common C standard libraries. This includes helpers for the
ISO-C Standard Library, but also other common specifications like POSIX or
common extended features of wide-spread compilers like gcc and clang.
### Project
* **Website**: <https://c-util.github.io/c-stdaux>
* **Bug Tracker**: <https://github.com/c-util/c-stdaux/issues>
### Requirements
The requirements for this project are:
* `libc` (e.g., `glibc >= 2.16`)
At build-time, the following software is required:
* `meson >= 0.41`
* `pkg-config >= 0.29`
### Build
The meson build-system is used for this project. Contact upstream
documentation for detailed help. In most situations the following
commands are sufficient to build and install from source:
```sh
mkdir build
cd build
meson setup ..
ninja
meson test
ninja install
```
No custom configuration options are available.
### Repository:
- **web**: <https://github.com/c-util/c-stdaux>
- **https**: `https://github.com/c-util/c-stdaux.git`
- **ssh**: `git@github.com:c-util/c-stdaux.git`
### License:
- **Apache-2.0** OR **LGPL-2.1-or-later**
- See AUTHORS file for details.
project(
'c-stdaux',
'c',
version: '1',
license: 'Apache',
default_options: [
'c_std=c11'
],
)
project_description = 'Auxiliary macros and functions for the C standard library'
add_project_arguments('-D_GNU_SOURCE', language: 'c')
mod_pkgconfig = import('pkgconfig')
subdir('src')
This diff is collapsed.
#
# target: libcstdaux.so
# (No .so is built so far, since we are header-only. This might change in the
# future, if we add more complex helpers.)
#
libcstdaux_dep = declare_dependency(
include_directories: include_directories('.'),
version: meson.project_version(),
)
if not meson.is_subproject()
install_headers('c-stdaux.h')
mod_pkgconfig.generate(
version: meson.project_version(),
name: 'libcstdaux',
filebase: 'libcstdaux',
description: project_description,
)
endif
#
# target: test-*
#
test_api = executable('test-api', ['test-api.c'], dependencies: libcstdaux_dep)
test('API Symbol Visibility', test_api)
test_basic = executable('test-basic', ['test-basic.c'], dependencies: libcstdaux_dep)
test('Basic API Behavior', test_basic)
/*
* API Visibility Tests
* This verifies the visibility and availability of the exported API.
*/
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "c-stdaux.h"
static _c_const_ int const_fn(void) { return 0; }
static _c_deprecated_ _c_unused_ int deprecated_fn(void) { return 0; }
_c_hidden_ int c_internal_hidden_fn(void) { return 0; }
static _c_printf_(1, 2) int printf_fn(const char *f, ...) { return 0; }
_c_public_ int c_internal_public_fn(void) { return 0; }
static _c_pure_ int pure_fn(void) { return 0; }
static _c_sentinel_ int sentinel_fn(const char *f, ...) { return 0; }
static _c_unused_ int unused_fn(void) { return 0; }
static void cleanup_fn(int p) {}
static void direct_cleanup_fn(int p) {}
C_DEFINE_CLEANUP(int, cleanup_fn);
C_DEFINE_DIRECT_CLEANUP(int, direct_cleanup_fn);
static void test_api_macros(void) {
/* _c_cleanup_ */
{
_c_cleanup_(c_freep) void *foo = NULL;
c_assert(!foo);
}
/* _c_const_ */
{
c_assert(!const_fn());
}
/* _c_deprecated_ */
{
/* see deprecated_fn() */
}
/* _c_hidden_ */
{
c_assert(!c_internal_hidden_fn());
}
/* _c_likely_ */
{
c_assert(_c_likely_(true));
}
/* _c_packed_ */
{
struct _c_packed_ FooBar {
int member;
} foobar = {};
c_assert(!foobar.member);
}
/* _c_printf_ */
{
c_assert(!printf_fn("%d", 1));
}
/* _c_public_ */
{
c_assert(!c_internal_public_fn());
}
/* _c_pure_ */
{
c_assert(!pure_fn());
}
/* _c_sentinel_ */
{
c_assert(!sentinel_fn("", NULL));
}
/* _c_unlikely_ */
{
c_assert(!_c_unlikely_(false));
}
/* _c_unused_ */
{
c_assert(!unused_fn());
}
/* C_EXPR_ASSERT */
{
int v = C_EXPR_ASSERT(0, true, "");
c_assert(!v);
}
/* C_STRINGIFY */
{
const char v[] = C_STRINGIFY(foobar);
c_assert(!strcmp(v, "foobar"));
}
/* C_CONCATENATE */
{
int C_CONCATENATE(a, b) = 0;
c_assert(!ab);
}
/* C_EXPAND */
{
int x[] = { C_EXPAND((0, 1)) };
c_assert(sizeof(x) / sizeof(*x) == 2);
}
/* C_VAR */
{
int C_VAR = 0; c_assert(!C_VAR); /* must be on the same line */
}
/* C_CC_MACRO1, C_CC_MACRO2, C_CC_MACRO3 */
{
#define MACRO_REAL(_x1, _x2, _x3) ((_x1 + _x2 + _x3) * 0)
#define MACRO1(_x1) C_CC_MACRO1(MACRO_REAL, _x1, 0, 0)
#define MACRO2(_x1, _x2) C_CC_MACRO2(MACRO_REAL, _x1, _x2, 0)
#define MACRO3(_x1, _x2, _x3) C_CC_MACRO3(MACRO_REAL, _x1, _x2, _x3)
c_assert(!MACRO1(1));
c_assert(!MACRO2(1, 1));
c_assert(!MACRO3(1, 1, 1));
#undef MACRO3
#undef MACRO2
#undef MACRO1
}
/* C_ARRAY_SIZE */
{
int v[] = { 0, 1, 2 };
c_assert(C_ARRAY_SIZE(v) == 3);
}
/* C_DECIMAL_MAX */
{
c_assert(C_DECIMAL_MAX(uint8_t) == 4);
}
/* c_container_of */
{
struct FooBarContainer {
int member;
} v = {};
c_assert(c_container_of(&v.member, struct FooBarContainer, member) == &v);
}
/* c_max, c_min, c_less_by, c_clamp, c_div_round_up */
{
c_assert(c_max(0, 0) == 0);
c_assert(c_min(0, 0) == 0);
c_assert(c_less_by(0, 0) == 0);
c_assert(c_clamp(0, 0, 0) == 0);
c_assert(c_div_round_up(1, 1) == 1);
}
/* c_align_to */
{
c_assert(c_align_to(0, 0) == 0);
}
/* c_assert */
{
c_assert(true);
}
/* C_DEFINE_CLEANUP / C_DEFINE_DIRECT_CLEANUP */
{
int v = 0;
cleanup_fnp(&v);
direct_cleanup_fnp(&v);
}
}
static void test_api_functions(void) {
void *fns[] = {
(void *)c_errno,
(void *)c_free,
(void *)c_close,
(void *)c_fclose,
(void *)c_closedir,
(void *)c_freep,
(void *)c_closep,
(void *)c_fclosep,
(void *)c_closedirp,
};
size_t i;
for (i = 0; i < sizeof(fns) / sizeof(*fns); ++i)
c_assert(!!fns[i]);
}
int main(int argc, char **argv) {
test_api_macros();
test_api_functions();
return 0;
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment