Skip to content

Commit

Permalink
Oh wow. A bunch of regrets here:
Browse files Browse the repository at this point in the history
1. Use specific methods, like `OSRDestroySpatialReference`, over generic ones, like
`OSRRelease`. The specific ones are always right.
2. `atexit` is always a mistake.
3. Questions end with a question mark.
  • Loading branch information
thejefflarson committed Jun 26, 2019
1 parent 2dba111 commit 89e6835
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@

static int initialized = 0;

// The atexit handler used to close all connections to open data stores
static void cleanup() {
OGRCleanupAll();
}

// Initialize libraries, register the atexit handler and set up error reporting.
void simplet_init() {
if (initialized) return;
CPLSetConfigOption("OGR_ENABLE_PARTIAL_REPROJECTION", "ON");
#ifdef DEBUG
CPLSetConfigOption("CPL_DEBUG", "ON");
#else
CPLSetConfigOption("CPL_DEBUG", "OFF");
#endif
OGRRegisterAll();
GDALAllRegister();
atexit(cleanup);
initialized = 1;
};
4 changes: 2 additions & 2 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void simplet_map_free(simplet_map_t *map) {
simplet_list_free(map->layers);
}

if (map->proj) OSRRelease(map->proj);
if (map->proj) OSRDestroySpatialReference(map->proj);

if (map->bgcolor) free(map->bgcolor);

Expand Down Expand Up @@ -248,7 +248,7 @@ const char *simplet_map_status_to_string(simplet_map_t *map) {

// Check if the map is valid for rendering
simplet_status_t simplet_map_is_valid(simplet_map_t *map) {
// Does it have a previously set error.
// Does it have a previously set error?
if (!(map->status == SIMPLET_OK)) return SIMPLET_ERR;

// Does it have a bounds?
Expand Down
1 change: 1 addition & 0 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ simplet_status_t simplet_query_process(simplet_query_t *query,
if (!(olayer = OGR_DS_ExecuteSQL(source, query->ogrsql, NULL, NULL))) {
int err = CPLGetLastErrorNo();
if (!err) {
// FIXME: This should be a problem, but it is ignored right now.
return SIMPLET_OK;
} else {
return set_error(query, SIMPLET_OGR_ERR, CPLGetLastErrorMsg());
Expand Down
3 changes: 0 additions & 3 deletions src/vector_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ simplet_status_t simplet_vector_layer_process(simplet_vector_layer_t *layer,
if (!(source = OGROpenShared(layer->source, 0, NULL)))
return set_error(layer, SIMPLET_OGR_ERR, "error opening layer source");

// Retain the datasource because we want to cache open connections to a
// data source like postgres.
if (OGR_DS_GetRefCount(source) == 1) OGR_DS_Reference(source);
if (!(iter = simplet_get_list_iter(layer->queries))) {
OGRReleaseDataSource(source);
return set_error(layer, SIMPLET_OOM, "out of memory getting list iterator");
Expand Down

0 comments on commit 89e6835

Please sign in to comment.