annotate libffi/src/debug.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* -----------------------------------------------------------------------
kono
parents:
diff changeset
2 debug.c - Copyright (c) 1996 Red Hat, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Permission is hereby granted, free of charge, to any person obtaining
kono
parents:
diff changeset
5 a copy of this software and associated documentation files (the
kono
parents:
diff changeset
6 ``Software''), to deal in the Software without restriction, including
kono
parents:
diff changeset
7 without limitation the rights to use, copy, modify, merge, publish,
kono
parents:
diff changeset
8 distribute, sublicense, and/or sell copies of the Software, and to
kono
parents:
diff changeset
9 permit persons to whom the Software is furnished to do so, subject to
kono
parents:
diff changeset
10 the following conditions:
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 The above copyright notice and this permission notice shall be included
kono
parents:
diff changeset
13 in all copies or substantial portions of the Software.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
kono
parents:
diff changeset
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
kono
parents:
diff changeset
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kono
parents:
diff changeset
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
kono
parents:
diff changeset
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
kono
parents:
diff changeset
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kono
parents:
diff changeset
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
kono
parents:
diff changeset
22 DEALINGS IN THE SOFTWARE.
kono
parents:
diff changeset
23 ----------------------------------------------------------------------- */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <ffi.h>
kono
parents:
diff changeset
26 #include <ffi_common.h>
kono
parents:
diff changeset
27 #include <stdlib.h>
kono
parents:
diff changeset
28 #include <stdio.h>
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 /* General debugging routines */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 void ffi_stop_here(void)
kono
parents:
diff changeset
33 {
kono
parents:
diff changeset
34 /* This function is only useful for debugging purposes.
kono
parents:
diff changeset
35 Place a breakpoint on ffi_stop_here to be notified of
kono
parents:
diff changeset
36 significant events. */
kono
parents:
diff changeset
37 }
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 /* This function should only be called via the FFI_ASSERT() macro */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 void ffi_assert(char *expr, char *file, int line)
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
kono
parents:
diff changeset
44 ffi_stop_here();
kono
parents:
diff changeset
45 abort();
kono
parents:
diff changeset
46 }
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Perform a sanity check on an ffi_type structure */
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 void ffi_type_test(ffi_type *a, char *file, int line)
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 FFI_ASSERT_AT(a != NULL, file, line);
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 FFI_ASSERT_AT(a->type <= FFI_TYPE_LAST, file, line);
kono
parents:
diff changeset
55 FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->size > 0, file, line);
kono
parents:
diff changeset
56 FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->alignment > 0, file, line);
kono
parents:
diff changeset
57 FFI_ASSERT_AT((a->type != FFI_TYPE_STRUCT && a->type != FFI_TYPE_COMPLEX)
kono
parents:
diff changeset
58 || a->elements != NULL, file, line);
kono
parents:
diff changeset
59 FFI_ASSERT_AT(a->type != FFI_TYPE_COMPLEX
kono
parents:
diff changeset
60 || (a->elements != NULL
kono
parents:
diff changeset
61 && a->elements[0] != NULL && a->elements[1] == NULL),
kono
parents:
diff changeset
62 file, line);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 }