Bug 13476 – [REG2.065] Writing stubs for dynamically loaded functions no longer works. (circular reference)

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-14T23:18:00Z
Last change time
2015-02-18T03:37:00Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
Marco.Leise

Comments

Comment #0 by Marco.Leise — 2014-09-14T23:18:07Z
When loading dynamic libraries we often only need a few functions out of a large set. Instead of eagerly loading all the symbols, we defer lookup until we actually call that function. This is done by initially having the function pointers set to a stub, that replaces its pointer with the correct one loaded via e.g. `dlsym` and calls it. The same applies to "extensions": functions that may or may not be present in a shared object. In DMD 2.064 this code worked fine: import std.traits; __gshared nothrow extern(C) void function(int) someFunc = &Stub!someFunc; nothrow extern(C) auto Stub(alias func)(ParameterTypeTuple!func args) { import core.stdc.stdio; printf("Loading %s...\n", func.stringof.ptr); nothrow extern(C) void function(int) impl = (i) { printf("Dummy function called with %d\n", i); }; return (func = impl)(args); } void main() { someFunc(42); someFunc(43); } Since 2.065 though, it produces a circular reference error: main.d(3): Error: circular reference to 'main.someFunc' The following code - if you think about it - exhibits the same theoretical circular dependency but still works: import std.traits; __gshared nothrow extern(C) void function(int) someFunc = &Stub!someFuncP; __gshared nothrow extern(C) void function(int)* someFuncP = &someFunc; nothrow extern(C) void Stub(alias func)(int args) { import core.stdc.stdio; enum name = func.stringof[0 .. $-1]; printf("Loading %s...\n", name.ptr); nothrow extern(C) void function(int) impl = (i) { printf("Dummy function called with %d\n", i); }; return (*func = impl)(args); } void main() { someFunc(42); someFunc(43); }
Comment #1 by k.hara.pg — 2014-09-15T08:32:11Z
The regression has introduced by the fix for issue 12040. Compiler fix: https://github.com/D-Programming-Language/dmd/pull/3989
Comment #2 by github-bugzilla — 2014-09-16T00:47:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a705e5399ca7aa826bce6f5168ad13f72ef6733f fix Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference) https://github.com/D-Programming-Language/dmd/commit/f2a07f856511a8c638b71c17c3c4db069b3c8213 Merge pull request #3989 from 9rnsr/fix13476 [REG2.065] Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference)
Comment #3 by github-bugzilla — 2014-09-18T13:20:26Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/90c5189a21c272a5c41de6d1d2252b170b5eb630 Merge pull request #3989 from 9rnsr/fix13476 [REG2.065] Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference)
Comment #4 by github-bugzilla — 2015-02-18T03:37:00Z
Commits pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a705e5399ca7aa826bce6f5168ad13f72ef6733f fix Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference) https://github.com/D-Programming-Language/dmd/commit/f2a07f856511a8c638b71c17c3c4db069b3c8213 Merge pull request #3989 from 9rnsr/fix13476