Files
imgui-java/imgui-binding/src/main/native/jni_common.h
T
MRLokop 30b731de54
CI / Build Java (push) Has been cancelled
CI / Build Native (macos-latest - macos) (push) Has been cancelled
CI / Build Native (ubuntu-latest - linux) (push) Has been cancelled
CI / Build Native (ubuntu-latest - windows) (push) Has been cancelled
CI / Archive Natives (push) Has been cancelled
CI / Update Binaries (push) Has been cancelled
CI / Release (push) Has been cancelled
fix: make Jni::FreeTrueUtf8 const-safe
TextEditor/TextEditorLanguageDefinition use 'const char* value =
env->GetStringUTFChars(...)' then release via the same pointer. After
the mass replace the release side called FreeTrueUtf8(char*) with a
const char* argument, which fails to compile. Switch the helper
signature to take const char* so both const and non-const call sites
build.
2026-04-20 11:27:00 +03:00

59 lines
2.0 KiB
C++

#pragma once
#include "stdlib.h"
#include "stdint.h"
#include "jni.h"
#include "imgui.h"
#ifndef SET_STRING_FIELD
#define SET_STRING_FIELD(field, value) \
do { \
static bool freeField = false; \
if (freeField) { \
free((void*)(field)); \
} \
if ((value) != NULL) { \
size_t length = strlen(value) + 1; \
(field) = (char*)malloc(length); \
if ((field) != NULL) { \
strcpy((char*)(field), value); \
freeField = true; \
} \
} else { \
(field) = NULL; \
freeField = false; \
} \
} while (0)
#endif
namespace Jni
{
void InitCommon(JNIEnv* env);
void ImVec2Cpy(JNIEnv* env, ImVec2* src, jobject dst);
void ImVec2Cpy(JNIEnv* env, ImVec2 src, jobject dst);
void ImVec2Cpy(JNIEnv* env, jobject src, ImVec2* dst);
void ImVec4Cpy(JNIEnv* env, ImVec4* src, jobject dst);
void ImVec4Cpy(JNIEnv* env, ImVec4 src, jobject dst);
void ImVec4Cpy(JNIEnv* env, jobject src, ImVec4* dst);
jobjectArray NewImVec2Array(JNIEnv* env, ImVec2* src, int size);
jobjectArray NewImVec4Array(JNIEnv* env, ImVec4* src, int size);
void ImVec2ArrayCpy(JNIEnv* env, jobjectArray src, ImVec2* dst, int size);
void ImVec4ArrayCpy(JNIEnv* env, jobjectArray src, ImVec4* dst, int size);
jobjectArray NewImGuiKeyDataArray(JNIEnv* env, const ImGuiKeyData* src, int size);
void ImGuiKeyDataArrayCpy(JNIEnv* env, jobjectArray src, ImGuiKeyData* dst, int size);
// Converts a jstring to a freshly-malloc'd C string in real UTF-8 (not JNI's MUTF-8).
// JNI's GetStringUTFChars encodes codepoints above U+FFFF as a surrogate pair of two
// 3-byte sequences, which ImGui's UTF-8 decoder rejects — so SMP emoji never reach
// the glyph atlas even when the glyph is registered. Caller must release with
// FreeTrueUtf8(). Returns nullptr iff the input jstring is null.
char* ToTrueUtf8(JNIEnv* env, jstring s);
void FreeTrueUtf8(const char* p);
}