| 1 |
/* Macro for checking that a function declaration is compliant. |
| 2 |
Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation, either version 3 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
#ifndef SIGNATURE_CHECK |
| 18 |
|
| 19 |
/* Check that the function FN takes the specified arguments ARGS with |
| 20 |
a return type of RET. This header is designed to be included after |
| 21 |
<config.h> and the one system header that is supposed to contain |
| 22 |
the function being checked, but prior to any other system headers |
| 23 |
that are necessary for the unit test. Therefore, this file does |
| 24 |
not include any system headers, nor reference anything outside of |
| 25 |
the macro arguments. For an example, if foo.h should provide: |
| 26 |
|
| 27 |
extern int foo (char, float); |
| 28 |
|
| 29 |
then the unit test named test-foo.c would start out with: |
| 30 |
|
| 31 |
#include <config.h> |
| 32 |
#include <foo.h> |
| 33 |
#include "signature.h" |
| 34 |
SIGNATURE_CHECK (foo, int, (char, float)); |
| 35 |
#include <other.h> |
| 36 |
... |
| 37 |
*/ |
| 38 |
# define SIGNATURE_CHECK(fn, ret, args) \ |
| 39 |
SIGNATURE_CHECK1 (fn, ret, args, __LINE__) |
| 40 |
|
| 41 |
/* Necessary to allow multiple SIGNATURE_CHECK lines in a unit test. |
| 42 |
Note that the checks must not occupy the same line. */ |
| 43 |
# define SIGNATURE_CHECK1(fn, ret, args, id) \ |
| 44 |
SIGNATURE_CHECK2 (fn, ret, args, id) /* macroexpand line */ |
| 45 |
# define SIGNATURE_CHECK2(fn, ret, args, id) \ |
| 46 |
_GL_UNUSED static ret (*signature_check ## id) args = fn |
| 47 |
|
| 48 |
#endif /* SIGNATURE_CHECK */ |