Skip to content

Commit

Permalink
fix: Fix format strings for rdevel (#93)
Browse files Browse the repository at this point in the history
* fix binary atomics

* more fixes

* more errors

* cran comments

* also clang-format

* add to build ignore
  • Loading branch information
paleolimbot authored Nov 30, 2023
1 parent 17f2f9e commit 1025240
Show file tree
Hide file tree
Showing 19 changed files with 1,247 additions and 1,352 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
^CRAN-RELEASE$
^\.vscode$
^CRAN-SUBMISSION$
^\.clang-format$
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
BasedOnStyle: Google
ColumnLimit: 90
DerivePointerAlignment: false
IncludeBlocks: Preserve
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

This release fixes new warnings from the M1Mac check.
This release fixes new warnings as shown on the package check page.

## R CMD check results

Expand Down
2 changes: 1 addition & 1 deletion src/geoarrow-imports.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ class Handler {
virtual ~Handler() {}
};

}
} // namespace util
42 changes: 17 additions & 25 deletions src/geos-basic-strtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
#include <R.h>
#include <Rinternals.h>

#include "libgeos.h"
#include "geos-common.h"
#include "libgeos.h"

#include <stdint.h>
#include <limits.h>
#include <stdint.h>

SEXP geos_c_basic_strtree_create(SEXP node_capacity_sexp) {
int node_capacity = INTEGER(node_capacity_sexp)[0];
GEOS_INIT();
GEOSSTRtree* tree = GEOSSTRtree_create_r(handle, node_capacity);
if (tree == NULL) {
GEOS_ERROR("%s", "Failed to create GEOSSTRtree*()"); // # nocov
GEOS_ERROR("%s", "Failed to create GEOSSTRtree*()"); // # nocov
}

SEXP tree_size_sexp = PROTECT(Rf_ScalarInteger(0));
SEXP tree_is_finalized = PROTECT(Rf_ScalarInteger(0));
SEXP tree_xptr = PROTECT(geos_common_tree_xptr(tree, tree_size_sexp, tree_is_finalized));
SEXP tree_xptr =
PROTECT(geos_common_tree_xptr(tree, tree_size_sexp, tree_is_finalized));
UNPROTECT(3);
return tree_xptr;
}
Expand All @@ -33,9 +34,8 @@ SEXP geos_c_basic_strtree_finalized(SEXP tree_xptr) {
return Rf_ScalarLogical(is_finalized);
}

GEOSGeometry* dummy_geometry_from_extent(GEOSContextHandle_t handle,
double xmin, double ymin,
double xmax, double ymax) {
GEOSGeometry* dummy_geometry_from_extent(GEOSContextHandle_t handle, double xmin,
double ymin, double xmax, double ymax) {
GEOSCoordSequence* seq = GEOSCoordSeq_create_r(handle, 2, 2);
if (seq == NULL) {
Rf_error("error creating GEOSCoordSequence");
Expand Down Expand Up @@ -71,7 +71,7 @@ SEXP geos_c_basic_strtree_insert_rect(SEXP tree_xptr, SEXP xmin_sexp, SEXP ymin_

GEOS_INIT();

GEOSSTRtree* tree = (GEOSSTRtree*) R_ExternalPtrAddr(tree_xptr);
GEOSSTRtree* tree = (GEOSSTRtree*)R_ExternalPtrAddr(tree_xptr);
if (tree == NULL) {
Rf_error("External pointer (GEOSSTRtree) is not valid");
}
Expand All @@ -92,17 +92,13 @@ SEXP geos_c_basic_strtree_insert_rect(SEXP tree_xptr, SEXP xmin_sexp, SEXP ymin_
R_CheckUserInterrupt();
}

if (xmin[i] > xmax[i] || ymin[i] > ymax[i] ||
R_IsNA(xmin[i]) || R_IsNA(ymin[i]) || R_IsNA(xmax[i]) || R_IsNA(ymax[i])) {
if (xmin[i] > xmax[i] || ymin[i] > ymax[i] || R_IsNA(xmin[i]) || R_IsNA(ymin[i]) ||
R_IsNA(xmax[i]) || R_IsNA(ymax[i])) {
tree_size[0]++;
continue;
}

geom = dummy_geometry_from_extent(
handle,
xmin[i], ymin[i],
xmax[i], ymax[i]
);
geom = dummy_geometry_from_extent(handle, xmin[i], ymin[i], xmax[i], ymax[i]);
payload = tree_size[0];
GEOSSTRtree_insert_r(handle, tree, geom, (void*)payload);
tree_size[0]++;
Expand Down Expand Up @@ -160,7 +156,7 @@ void basic_query_finalize(SEXP query_xptr) {
}
}

static void basic_query_callback(void *item, void *userdata) {
static void basic_query_callback(void* item, void* userdata) {
uintptr_t item_value = (uintptr_t)item;
struct BasicQuery* query = (struct BasicQuery*)userdata;
if (query->has_error || query->limit <= 0) {
Expand All @@ -171,8 +167,8 @@ static void basic_query_callback(void *item, void *userdata) {
}

SEXP geos_c_basic_strtree_query_geom(SEXP tree_xptr, SEXP xmin_sexp, SEXP ymin_sexp,
SEXP xmax_sexp, SEXP ymax_sexp,
SEXP limit_sexp, SEXP fill_sexp) {
SEXP xmax_sexp, SEXP ymax_sexp, SEXP limit_sexp,
SEXP fill_sexp) {
int limit = INTEGER(limit_sexp)[0];
if (limit < 0) {
limit = INT_MAX;
Expand All @@ -192,7 +188,7 @@ SEXP geos_c_basic_strtree_query_geom(SEXP tree_xptr, SEXP xmin_sexp, SEXP ymin_s

GEOS_INIT();

GEOSSTRtree* tree = (GEOSSTRtree*) R_ExternalPtrAddr(tree_xptr);
GEOSSTRtree* tree = (GEOSSTRtree*)R_ExternalPtrAddr(tree_xptr);
if (tree == NULL) {
Rf_error("External pointer (GEOSSTRtree) is not valid");
}
Expand All @@ -215,19 +211,15 @@ SEXP geos_c_basic_strtree_query_geom(SEXP tree_xptr, SEXP xmin_sexp, SEXP ymin_s
R_CheckUserInterrupt();
}

geom = dummy_geometry_from_extent(
handle,
xmin[i], ymin[i],
xmax[i], ymax[i]
);
geom = dummy_geometry_from_extent(handle, xmin[i], ymin[i], xmax[i], ymax[i]);

query->ix_ = i + 1;
query->has_error = 0;
query->limit = limit;
GEOSSTRtree_query_r(handle, tree, geom, &basic_query_callback, query);
GEOSGeom_destroy_r(handle, geom);
if (query->has_error) {
Rf_error("Failed to allocate container for result indices [i = %d]", i + 1);
Rf_error("Failed to allocate container for result indices [i = %ld]", (long)i + 1);
}

if (fill && query->limit > 0) {
Expand Down
Loading

0 comments on commit 1025240

Please sign in to comment.