Debian Codegraph @

external/glpk/glpenv01.c

raw symbols SCIP
1 /* glpenv01.c (environment initialization/termination) */cxx . . $ `<file>/external/glpk/glpenv01.c`/
2
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
5 *
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <[email protected]>.
10 *
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
24
25 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
26
27 /***********************************************************************
28 * NAME
29 *
30 * glp_init_env - initialize GLPK environment
31 *
32 * SYNOPSIS
33 *
34 * int glp_init_env(void);
35 *
36 * DESCRIPTION
37 *
38 * The routine glp_init_env initializes the GLPK environment. Normally
39 * the application program does not need to call this routine, because
40 * it is called automatically on the first call to any API routine.
41 *
42 * RETURNS
43 *
44 * The routine glp_init_env returns one of the following codes:
45 *
46 * 0 - initialization successful;
47 * 1 - environment has been already initialized;
48 * 2 - initialization failed (insufficient memory);
49 * 3 - initialization failed (unsupported programming model). */
50
51 int glp_init_envcxx . . $ glp_init_env(b126dc7c1de90089).(void)
52 { ENVcxx . . $ ENV# *env;
53 int ok;
54 /* check if the programming model is supported */
55 ok = (CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`! == 8 && sizeof(char) == 1 &&
56 sizeof(short) == 2 && sizeof(int) == 4 &&
57 (sizeof(void *) == 4 || sizeof(void *) == 8));
58 if (!ok) return 3;
59 /* check if the environment is already initialized */
60 if (tls_get_ptrcxx . . $ `external/glpk/glpenv.h:141:9`!() != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return 1;
61 /* allocate and initialize the environment block */
62 env = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(ENVcxx . . $ ENV#));
63 if (env == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return 2;
64 env->magiccxx . . $ ENV#magic. = ENV_MAGICcxx . . $ `external/glpk/glpenv.h:35:9`!;
65 sprintfcxx . . $ sprintf(26c8642d26409d6d).(env->versioncxx . . $ ENV#version., "%d.%d",
66 GLP_MAJOR_VERSIONcxx . . $ `external/glpk/glpk.h:40:9`!, GLP_MINOR_VERSIONcxx . . $ `external/glpk/glpk.h:41:9`!);
67 env->term_bufcxx . . $ ENV#term_buf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(TERM_BUF_SIZEcxx . . $ `external/glpk/glpenv.h:38:9`!);
68 if (env->term_bufcxx . . $ ENV#term_buf. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
69 { freecxx . . $ free(5d22bdacc48458e8).(env);
70 return 2;
71 }
72 env->term_outcxx . . $ ENV#term_out. = GLP_ONcxx . . $ `external/glpk/glpk.h:221:9`!;
73 env->term_hookcxx . . $ ENV#term_hook. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
74 env->term_infocxx . . $ ENV#term_info. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
75 env->tee_filecxx . . $ ENV#tee_file. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
76 env->err_filecxx . . $ ENV#err_file. = "";
77 env->err_linecxx . . $ ENV#err_line. = 0;
78 env->err_hookcxx . . $ ENV#err_hook. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
79 env->err_infocxx . . $ ENV#err_info. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
80 env->mem_limitcxx . . $ ENV#mem_limit..hicxx . . $ $anonymous_type_2d15b5456314bbc5_9#hi. = 0x7FFFFFFF, env->mem_limitcxx . . $ ENV#mem_limit..locxx . . $ $anonymous_type_2d15b5456314bbc5_9#lo. = 0xFFFFFFFF;
81 env->mem_ptrcxx . . $ ENV#mem_ptr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
82 env->mem_countcxx . . $ ENV#mem_count. = env->mem_cpeakcxx . . $ ENV#mem_cpeak. = 0;
83 env->mem_totalcxx . . $ ENV#mem_total. = env->mem_tpeakcxx . . $ ENV#mem_tpeak. = xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(0);
84 env->file_ptrcxx . . $ ENV#file_ptr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
85 env->ioerr_msgcxx . . $ ENV#ioerr_msg. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(IOERR_MSG_SIZEcxx . . $ `external/glpk/glpenv.h:41:9`!);
86 if (env->ioerr_msgcxx . . $ ENV#ioerr_msg. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
87 { freecxx . . $ free(5d22bdacc48458e8).(env->term_bufcxx . . $ ENV#term_buf.);
88 freecxx . . $ free(5d22bdacc48458e8).(env);
89 return 2;
90 }
91 strcpycxx . . $ strcpy(b7b3a83273496486).(env->ioerr_msgcxx . . $ ENV#ioerr_msg., "No error");
92 env->h_odbccxx . . $ ENV#h_odbc. = env->h_mysqlcxx . . $ ENV#h_mysql. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
93 /* save pointer to the environment block */
94 tls_set_ptrcxx . . $ `external/glpk/glpenv.h:137:9`!(env);
95 /* initialization successful */
96 return 0;
97 }
98
99 /***********************************************************************
100 * NAME
101 *
102 * get_env_ptr - retrieve pointer to environment block
103 *
104 * SYNOPSIS
105 *
106 * #include "glpenv.h"
107 * ENV *get_env_ptr(void);
108 *
109 * DESCRIPTION
110 *
111 * The routine get_env_ptr retrieves and returns a pointer to the GLPK
112 * environment block.
113 *
114 * If the GLPK environment has not been initialized yet, the routine
115 * performs initialization. If initialization fails, the routine prints
116 * an error message to stderr and terminates the program.
117 *
118 * RETURNS
119 *
120 * The routine returns a pointer to the environment block. */
121
122 ENVcxx . . $ ENV# *get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!(void)
123 { ENVcxx . . $ ENV# *env = tls_get_ptrcxx . . $ `external/glpk/glpenv.h:141:9`!();
124 /* check if the environment has been initialized */
125 if (env == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
126 { /* not initialized yet; perform initialization */
127 if (glp_init_envcxx . . $ glp_init_env(b126dc7c1de90089).() != 0)
128 { /* initialization failed; display an error message */
129 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "GLPK initialization failed\n");
130 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
131 /* and abnormally terminate the program */
132 abortcxx . . $ abort(8df32a62017fbbf6).();
133 }
134 /* initialization successful; retrieve the pointer */
135 env = tls_get_ptrcxx . . $ `external/glpk/glpenv.h:141:9`!();
136 }
137 /* check if the environment block is valid */
138 if (env->magiccxx . . $ ENV#magic. != ENV_MAGICcxx . . $ `external/glpk/glpenv.h:35:9`!)
139 { fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid GLPK environment\n");
140 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
141 abortcxx . . $ abort(8df32a62017fbbf6).();
142 }
143 return env;
144 }
145
146 /***********************************************************************
147 * NAME
148 *
149 * glp_version - determine library version
150 *
151 * SYNOPSIS
152 *
153 * const char *glp_version(void);
154 *
155 * RETURNS
156 *
157 * The routine glp_version returns a pointer to a null-terminated
158 * character string, which specifies the version of the GLPK library in
159 * the form "X.Y", where X is the major version number, and Y is the
160 * minor version number, for example, "4.16". */
161
162 const char *glp_versioncxx . . $ glp_version(33a1f659e94feb42).(void)
163 { ENVcxx . . $ ENV# *env = get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!();
164 return env->versioncxx . . $ ENV#version.;
165 }
166
167 /***********************************************************************
168 * NAME
169 *
170 * glp_free_env - free GLPK environment
171 *
172 * SYNOPSIS
173 *
174 * int glp_free_env(void);
175 *
176 * DESCRIPTION
177 *
178 * The routine glp_free_env frees all resources used by GLPK routines
179 * (memory blocks, etc.) which are currently still in use.
180 *
181 * Normally the application program does not need to call this routine,
182 * because GLPK routines always free all unused resources. However, if
183 * the application program even has deleted all problem objects, there
184 * will be several memory blocks still allocated for the library needs.
185 * For some reasons the application program may want GLPK to free this
186 * memory, in which case it should call glp_free_env.
187 *
188 * Note that a call to glp_free_env invalidates all problem objects as
189 * if no GLPK routine were called.
190 *
191 * RETURNS
192 *
193 * 0 - termination successful;
194 * 1 - environment is inactive (was not initialized). */
195
196 int glp_free_envcxx . . $ glp_free_env(b126dc7c1de90089).(void)
197 { ENVcxx . . $ ENV# *env = tls_get_ptrcxx . . $ `external/glpk/glpenv.h:141:9`!();
198 MEMcxx . . $ MEM# *desc;
199 /* check if the environment is active */
200 if (env == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return 1;
201 /* check if the environment block is valid */
202 if (env->magiccxx . . $ ENV#magic. != ENV_MAGICcxx . . $ `external/glpk/glpenv.h:35:9`!)
203 { fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid GLPK environment\n");
204 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
205 abortcxx . . $ abort(8df32a62017fbbf6).();
206 }
207 /* close handles to shared libraries */
208 if (env->h_odbccxx . . $ ENV#h_odbc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
209 xdlclosecxx . . $ `external/glpk/glpenv.h:223:9`!(env->h_odbccxx . . $ ENV#h_odbc.);
210 if (env->h_mysqlcxx . . $ ENV#h_mysql. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
211 xdlclosecxx . . $ `external/glpk/glpenv.h:223:9`!(env->h_mysqlcxx . . $ ENV#h_mysql.);
212 /* close streams which are still open */
213 while (env->file_ptrcxx . . $ ENV#file_ptr. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
214 xfclosecxx . . $ `external/glpk/glpenv.h:211:9`!(env->file_ptrcxx . . $ ENV#file_ptr.);
215 /* free memory blocks which are still allocated */
216 while (env->mem_ptrcxx . . $ ENV#mem_ptr. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
217 { desc = env->mem_ptrcxx . . $ ENV#mem_ptr.;
218 env->mem_ptrcxx . . $ ENV#mem_ptr. = desc->nextcxx . . $ MEM#next.;
219 freecxx . . $ free(5d22bdacc48458e8).(desc);
220 }
221 /* invalidate the environment block */
222 env->magiccxx . . $ ENV#magic. = -1;
223 /* free memory allocated to the environment block */
224 freecxx . . $ free(5d22bdacc48458e8).(env->term_bufcxx . . $ ENV#term_buf.);
225 freecxx . . $ free(5d22bdacc48458e8).(env->ioerr_msgcxx . . $ ENV#ioerr_msg.);
226 freecxx . . $ free(5d22bdacc48458e8).(env);
227 /* reset a pointer to the environment block */
228 tls_set_ptrcxx . . $ `external/glpk/glpenv.h:137:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
229 /* termination successful */
230 return 0;
231 }
232
233 /* eof */