2

I am trying to append data to block from Red/System.

Red []

my-red-block: ["some text"] ; some already existen data in block

foo: routine [
    blk
]
[
    block/rs-append as red-block! blk as red-value! unicode/load-utf8 "new text" size? "new text"
]

foo my-red-block

print my-red-block

I decided to pass block to routine end modify it there.

I am getting error:

*** Runtime Error 1: access violation
*** at: 630EB4DFh
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145

1 Answers1

4

The reason for that is because load-utf8 returns a node! that references an external string buffer, not the string! value itself.

node! is essentially a pointer, and it doesn't match the structure of high-level Red values; however, since it's a pointer, it can be casted to a pointer of another type, like e.g. red-value! or any other struct. The crash happens when you try to access that malformed value slot.

As for the original question, this should answer it.

9214
  • 2,105
  • 11
  • 15