Skip to content

Commit

Permalink
Merge pull request #3989 from 9rnsr/fix13476
Browse files Browse the repository at this point in the history
[REG2.065] Issue 13476 - Writing stubs for dynamically loaded functions no longer works. (circular reference)
  • Loading branch information
WalterBright committed Sep 16, 2014
2 parents 73bb17a + a705e53 commit f2a07f8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
12 changes: 11 additions & 1 deletion src/dsymbol.c
Expand Up @@ -455,14 +455,24 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
Dsymbol *s = toAlias();
Dsymbol *sm;

if (Declaration *d = s->isDeclaration())
{
if (d->inuse)
{
::error(loc, "circular reference to '%s'", d->toPrettyChars());
return NULL;
}
}

switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, (Identifier *)id);
break;

case DYNCAST_DSYMBOL:
{ // It's a template instance
{
// It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
Expand Down
12 changes: 0 additions & 12 deletions src/mtype.c
Expand Up @@ -6558,18 +6558,6 @@ void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsy
}

Dsymbol *s = sc->search(loc, ident, &scopesym);
if (s)
{
Declaration *d = s->isDeclaration();
if (d && d->inuse)
{
error(loc, "circular reference to '%s'", d->toPrettyChars());
*pe = NULL;
*ps = NULL;
*pt = Type::terror;
return;
}
}
resolveHelper(loc, sc, s, scopesym, pe, pt, ps, intypeid);
if (*pt)
(*pt) = (*pt)->addMod(mod);
Expand Down
48 changes: 48 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -7124,6 +7124,53 @@ void test13437()
assert(n == [1,2,3,4]);
}

/***************************************************/
// 13476

template ParameterTypeTuple13476(func...)
{
static if (is(typeof(*func[0]) P == function))
alias ParameterTypeTuple13476 = P;
else
static assert(0, "argument has no parameters");
}

int flag13476;

__gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476;

extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args)
{
++flag13476;
extern(C) void function(int) nothrow impl = (i) { };
return (func = impl)(args);
}

__gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP;
__gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt;

extern(C) auto Stub13476Alt(alias func)(int args) nothrow
{
++flag13476;
extern(C) void function(int) nothrow impl = (i) {};
return (*func = impl)(args);
}

void test13476()
{
assert(flag13476 == 0);

someFunc13476(42);
assert(flag13476 == 1);
someFunc13476(43);
assert(flag13476 == 1);

someFunc13476Alt(42);
assert(flag13476 == 2);
someFunc13476Alt(43);
assert(flag13476 == 2);
}

/***************************************************/

int main()
Expand Down Expand Up @@ -7421,6 +7468,7 @@ int main()
test12937();
test13154();
test13437();
test13476();

printf("Success\n");
return 0;
Expand Down

0 comments on commit f2a07f8

Please sign in to comment.