Grid Community Toolkit  6.2.1653033972 (tag: v6.2.20220524)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
oldgaa_gl_internal_err.h
1 /*
2  * Copyright 1999-2006 University of Chicago
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * Copyright (c) 1991-1994 by the University of Southern California
19  * Part of GOST library
20  */
21 
22 #ifndef OLDGAA_GL_INTERNAL_ERR_H
23 
24 /* OUT OF MEMORY */
25 extern int gl__is_out_of_memory; /* used internally by gl__fout_of_memory() */
26 void oldgaa_gl__fout_of_memory(const char file[], int lineno);
27 
28 /* #define out_of_memory() \
29  gl__fout_of_memory(__FILE__, __LINE__); */
30 
31 extern void (*gl_out_of_memory_handler)(const char file[], int line);
32 
33 
34 /* BUFFER FULL */
35 
36 #define interr_buffer_full() \
37  gl__function_internal_error_helper(__FILE__, __LINE__, "A buffer filled up");
38 
39 /*********************/
40 
41 /* ASSERT */
42 #ifdef assert /* in case ASSERT.H was already included. We
43  want to over-ride it. */
44 #undef assert
45 #endif /* assert */
46 
47 #ifndef NDEBUG
48 #define assert(expr) do { \
49  if (!(expr)) \
50  gl__function_internal_error_helper(__FILE__, __LINE__, "assertion violated: " #expr); \
51 } while(0)
52 #else /* NDEBUG */
53 #define assert(expr) do {;} while(0)
54 #endif /* NDEBUG */
55 /*****************************************/
56 
57 
58 /* INTERNAL_ERROR */
59 /* This is the main macro we call when an 'internal error' has occurred.
60  This is usually a "can't happen" condition. */
61 
62 #define internal_error(msg) \
63  gl__function_internal_error_helper(__FILE__, __LINE__, msg)
64 
65 /* There are two helpers you can set this to. */
66 /* The macro version might be useful in instances where we might have blown the
67  stack. The function version is used instead of the macro version in order
68  to save a bit of code space (one function call instead of that inline code).
69  Each has a description below. */
70 
71 /* The macro version currently (8/9/96) displays errors of the form:
72  Internal error in file foo.c (line __LINE__): strange error */
73 /* We are trying to figure out how to handle this one. --steve 8/9/96 */
74 /* 8/9/96: I don't know under what circumstances we would have LINE be zero.
75  Must've happened oor I wouldn't have written it. --swa */
76 /* 8/9/96: using gl__function_internal_error_helper() always now; this
77  is (a) a way around the __LINE__ problem and (b) if the stack is
78  really trashed (the rationale for making the internal error handler
79  into inline code), then we won't be able to call write() or
80  abort() either, so the macro wouldn't buy us anything useful. */
81 /* I wish there were a way of getting rid of the strlen() and the
82  write() in the macro version; don't think we can do this in a
83  machine-independent way, though. If you ever encounter a problem and need
84  to enable this macro again to debug it, then I recommend using inline
85  assembly code with the C ASM construct. */
86 /* I know I could find a way around the macro's problem in printing the
87  __LINE__ appropriately, but I am not doing so, since this code is not in
88  use; we use the function version exclusively */
89 
90 #define gl__macro_internal_error_helper(file,line,msg) \
91 do { \
92  /* If LINE is ZERO, then print no prefatory message. */ \
93  if (line) { \
94  write(2, "Internal error in file " file " (line " #line "): ",\
95  sizeof "Internal error in file " file " (line " #line "): " -1);\
96  } \
97  write(2, msg, strlen(msg)); \
98  /* If LINE is ZERO, then print no terminal \n. */ \
99  if (line) \
100  write(2, "\n", 1); \
101  if (internal_error_handler) \
102  (*internal_error_handler)(file, line, msg); \
103  /* If the internal_error_handler() ever returns, we should not continue.
104  */ \
105  abort(); \
106 } while(0)
107 
108 /* Function form of internal_error. Shrinks code size. It is not clear that
109  both this and the MACRO version are needed; they have the same
110  interface. */
111 
112 void gl__function_internal_error_helper(const char file[], int linenumber, const char mesg[]);
113 
114 /* This function may be set to handle internal errors. Dirsrv handles them in
115  this way, by logging to plog. It is int instead of void for historical
116  reasons: older versions of the PCC (Portable C Compiler) cannot handle
117  pointers to void functions. */
118 
119 extern int (*internal_error_handler)(const char file[], int linenumber, const char mesg[]);
120 
121 void gl_function_arguments_error(const char *format, ...);
122 
123 #endif /* OLDGAA_GL_INTERNAL_ERR_H */