1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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 // -------------------------------------------------------------------------*/
12 #include "sjme/alloc.h"
13 #include "frontend/emulator/jniHelper.h"
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.
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
;
30 /* Attempt pool allocation. */
32 if (SJME_IS_ERROR(error
= sjme_alloc_poolInitMalloc(&result
,
33 size
)) || result
== NULL
)
35 sjme_jni_throwVMException(env
, error
);
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
);