Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.4 backports #2013

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# require at least cmake 2.8.12
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR )
# require at least cmake 3.12
CMAKE_MINIMUM_REQUIRED(VERSION 3.12 FATAL_ERROR)

# path for helper modules
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake/modules")
Expand Down
10 changes: 5 additions & 5 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ENDIF(INSTALL_HELPER_SCRIPTS)

# Inspired by http://bloerg.net/2012/11/10/cmake-and-distutils.html

FIND_PROGRAM(PYTHON "python3")
IF(PYTHON)
FIND_PACKAGE(Python3 COMPONENTS Interpreter REQUIRED)
IF(Python3_Interpreter_FOUND)
SET(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
SET(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
SET(DEPS_IN "${CMAKE_CURRENT_SOURCE_DIR}/lensfun/__init__.py.in")
Expand All @@ -33,7 +33,7 @@ IF(PYTHON)
CONFIGURE_FILE(${DEPS_IN} ${DEPS})

ADD_CUSTOM_COMMAND(OUTPUT ${OUTPUT}
COMMAND ${PYTHON} ${SETUP_PY} build
COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} build
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS_IN})

Expand All @@ -42,5 +42,5 @@ IF(PYTHON)
IF(NOT DEFINED SETUP_PY_INSTALL_PREFIX)
SET(SETUP_PY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
ENDIF()
INSTALL(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install --prefix=\$ENV{DESTDIR}${SETUP_PY_INSTALL_PREFIX})")
ENDIF(PYTHON)
INSTALL(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --prefix=\$ENV{DESTDIR}${SETUP_PY_INSTALL_PREFIX})")
ENDIF()
38 changes: 28 additions & 10 deletions libs/lensfun/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,14 @@ lfError lfDatabase::Load (const char *errcontext, const char *data, size_t data_
};

/* Temporarily drop numeric format to "C" */
char *old_numeric = setlocale (LC_NUMERIC, NULL);
old_numeric = strdup(old_numeric);
setlocale(LC_NUMERIC,"C");
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
setlocale (LC_NUMERIC, "C");
#else
auto loc = uselocale((locale_t) 0); // get current local
auto nloc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
uselocale(nloc);
#endif

/* eek! GPtrArray does not have a method to insert a pointer
into middle of the array... We have to remove the trailing
Expand Down Expand Up @@ -777,8 +782,12 @@ lfError lfDatabase::Load (const char *errcontext, const char *data, size_t data_
g_ptr_array_add ((GPtrArray *)Lenses, NULL);

/* Restore numeric format */
setlocale (LC_NUMERIC, old_numeric);
free(old_numeric);
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
#else
uselocale(loc);
freelocale(nloc);
#endif

return e;
}
Expand Down Expand Up @@ -828,9 +837,14 @@ char *lfDatabase::Save (const lfMount *const *mounts,
const lfLens *const *lenses)
{
/* Temporarily drop numeric format to "C" */
char *old_numeric = setlocale (LC_NUMERIC, NULL);
old_numeric = strdup(old_numeric);
setlocale(LC_NUMERIC,"C");
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
setlocale (LC_NUMERIC, "C");
#else
auto loc = uselocale((locale_t) 0); // get current local
auto nloc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
uselocale(nloc);
#endif

int i, j;
GString *output = g_string_sized_new (1024);
Expand Down Expand Up @@ -1074,8 +1088,12 @@ char *lfDatabase::Save (const lfMount *const *mounts,
g_string_append (output, "</lensdatabase>\n");

/* Restore numeric format */
setlocale (LC_NUMERIC, old_numeric);
free(old_numeric);
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
#else
uselocale(loc);
freelocale(nloc);
#endif

return g_string_free (output, FALSE);
}
Expand Down
20 changes: 14 additions & 6 deletions libs/lensfun/lens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ void lfLens::GuessParameters ()
float minf = float (INT_MAX), maxf = float (INT_MIN);
float mina = float (INT_MAX), maxa = float (INT_MIN);

char *old_numeric = setlocale (LC_NUMERIC, NULL);
old_numeric = strdup (old_numeric);
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
setlocale (LC_NUMERIC, "C");
#else
auto loc = uselocale((locale_t) 0); // get current local
auto nloc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
uselocale(nloc);
#endif

if (Model && (!MinAperture || !MinFocal) &&
!strstr (Model, "adapter") &&
Expand Down Expand Up @@ -334,11 +339,14 @@ void lfLens::GuessParameters ()
if (maxa != INT_MIN && !MaxAperture)
MaxAperture = maxa;

if (!MaxFocal)
MaxFocal = MinFocal;
if (!MaxFocal) MaxFocal = MinFocal;

setlocale (LC_NUMERIC, old_numeric);
free (old_numeric);
#if defined(PLATFORM_WINDOWS)
_configthreadlocale(_DISABLE_PER_THREAD_LOCALE);
#else
uselocale(loc);
freelocale(nloc);
#endif
}

bool lfLens::Check ()
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ ADD_EXECUTABLE(test_modifier_coord_geometry test_modifier_coord_geometry.cpp)
TARGET_LINK_LIBRARIES(test_modifier_coord_geometry lensfun ${COMMON_LIBS})
ADD_TEST(Modifier_coord_geometry test_modifier_coord_geometry)

FIND_PACKAGE(PythonInterp REQUIRED)
ADD_TEST(NAME Database_integrity COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/check_database/check_database.py ${CMAKE_SOURCE_DIR}/data/db)
FIND_PACKAGE(Python3 COMPONENTS Interpreter REQUIRED)
ADD_TEST(NAME Database_integrity COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/check_database/check_database.py ${CMAKE_SOURCE_DIR}/data/db)