From 664bd689bf8dd3ca38a5071459902b89114e88eb Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 30 Nov 2018 02:36:00 +0100 Subject: C API: do not 'cache' PROJ context in PJ_OBJ objects We store the PJ_CONTEXT* in the PJ_OBJ objects, but this might cause issues in multi-threaded uses. For example, before this change, let's imagie: - a PJ_OBJ is created in thread A with a PJ_CONTEXT that is specific to this thread A - PJ_OBJ is transfered to another thread that operates on it. It might thus use the PJ_CONTEXT that was TLS(A) - in the meantime thread A does completely different things, but still operate on its PJ_CONTEXT. We might get a concurrent use of the PJ_CONTEXT despite working on different PJ_OBJ Another situation is when using constructor functions that take two PJ_OBJ. Up to now, we arbitrarily selected the context of one of the arguments to attach it to the new object. So better be explicit on which context is used. For reference, in those wrappers of the C++ API, the context is mostly used for two things: - reporting C++ exceptions as PROJ errors with the error handler attached to the PJ_CONTEXT - using the database handle that is associated with the PJ_CONTEXT. --- scripts/create_c_api_projections.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/create_c_api_projections.py') diff --git a/scripts/create_c_api_projections.py b/scripts/create_c_api_projections.py index a56e99b3..a551469d 100755 --- a/scripts/create_c_api_projections.py +++ b/scripts/create_c_api_projections.py @@ -137,6 +137,7 @@ for sectiondef in compounddef.iter('sectiondef'): cppfile.write(" * Angular parameters are expressed in (angUnitName, angUnitConvFactor).\n") cppfile.write(" */\n") cppfile.write("PJ_OBJ* " + decl + "{\n"); + cppfile.write(" SANITIZE_CTX(ctx);\n"); cppfile.write(" try {\n"); if has_linear: cppfile.write(" UnitOfMeasure linearUnit(createLinearUnit(linearUnitName, linearUnitConvFactor));\n") @@ -156,7 +157,7 @@ for sectiondef in compounddef.iter('sectiondef'): cppfile.write(", Scale(" + param[1] + ")") cppfile.write(");\n") - cppfile.write(" return proj_obj_create_conversion(ctx, conv);\n") + cppfile.write(" return proj_obj_create_conversion(conv);\n") cppfile.write(" } catch (const std::exception &e) {\n"); cppfile.write(" proj_log_error(ctx, __FUNCTION__, e.what());\n") cppfile.write(" }\n") -- cgit v1.2.3