1
0
forked from Mirror/wren

Don't allow fibers as map keys.

I hacked in support for it for a misguided reason (trying to fake
"thread-local storage") and ended up not using it for that anyway.
This commit is contained in:
Bob Nystrom
2015-12-15 10:42:21 -08:00
parent 8d9feb4bc9
commit 873926915f
9 changed files with 9 additions and 24 deletions

View File

@ -54,13 +54,13 @@ bool validateInt(WrenVM* vm, Value arg, const char* argName)
bool validateKey(WrenVM* vm, Value arg)
{
if (IS_BOOL(arg) || IS_CLASS(arg) || IS_FIBER(arg) || IS_NULL(arg) ||
if (IS_BOOL(arg) || IS_CLASS(arg) || IS_NULL(arg) ||
IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
{
return true;
}
vm->fiber->error = CONST_STRING(vm, "Key must be a value type or fiber.");
vm->fiber->error = CONST_STRING(vm, "Key must be a value type.");
return false;
}

View File

@ -155,7 +155,6 @@ ObjFiber* wrenNewFiber(WrenVM* vm, Obj* fn)
ObjFiber* fiber = ALLOCATE(vm, ObjFiber);
initObj(vm, &fiber->obj, OBJ_FIBER, vm->fiberClass);
fiber->id = vm->nextFiberId++;
fiber->frames = frames;
fiber->frameCapacity = INITIAL_CALL_FRAMES;
fiber->stack = stack;
@ -344,9 +343,6 @@ static uint32_t hashObject(Obj* object)
// Classes just use their name.
return hashObject((Obj*)((ObjClass*)object)->name);
case OBJ_FIBER:
return ((ObjFiber*)object)->id;
case OBJ_RANGE:
{
ObjRange* range = (ObjRange*)object;

View File

@ -242,10 +242,6 @@ typedef struct sObjFiber
// error object. Otherwise, it will be null.
Value error;
// A unique-ish numeric ID for the fiber. Lets fibers be used as map keys.
// Unique-ish since IDs may overflow and wrap around.
uint16_t id;
// This will be true if the caller that called this fiber did so using "try".
// In that case, if this fiber fails with an error, the error will be given
// to the caller.

View File

@ -50,11 +50,6 @@ struct WrenVM
// for the module.
ObjMap* modules;
// The ID that will be assigned to the next fiber that is allocated. Fibers
// are given unique-ish (not completely unique since this can overflow) IDs
// so that they can be used as map keys.
uint16_t nextFiberId;
// Memory management data:
// The number of bytes that are known to be currently allocated. Includes all

View File

@ -1 +1 @@
var result = {}.containsKey([]) // expect runtime error: Key must be a value type or fiber.
var result = {}.containsKey([]) // expect runtime error: Key must be a value type.

View File

@ -8,8 +8,7 @@ var map = {
1.2: "1 point 2",
List: "list class",
"null": "string value",
(1..3): "1 to 3",
fiber: "fiber"
(1..3): "1 to 3"
}
System.print(map[null]) // expect: null value
@ -20,9 +19,8 @@ System.print(map[1.2]) // expect: 1 point 2
System.print(map[List]) // expect: list class
System.print(map["null"]) // expect: string value
System.print(map[1..3]) // expect: 1 to 3
System.print(map[fiber]) // expect: fiber
System.print(map.count) // expect: 9
System.print(map.count) // expect: 8
// Use the same keys (but sometimes different objects) to ensure keys have the
// right equality semantics.
@ -44,4 +42,4 @@ System.print(map[List]) // expect: new list class
System.print(map["null"]) // expect: new string value
System.print(map[1..3]) // expect: new 1 to 3
System.print(map.count) // expect: 9
System.print(map.count) // expect: 8

View File

@ -1 +1 @@
var result = {}.remove([]) // expect runtime error: Key must be a value type or fiber.
var result = {}.remove([]) // expect runtime error: Key must be a value type.

View File

@ -1 +1 @@
var result = {}[[]] // expect runtime error: Key must be a value type or fiber.
var result = {}[[]] // expect runtime error: Key must be a value type.

View File

@ -1 +1 @@
var result = {}[[]] = "value" // expect runtime error: Key must be a value type or fiber.
var result = {}[[]] = "value" // expect runtime error: Key must be a value type.