From aa46197d66ce70ece382bf955326c46b13f35864 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sat, 14 Nov 2020 22:55:31 +0100 Subject: Weed out proj_api.h datatypes and replace them with their proj.h counterparts --- src/init.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 101fc8ad..a42bf963 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -415,7 +415,7 @@ pj_init_plus( const char *definition ) } PJ * -pj_init_plus_ctx( projCtx ctx, const char *definition ) +pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) { #define MAX_ARG 200 char *argv[MAX_ARG]; @@ -511,7 +511,7 @@ static PJ_CONSTRUCTOR locate_constructor (const char *name) { PJ * -pj_init_ctx(projCtx ctx, int argc, char **argv) { +pj_init_ctx(PJ_CONTEXT *ctx, int argc, char **argv) { /* Legacy interface: allow init=epsg:XXXX syntax by default */ int allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, TRUE); return pj_init_ctx_with_allow_init_epsg(ctx, argc, argv, allow_init_epsg); @@ -519,7 +519,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) { PJ * -pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_init_epsg) { +pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int allow_init_epsg) { const char *s; char *name; PJ_CONSTRUCTOR proj; -- cgit v1.2.3 From a74b985b5006c2d279353a245cfcb850cf7fcc94 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 17 Nov 2020 12:54:24 +0100 Subject: Remove pj_ctx_* functions and use their proj_context counterparts --- src/init.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index a42bf963..2d679618 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -257,7 +257,7 @@ Expand key from buffer or (if not in buffer) from init file PJ* src; const char* proj_string; - pj_ctx_set_errno( ctx, 0 ); + proj_context_errno_set( ctx, 0 ); if( !allow_init_epsg ) { pj_log (ctx, PJ_LOG_TRACE, "%s expansion disallowed", xkey); @@ -448,7 +448,7 @@ pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) if( argc+1 == MAX_ARG ) { pj_dalloc( defn_copy ); - pj_ctx_set_errno( ctx, PJD_ERR_UNPARSEABLE_CS_DEF ); + proj_context_errno_set( ctx, PJD_ERR_UNPARSEABLE_CS_DEF ); return nullptr; } @@ -538,7 +538,7 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all ctx->last_errno = 0; if (argc <= 0) { - pj_ctx_set_errno (ctx, PJD_ERR_NO_ARGS); + proj_context_errno_set (ctx, PJD_ERR_NO_ARGS); return nullptr; } @@ -552,13 +552,13 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all /* can't have nested pipelines directly */ if (n_pipelines > 1) { - pj_ctx_set_errno (ctx, PJD_ERR_MALFORMED_PIPELINE); + proj_context_errno_set (ctx, PJD_ERR_MALFORMED_PIPELINE); return nullptr; } /* don't allow more than one +init in non-pipeline operations */ if (n_pipelines == 0 && n_inits > 1) { - pj_ctx_set_errno (ctx, PJD_ERR_TOO_MANY_INITS); + proj_context_errno_set (ctx, PJD_ERR_TOO_MANY_INITS); return nullptr; } -- cgit v1.2.3 From 43efca4ab87fb37a0931edcb6be11c0bd3784098 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 18 Nov 2020 09:57:42 +0100 Subject: Remove pj_free() and move it's functional parts to proj_destroy() --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 2d679618..95bb404f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1,7 +1,7 @@ /****************************************************************************** * Project: PROJ.4 * Purpose: Initialize projection object from string definition. Includes - * pj_init(), pj_init_plus() and pj_free() function. + * pj_init(), and pj_init_plus() function. * Author: Gerald Evenden, Frank Warmerdam * ****************************************************************************** @@ -829,7 +829,7 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all err = proj_errno_reset (PIN); PIN = proj(PIN); if (proj_errno (PIN)) { - pj_free(PIN); + proj_destroy(PIN); return nullptr; } proj_errno_restore (PIN, err); -- cgit v1.2.3 From 046270a85faf20f38d01e02942d197db74bb8542 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Fri, 20 Nov 2020 16:37:12 +0100 Subject: Remove old pj_ memory (de)allocation functions Gone are pj_malloc, pj_calloc, pj_dalloc and pj_dealloc. Their primary function as API memory functions in proj_api.h is no longer there and the other use as a workaround for old errno problems is no longer valid either. Replaced with malloc and free across the codebase. --- src/init.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 95bb404f..7b614c5f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -55,7 +55,7 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) { /* Keep a handle to the start of the list, so we have something to return */ auto param = pj_mkparam_ws (c, &c); if (nullptr==param) { - pj_dealloc_params (ctx, first, ENOMEM); + free_params (ctx, first, ENOMEM); return nullptr; } if (nullptr==last) { @@ -84,7 +84,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { char *buffer = nullptr; size_t n; - fname = static_cast(pj_malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3)); + fname = static_cast(malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3)); if (nullptr==fname) { return nullptr; } @@ -96,7 +96,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { else key += 5; if (MAX_PATH_FILENAME + ID_TAG_MAX + 2 < strlen (key)) { - pj_dealloc (fname); + free (fname); return nullptr; } memmove (fname, key, strlen (key) + 1); @@ -105,7 +105,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { section = strrchr(fname, ':'); if (nullptr==section) { proj_context_errno_set (ctx, PJD_ERR_NO_COLON_IN_INIT_STRING); - pj_dealloc (fname); + free (fname); return nullptr; } *section = 0; @@ -117,7 +117,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { auto file = NS_PROJ::FileManager::open_resource_file(ctx, fname); if (nullptr==file) { - pj_dealloc (fname); + free (fname); proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE); return nullptr; } @@ -131,7 +131,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { line = file->read_line(MAX_LINE_LENGTH, maxLenReached, eofReached); /* End of file? */ if (maxLenReached || eofReached) { - pj_dealloc (fname); + free (fname); proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE); return nullptr; } @@ -149,9 +149,9 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { } /* We're at the first line of the right section - copy line to buffer */ - buffer = static_cast(pj_malloc (current_buffer_size)); + buffer = static_cast(malloc (current_buffer_size)); if (nullptr==buffer) { - pj_dealloc (fname); + free (fname); return nullptr; } @@ -183,22 +183,22 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) { pj_chomp (&line[0]); /* Remove '#' style comments */ next_length = strlen (line.data()) + buffer_length + 2; if (next_length > current_buffer_size) { - char *b = static_cast(pj_malloc (2 * current_buffer_size)); + char *b = static_cast(malloc (2 * current_buffer_size)); if (nullptr==b) { - pj_dealloc (buffer); + free (buffer); buffer = nullptr; break; } strcpy (b, buffer); current_buffer_size *= 2; - pj_dealloc (buffer); + free (buffer); buffer = b; } buffer[buffer_length] = ' '; strcpy (buffer + buffer_length + 1, line.data()); } - pj_dealloc (fname); + free (fname); if (nullptr==buffer) return nullptr; pj_shrink (buffer); @@ -306,7 +306,7 @@ Expand key from buffer or (if not in buffer) from init file definition, init_items->param, init_items->next ? init_items->next->param : "(empty)"); - pj_dealloc (definition); + free (definition); if (nullptr==init_items) return nullptr; @@ -424,7 +424,7 @@ pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) PJ *result = nullptr; /* make a copy that we can manipulate */ - defn_copy = (char *) pj_malloc( strlen(definition)+1 ); + defn_copy = (char *) malloc( strlen(definition)+1 ); if (!defn_copy) return nullptr; strcpy( defn_copy, definition ); @@ -447,7 +447,7 @@ pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) if( argc+1 == MAX_ARG ) { - pj_dalloc( defn_copy ); + free( defn_copy ); proj_context_errno_set( ctx, PJD_ERR_UNPARSEABLE_CS_DEF ); return nullptr; } @@ -477,7 +477,7 @@ pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) /* perform actual initialization */ result = pj_init_ctx( ctx, argc, argv ); - pj_dalloc( defn_copy ); + free( defn_copy ); return result; } @@ -566,14 +566,14 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all /* put arguments into internal linked list */ start = curr = pj_mkparam(argv[0]); if (!curr) { - pj_dealloc_params (ctx, start, ENOMEM); + free_params (ctx, start, ENOMEM); return nullptr; } for (i = 1; i < argc; ++i) { curr->next = pj_mkparam(argv[i]); if (!curr->next) { - pj_dealloc_params (ctx, start, ENOMEM); + free_params (ctx, start, ENOMEM); return nullptr; } curr = curr->next; @@ -588,31 +588,31 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all if (init && n_pipelines == 0) { init = pj_expand_init_internal (ctx, init, allow_init_epsg); if (!init) { - pj_dealloc_params (ctx, start, PJD_ERR_NO_ARGS); + free_params (ctx, start, PJD_ERR_NO_ARGS); return nullptr; } } if (ctx->last_errno) { - pj_dealloc_params (ctx, start, ctx->last_errno); + free_params (ctx, start, ctx->last_errno); return nullptr; } /* Find projection selection */ curr = pj_param_exists (start, "proj"); if (nullptr==curr) { - pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED); + free_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED); return nullptr; } name = curr->param; if (strlen (name) < 6) { - pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED); + free_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED); return nullptr; } name += 5; proj = locate_constructor (name); if (nullptr==proj) { - pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID); + free_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID); return nullptr; } @@ -621,7 +621,7 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all /* Allocate projection structure */ PIN = proj(nullptr); if (nullptr==PIN) { - pj_dealloc_params (ctx, start, ENOMEM); + free_params (ctx, start, ENOMEM); return nullptr; } @@ -820,7 +820,7 @@ pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int all PIN->from_greenwich = 0.0; /* Private object for the geodesic functions */ - PIN->geod = static_cast(pj_calloc (1, sizeof (struct geod_geodesic))); + PIN->geod = static_cast(calloc (1, sizeof (struct geod_geodesic))); if (nullptr==PIN->geod) return pj_default_destructor (PIN, ENOMEM); geod_init(PIN->geod, PIN->a, (1 - sqrt (1 - PIN->es))); -- cgit v1.2.3 From f4dc79075c19706dda6e3253c2f224e9df468291 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 30 Nov 2020 01:35:59 +0100 Subject: API cleanup: unexport number of internal symbols, and remove/replace a few unused ones --- src/init.cpp | 97 ------------------------------------------------------------ 1 file changed, 97 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 7b614c5f..1e89402d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -399,90 +399,6 @@ paralist *pj_expand_init(PJ_CONTEXT *ctx, paralist *init) { } -/************************************************************************/ -/* pj_init_plus() */ -/* */ -/* Same as pj_init() except it takes one argument string with */ -/* individual arguments preceded by '+', such as "+proj=utm */ -/* +zone=11 +ellps=WGS84". */ -/************************************************************************/ - -PJ * -pj_init_plus( const char *definition ) - -{ - return pj_init_plus_ctx( pj_get_default_ctx(), definition ); -} - -PJ * -pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) -{ -#define MAX_ARG 200 - char *argv[MAX_ARG]; - char *defn_copy; - int argc = 0, i, blank_count = 0; - PJ *result = nullptr; - - /* make a copy that we can manipulate */ - defn_copy = (char *) malloc( strlen(definition)+1 ); - if (!defn_copy) - return nullptr; - strcpy( defn_copy, definition ); - - /* split into arguments based on '+' and trim white space */ - - for( i = 0; defn_copy[i] != '\0'; i++ ) - { - switch( defn_copy[i] ) - { - case '+': - if( i == 0 || defn_copy[i-1] == '\0' || blank_count > 0 ) - { - /* trim trailing spaces from the previous param */ - if( blank_count > 0 ) - { - defn_copy[i - blank_count] = '\0'; - blank_count = 0; - } - - if( argc+1 == MAX_ARG ) - { - free( defn_copy ); - proj_context_errno_set( ctx, PJD_ERR_UNPARSEABLE_CS_DEF ); - return nullptr; - } - - argv[argc++] = defn_copy + i + 1; - } - break; - - case ' ': - case '\t': - case '\n': - /* trim leading spaces from the current param */ - if( i == 0 || defn_copy[i-1] == '\0' || argc == 0 || argv[argc-1] == defn_copy + i ) - defn_copy[i] = '\0'; - else - blank_count++; - break; - - default: - /* reset blank_count */ - blank_count = 0; - } - } - /* trim trailing spaces from the last param */ - defn_copy[i - blank_count] = '\0'; - - /* perform actual initialization */ - result = pj_init_ctx( ctx, argc, argv ); - - free( defn_copy ); - return result; -} - - - /************************************************************************/ /* pj_init() */ /* */ @@ -492,11 +408,6 @@ pj_init_plus_ctx( PJ_CONTEXT *ctx, const char *definition ) /* large enough to hold projection specific parameters. */ /************************************************************************/ -PJ * -pj_init(int argc, char **argv) { - return pj_init_ctx( pj_get_default_ctx(), argc, argv ); -} - static PJ_CONSTRUCTOR locate_constructor (const char *name) { int i; @@ -510,14 +421,6 @@ static PJ_CONSTRUCTOR locate_constructor (const char *name) { } -PJ * -pj_init_ctx(PJ_CONTEXT *ctx, int argc, char **argv) { - /* Legacy interface: allow init=epsg:XXXX syntax by default */ - int allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, TRUE); - return pj_init_ctx_with_allow_init_epsg(ctx, argc, argv, allow_init_epsg); -} - - PJ * pj_init_ctx_with_allow_init_epsg(PJ_CONTEXT *ctx, int argc, char **argv, int allow_init_epsg) { const char *s; -- cgit v1.2.3