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

Fix version with NULLPTR in JSON output #11640

Merged
merged 1 commit into from
Sep 4, 2020
Merged

Conversation

wilzbach
Copy link
Member

@wilzbach wilzbach commented Aug 28, 2020

global._version has been changed at some point to an
null-terminated string. However, its type was still a D string. Some
parts of the code base were updated to do .length - 1, but other like
the compilerInfo were forgotten. This change remedies this and:

  • removes manual null terminator addition from the D string of _version
  • parses the versionNumber at compile-time
  • exposes _version as versionString

CC @MoonlightSentinel

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11640"

src/dmd/backend/elfobj.d Outdated Show resolved Hide resolved
@wilzbach wilzbach force-pushed the _version branch 3 times, most recently from c35d69d to 5c58089 Compare August 28, 2020 16:10
@@ -316,7 +316,8 @@ extern (C++) struct Global
Array!(const(char)*)* path; // Array of char*'s which form the import lookup path
Array!(const(char)*)* filePath; // Array of char*'s which form the file import lookup path

string _version;
enum string _version = import("VERSION");
enum uint _versionNumber = calcVersionNumber(_version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't enums only existent at CT and not passed to the layout?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't enums only existent at CT and not passed to the layout?

Yes. But there is still the field in the headers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I set _version to private, removed it from the header and exposed it to C++ via versionString and added a small test to cxx-frontend. I hope that works for GDC?

@wilzbach
Copy link
Member Author

Great, so there's https://issues.dlang.org/show_bug.cgi?id=21206 (and the entire mess of arrays/string interop with C++).
We really need to get #8120 in :/

Example:

extern(C++):

struct Foo {
  string s;   
}

void foo(Foo s) {} // OK
string foo() { return ""; } // OK on Posix, Error on Windows

void foo(string s) {} // error

https://run.dlang.io/is/FaSmWk

Generated header file:

// Automatically generated by Digital Mars D Compiler v2093

#pragma once

#include <stddef.h>
#include <stdint.h>


struct Foo;

struct Foo
{
    DArray< char > s;
    Foo() : s() {}
};

extern void foo(Foo s);

extern DArray< char > foo();

extern void foo(DArray< char > s);

https://run.dlang.io/is/lSm56k

@ibuclaw
Copy link
Member

ibuclaw commented Aug 29, 2020

Could you make the extern(C++) function return a const char* instead? The only reason why a implementing compiler needs to have access to the version field is for:

message ("version   %s", global.version.ptr);

@wilzbach
Copy link
Member Author

Could you make the extern(C++) function return a const char* instead? The only reason why a implementing compiler needs to have access to the version field is for:

Done.

@MoonlightSentinel MoonlightSentinel added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Sep 1, 2020
@wilzbach wilzbach requested a review from kinke as a code owner September 3, 2020 17:46
@wilzbach
Copy link
Member Author

wilzbach commented Sep 3, 2020

DArray< char > _version;
ENUM_CONSTANT(const char*, _version, "v2.093.1-503-g4c81d4e38")

ENUM_CONSTANT_NUMERIC(uint32_t, _versionNumber, 2093u)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you plan to leave this hardcoded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave this hardcoded?

It's gone now ;-)

global._version has been changed at some point to an
null-terminated string. However, its type was still a D string. Some
parts of the code base were updated to do `.length - 1`, but other like
the `compilerInfo` were forgotten. This change remedies this and:
- removes null terminator from the D string of _version
- initializes versionNumber at compile-time
- expose _version as versionString (D) and versionChars (C++)
@MoonlightSentinel MoonlightSentinel added auto-merge and removed 72h no objection -> merge The PR will be merged if there are no objections raised. labels Sep 4, 2020
@dlang-bot dlang-bot merged commit b4b04e7 into dlang:master Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants