From e2dd223c5601b387cd622b88583e857b03e9fade Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sat, 14 Nov 2020 11:28:36 +0100 Subject: Remove src/transform.cpp and related tests --- src/malloc.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/malloc.cpp') diff --git a/src/malloc.cpp b/src/malloc.cpp index c8de6630..eb64023f 100644 --- a/src/malloc.cpp +++ b/src/malloc.cpp @@ -262,7 +262,6 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */ void proj_cleanup() { /*****************************************************************************/ pj_clear_initcache(); - pj_deallocate_grids(); FileManager::clearMemoryCache(); pj_clear_hgridshift_knowngrids_cache(); pj_clear_vgridshift_knowngrids_cache(); -- 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/malloc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/malloc.cpp') diff --git a/src/malloc.cpp b/src/malloc.cpp index eb64023f..b1bcea1d 100644 --- a/src/malloc.cpp +++ b/src/malloc.cpp @@ -166,7 +166,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { n = t->next; pj_dealloc(t); } - pj_ctx_set_errno (ctx, errlev); + proj_context_errno_set (ctx, errlev); return (void *) nullptr; } @@ -218,7 +218,7 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */ /* Note that both, in the multithreaded case, may then contain undefined */ /* values. This is expected behavior. For MT have one ctx per thread */ if (0!=errlev) - pj_ctx_set_errno (pj_get_ctx(P), errlev); + proj_context_errno_set (pj_get_ctx(P), errlev); if (nullptr==P) 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/malloc.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/malloc.cpp') diff --git a/src/malloc.cpp b/src/malloc.cpp index b1bcea1d..590dd27f 100644 --- a/src/malloc.cpp +++ b/src/malloc.cpp @@ -174,7 +174,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { /************************************************************************/ -/* pj_free() */ +/* proj_destroy() */ /* */ /* This is the application callable entry point for destroying */ /* a projection definition. It does work generic to all */ @@ -183,15 +183,16 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { /* In most cases P->destructor()==pj_default_destructor. */ /************************************************************************/ -void pj_free(PJ *P) { +PJ *proj_destroy(PJ *P) { if (nullptr==P || !P->destructor) - return; + return nullptr; /* free projection parameters - all the hard work is done by */ /* pj_default_destructor, which is supposed */ /* to be called as the last step of the local destructor */ /* pointed to by P->destructor. In most cases, */ /* pj_default_destructor actually *is* what is pointed to */ P->destructor (P, proj_errno(P)); + return nullptr; } /*****************************************************************************/ @@ -246,12 +247,12 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */ pj_dealloc (P->def_full); /* free the cs2cs emulation elements */ - pj_free (P->axisswap); - pj_free (P->helmert); - pj_free (P->cart); - pj_free (P->cart_wgs84); - pj_free (P->hgridshift); - pj_free (P->vgridshift); + proj_destroy (P->axisswap); + proj_destroy (P->helmert); + proj_destroy (P->cart); + proj_destroy (P->cart_wgs84); + proj_destroy (P->hgridshift); + proj_destroy (P->vgridshift); pj_dealloc (static_cast(P->opaque)); delete P; -- 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/malloc.cpp | 112 +++++++-------------------------------------------------- 1 file changed, 13 insertions(+), 99 deletions(-) (limited to 'src/malloc.cpp') diff --git a/src/malloc.cpp b/src/malloc.cpp index 590dd27f..6b7fbf26 100644 --- a/src/malloc.cpp +++ b/src/malloc.cpp @@ -53,99 +53,13 @@ using namespace NS_PROJ; -/**********************************************************************/ -void *pj_malloc(size_t size) { -/*********************************************************************** -Currently, pj_malloc is a hack to solve an errno problem. -The problem is described in more details at -https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=86420. -It seems, that pj_init and similar functions incorrectly -(under debian/glibs-2.3.2) assume that pj_malloc resets -errno after success. pj_malloc tries to mimic this. - -NOTE (2017-09-29): The problem described at the bugzilla page -referred to above, is most likely a case of someone not -understanding the proper usage of errno. We should review -whether "the problem is actually a problem" in PROJ.4 code. - -Library specific allocators can be useful, and improve -interoperability, if properly used. That is, by making them -run/initialization time switchable, somewhat like the file i/o -interface. - -But as things stand, we are more likely to get benefit -from reviewing the code for proper errno usage, which is hard, -due to the presence of context local and global pj_errnos. - -Probably, these were introduced in order to support incomplete -implementations of thread local errnos at an early phase of the -implementation of multithreading support in PROJ.4). - -It is likely too late to get rid of contexts, but we can still -benefit from a better usage of errno. -***********************************************************************/ - int old_errno = errno; - void *res = malloc(size); - if ( res && !old_errno ) - errno = 0; - return res; -} - - -/**********************************************************************/ -void *pj_calloc (size_t n, size_t size) { -/*********************************************************************** -pj_calloc is the pj-equivalent of calloc(). - -It allocates space for an array of elements of size . -The array is initialized to zeros. -***********************************************************************/ - void *res = pj_malloc (n*size); - if (nullptr==res) - return nullptr; - memset (res, 0, n*size); - return res; -} - - -/**********************************************************************/ -void pj_dalloc(void *ptr) { -/**********************************************************************/ - free(ptr); -} - - -/**********************************************************************/ -void *pj_dealloc (void *ptr) { -/*********************************************************************** -pj_dealloc supports the common use case of "clean up and return a null -pointer" to signal an error in a multi level allocation: - - struct foo { int bar; int *baz; }; - - struct foo *p = pj_calloc (1, sizeof (struct foo)); - if (0==p) - return 0; - - p->baz = pj_calloc (10, sizeof(int)); - if (0==p->baz) - return pj_dealloc (p); // clean up + signal error by 0-return - - return p; // success - -***********************************************************************/ - if (nullptr==ptr) - return nullptr; - pj_dalloc (ptr); - return nullptr; -} /**********************************************************************/ char *pj_strdup(const char *str) /**********************************************************************/ { size_t len = strlen(str) + 1; - char *dup = static_cast(pj_malloc(len)); + char *dup = static_cast(malloc(len)); if (dup) memcpy(dup, str, len); return dup; @@ -153,7 +67,7 @@ char *pj_strdup(const char *str) /*****************************************************************************/ -void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { +void *free_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { /***************************************************************************** Companion to pj_default_destructor (below). Deallocates a linked list of "+proj=xxx" initialization parameters. @@ -164,7 +78,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) { paralist *t, *n; for (t = start; t; t = n) { n = t->next; - pj_dealloc(t); + free(t); } proj_context_errno_set (ctx, errlev); return (void *) nullptr; @@ -225,26 +139,26 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */ return nullptr; - pj_dealloc(P->def_size); - pj_dealloc(P->def_shape); - pj_dealloc(P->def_spherification); - pj_dealloc(P->def_ellps); + free(P->def_size); + free(P->def_shape); + free(P->def_spherification); + free(P->def_ellps); delete static_cast(P->hgrids_legacy); delete static_cast(P->vgrids_legacy); - /* We used to call pj_dalloc( P->catalog ), but this will leak */ + /* We used to call free( P->catalog ), but this will leak */ /* memory. The safe way to clear catalog and grid is to call */ - /* pj_gc_unloadall(pj_get_default_ctx()); and pj_deallocate_grids(); */ + /* pj_gc_unloadall(pj_get_default_ctx()); and freeate_grids(); */ /* TODO: we should probably have a public pj_cleanup() method to do all */ /* that */ /* free the interface to Charles Karney's geodesic library */ - pj_dealloc( P->geod ); + free( P->geod ); /* free parameter list elements */ - pj_dealloc_params (pj_get_ctx(P), P->params, errlev); - pj_dealloc (P->def_full); + free_params (pj_get_ctx(P), P->params, errlev); + free (P->def_full); /* free the cs2cs emulation elements */ proj_destroy (P->axisswap); @@ -254,7 +168,7 @@ PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */ proj_destroy (P->hgridshift); proj_destroy (P->vgridshift); - pj_dealloc (static_cast(P->opaque)); + free (static_cast(P->opaque)); delete P; return nullptr; } -- cgit v1.2.3