-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87f1f35
commit 282347b
Showing
3 changed files
with
45 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#define R_NO_REMAP | ||
#include <R.h> | ||
#include <Rinternals.h> | ||
#include <proj.h> | ||
#include "proj-context.h" | ||
|
||
SEXP proj_context_xptr_create(PJ_CONTEXT* ctx) { | ||
SEXP ctx_xptr = PROTECT(R_MakeExternalPtr(ctx, R_NilValue, R_NilValue)); | ||
R_RegisterCFinalizer(ctx_xptr, &proj_context_xptr_destroy); | ||
UNPROTECT(1); | ||
return ctx_xptr; | ||
} | ||
|
||
void proj_context_xptr_destroy(SEXP ctx_xptr) { | ||
if (TYPEOF(ctx_xptr) != EXTPTRSXP) { | ||
Rf_error("`ctx_xptr` must be an externalptr"); | ||
} | ||
|
||
PJ_CONTEXT* ctx = (PJ_CONTEXT*) R_ExternalPtrAddr(ctx_xptr); | ||
if (ctx != NULL) proj_context_destroy(ctx); | ||
} | ||
|
||
#if PROJ_VERSION_MAJOR < 8 | ||
static const char* proj_context_errno_string(PJ_CONTEXT*, int err) { | ||
// deprecated in proj 8 | ||
return proj_errno_string(err); | ||
} | ||
#endif | ||
|
||
void stop_proj_error(PJ_CONTEXT* ctx) { | ||
int err = proj_context_errno(ctx); | ||
const char* msg = proj_context_errno_string(ctx, err); | ||
|
||
Rf_error("%s", msg); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <R.h> | ||
#include <Rinternals.h> | ||
#include <proj.h> | ||
|
||
SEXP proj_context_xptr_create(PJ_CONTEXT* ctx); | ||
void proj_context_xptr_destroy(SEXP ctx_xptr); | ||
void stop_proj_error(PJ_CONTEXT* ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters