From d938f978a8ce46b66dfc0dc39e6115adcd3f548b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 14 Jan 2025 08:30:15 +0100 Subject: [PATCH 1/2] [primitives] fix benchmark if no primitives benchmark is run use optimized implementation instead of generic if one is available. --- libfreerdp/primitives/primitives.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfreerdp/primitives/primitives.c b/libfreerdp/primitives/primitives.c index f968bf9d8..484e06300 100644 --- a/libfreerdp/primitives/primitives.c +++ b/libfreerdp/primitives/primitives.c @@ -165,6 +165,7 @@ fail: return ret; } +#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES) && defined(WITH_OPENCL) static BOOL primitives_YUV_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims, UINT64 runTime, UINT32* computations) { @@ -196,6 +197,7 @@ static BOOL primitives_YUV_benchmark_run(primitives_YUV_benchmark* bench, primit } return TRUE; } +#endif static BOOL primitives_autodetect_best(primitives_t* prims) { @@ -222,7 +224,11 @@ static BOOL primitives_autodetect_best(primitives_t* prims) #if !defined(HAVE_CPU_OPTIMIZED_PRIMITIVES) || !defined(WITH_OPENCL) { +#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES) || defined(WITH_OPENCL) + struct prim_benchmark* cur = &testcases[1]; +#else struct prim_benchmark* cur = &testcases[0]; +#endif cur->prims = primitives_get_by_type(cur->flags); if (!cur->prims) { From 5a45a8cad4733ab4337711484210eadb97825944 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 13 Jan 2025 18:23:47 +0100 Subject: [PATCH 2/2] [winpr,timezone] unify TZ override and restore --- winpr/libwinpr/timezone/CMakeLists.txt | 2 +- .../libwinpr/timezone/TimeZoneIanaAbbrevMap.c | 18 ++---- winpr/libwinpr/timezone/timezone.c | 57 +++++++++++-------- winpr/libwinpr/timezone/timezone.h | 26 +++++++++ 4 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 winpr/libwinpr/timezone/timezone.h diff --git a/winpr/libwinpr/timezone/CMakeLists.txt b/winpr/libwinpr/timezone/CMakeLists.txt index cb38a8a6a..7012b95bf 100644 --- a/winpr/libwinpr/timezone/CMakeLists.txt +++ b/winpr/libwinpr/timezone/CMakeLists.txt @@ -30,7 +30,7 @@ if(WITH_TIMEZONE_FROM_FILE) install(FILES TimeZoneNameMap.json DESTINATION ${WINPR_RESOURCE_ROOT}) endif() -set(SRCS TimeZoneNameMapUtils.c TimeZoneNameMap.h timezone.c) +set(SRCS TimeZoneNameMapUtils.c TimeZoneNameMap.h timezone.c timezone.h) if(WITH_TIMEZONE_COMPILED) list(APPEND SRCS TimeZoneNameMap_static.h) endif() diff --git a/winpr/libwinpr/timezone/TimeZoneIanaAbbrevMap.c b/winpr/libwinpr/timezone/TimeZoneIanaAbbrevMap.c index ca2d7d977..d1d604295 100644 --- a/winpr/libwinpr/timezone/TimeZoneIanaAbbrevMap.c +++ b/winpr/libwinpr/timezone/TimeZoneIanaAbbrevMap.c @@ -27,6 +27,7 @@ #include #include +#include "timezone.h" typedef struct { @@ -73,25 +74,14 @@ static void append_timezone(const char* dir, const char* name) if (!tz) return; - const char* otz = getenv("TZ"); - char* oldtz = NULL; - if (otz) - oldtz = _strdup(otz); - setenv("TZ", tz, 1); - tzset(); + char* oldtz = setNewAndSaveOldTZ(tz); + const time_t t = time(NULL); struct tm lt = { 0 }; (void)localtime_r(&t, <); append(tz, lt.tm_zone); - if (oldtz) - { - setenv("TZ", oldtz, 1); - free(oldtz); - } - else - unsetenv("TZ"); + restoreSavedTZ(oldtz); free(tz); - tzset(); } static void handle_link(const char* base, const char* dir, const char* name); diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index bd71ac44f..908b7ba6d 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -28,6 +28,7 @@ #include #include #include "../log.h" +#include "timezone.h" #define TAG WINPR_TAG("timezone") @@ -875,31 +876,12 @@ DWORD EnumDynamicTimeZoneInformation(const DWORD dwIndex, const time_t t = time(NULL); struct tm tres = { 0 }; - const char* tz = getenv("TZ"); - char* tzcopy = NULL; - if (tz) - { - size_t tzianalen = 0; - winpr_asprintf(&tzcopy, &tzianalen, "TZ=%s", tz); - } + char* tzcopy = entry->Iana ? setNewAndSaveOldTZ(entry->Iana) : NULL; - char* tziana = NULL; - { - size_t tzianalen = 0; - winpr_asprintf(&tziana, &tzianalen, "TZ=%s", entry->Iana); - } - if (tziana) - putenv(tziana); - - tzset(); struct tm* local_time = localtime_r(&t, &tres); - free(tziana); - if (tzcopy) - putenv(tzcopy); - else - unsetenv("TZ"); - free(tzcopy); - tzset(); + + if (entry->Iana) + restoreSavedTZ(tzcopy); if (local_time) dynamic_time_zone_from_localtime(local_time, lpTimeZoneInformation); @@ -936,3 +918,32 @@ DWORD GetDynamicTimeZoneInformationEffectiveYears( return ERROR_FILE_NOT_FOUND; } #endif + +#if !defined(_WIN32) +char* setNewAndSaveOldTZ(const char* val) +{ + // NOLINTBEGIN(concurrency-mt-unsafe) + const char* otz = getenv("TZ"); + char* oldtz = NULL; + if (otz) + oldtz = _strdup(otz); + setenv("TZ", val, 1); + tzset(); + // NOLINTEND(concurrency-mt-unsafe) + return oldtz; +} + +void restoreSavedTZ(char* saved) +{ + // NOLINTBEGIN(concurrency-mt-unsafe) + if (saved) + { + setenv("TZ", saved, 1); + free(saved); + } + else + unsetenv("TZ"); + tzset(); + // NOLINTEND(concurrency-mt-unsafe) +} +#endif diff --git a/winpr/libwinpr/timezone/timezone.h b/winpr/libwinpr/timezone/timezone.h new file mode 100644 index 000000000..bb656e8e2 --- /dev/null +++ b/winpr/libwinpr/timezone/timezone.h @@ -0,0 +1,26 @@ +/** + * WinPR: Windows Portable Runtime + * Time Zone + * + * Copyright 2025 Armin Novak + * Copyright 2025 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#if !defined(_WIN32) +char* setNewAndSaveOldTZ(const char* val); +void restoreSavedTZ(char* saved); +#endif