Skip to content

Commit 6577ec6

Browse files
committed
[lib] Embed libtoml in the source tree
This library is only packaged on Fedora. To avoid having to build it on every other platform, embed it in this tree. This also removes the need for ragel as a build dependency. Go ahead and pre-generate the toml_parse.c file. For Fedora systems, meson_options.txt has with_system_libtoml as a boolean so you can link with the one on the library if you have it. By default rpminspect will just use the embedded copy in this source tree. Signed-off-by: David Cantrell <[email protected]>
1 parent 6e93808 commit 6577ec6

18 files changed

+123845
-9
lines changed

lib/meson.build

+12-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ deps = [
128128
libcurl,
129129
zlib,
130130
yaml,
131-
toml,
132131
openssl,
133132
mandoc,
134133
magic,
@@ -170,12 +169,22 @@ if build_machine.system() == 'freebsd'
170169
deps += [ intl ]
171170
endif
172171

172+
incdirs = [ inc, incxdiff ]
173+
locallibs = [ libxdiff ]
174+
175+
if get_option('with_system_libtoml')
176+
deps += [ toml ]
177+
else
178+
incdirs += [ inctoml ]
179+
locallibs += [ libtoml ]
180+
endif
181+
173182
librpminspect = library(
174183
'rpminspect',
175184
librpminspect_sources,
176-
include_directories : [ inc, incxdiff ],
185+
include_directories : incdirs,
177186
version : '0.5.0',
178187
install : true,
179-
link_with : [ libxdiff, ],
188+
link_with : locallibs,
180189
dependencies : deps
181190
)

libtoml/LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2013, Andrew Wansink
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the author nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

libtoml/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
libtoml
2+
=======
3+
4+
Fast C parser using Ragel to generate the state machine.
5+
6+
Currently targetted at TOML v0.4.0
7+
8+
Usage
9+
=====
10+
11+
```c
12+
#include <toml.h>
13+
14+
struct toml_node *root;
15+
struct toml_node *node;
16+
char *buf = "[foo]\nbar = 1\n";
17+
char *value;
18+
19+
toml_init(&root);
20+
toml_parse(root, buf, len);
21+
22+
node = toml_get(root, "foo.bar");
23+
24+
toml_dump(root, stdout);
25+
26+
value = toml_value_as_string(node);
27+
free(value);
28+
29+
toml_free(root);
30+
```
31+
32+
Building it
33+
===========
34+
35+
Building libtoml requires cmake, ragel (the parser generator) and libicu for unicode support.
36+
37+
```sh
38+
> cmake -G "Unix Makefiles" .
39+
> make
40+
```
41+
42+
Testing it
43+
==========
44+
45+
Compatible with [toml-test](https://github.com/BurntSushi/toml-test) when invoked
46+
as 'parser_test'
47+
48+
```sh
49+
> ln -s main parser_test
50+
> $GOPATH/bin/toml-test $PWD/parser_test
51+
```
52+
53+
TODO
54+
====
55+
56+
More tests

libtoml/README.rpminspect

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is a bundled copy of libtoml from this project:
2+
3+
https://github.com/ajwans/libtoml
4+
5+
The examples/ subdirectory has been removed as well as the
6+
CMakeLists.txt file. I also removed test.c and main.c because this
7+
bundled library is only to build libtoml.a. config.h has been removed
8+
as well because it was only used by ccan and the value was static, so
9+
ccan has been modified to not conditonalize HAVE_TYPEOF.
10+
11+
The parser has already been generated with ragel so that ragel is not
12+
a build dependency of rpminspect. The toml_parse.c file can be
13+
regenerated with ragel with this command:
14+
15+
ragel -e -p -o toml_parse.c toml_parse.rl
16+
17+
The generated toml_parse.c file was then stripped of all #line lines,
18+
uninitialized variables initialized, and unused variables removed.
19+
20+
Other compile fixes have been committed to this fork.
21+
22+
--
23+
David Cantrell
24+

libtoml/ccan/build_assert.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef CCAN_BUILD_ASSERT_H
2+
#define CCAN_BUILD_ASSERT_H
3+
4+
/**
5+
* BUILD_ASSERT - assert a build-time dependency.
6+
* @cond: the compile-time condition which must be true.
7+
*
8+
* Your compile will fail if the condition isn't true, or can't be evaluated
9+
* by the compiler. This can only be used within a function.
10+
*
11+
* Example:
12+
* #include <stddef.h>
13+
* ...
14+
* static char *foo_to_char(struct foo *foo)
15+
* {
16+
* // This code needs string to be at start of foo.
17+
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
18+
* return (char *)foo;
19+
* }
20+
*/
21+
#define BUILD_ASSERT(cond) \
22+
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
23+
24+
/**
25+
* EXPR_BUILD_ASSERT - assert a build-time dependency, as an expression.
26+
* @cond: the compile-time condition which must be true.
27+
*
28+
* Your compile will fail if the condition isn't true, or can't be evaluated
29+
* by the compiler. This can be used in an expression: its value is "0".
30+
*
31+
* Example:
32+
* #define foo_to_char(foo) \
33+
* ((char *)(foo) \
34+
* + EXPR_BUILD_ASSERT(offsetof(struct foo, string) == 0))
35+
*/
36+
#define EXPR_BUILD_ASSERT(cond) \
37+
(sizeof(char [1 - 2*!(cond)]) - 1)
38+
39+
#endif /* CCAN_BUILD_ASSERT_H */
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef CCAN_BUILD_ASSERT_H
2+
#define CCAN_BUILD_ASSERT_H
3+
4+
/**
5+
* BUILD_ASSERT - assert a build-time dependency.
6+
* @cond: the compile-time condition which must be true.
7+
*
8+
* Your compile will fail if the condition isn't true, or can't be evaluated
9+
* by the compiler. This can only be used within a function.
10+
*
11+
* Example:
12+
* #include <stddef.h>
13+
* ...
14+
* static char *foo_to_char(struct foo *foo)
15+
* {
16+
* // This code needs string to be at start of foo.
17+
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
18+
* return (char *)foo;
19+
* }
20+
*/
21+
#define BUILD_ASSERT(cond) \
22+
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
23+
24+
/**
25+
* EXPR_BUILD_ASSERT - assert a build-time dependency, as an expression.
26+
* @cond: the compile-time condition which must be true.
27+
*
28+
* Your compile will fail if the condition isn't true, or can't be evaluated
29+
* by the compiler. This can be used in an expression: its value is "0".
30+
*
31+
* Example:
32+
* #define foo_to_char(foo) \
33+
* ((char *)(foo) \
34+
* + EXPR_BUILD_ASSERT(offsetof(struct foo, string) == 0))
35+
*/
36+
#define EXPR_BUILD_ASSERT(cond) \
37+
(sizeof(char [1 - 2*!(cond)]) - 1)
38+
39+
#endif /* CCAN_BUILD_ASSERT_H */

libtoml/ccan/check_type/check_type.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef CCAN_CHECK_TYPE_H
2+
#define CCAN_CHECK_TYPE_H
3+
4+
/**
5+
* check_type - issue a warning or build failure if type is not correct.
6+
* @expr: the expression whose type we should check (not evaluated).
7+
* @type: the exact type we expect the expression to be.
8+
*
9+
* This macro is usually used within other macros to try to ensure that a macro
10+
* argument is of the expected type. No type promotion of the expression is
11+
* done: an unsigned int is not the same as an int!
12+
*
13+
* check_type() always evaluates to 1.
14+
*
15+
* If your compiler does not support typeof, then the best we can do is fail
16+
* to compile if the sizes of the types are unequal (a less complete check).
17+
*
18+
* Example:
19+
* // They should always pass a 64-bit value to _set_some_value!
20+
* #define set_some_value(expr) \
21+
* _set_some_value((check_type((expr), uint64_t), (expr)))
22+
*/
23+
24+
/**
25+
* check_types_match - issue a warning or build failure if types are not same.
26+
* @expr1: the first expression (not evaluated).
27+
* @expr2: the second expression (not evaluated).
28+
*
29+
* This macro is usually used within other macros to try to ensure that
30+
* arguments are of identical types. No type promotion of the expressions is
31+
* done: an unsigned int is not the same as an int!
32+
*
33+
* check_types_match() always evaluates to 0.
34+
*
35+
* If your compiler does not support typeof, then the best we can do is fail
36+
* to compile if the sizes of the types are unequal (a less complete check).
37+
*
38+
* Example:
39+
* // Do subtraction to get to enclosing type, but make sure that
40+
* // pointer is of correct type for that member.
41+
* #define container_of(mbr_ptr, encl_type, mbr) \
42+
* (check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \
43+
* ((encl_type *) \
44+
* ((char *)(mbr_ptr) - offsetof(enclosing_type, mbr))))
45+
*/
46+
#define check_type(expr, type) \
47+
((typeof(expr) *)0 != (type *)0)
48+
49+
#define check_types_match(expr1, expr2) \
50+
((typeof(expr1) *)0 != (typeof(expr2) *)0)
51+
52+
#endif /* CCAN_CHECK_TYPE_H */
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef CCAN_CONTAINER_OF_H
2+
#define CCAN_CONTAINER_OF_H
3+
#include <stddef.h>
4+
5+
#include <ccan/check_type/check_type.h>
6+
7+
/**
8+
* container_of - get pointer to enclosing structure
9+
* @member_ptr: pointer to the structure member
10+
* @containing_type: the type this member is within
11+
* @member: the name of this member within the structure.
12+
*
13+
* Given a pointer to a member of a structure, this macro does pointer
14+
* subtraction to return the pointer to the enclosing type.
15+
*
16+
* Example:
17+
* struct foo {
18+
* int fielda, fieldb;
19+
* // ...
20+
* };
21+
* struct info {
22+
* int some_other_field;
23+
* struct foo my_foo;
24+
* };
25+
*
26+
* static struct info *foo_to_info(struct foo *foo)
27+
* {
28+
* return container_of(foo, struct info, my_foo);
29+
* }
30+
*/
31+
#define container_of(member_ptr, containing_type, member) \
32+
((containing_type *) \
33+
((char *)(member_ptr) - offsetof(containing_type, member)) \
34+
- check_types_match(*(member_ptr), ((containing_type *)0)->member))
35+
36+
37+
/**
38+
* container_of_var - get pointer to enclosing structure using a variable
39+
* @member_ptr: pointer to the structure member
40+
* @var: a pointer to a structure of same type as this member is within
41+
* @member: the name of this member within the structure.
42+
*
43+
* Given a pointer to a member of a structure, this macro does pointer
44+
* subtraction to return the pointer to the enclosing type.
45+
*
46+
* Example:
47+
* static struct info *foo_to_i(struct foo *foo)
48+
* {
49+
* struct info *i = container_of_var(foo, i, my_foo);
50+
* return i;
51+
* }
52+
*/
53+
#define container_of_var(member_ptr, var, member) \
54+
container_of(member_ptr, typeof(*var), member)
55+
56+
#endif /* CCAN_CONTAINER_OF_H */

0 commit comments

Comments
 (0)