Skip to content

Commit b67861b

Browse files
Merge branch 'aous72:master' into feature/add-32bit-tif-support
2 parents dedfb39 + edc3210 commit b67861b

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
# Initializes the CodeQL tools for scanning.
5252
- name: Initialize CodeQL
53-
uses: github/codeql-action/init@v3
53+
uses: github/codeql-action/init@v4
5454
with:
5555
languages: ${{ matrix.language }}
5656
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -64,7 +64,7 @@ jobs:
6464
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6565
# If this step fails, then you should remove it and run the build manually (see below)
6666
- name: Autobuild
67-
uses: github/codeql-action/autobuild@v3
67+
uses: github/codeql-action/autobuild@v4
6868

6969
# ℹ️ Command-line programs to run using the OS shell.
7070
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -77,6 +77,6 @@ jobs:
7777
# ./location_of_script_within_repo/buildscript.sh
7878

7979
- name: Perform CodeQL Analysis
80-
uses: github/codeql-action/analyze@v3
80+
uses: github/codeql-action/analyze@v4
8181
with:
8282
category: "/language:${{matrix.language}}"

src/apps/others/ojph_sockets.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ namespace ojph
165165
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
166166
buf, max_buf_size, NULL);
167167
buf[max_buf_size - 1] = 0;
168-
#elif (defined OJPH_OS_APPLE) || \
169-
((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
168+
#elif (defined __GLIBC__) && \
169+
((defined _GNU_SOURCE) || (_POSIX_C_SOURCE < 200112L))
170+
v = strerror_r(errnum, (char*)buf, max_buf_size);
171+
#else
170172
// it is not clear if the returned value is in buf or in v
171173
int t = strerror_r(errnum, (char*)buf, max_buf_size);
172174
if (t != 0)
173175
OJPH_ERROR(0x00080002, "Error retrieving a text message for "
174176
"socket error number %d\n", errnum);
175177
buf[max_buf_size - 1] = 0;
176-
#else
177-
v = strerror_r(errnum, (char*)buf, max_buf_size);
178178
#endif
179179
std::string str;
180180
str = v;

src/core/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ set_target_properties(openjph PROPERTIES POSITION_INDEPENDENT_CODE ON)
139139
target_compile_definitions(openjph PUBLIC _FILE_OFFSET_BITS=64)
140140
target_include_directories(openjph PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common> $<INSTALL_INTERFACE:include>)
141141

142+
## This is to check if aligned_alloc or posix_memalign is available
143+
# We want the code to compile for C11 and C++11.
144+
# std::aligned_alloc is only availabe in C++17.
145+
# So here we try to see which API is available and adapt the code to use it
146+
if (NOT MSVC)
147+
include(CheckSymbolExists)
148+
check_symbol_exists(aligned_alloc "stdlib.h" OJPH_ALIGNED_ALLOC_EXISTS)
149+
if (OJPH_ALIGNED_ALLOC_EXISTS)
150+
target_compile_definitions(openjph PRIVATE OJPH_ALIGNED_ALLOC_EXISTS)
151+
else()
152+
check_symbol_exists(posix_memalign "stdlib.h" OJPH_POSIX_MEMALIGN_EXISTS)
153+
if (OJPH_POSIX_MEMALIGN_EXISTS)
154+
target_compile_definitions(openjph PRIVATE OJPH_POSIX_MEMALIGN_EXISTS)
155+
endif()
156+
endif()
157+
endif()
158+
142159
if (MSVC)
143160
set(OJPH_LIB_NAME_STRING "openjph.${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}")
144161
set_target_properties(openjph

src/core/common/ojph_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535

3636
#define OPENJPH_VERSION_MAJOR 0
3737
#define OPENJPH_VERSION_MINOR 25
38-
#define OPENJPH_VERSION_PATCH 2
38+
#define OPENJPH_VERSION_PATCH 3

src/core/others/ojph_mem.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
// Date: 17 October 2025
3636
//***************************************************************************/
3737

38+
#include <assert.h>
3839
#include <stdlib.h>
40+
#include <stdint.h>
3941

4042
////////////////////////////////////////////////////////////////////////////////
4143
// OS detection definitions for C only
@@ -59,25 +61,69 @@
5961
#define OJPH_EXPORT
6062
#endif
6163

62-
////////////////////////////////////////////////////////////////////////////
64+
////////////////////////////////////////////////////////////////////////////////
6365
#ifdef OJPH_OS_WINDOWS
6466
OJPH_EXPORT void* ojph_aligned_malloc(size_t alignment, size_t size)
6567
{
68+
assert(alignment != 0 && (alignment & (alignment - 1)) == 0);
6669
return _aligned_malloc(size, alignment);
6770
}
6871

6972
OJPH_EXPORT void ojph_aligned_free(void* pointer)
7073
{
7174
_aligned_free(pointer);
7275
}
73-
#else
76+
#elif (defined OJPH_ALIGNED_ALLOC_EXISTS)
7477
void* ojph_aligned_malloc(size_t alignment, size_t size)
7578
{
79+
assert(alignment != 0 && (alignment & (alignment - 1)) == 0);
7680
return aligned_alloc(alignment, size);
7781
}
7882

7983
void ojph_aligned_free(void* pointer)
8084
{
8185
free(pointer);
8286
}
87+
#elif (defined OJPH_POSIX_MEMALIGN_EXISTS)
88+
void* ojph_aligned_malloc(size_t alignment, size_t size)
89+
{
90+
assert(alignment != 0 && (alignment & (alignment - 1)) == 0);
91+
void *p = NULL;
92+
int e = posix_memalign(&p, alignment, size);
93+
return (e ? NULL : p);
94+
}
95+
96+
void ojph_aligned_free(void* pointer)
97+
{
98+
free(pointer);
99+
}
100+
#else
101+
void* ojph_aligned_malloc(size_t alignment, size_t size)
102+
{
103+
assert(alignment != 0 && (alignment & (alignment - 1)) == 0);
104+
105+
// emulate aligned_alloc
106+
void* orig_ptr = malloc(size + alignment + sizeof(void*));
107+
if (orig_ptr == NULL)
108+
return NULL; // Allocation failed
109+
110+
uintptr_t start_of_mem = (uintptr_t)orig_ptr + sizeof(void*);
111+
uintptr_t aligned_addr = (start_of_mem + alignment - 1) & ~(alignment - 1);
112+
113+
void** ptr_to_orig_ptr = (void**)aligned_addr;
114+
ptr_to_orig_ptr[-1] = orig_ptr;
115+
116+
return (void*)aligned_addr;
117+
}
118+
119+
void ojph_aligned_free(void* pointer)
120+
{
121+
if (pointer) {
122+
// Retrieve the original pointer stored just before aligned pointer
123+
void** ptr_to_orig_ptr = (void**)pointer;
124+
void* orig_ptr = ptr_to_orig_ptr[-1];
125+
126+
free(orig_ptr);
127+
}
128+
}
83129
#endif

0 commit comments

Comments
 (0)