libminizinc icon indicating copy to clipboard operation
libminizinc copied to clipboard

Segfault using record types, enum and json data file

Open CervEdin opened this issue 2 years ago • 11 comments

The following model

model.mzn

enum nume = { A };
type item = record(nume: x);
array[int] of item: arr;

and the following json data file

data.json

{"arr":[{"x":{"e":"A"}}]}

compiled using MiniZinc version 2.7.6, build 905165378 like this

minizinc -c model.mzn data.json

crashes with a segfault

CervEdin avatar Oct 31 '23 12:10 CervEdin

I'm afraid that the problem lies in the combination of type aliases with the JSON parser. The parser requires the types as input, but the resolves aliases are not yet known. I will have a look at fixing this in the the close future

Dekker1 avatar Nov 01 '23 04:11 Dekker1

Currently a workaround is to use the record definition directly in the definition of the array:

enum nume = { A };
array[int] of record(nume: x): arr;

or to provide the data as DZN

Dekker1 avatar Nov 01 '23 04:11 Dekker1

Thank you Jip!

CervEdin avatar Nov 01 '23 06:11 CervEdin

Currently a workaround is to use the record definition directly in the definition of the array:

enum nume = { A };
array[int] of record(nume: x): arr;

or to provide the data as DZN

The inlining work-around of the type definition didn't work on my actual and more complicated problem :/ Although, that may be a separate issue. Trying to see if I can get a small repro

CervEdin avatar Nov 06 '23 09:11 CervEdin

Nested records also result in a segfault, regardless whether the type alias is inlined or not

model.mzn

enum nume = { A };
array[int] of record(record(nume: x) : drocer): arr;

data.json

{
  "arr": [
    {
      "drocer": { "x": { "e": "A" } }
    }
  ]
}

CervEdin avatar Nov 06 '23 09:11 CervEdin

A fix for the problem with nested records has already been merged into the develop branch and should be part of the upcoming release. (And the first problem is no longer a segfault, but still not possible).

Dekker1 avatar Nov 07 '23 23:11 Dekker1

@Dekker1 looks like the fix you mentioned (for the nested inline records) made it to the 2.8 release, right?

CervEdin avatar Nov 16 '23 09:11 CervEdin

Yes, this is part of the 2.8 release

Dekker1 avatar Nov 16 '23 11:11 Dekker1

I can confirm that nested arrays of records work with JSON parsing in version 2.8.3. However are there any news about the alias resolution being done before the JSON parsing? (Related to Dekker1's answer here)

Mommessc avatar Mar 27 '24 10:03 Mommessc

I'm afraid we haven't found the time yet to change the order of the process, but I will try to get around to it when I can

Dekker1 avatar Mar 27 '24 22:03 Dekker1

I can confirm that nested arrays of records work with JSON parsing in version 2.8.3. However are there any news about the alias resolution being done before the JSON parsing? (Related to Dekker1's answer here)

FWIW, I think the best current work-around is introducing a dummy input par

type foo = record(int:a);
array[int] of record(int:a): inline_foos;
array[int] of foo: foos = inline_foos;

example

This is basically how I get around the issue atm

CervEdin avatar Mar 28 '24 07:03 CervEdin