GNU PROLOG with UTF8 support
misc.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------*
2  * GNU Prolog *
3  * *
4  * Part : Prolog engine *
5  * File : misc.h *
6  * Descr.: miscellaneous operations - header file *
7  * Author: Daniel Diaz *
8  * *
9  * Copyright (C) 1999-2015 Daniel Diaz *
10  * *
11  * This file is part of GNU Prolog *
12  * *
13  * GNU Prolog is free software: you can redistribute it and/or *
14  * modify it under the terms of either: *
15  * *
16  * - the GNU Lesser General Public License as published by the Free *
17  * Software Foundation; either version 3 of the License, or (at your *
18  * option) any later version. *
19  * *
20  * or *
21  * *
22  * - the GNU General Public License as published by the Free *
23  * Software Foundation; either version 2 of the License, or (at your *
24  * option) any later version. *
25  * *
26  * or both in parallel, as here. *
27  * *
28  * GNU Prolog is distributed in the hope that it will be useful, *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
31  * General Public License for more details. *
32  * *
33  * You should have received copies of the GNU General Public License and *
34  * the GNU Lesser General Public License along with this program. If *
35  * not, see http://www.gnu.org/licenses/. *
36  *-------------------------------------------------------------------------*/
37 
38 
39 #include <stdlib.h>
40 
41 /*---------------------------------*
42  * Constants *
43  *---------------------------------*/
44 
45 /*---------------------------------*
46  * Type Definitions *
47  *---------------------------------*/
48 
49 /*---------------------------------*
50  * Global Variables *
51  *---------------------------------*/
52 
53 /*---------------------------------*
54  * Function Prototypes *
55  *---------------------------------*/
56 
57 char *Pl_Malloc_Check(unsigned size, char *src_file, int src_line);
58 
59 char *Pl_Calloc_Check(unsigned nb, unsigned size, char *src_file,
60  int src_line);
61 
62 char *Pl_Realloc_Check(char *ptr, unsigned size, char *src_file, int src_line);
63 
64 char *Pl_Strdup_Check(char *str, char *src_file, int src_line);
65 
66 #define Malloc(size) Pl_Malloc_Check(size, __FILE__, __LINE__)
67 
68 #define Calloc(nb, size) Pl_Calloc_Check(nb, size, __FILE__, __LINE__)
69 
70 #define Realloc(ptr, size) Pl_Realloc_Check(ptr, size, __FILE__, __LINE__)
71 
72 #define Free(ptr) free(ptr)
73 
74 #define Strdup(str) Pl_Strdup_Check(str, __FILE__, __LINE__)
75 
76 void Pl_Extend_Table_If_Needed(char **hash_tbl);
77 
78 void Pl_Extend_Array(char **ptbl, int *nb_elem, int elem_size, Bool bzero);
79 
80 void Pl_Exit_With_Value(int ret_val);
81 
82 void Pl_Fatal_Error(char *format, ...);
83 
84 
85 
86 /* NB: for LSB/MSB the result is undefined if x == 0 */
87 
88 #if defined(__GNUC__) && __GNUC__ >= 4 && SIZEOF_LONG == SIZEOF_PTR
89 
90 #define Pl_Least_Significant_Bit(x) (__builtin_ctzl(x))
91 
92 #define Pl_Most_Significant_Bit(x) (WORD_SIZE - 1 - __builtin_clzl(x))
93 
94 #define Pl_Count_Set_Bits(x) (__builtin_popcountl(x))
95 
96 
97 #else /* !__GNUC__ || __GNUC__ < 4 || SIZEOF_LONG != SIZEOF_PTR */
98 
99 #define Pl_Least_Significant_Bit(x) Pl_LSB(x)
100 
101 #define Pl_Most_Significant_Bit(x) Pl_MSB(x)
102 
103 #define Pl_Count_Set_Bits(x) Pl_Popcount(x)
104 
105 int Pl_LSB(PlLong x);
106 
107 int Pl_MSB(PlLong x);
108 
109 int Pl_Popcount(PlLong x);
110 
111 #endif /* !__GNUC__ || __GNUC__ < 4 || SIZEOF_LONG != SIZEOF_PTR */
112 
113 
114 void *Pl_Dummy_Ptr(void *p);
115 
116 
char * format
Definition: hexfilter.c:78
char * Pl_Strdup_Check(char *str, char *src_file, int src_line)
Definition: misc.c:145
intptr_t PlLong
Definition: gprolog.h:88
char * Pl_Calloc_Check(unsigned nb, unsigned size, char *src_file, int src_line)
Definition: misc.c:109
static PlLong ret_val
Definition: ctrl_c.c:71
int Pl_LSB(PlLong x)
Definition: misc.c:249
void Pl_Exit_With_Value(int ret_val)
Definition: misc.c:202
int Pl_MSB(PlLong x)
Definition: misc.c:286
int Pl_Popcount(PlLong x)
Definition: misc.c:322
char * Pl_Realloc_Check(char *ptr, unsigned size, char *src_file, int src_line)
Definition: misc.c:127
void * Pl_Dummy_Ptr(void *p)
Definition: misc.c:369
void Pl_Fatal_Error(char *format,...)
Definition: misc.c:220
char * Pl_Malloc_Check(unsigned size, char *src_file, int src_line)
Definition: misc.c:91
void Pl_Extend_Array(char **ptbl, int *nb_elem, int elem_size, Bool bzero)
Definition: misc.c:179
PlLong x
Definition: chkma.c:99
void Pl_Extend_Table_If_Needed(char **hash_tbl)
Definition: misc.c:163
int Bool
Definition: bool.h:65