Skip to content

err: Implement basis for new error API #83

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

Merged
merged 1 commit into from
Jun 3, 2022

Conversation

Geod24
Copy link
Collaborator

@Geod24 Geod24 commented Jun 2, 2022

Fairly straightforward, didn't cover the full header though.

Comment on lines 341 to 342
auto ERR_raise_data () (
string file = __FILE__, int line = __LINE__, string func = __FUNCTION__)
Copy link
Member

Choose a reason for hiding this comment

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

Signature in docs seems to be:

void ERR_raise_data(int lib, int reason, const char *fmt, ...);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Geod24
Copy link
Collaborator Author

Geod24 commented Jun 2, 2022

Hum I don't think the FILE/LINE/FUNC thing can work with the same API.

@Geod24 Geod24 marked this pull request as draft June 2, 2022 21:12
@Geod24
Copy link
Collaborator Author

Geod24 commented Jun 2, 2022

@CyberShadow : Updated. Not found of the API, but it's the only one that provides the same functionality (automatic file / line / func). Any suggestion / idea ?

@Geod24 Geod24 marked this pull request as ready for review June 2, 2022 21:26
Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

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

LGTM. I think an alternative which would be closer to the C macros would be to make ERR_raise_data a @property function which returns &ERR_set_error. Then, ERR_raise_data wouldn't need to copy ERR_set_error's signature.

@Geod24
Copy link
Collaborator Author

Geod24 commented Jun 2, 2022

But it wouldn't get rid of the template bloat, which is my main concern.

Also I don't think it works:

import std.stdio;

void main ()
{
 	ERR_raise_data(42, 69, "Hello World");   
}

@property auto ERR_raise_data () ()
{
 	return &ERR_set_error;   
}

void ERR_set_error(int lib, int reason, string fmt)
{
 	writeln(fmt, " -- ", lib, " -- ", reason);   
}
onlineapp.d(5): Error: none of the overloads of template `onlineapp.ERR_raise_data` are callable using argument types `!()(int, int, string)`
onlineapp.d(8):        Candidate is: `ERR_raise_data()()`

You'll need two sets of parenthesis which IMO is not worth the cost for the benefit of avoiding duplication. YMMV.

@CyberShadow
Copy link
Member

Right, I forgot properties are useless :(

I don't think you can do better without requiring object files.

@CyberShadow CyberShadow merged commit 6ad312b into D-Programming-Deimos:master Jun 3, 2022
@Geod24 Geod24 deleted the err-fixes branch June 3, 2022 08:56
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