Set of virtual suite functions.
[SquirrelJME.git] / nanocoat / frontend / emulator / nativeAlloc.c
blobaaa9f3fc2f5f50096a639d6cf5169575604e9d1e
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <jni.h>
12 #include "sjme/alloc.h"
13 #include "frontend/emulator/jniHelper.h"
15 /**
16 * Allocates a pool via @c malloc() and returns the pointer to it.
18 * @param size The size of the pool.
19 * @param wrapper The front end wrapper.
20 * @return The native pointer to the pool.
21 * @throws VMException If the pool could not be allocated or initialized.
22 * @since 2023/12/08
24 jlong SJME_JNI_METHOD(SJME_CLASS_ALLOC_POOL, _1_1poolMalloc)
25 (JNIEnv* env, jclass classy, jint size, jobject wrapper)
27 sjme_alloc_pool* result;
28 sjme_errorCode error;
30 /* Attempt pool allocation. */
31 result = NULL;
32 if (SJME_IS_ERROR(error = sjme_alloc_poolInitMalloc(&result,
33 size)) || result == NULL)
35 sjme_jni_throwVMException(env, error);
36 return 0L;
39 /* Set self reference object, we need a global reference for it. */
40 result->frontEnd.data = env;
41 result->frontEnd.wrapper = SJME_FRONT_END_WRAP(
42 (*env)->NewGlobalRef(env, wrapper));
44 return SJME_POINTER_TO_JLONG(result);