Skip to content

Commit f09840e

Browse files
committed
CHANGE: using NOT_FOUND instead of 0 in handle's registration
1 parent 97974e8 commit f09840e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/core/c-handle.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@
4343
/*
4444
** Stores handle's specification (required data size and optional free callback.
4545
** Returns table index for the word (whether found or new).
46-
** Returns 0 if handle with give ID is already registered.
46+
** Returns NOT_FOUND if handle with give ID is already registered.
4747
**
4848
***********************************************************************/
4949
{
5050
REBCNT idx;
5151
REBVAL *handles = Get_System(SYS_CATALOG, CAT_HANDLES);
5252

53-
if (!sym) return 0;
53+
if (!sym) return NOT_FOUND;
5454

5555
//printf("Register_Handle: %s with size %u\n", SYMBOL_TO_NAME(sym), size);
5656

5757
idx = Find_Handle_Index(sym);
58-
if (idx) Crash(RP_HANDLE_ALREADY_REGISTERED);
59-
idx = VAL_TAIL(handles) + 1;
58+
if (idx != NOT_FOUND) Crash(RP_HANDLE_ALREADY_REGISTERED);
59+
idx = VAL_TAIL(handles);
6060
if (idx >= MAX_HANDLE_TYPES) Crash(RP_MAX_HANDLES);
6161

6262
REBVAL *val = Append_Value(VAL_SERIES(handles));
6363
Set_Word(val, sym, 0, 0);
6464

65-
PG_Handles[idx-1].size = size;
66-
PG_Handles[idx-1].free = free_func;
65+
PG_Handles[idx].size = size;
66+
PG_Handles[idx].free = free_func;
6767

6868
return idx;
6969
}
@@ -82,9 +82,9 @@
8282
REBYTE *data;
8383
REBHOB *hob;
8484
REBCNT idx = Find_Handle_Index(sym);
85-
if (!idx) return NULL;
85+
if (idx == NOT_FOUND) return NULL;
8686

87-
spec = PG_Handles[idx-1];
87+
spec = PG_Handles[idx];
8888
size = spec.size;
8989

9090
//printf("Requested HOB for %s (%u) of size %u\n", SYMBOL_TO_NAME(sym), sym, size);
@@ -104,18 +104,18 @@
104104
*/ REBCNT Find_Handle_Index(REBCNT sym)
105105
/*
106106
** Finds handle's word in system/catalog/handles and returns it's index
107-
** Returns one-based value or 0 if handle is not found.
107+
** Returns NOT_FOUND if handle is not found.
108108
**
109109
***********************************************************************/
110110
{
111-
REBCNT idx = 1;
111+
REBCNT idx = 0;
112112
REBVAL *handle = VAL_BLK(Get_System(SYS_CATALOG, CAT_HANDLES));
113113

114114
while(IS_WORD(handle)){
115115
if(VAL_WORD_SYM(handle) == sym) return idx;
116116
idx++; handle++;
117117
}
118-
return 0;
118+
return NOT_FOUND;
119119
}
120120

121121
/***********************************************************************

src/core/m-pools.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
610610
REBHSP spec;
611611
REBCNT idx = hob->index;
612612

613-
if( idx == 0 || !IS_USED_HOB(hob) || hob->data == NULL) return;
613+
if( !IS_USED_HOB(hob) || hob->data == NULL ) return;
614614

615-
spec = PG_Handles[idx-1];
615+
spec = PG_Handles[idx];
616616
//printf("HOB free mem: %0x\n", hob->data);
617617

618618
if (spec.free)

0 commit comments

Comments
 (0)