From 8eb60010da1aff7969d5fa6869152c40972c2526 Mon Sep 17 00:00:00 2001 From: snowman2 Date: Fri, 16 Oct 2020 19:15:08 -0500 Subject: [PATCH 1/3] ENH: Added proj_context_clone --- .../development/reference/functions.rst | 8 +++++++ src/4D_api.cpp | 9 ++++++- src/ctx.cpp | 10 ++++++++ src/proj.h | 1 + src/proj_api.h | 1 + test/unit/test_c_api.cpp | 24 ++++++++++++++++++- 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/docs/source/development/reference/functions.rst b/docs/source/development/reference/functions.rst index 770fb8ec5a..cc29743c15 100644 --- a/docs/source/development/reference/functions.rst +++ b/docs/source/development/reference/functions.rst @@ -13,6 +13,14 @@ Threading contexts :returns: a new context +.. c:function:: PJ_CONTEXT* proj_context_clone(PJ_CONTEXT *ctx) + + .. versionadded:: 7.2 + + Create a new threading-context based on an existing context. + + :returns: a new context + .. c:function:: void proj_context_destroy(PJ_CONTEXT *ctx) Deallocate a threading-context. diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 3c6ab8026e..f22a31b772 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1448,11 +1448,18 @@ int proj_errno_reset (const PJ *P) { } -/* Create a new context */ +/* Create a new context based on the default context */ PJ_CONTEXT *proj_context_create (void) { return pj_ctx_alloc (); } +/* Create a new context based on a custom context */ +PJ_CONTEXT *proj_context_clone (PJ_CONTEXT *ctx) { + if (nullptr==ctx) + return pj_ctx_alloc (); + + return pj_ctx_clone (ctx); +} PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) { if (nullptr==ctx) diff --git a/src/ctx.cpp b/src/ctx.cpp index 5575d3aa93..5089f22608 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -225,6 +225,16 @@ projCtx pj_ctx_alloc() return new (std::nothrow) projCtx_t(*pj_get_default_ctx()); } +/************************************************************************/ +/* pj_ctx_clone() */ +/************************************************************************/ + +projCtx pj_ctx_clone( projCtx ctx ) + +{ + return new (std::nothrow) projCtx_t(*ctx); +} + /************************************************************************/ /* pj_ctx_free() */ /************************************************************************/ diff --git a/src/proj.h b/src/proj.h index b758663aeb..c98fcc1f5b 100644 --- a/src/proj.h +++ b/src/proj.h @@ -361,6 +361,7 @@ typedef struct projCtx_t PJ_CONTEXT; #endif PJ_CONTEXT PROJ_DLL *proj_context_create (void); PJ_CONTEXT PROJ_DLL *proj_context_destroy (PJ_CONTEXT *ctx); +PJ_CONTEXT PROJ_DLL *proj_context_clone (PJ_CONTEXT *ctx); /** Callback to resolve a filename to a full path */ typedef const char* (*proj_file_finder) (PJ_CONTEXT *ctx, const char*, void* user_data); diff --git a/src/proj_api.h b/src/proj_api.h index a1b6393c1a..77cf421665 100644 --- a/src/proj_api.h +++ b/src/proj_api.h @@ -192,6 +192,7 @@ void PROJ_DLL pj_cleanup_lock(void); void PROJ_DLL pj_set_ctx( projPJ, projCtx ); projCtx PROJ_DLL pj_ctx_alloc(void); +projCtx PROJ_DLL pj_ctx_clone( projCtx ); void PROJ_DLL pj_ctx_free( projCtx ); int PROJ_DLL pj_ctx_get_errno( projCtx ); void PROJ_DLL pj_ctx_set_errno( projCtx, int ); diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index c0db38803e..49d023bc8e 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -4073,7 +4073,7 @@ TEST_F(Fixture_proj_context_set_autoclose_database, // --------------------------------------------------------------------------- -TEST_F(CApi, proj_context_clone) { +TEST_F(CApi, proj_context_copy_from_default) { auto c_path = proj_context_get_database_path(m_ctxt); ASSERT_TRUE(c_path != nullptr); std::string path(c_path); @@ -4123,6 +4123,28 @@ TEST_F(CApi, proj_context_clone) { ASSERT_EQ(new_db_path, tmp_filename); } + +// --------------------------------------------------------------------------- + +TEST_F(CApi, proj_context_clone) { + int new_init_rules = proj_context_get_use_proj4_init_rules(NULL, 0) > 0 ? 0 : 1; + PJ_CONTEXT *new_ctx = proj_context_create(); + EXPECT_NE(new_ctx, nullptr); + PjContextKeeper keeper_ctxt(new_ctx); + proj_context_use_proj4_init_rules(new_ctx, new_init_rules); + PJ_CONTEXT *clone_ctx = proj_context_clone(new_ctx); + EXPECT_NE(clone_ctx, nullptr); + PjContextKeeper keeper_clone_ctxt(clone_ctx); + ASSERT_EQ( + proj_context_get_use_proj4_init_rules(new_ctx, 0), + proj_context_get_use_proj4_init_rules(clone_ctx, 0) + ); + EXPECT_NE( + proj_context_get_use_proj4_init_rules(NULL, 0), + proj_context_get_use_proj4_init_rules(clone_ctx, 0) + ); +} + // --------------------------------------------------------------------------- TEST_F(CApi, proj_create_crs_to_crs_from_pj) { From aa87828d929ed688d01cfa6183f674b4c113f16f Mon Sep 17 00:00:00 2001 From: snowman2 Date: Fri, 16 Oct 2020 21:33:37 -0500 Subject: [PATCH 2/3] Fix exported symbols and ignore test output --- .gitignore | 1 + scripts/reference_exported_symbols.txt | 2 ++ src/proj_symbol_rename.h | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 5f9508c30e..1d9aa7933e 100644 --- a/.gitignore +++ b/.gitignore @@ -134,6 +134,7 @@ m4/lt~obsolete.m4 /test/unit/proj_errno_string_test /test/unit/test_defmodel /test/unit/test_network +/test/unit/test_tinshift /tmp_alias/ # jniwrap diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index 8f225b3b56..b81db715a4 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -752,6 +752,7 @@ pj_compare_datums pj_context_get_grid_cache_filename(projCtx_t*) pj_context_set_user_writable_directory(projCtx_t*, std::string const&) pj_ctx_alloc +pj_ctx_clone pj_ctx_fclose pj_ctx_fgets pj_ctx_fopen @@ -830,6 +831,7 @@ proj_cleanup proj_clone proj_concatoperation_get_step proj_concatoperation_get_step_count +proj_context_clone proj_context_create proj_context_delete_cpp_context(projCppContext*) proj_context_destroy diff --git a/src/proj_symbol_rename.h b/src/proj_symbol_rename.h index cb6fcd23c3..0df7357583 100644 --- a/src/proj_symbol_rename.h +++ b/src/proj_symbol_rename.h @@ -29,6 +29,7 @@ #define pj_clear_initcache internal_pj_clear_initcache #define pj_compare_datums internal_pj_compare_datums #define pj_ctx_alloc internal_pj_ctx_alloc +#define pj_ctx_clone internal_pj_ctx_clone #define pj_ctx_fclose internal_pj_ctx_fclose #define pj_ctx_fgets internal_pj_ctx_fgets #define pj_ctx_fopen internal_pj_ctx_fopen @@ -97,6 +98,7 @@ #define proj_clone internal_proj_clone #define proj_concatoperation_get_step internal_proj_concatoperation_get_step #define proj_concatoperation_get_step_count internal_proj_concatoperation_get_step_count +#define proj_context_clone internal_proj_context_clone #define proj_context_create internal_proj_context_create #define proj_context_destroy internal_proj_context_destroy #define proj_context_errno internal_proj_context_errno @@ -235,6 +237,8 @@ #define proj_crs_get_coordinate_system internal_proj_crs_get_coordinate_system #define proj_crs_get_coordoperation internal_proj_crs_get_coordoperation #define proj_crs_get_datum internal_proj_crs_get_datum +#define proj_crs_get_datum_ensemble internal_proj_crs_get_datum_ensemble +#define proj_crs_get_datum_forced internal_proj_crs_get_datum_forced #define proj_crs_get_geodetic_crs internal_proj_crs_get_geodetic_crs #define proj_crs_get_horizontal_datum internal_proj_crs_get_horizontal_datum #define proj_crs_get_sub_crs internal_proj_crs_get_sub_crs @@ -243,11 +247,15 @@ #define proj_cs_get_axis_count internal_proj_cs_get_axis_count #define proj_cs_get_axis_info internal_proj_cs_get_axis_info #define proj_cs_get_type internal_proj_cs_get_type +#define proj_datum_ensemble_get_accuracy internal_proj_datum_ensemble_get_accuracy +#define proj_datum_ensemble_get_member internal_proj_datum_ensemble_get_member +#define proj_datum_ensemble_get_member_count internal_proj_datum_ensemble_get_member_count #define proj_degree_input internal_proj_degree_input #define proj_degree_output internal_proj_degree_output #define proj_destroy internal_proj_destroy #define proj_dmstor internal_proj_dmstor #define proj_download_file internal_proj_download_file +#define proj_dynamic_datum_get_frame_reference_epoch internal_proj_dynamic_datum_get_frame_reference_epoch #define proj_ellipsoid_get_parameters internal_proj_ellipsoid_get_parameters #define proj_errno internal_proj_errno #define proj_errno_reset internal_proj_errno_reset From f208a8c49a599ab73aec2cc7d65cfee56e237c08 Mon Sep 17 00:00:00 2001 From: snowman2 Date: Sat, 17 Oct 2020 07:32:38 -0500 Subject: [PATCH 3/3] Move proj_context_clone to ctx.cpp and remove pj_ctx_clone --- scripts/reference_exported_symbols.txt | 1 - src/4D_api.cpp | 7 ------- src/ctx.cpp | 9 ++++++--- src/proj_api.h | 1 - src/proj_symbol_rename.h | 1 - 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index b81db715a4..cee89a5e3c 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -752,7 +752,6 @@ pj_compare_datums pj_context_get_grid_cache_filename(projCtx_t*) pj_context_set_user_writable_directory(projCtx_t*, std::string const&) pj_ctx_alloc -pj_ctx_clone pj_ctx_fclose pj_ctx_fgets pj_ctx_fopen diff --git a/src/4D_api.cpp b/src/4D_api.cpp index f22a31b772..0c26840d9c 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1453,13 +1453,6 @@ PJ_CONTEXT *proj_context_create (void) { return pj_ctx_alloc (); } -/* Create a new context based on a custom context */ -PJ_CONTEXT *proj_context_clone (PJ_CONTEXT *ctx) { - if (nullptr==ctx) - return pj_ctx_alloc (); - - return pj_ctx_clone (ctx); -} PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) { if (nullptr==ctx) diff --git a/src/ctx.cpp b/src/ctx.cpp index 5089f22608..6dbe0de5c3 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -226,12 +226,15 @@ projCtx pj_ctx_alloc() } /************************************************************************/ -/* pj_ctx_clone() */ +/* proj_context_clone() */ +/* Create a new context based on a custom context */ /************************************************************************/ -projCtx pj_ctx_clone( projCtx ctx ) - +PJ_CONTEXT *proj_context_clone (PJ_CONTEXT *ctx) { + if (nullptr==ctx) + return pj_ctx_alloc (); + return new (std::nothrow) projCtx_t(*ctx); } diff --git a/src/proj_api.h b/src/proj_api.h index 77cf421665..a1b6393c1a 100644 --- a/src/proj_api.h +++ b/src/proj_api.h @@ -192,7 +192,6 @@ void PROJ_DLL pj_cleanup_lock(void); void PROJ_DLL pj_set_ctx( projPJ, projCtx ); projCtx PROJ_DLL pj_ctx_alloc(void); -projCtx PROJ_DLL pj_ctx_clone( projCtx ); void PROJ_DLL pj_ctx_free( projCtx ); int PROJ_DLL pj_ctx_get_errno( projCtx ); void PROJ_DLL pj_ctx_set_errno( projCtx, int ); diff --git a/src/proj_symbol_rename.h b/src/proj_symbol_rename.h index 0df7357583..7fbe4242f4 100644 --- a/src/proj_symbol_rename.h +++ b/src/proj_symbol_rename.h @@ -29,7 +29,6 @@ #define pj_clear_initcache internal_pj_clear_initcache #define pj_compare_datums internal_pj_compare_datums #define pj_ctx_alloc internal_pj_ctx_alloc -#define pj_ctx_clone internal_pj_ctx_clone #define pj_ctx_fclose internal_pj_ctx_fclose #define pj_ctx_fgets internal_pj_ctx_fgets #define pj_ctx_fopen internal_pj_ctx_fopen