mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
The code reachable from overzooming a tile no longer calls exit(). It reports errors by throwing tippecanoe_error, and owns its FILE * and json_pull * handles through RAII wrappers so that nothing leaks when an error unwinds the stack. New files: * errors.hpp/errors.cpp: the tippecanoe_error exception class, plus throw_tippecanoe_error() and throw_perror() helpers. * raii.hpp: unique_file and unique_json_pull, both std::unique_ptr aliases, for FILE * and json_pull *. exit() becomes throw in clip.cpp, mvt.cpp, mvt.hpp, read_json.cpp, evaluator.cpp, text.cpp, geometry.cpp, attribute.cpp, and write_json.hpp. Each tool's main() is now a try/catch around an inner_main(), so the command-line tools exit with the status they always did. Along the way this fixes a z_stream leaked when compress() failed, an exit() that could run from json_writer's destructor during unwinding, and an exit() in mvt_value's hash function. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DuCSVGssWNUCpVEE8Yp5HT
29 lines
483 B
C++
29 lines
483 B
C++
#ifndef RAII_HPP
|
|
#define RAII_HPP
|
|
|
|
#include <memory>
|
|
#include <stdio.h>
|
|
#include "jsonpull/jsonpull.h"
|
|
|
|
// FILE* → unique_file
|
|
struct file_closer {
|
|
void operator()(FILE *f) {
|
|
if (f) {
|
|
fclose(f);
|
|
}
|
|
}
|
|
};
|
|
using unique_file = std::unique_ptr<FILE, file_closer>;
|
|
|
|
// json_pull* → unique_json_pull
|
|
struct json_pull_closer {
|
|
void operator()(json_pull *jp) {
|
|
if (jp) {
|
|
json_end(jp);
|
|
}
|
|
}
|
|
};
|
|
using unique_json_pull = std::unique_ptr<json_pull, json_pull_closer>;
|
|
|
|
#endif
|