Nim: The `json` module is not usable in the VM

Created on 12 Sep 2018  路  10Comments  路  Source: nim-lang/Nim

When I try to run the following example with "nim test.nims":

import json

var j = parseJson("{\"foo\": \"bar\"}")

I get:
Error: undeclared identifier: 'copyMem'

Feature Low Priority Stdlib

Most helpful comment

I think we need to introduce a copyRange[T] helper in system.nim that is aware of things like:

1) The VM and JavaScript need copying with regular for loops
2) Some user-defined types need to use a user-defined = operator
3) The rest of the cases are optimized to copyMem

Few of the existing generic containers in the standard library are using copyMem, which is not appropriate in the long-term.

All 10 comments

I think we need to introduce a copyRange[T] helper in system.nim that is aware of things like:

1) The VM and JavaScript need copying with regular for loops
2) Some user-defined types need to use a user-defined = operator
3) The rest of the cases are optimized to copyMem

Few of the existing generic containers in the standard library are using copyMem, which is not appropriate in the long-term.

lexbase uses alloc, not copyMem so copyRange[T] wouldn't solve anything.

Does it have to, though? It manages a char buffer. Why coudn't it use a seq[char] instead?

@narimiran This has been fixed in #10746 .

I have the same problem

@unihernandez22 can you elaborate?

@unihernandez22 can you elaborate?

When I do import json in a NimScript file, I get the same error

/usr/lib/nim/pure/streams.nim(276, 9) Error: undeclared identifier: 'copyMem'

@unihernandez22 what's your Nim version?

@unihernandez22 what's your Nim version?

Nim Compiler Version 1.2.4 [Linux: amd64]
Compiled at 2020-07-16
Copyright (c) 2006-2020 by Andreas Rumpf
Was this page helpful?
0 / 5 - 0 ratings