Ticket #716 (closed defect: invalid)

Opened 4 years ago

Last modified 4 years ago

WITH-HASH-TABLE-ITERATOR plays badly with closures

Reported by: rongarret Owned by:
Priority: major Milestone:
Component: ANSI CL Compliance Version: trunk
Keywords: Cc:

Description (last modified by gb) (diff)

? h
#<HASH-TABLE :TEST EQUAL size 3/60 #x3020010965ED>
? (with-hash-table-iterator (f h) (lambda () (multiple-value-list (f))))
#<COMPILED-LEXICAL-CLOSURE #x30200126EE0F>
? (funcall *)
> Error: value #<HASH-TABLE :TEST EQ size 3/60 #x302000C9D12D> is not of the expected type SIMPLE-VECTOR.

Change History

comment:1 Changed 4 years ago by rongarret

Damn, forgot the curly braces. Really need a way to go back and edit these things.

? h
#<HASH-TABLE :TEST EQUAL size 3/60 #x3020010965ED>
? (with-hash-table-iterator (f h) (lambda () (multiple-value-list (f))))
#<COMPILED-LEXICAL-CLOSURE #x30200126EE0F>
? (funcall *)
> Error: value #<HASH-TABLE :TEST EQ size 3/60 #x302000C9D12D> is not of the expected type SIMPLE-VECTOR.

comment:2 Changed 4 years ago by gb

  • Status changed from new to closed
  • Resolution set to invalid
  • Description modified (diff)

The dictionary entry for WITH-HASH-TABLE-ITERATOR says:

"It is unspecified what happens if any of the implicit interior state of an iteration is returned outside the dynamic extent of the with-hash-table-iterator form such as by returning some closure over the invocation form."

In other words: F is allowed to refer to things that have dynamic extent (can be stack-allocated), and referring to those things after the body has exited has undefined results. (IIRC, the implicit internal state in question is represented as a stack-allocated SIMPLE-VECTOR, and the "undefined behavior" in this case has to do with the fact that there's something else where that stack-allocated vector used to be.)

Note: See TracTickets for help on using tickets.