1 /*<html><pre>  -<a                             href="qh-user_r.htm"
2   >-------------------------------</a><a name="TOP">-</a>
3 
4    usermem_r.c
5    qh_exit(), qh_free(), and qh_malloc()
6 
7    See README.txt.
8 
9    If you redefine one of these functions you must redefine all of them.
10    If you recompile and load this file, then usermem.o will not be loaded
11    from qhull.a or qhull.lib
12 
13    See libqhull_r.h for data structures, macros, and user-callable functions.
14    See user_r.c for qhull-related, redefinable functions
15    see user_r.h for user-definable constants
16    See userprintf_r.c for qh_fprintf and userprintf_rbox_r.c for qh_fprintf_rbox
17 
18    Please report any errors that you fix to qhull@qhull.org
19 */
20 
21 #include "libqhull_r.h"
22 
23 #include <stdarg.h>
24 #include <stdlib.h>
25 
26 /*-<a                             href="qh-user_r.htm#TOC"
27   >-------------------------------</a><a name="qh_exit">-</a>
28 
29   qh_exit( exitcode )
30     exit program
31 
32   notes:
33     qh_exit() is called when qh_errexit() and longjmp() are not available.
34 
35     This is the only use of exit() in Qhull
36     To replace qh_exit with 'throw', see libqhullcpp/usermem_r-cpp.cpp
37 */
qh_exit(int exitcode)38 void qh_exit(int exitcode) {
39     /* CHANGE TO SOURCE: The commented line below is the original. It
40      needs to be replaced to fix warnings about exit being called. --
41      David Sterratt 3/4/12. */
42     /* exit(exitcode); */
43     error("Qhull exit, code %i", exitcode);
44 } /* exit */
45 
46 /*-<a                             href="qh-user_r.htm#TOC"
47   >-------------------------------</a><a name="qh_fprintf_stderr">-</a>
48 
49   qh_fprintf_stderr( msgcode, format, list of args )
50     fprintf to stderr with msgcode (non-zero)
51 
52   notes:
53     qh_fprintf_stderr() is called when qh->ferr is not defined, usually due to an initialization error
54 
55     It is typically followed by qh_errexit().
56 
57     Redefine this function to avoid using stderr
58 
59     Use qh_fprintf [userprintf_r.c] for normal printing
60 */
qh_fprintf_stderr(int msgcode,const char * fmt,...)61 void qh_fprintf_stderr(int msgcode, const char *fmt, ... ) {
62     va_list args;
63 
64     va_start(args, fmt);
65     if(msgcode)
66       /* CHANGE TO SOURCE */
67       /* fprintf(stderr, "QH%.4d ", msgcode); */
68       REprintf("QH%.4d", msgcode);
69     /* CHANGE TO SOURCE */
70     /* vfprintf(stderr, fmt, args); */
71     REvprintf(fmt, args);
72     va_end(args);
73 } /* fprintf_stderr */
74 
75 /*-<a                             href="qh-user_r.htm#TOC"
76 >-------------------------------</a><a name="qh_free">-</a>
77 
78   qh_free(qhT *qh, mem )
79     free memory
80 
81   notes:
82     same as free()
83     No calls to qh_errexit()
84 */
qh_free(void * mem)85 void qh_free(void *mem) {
86     free(mem);
87 } /* free */
88 
89 /*-<a                             href="qh-user_r.htm#TOC"
90     >-------------------------------</a><a name="qh_malloc">-</a>
91 
92     qh_malloc( mem )
93       allocate memory
94 
95     notes:
96       same as malloc()
97 */
qh_malloc(size_t size)98 void *qh_malloc(size_t size) {
99     return malloc(size);
100 } /* malloc */
101 
102 
103