Skip to content

Commit

Permalink
feat: Switch malloc to calloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Berstanio committed Jan 5, 2025
1 parent 5be3776 commit b53e540
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public static void deregisterFunctionPointer(long fnPtr) {

public static native long malloc(long size);

public static native long calloc(long count, long size);

public static native void free(long pointer);

public static native void memcpy(long dst, long src, long size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Pointing(long pointer, boolean freeOnGC) {
}

public Pointing(int size, boolean freeOnGC, boolean guard) {
this(CHandler.malloc(size), freeOnGC);
this(CHandler.calloc(1, size), freeOnGC);
if (guard)
guardBytes(size);
}
Expand Down
4 changes: 4 additions & 0 deletions gdx-jnigen-runtime/src/main/native/CHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ JNIEXPORT jlong JNICALL Java_com_badlogic_gdx_jnigen_runtime_CHandler_malloc(JNI
return reinterpret_cast<jlong>(malloc(size));
}

JNIEXPORT jlong JNICALL Java_com_badlogic_gdx_jnigen_runtime_CHandler_calloc(JNIEnv* env, jclass clazz, jlong count, jlong size) {
return reinterpret_cast<jlong>(calloc(count, size));
}

JNIEXPORT void JNICALL Java_com_badlogic_gdx_jnigen_runtime_CHandler_free(JNIEnv* env, jclass clazz, jlong pointer) {
free((void*)pointer);
}
Expand Down
8 changes: 8 additions & 0 deletions gdx-jnigen-runtime/src/main/native/CHandler.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b53e540

Please sign in to comment.