Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when key/value is object/tuple/array which contains string field #3

Open
eienEika opened this issue May 28, 2023 · 2 comments
Open
Assignees
Labels
bug Something isn't working
Milestone

Comments

@eienEika
Copy link

Following code:

import limdb
type Foo = object
  a: string
let db = initDatabase("db", (int, Foo))
db[1] = Foo(a: "a")
echo db[1]

runs without error.
But in next run (without resetting value) when you try read db[1] program crashes with SIGSEGV.
Some remarks:

  • Foo.a is empty string works;
  • string and seq[string] as db value works.

Also for Foo as key there is another error. It doesn't compile because there are no compare procedure for string, string.

Nim version 1.6.12 and devel, no matter of --mm is refc or arc/orc.

@capocasa
Copy link
Owner

Thanks for letting me know!

For an immediate workaround, use a cstring. I will update the type checker to show an error for unsupported types.

It might be possible to support some heap types like string and seq as part of objects without degrading performance but I haven't had any great ideas so far.

@capocasa capocasa self-assigned this May 29, 2023
@capocasa capocasa added the bug Something isn't working label May 29, 2023
@capocasa capocasa added this to the 0.3.1 milestone May 29, 2023
@winrid
Copy link

winrid commented Dec 1, 2023

@capocasa Confirmed still broken in Nim 2 with cstring:

import limdb
import std/strformat

type
  PersonCStr = object
    name: cstring
    age: Natural # Ensures the age is positive

let db = initDatabase("dbTestPersonCStr", (string, PersonCStr))

if "person" in db:
  echo "reading"
  echo db["person"]
else:
  db["person"] = PersonCStr(name: "John", age: 45)
  echo "saved"

Run this twice (once to save, once to read). Read on 2nd run fails at runtime:

reading
Traceback (most recent call last)
/home/winrid/CLionProjects/nimtest/main.nim(13) main
/home/winrid/.choosenim/toolchains/nim-2.0.0/lib/std/private/miscdollars.nim(31) $
/home/winrid/.choosenim/toolchains/nim-2.0.0/lib/system/iterators.nim(87) addQuoted
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants