Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

qsort/bsearch compare function is not @nogc #779

Merged
merged 1 commit into from
May 5, 2014

Conversation

WalterBright
Copy link
Member

No description provided.

This was referenced Apr 26, 2014
@braddr
Copy link
Member

braddr commented Apr 26, 2014

How can qsort be @nogc if it receives and executes function pointers that aren't @nogc? (etc for the same style functions. etc again for the other function attributes that have the same implication)

void* bsearch(in void* key, in void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
void qsort(void* base, size_t nmemb, size_t size, int function(in void*, in void*) compar);
void* bsearch(in void* key, in void* base, size_t nmemb, size_t size, _compare_fp_t compar);
void qsort(void* base, size_t nmemb, size_t size, _compare_fp_t compar);
Copy link
Member

Choose a reason for hiding this comment

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

if the callback is not @nogc, the function itself must not be @nogc, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

How did I miss that? Grrr. The thing is, if dmd actually compiled the source to qsort, it would flag the call to compar. But being an extern function, it can't check it.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a similar issue if the compar function throws. qsort() may not be exception safe. I don't know that there is a solution, other than when calling external C functions you're on your own, as has always been the case.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I don't see a way to make them @nogc either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically the story of druntime...

@WalterBright
Copy link
Member Author

Redid this to move qsort and bsearch outside of @nogc

If someone really needs qsort and bsearch to be be @nogc, all they need to do is supply their own local extern declaration.

@MartinNowak
Copy link
Member

Auto-merge toggled on

MartinNowak added a commit that referenced this pull request May 5, 2014
qsort/bsearch compare function is not @nogc
@MartinNowak MartinNowak merged commit 6330ff4 into dlang:master May 5, 2014
@denis-sh
Copy link
Contributor

denis-sh commented May 8, 2014

compare function is not @nogc

Misleading description. _compare_fp_t/qsort/bsearch are also not nothrow now. I think it's incorrect as there is no guarantee a C standard library doesn't use its own exception handler for some reason.

@denis-sh
Copy link
Contributor

denis-sh commented May 8, 2014

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

Successfully merging this pull request may close these issues.

7 participants