GCC Code Coverage Report


Directory: ./
File: basic/common.cpp
Date: 2026-11-30 06:25:12
Exec Total Coverage
Lines: 60 66 90.9%
Functions: 4 5 80.0%
Branches: 64 118 54.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/basic/common.h>
41 #include <geogram/basic/process.h>
42 #include <geogram/basic/logger.h>
43 #include <geogram/basic/progress.h>
44 #include <geogram/basic/command_line.h>
45 #include <geogram/basic/file_system.h>
46 #include <geogram/basic/stopwatch.h>
47 #include <geogram/numerics/multi_precision.h>
48 #include <geogram/numerics/predicates.h>
49 #include <geogram/delaunay/delaunay.h>
50 #include <geogram/mesh/mesh_io.h>
51 #include <geogram/version.h>
52 #include <geogram/bibliography/bibliography.h>
53
54 #include <geogram/image/image.h>
55 #include <geogram/image/image_library.h>
56 #include <geogram/image/image_serializer_stb.h>
57 #include <geogram/image/image_serializer_xpm.h>
58 #include <geogram/image/image_serializer_pgm.h>
59
60 #include <sstream>
61 #include <iomanip>
62 #include <optional>
63
64 #ifdef GEO_OS_EMSCRIPTEN
65 #include <emscripten.h>
66 #pragma GCC diagnostic ignored "-Wc++20-extensions" // for EM_ASM()
67 #endif
68
69 namespace GEO {
70
71 namespace {
72
73 /**
74 * \brief A global object that manages initialization and
75 * termination of the Geogram library
76 */
77 struct GeogramLibSingleton {
78
79 258 static std::optional<GeogramLibSingleton>& instance(int flags) {
80
3/8
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 258 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 258 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
258 static std::optional<GeogramLibSingleton> instance(flags);
81 258 return instance;
82 }
83
84 258 GeogramLibSingleton(int flags) {
85
86 // When locale is set to non-us countries,
87 // this may cause some problems when reading
88 // floating-point numbers (some locale expect
89 // a decimal ',' instead of a '.').
90 // This restores the default behavior for
91 // reading floating-point numbers.
92 #ifdef GEO_OS_UNIX
93
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 2 times.
258 if (flags & GEOGRAM_INSTALL_LOCALE) {
94 256 setenv("LC_NUMERIC","POSIX",1);
95 }
96 #endif
97
98 #ifndef GEOGRAM_PSM
99 258 Environment* env = Environment::instance();
100
3/6
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
1032 env->set_value("version", GEOGRAM_VERSION);
101
3/6
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
1032 env->set_value("release_date", VORPALINE_BUILD_DATE);
102
3/6
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
1032 env->set_value("SVN revision", VORPALINE_SVN_REVISION);
103 #endif
104 258 FileSystem::initialize();
105 258 Logger::initialize();
106 258 Process::initialize(flags);
107 258 Progress::initialize();
108 258 CmdLine::initialize();
109 258 Stopwatch::initialize();
110 258 PCK::initialize();
111 258 Delaunay::initialize();
112
113 #ifndef GEOGRAM_PSM
114
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 2 times.
258 if (flags & GEOGRAM_INSTALL_BIBLIO) {
115 256 Biblio::initialize();
116 }
117 #endif
118
119 #ifndef GEOGRAM_PSM
120 258 mesh_io_initialize();
121 #endif
122
123 // Clear lastest system error
124
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 2 times.
258 if (flags & GEOGRAM_INSTALL_ERRNO) {
125 256 errno = 0;
126 }
127
128 #ifndef GEOGRAM_PSM
129 // Register attribute types that can be saved into files.
130
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<bool,Numeric::uint8>("bool");
131
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<char>("char");
132
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<unsigned char>("unsigned char");
133
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<int>("int");
134
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<unsigned int>("unsigned int");
135
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<index_t>("index_t");
136
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<signed_index_t>("signed_index_t");
137
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<float>("float");
138
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<double>("double");
139
140
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_register_attribute_type<vec2>("vec2");
141
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
258 geo_register_attribute_type<vec3>("vec3");
142 #endif
143
144 #ifdef GEO_OS_EMSCRIPTEN
145
146 // This mounts the local file system when an emscripten-compiled
147 // program runs in node.js.
148 // Current working directory is mounted in /working,
149 // and root directory is mounted in /root
150 //
151 // Skip this when NODERAWFS is enabled: the real
152 // filesystem is already mounted at '/', so
153 // FS.mkdir('/working') would try to create a
154 // directory at the real root and fail with EROFS
155 // (crashing worker pthreads).
156
157 EM_ASM(
158 if(
159 typeof NODERAWFS === 'undefined' &&
160 typeof module !== 'undefined' &&
161 this.module !== module
162 ) {
163 FS.mkdir('/working');
164 FS.mkdir('/root');
165 FS.mount(NODEFS, { root: '.' }, '/working');
166 FS.mount(NODEFS, { root: '/' }, '/root');
167 }
168 );
169
170 #endif
171
172 #ifndef GEOGRAM_PSM
173 258 ImageLibrary::initialize() ;
174
175
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("png");
176
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpg");
177
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpeg");
178
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("tga");
179
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("bmp");
180
181
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
516 geo_declare_image_serializer<ImageSerializer_xpm>("xpm") ;
182
2/4
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
258 geo_declare_image_serializer<ImageSerializer_pgm>("pgm") ;
183 #endif
184 258 }
185
186 258 ~GeogramLibSingleton() {
187
188 258 if(
189
4/6
✓ Branch 2 taken 255 times.
✓ Branch 3 taken 3 times.
✓ Branch 5 taken 258 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 258 times.
1287 CmdLine::arg_is_declared("sys:stats") &&
190
6/8
✗ Branch 2 not taken.
✓ Branch 3 taken 255 times.
✓ Branch 4 taken 255 times.
✓ Branch 5 taken 3 times.
✓ Branch 7 taken 255 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 258 times.
✗ Branch 10 not taken.
768 CmdLine::get_arg_bool("sys:stats")
191 ) {
192 ✗ Logger::div("System Statistics");
193 ✗ PCK::show_stats();
194 ✗ Process::show_stats();
195 }
196
197 258 PCK::terminate();
198
199 #ifndef GEOGRAM_PSM
200 258 ImageLibrary::terminate() ;
201 258 Biblio::terminate();
202 #endif
203
204 258 Progress::terminate();
205 258 Process::terminate();
206 258 CmdLine::terminate();
207 258 Logger::terminate();
208 258 FileSystem::terminate();
209 258 Environment::terminate();
210
211 258 }
212 };
213
214 }
215
216 258 void initialize(int flags) {
217 258 GeogramLibSingleton::instance(flags);
218 258 }
219
220 ✗ void terminate() {
221 ✗ GeogramLibSingleton::instance(GEOGRAM_INSTALL_NONE).reset();
222 ✗ }
223 }
224