[Issue 15594] New: Make all of std.json @safe-friendly

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jan 22 15:57:20 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15594

          Issue ID: 15594
           Summary: Make all of std.json @safe-friendly
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: dhasenan at gmail.com

std.json has erroneously left several methods as @system. Ignoring everything
else, those should be marked @safe.

The code reads pointer fields from a union. This prevents it from marking
several methods as @safe.

Option 1:
=========
Make it @safe by not using unions for reference types.

This costs an extra 5 words per item. That's a non-trivial cost.

Option 2:
=========
Mark the following methods @trusted:
* str()
* object()
* array()

Then modify the rest of the code to use those accessors when applicable. (It
usually goes through the union directly.) There will be a negligible cost from
extra function calls, plus a few redundant checks, but on the whole it should
be pretty much the same experience.

The main problem is that it adds @trusted code.

Option 3:
=========
Switch from structs to classes. Use a class hierarchy to only store the data.
This has a memory cost as well -- object overhead is at least one word, plus it
adds indirection.

I'm favoring option 2, since it's only got three @trusted methods.

--


More information about the Digitalmars-d-bugs mailing list