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

Bcc32 compatibility #1079

Closed
wants to merge 1 commit into from
Closed

Conversation

starkmapper
Copy link

I did some work to get fmt working on the "classic" Embarcadero compiler.

@vitaut
Copy link
Contributor

vitaut commented Mar 15, 2019

Hi @starkmapper, thanks for the PR!

Since this is your first contribution to {fmt}, please review CONTRIBUTING.md, particularly the part about licensing, and comment here whether you agree with it being applied to your contributions including this PR.

@starkmapper
Copy link
Author

I have read contributing.md and agree that my contribution will be licensed under the fmt license.

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

Left some comments in the first commit. Also instead of fixing issues in the follow-up commits, please amend the ones earlier in the stack for easier review and sensible revision history.

fmt/format.cc Outdated Show resolved Hide resolved
fmt/format.h Outdated Show resolved Hide resolved
fmt/format.h Outdated Show resolved Hide resolved
fmt/format.h Outdated Show resolved Hide resolved
@starkmapper
Copy link
Author

I didn't want to rebase+squash just yet, but let me know if that would help you.

@starkmapper
Copy link
Author

I'm also a little worried about the CI failing, is there anything I can do about that?

@vitaut
Copy link
Contributor

vitaut commented Mar 19, 2019

I didn't want to rebase+squash just yet, but let me know if that would help you.

That would help.

I'm also a little worried about the CI failing, is there anything I can do about that?

Please check the error at https://travis-ci.org/fmtlib/fmt/jobs/507890085. Looks like they are mostly namespace-related.

@starkmapper
Copy link
Author

starkmapper commented Mar 19, 2019

Squashed and fixed non-windows builds. I'm not sure what's going on with the appveyor build. Did I break that or is something else going on?

@starkmapper
Copy link
Author

I'm not sure what's going on with the appveyor build. Did I break that or is something else going on?
Tried the appveyor script locally and that seems to work.
image

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

I think the Appveyor build is failing because the cmake command in https://github.com/fmtlib/fmt/blob/4.x/support/appveyor-build.py#L11 is missing ".." at the end for some reason. Could you add it by any chance while at it? Also a few comments inline.

