Skip to content

Commit 4b49325

Browse files
committed
Push queue to VM before trying to allocate
1 parent 32e2584 commit 4b49325

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/optionals/queue.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ static Value queuePush(DictuVM *vm, int argCount, Value *args) {
9494

9595
queue->dq[++queue->rear] = data;
9696
queue->count++;
97-
98-
return newResultSuccess(vm, NIL_VAL);
9997
}
10098

10199
return newResultSuccess(vm, NIL_VAL);
@@ -111,7 +109,7 @@ static Value queuePop(DictuVM *vm, int argCount, Value *args) {
111109

112110
void *data = queue->dq[queue->front++];
113111

114-
if(queue->front == queue->size) {
112+
if (queue->front == queue->size) {
115113
queue->front = 0;
116114
}
117115

@@ -160,14 +158,15 @@ static Value newQueue(DictuVM *vm, int argCount, Value *args) {
160158
}
161159

162160
ObjAbstract *abstract = newQueueObj(vm);
161+
push(vm, OBJ_VAL(abstract));
162+
163163
Queue *queue = abstract->data;
164164
queue->dq = ALLOCATE(vm, void*, size);
165165
queue->size = size;
166166
queue->front = 0;
167167
queue->rear = -1;
168168
abstract->data = queue;
169169

170-
push(vm, OBJ_VAL(abstract));
171170
Value success = newResultSuccess(vm, OBJ_VAL(abstract));
172171
pop(vm);
173172

0 commit comments

Comments
 (0)