|
43 | 43 | /*
|
44 | 44 | ** Stores handle's specification (required data size and optional free callback.
|
45 | 45 | ** 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. |
47 | 47 | **
|
48 | 48 | ***********************************************************************/
|
49 | 49 | {
|
50 | 50 | REBCNT idx;
|
51 | 51 | REBVAL *handles = Get_System(SYS_CATALOG, CAT_HANDLES);
|
52 | 52 |
|
53 |
| - if (!sym) return 0; |
| 53 | + if (!sym) return NOT_FOUND; |
54 | 54 |
|
55 | 55 | //printf("Register_Handle: %s with size %u\n", SYMBOL_TO_NAME(sym), size);
|
56 | 56 |
|
57 | 57 | 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); |
60 | 60 | if (idx >= MAX_HANDLE_TYPES) Crash(RP_MAX_HANDLES);
|
61 | 61 |
|
62 | 62 | REBVAL *val = Append_Value(VAL_SERIES(handles));
|
63 | 63 | Set_Word(val, sym, 0, 0);
|
64 | 64 |
|
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; |
67 | 67 |
|
68 | 68 | return idx;
|
69 | 69 | }
|
|
82 | 82 | REBYTE *data;
|
83 | 83 | REBHOB *hob;
|
84 | 84 | REBCNT idx = Find_Handle_Index(sym);
|
85 |
| - if (!idx) return NULL; |
| 85 | + if (idx == NOT_FOUND) return NULL; |
86 | 86 |
|
87 |
| - spec = PG_Handles[idx-1]; |
| 87 | + spec = PG_Handles[idx]; |
88 | 88 | size = spec.size;
|
89 | 89 |
|
90 | 90 | //printf("Requested HOB for %s (%u) of size %u\n", SYMBOL_TO_NAME(sym), sym, size);
|
|
104 | 104 | */ REBCNT Find_Handle_Index(REBCNT sym)
|
105 | 105 | /*
|
106 | 106 | ** 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. |
108 | 108 | **
|
109 | 109 | ***********************************************************************/
|
110 | 110 | {
|
111 |
| - REBCNT idx = 1; |
| 111 | + REBCNT idx = 0; |
112 | 112 | REBVAL *handle = VAL_BLK(Get_System(SYS_CATALOG, CAT_HANDLES));
|
113 | 113 |
|
114 | 114 | while(IS_WORD(handle)){
|
115 | 115 | if(VAL_WORD_SYM(handle) == sym) return idx;
|
116 | 116 | idx++; handle++;
|
117 | 117 | }
|
118 |
| - return 0; |
| 118 | + return NOT_FOUND; |
119 | 119 | }
|
120 | 120 |
|
121 | 121 | /***********************************************************************
|
|
0 commit comments