fmt/format.h Show resolved Hide resolved
fmt/format.h Outdated
@@ -2593,11 +2687,8 @@ class SystemError : public internal::RuntimeError {
throw fmt::SystemError(errno, "cannot open file '{}'", filename);
\endrst
*/
SystemError(int error_code, CStringRef message) {
init(error_code, message, ArgList());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep this ctor.

Copy link
Author

Choose a reason for hiding this comment

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

It is generated by the FMT_VARIADIC_ macro.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's here for documentation purposes (note the apidoc above). If it is causing problems for bcc, I suggest conditionally compiling instead of removing.

Copy link
Author

Choose a reason for hiding this comment

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

It's not a bcc issue, it's because all FMT_VARIADIC_* macros now use the FMT_VARIADIC_ macro, this normalizing variadic template handing, and less macro magic to maintain. The FMT_VARIADIC_ macro generates functions with 0..15 templated arguments to mimic variadic templates, where the 0 argument one has the exact same signature as this manually defined one.
I propose to make it consistent with functions printf, format etc and add an overload with an extra ArgList parameter:

SystemError(int error_code, CStringRef message, ArgList args) {
    init(error_code, message, args);
  }

This would be the best of both worlds: singe FMT_VARIADIC_ macro and documentation (and more consistency as a bonus :-) ).

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is not bcc issue, could you remove the macro changes from the current PR?

Copy link
Author

Choose a reason for hiding this comment

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

The need for the macro changes is because of a bcc issue. If you feel very strongly about not changing the constructor signature in the documentation I can change the FMT_VARIADIC_CTOR macro not to generate the conflicting overload.

Background

The original macro did c-style array initialization:

ArgArray<2>::Type array = { MakeValue<BasicFormatter<char>>(v0), 
                            MakeValue<BasicFormatter<char>>(v1)};

Where ArgArray<2>::Type is an array of Value.
Somehow bcc tried to assign the results of MakeValue<BasicFormatter<char>>(vN) to the first member of Value (int int_value in the anonymous union) causing a "Cannot convert `MakeValue<BasicFormatter>(vN) to int" error.

When I started fixing this issue I found the FMT_VARIADIC_ function and started using that. This had already solved this issue by generating the individual assignment statements for the array:

ArgArray<2>::Type arr;
arr[0] = MakeValue<BasicFormatter<char>>(v0), arr[1] = MakeValue<BasicFormatter<char>>(v1);

note: I left out namespaces for clarity

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. The macro logic is fairly complicated and version 4.x is in maintenance mode, so I'd like the changes in this PR to be minimal, just enough for bcc32 compatibility. Right now it's hard to see what actually changed because the macros have been moved around. Could you return them to their original places and make changes there?

Copy link
Author

Choose a reason for hiding this comment

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

I started doing that, but found that the solution would depend on the (newer and more versatile) macros defined later on in the file. That is why I moved the large macros block up. To verify that I only moved them I used kdiff3 with manual alignment. I'll post those diffs so you can get a better idea of the changes I made.

Copy link
Author

Choose a reason for hiding this comment

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

Here you can see what I changed to get this working for bcc with the existing macros. Not only achieving bcc compatibility, but also removing the second set of macro's, resulting in less "magic" to maintain:
Macro-diff

And the diff for the FMT_MAKE_REF macro's:
Macro-diff - old macros

The alignment of the diff is shown below. I marked the manual alignment markers with red.
Macro-diff alignment

I hope this makes it clear that I only made minor changes, apart from moving the macros.

fmt/format.h Outdated Show resolved Hide resolved
@starkmapper
Copy link
Author

I'll make the proposed changes. Would you like me to squash again, or just push updates? Also, should I check the documentation using doxygen, or apidoc like you mentioned?

@starkmapper
Copy link
Author

starkmapper commented Mar 20, 2019

Adding the .. didn't fix the appveyor build unfortunately. (https://ci.appveyor.com/project/vitaut/fmt/builds/23233738)

@starkmapper
Copy link
Author

Adding the .. didn't fix the appveyor build unfortunately. (https://ci.appveyor.com/project/vitaut/fmt/builds/23233738)

But adding . did, seems that adding the source path to the commandline became required in v3.13.

@starkmapper starkmapper reopened this Mar 20, 2019
@vitaut
Copy link
Contributor

vitaut commented Mar 21, 2019

But adding . did, seems that adding the source path to the commandline became required in v3.13.

Thanks for fixing this.

Would you like me to squash again, or just push updates?

Yes, please squash and remove the macro changes as discussed above.

Also, should I check the documentation using doxygen, or apidoc like you mentioned?

I don't think it's necessary.

Resolve namespace issues
Add workaround for compile error on bool template argument of ArgArray struct
Squelch bcc32 warning on accessing the digits array
Squelch bcc32 warning on unused values
Use FMT_VARIADIC_ for FMT_VARIADIC_VOID and FMT_VARIADIC_CTOR
Fix warnings about redefinig macros and conditions always true
Disable "LConv" block for bcc32 compiler
Remove macro test for deprecated macro
Fix appveyor-build for cmake v3.13+
@starkmapper
Copy link
Author

I changed the macros so the WindowsError and SystemError constructors can remain unchanged. Please let me know if there is anything else.

@vitaut
Copy link
Contributor

vitaut commented Mar 27, 2019

Merged everything except the macro changes in d2744bc. The macros need a bit more work because they are in their present location for a reason: to make the system_header pragma apply to them and not to the other parts of the code. Also it's not entirely clear to me how FMT_VARIADIC_VAR_ARG fixes anything.

@vitaut vitaut closed this Mar 27, 2019
@starkmapper
Copy link
Author

I'll try to find a less invasive way to make the macros work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants