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 // -------------------------------------------------------------------------*/
10 #include "sjme/cleanup.h"
12 sjme_errorCode
sjme_nvm_enqueueHandler(
13 sjme_attrInNotNull sjme_alloc_weak weak
,
14 sjme_attrInNullable sjme_pointer data
,
15 sjme_attrInValue sjme_jboolean isBlockFree
)
17 sjme_nvm_common common
;
20 common
= (sjme_nvm_common
)data
;
22 /* Do nothing if this was already cleared. */
24 return SJME_ERROR_NONE
;
26 /* Specific handling depends on the type. */
29 /* Forward to enqueue handler for closeable, since we do */
30 /* not have anything special to do. */
32 return sjme_closeable_autoEnqueue(weak
, data
, isBlockFree
);
36 sjme_errorCode
sjme_nvm_objectInit(
37 sjme_attrInNotNull sjme_nvm_common inCommon
,
38 sjme_attrInValue sjme_nvm_structType inType
)
44 return SJME_ERROR_NULL_ARGUMENTS
;
46 if (inType
<= SJME_NVM_STRUCTTYPE_UNKNOWN
||
47 inType
>= SJME_NVM_NUM_STRUCTTYPE
)
48 return SJME_ERROR_INVALID_ARGUMENT
;
50 /* Must be a weak pointer. */
52 if (sjme_error_is(error
= sjme_alloc_weakRefGet(inCommon
,
53 &weak
)) || weak
== NULL
)
54 return sjme_error_default(error
);
56 /* And must have enqueue cleanup. */
57 if (weak
->enqueue
!= sjme_nvm_enqueueHandler
)
58 return SJME_ERROR_ILLEGAL_STATE
;
60 /* Set type information. */
61 inCommon
->type
= inType
;
64 return SJME_ERROR_NONE
;