devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

[Issue Report]: nxdk does not implement `strtod()`

Open StephenCWills opened this issue 1 year ago • 4 comments

Operating System

Other (please specify)

DevilutionX version

Custom build (please specify commit ID)

Describe

Platform: OG Xbox Commit ID: 55a5337 (no release versions are affected)

The build for OG Xbox fails at startup with the following message.

Assertion failed: '0' in function 'strtod', file '/opt/nxdk/lib/xboxrt/libc_extensions/stdlib_ext_.c', line 91

To Reproduce

  1. Run the OG Xbox build in xemu
  2. You will see the error message almost immediately

Expected Behavior

No response

Additional context

I added some trace logging and found that the assertion is raised here in LuaInitialize().

https://github.com/diasurgical/devilutionX/blob/55a5337834a9c26861e3f6db790c8949adef8e20/Source/lua/lua.cpp#L218-L229

I didn't dig any deeper than this since I'm pretty sure it's called by Lua internals. There's likely no reasonable way for us to work around the missing function.


Someone already posted an issue for this a few years back: https://github.com/XboxDev/nxdk/issues/508. We will probably need to submit a PR to have any hope of getting this implemented for 1.6.0. Otherwise, we'll just have to disable Lua on OG Xbox.

Here is the link to their stub for the function. https://github.com/XboxDev/nxdk/blob/ed21e83da43b8b8da14a9a78cf2528d9b5df86a7/lib/xboxrt/libc_extensions/stdlib_ext_.c#L89-L93


Also, this isn't really necessary, but I did take a screenshot of the error earlier so I may as well share it.

image

StephenCWills avatar Feb 16 '24 02:02 StephenCWills

nxdk uses PDClib, which doesn't have strtod but they have a draft implementation:

https://github.com/DevSolar/pdclib/blob/7d471427fa986a9f4cafb069af17821ee7868141/functions/_PDCLIB/_PDCLIB_strtod_main.c#L16-L20

It'd probably be best to submit a PR to PDClib directly.

glebm avatar Feb 16 '24 09:02 glebm

https://github.com/XboxDev/nxdk-pdclib/pull/57#issuecomment-1948043421

AJenbo avatar Feb 16 '24 10:02 AJenbo

I found high quality public domain implementations of float<->string conversions in sqlite https://github.com/DevSolar/pdclib/issues/5#issuecomment-1950136787

glebm avatar Feb 17 '24 13:02 glebm

Sent a PR to PDClib with a partial strtod implementation based on the one from SQLite https://github.com/DevSolar/pdclib/pull/22

glebm avatar Feb 25 '24 12:02 glebm