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

fix issue 2968 by adding a new pragma(framework) #10615

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/pragma_framework.dd
@@ -0,0 +1,3 @@
This add the new pragma(framework, FRAMEWORK_NAME)

It adds the arguments "-framework FRAMEWORK_NAME" to the linker commandline.
30 changes: 30 additions & 0 deletions src/dmd/dsymbolsem.d
Expand Up @@ -1902,6 +1902,36 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
}
goto Lnodecl;
}
else if (pd.ident == Id.framework)
{
if (!pd.args || pd.args.dim != 1)
pd.error("string expected for framework name");
else
{
auto se = semanticString(sc, (*pd.args)[0], "framework name");
if (!se)
goto Lnodecl;
(*pd.args)[0] = se;

auto name = se.peekString().xarraydup;
if (global.params.verbose)
message("framework %s", name.ptr);
if (global.params.moduleDeps && !global.params.moduleDepsFile)
{
OutBuffer* ob = global.params.moduleDeps;
Module imod = sc.instantiatingModule();
ob.writestring("depsFramework ");
ob.writestring(imod.toPrettyChars());
ob.writestring(" (");
escapePath(ob, imod.srcfile.toChars());
ob.writestring(") : ");
ob.writestring(name);
ob.writenl();
}
mem.xfree(name.ptr);
}
goto Lnodecl;
}
else if (pd.ident == Id.startaddress)
{
if (!pd.args || pd.args.dim != 1)
Expand Down
1 change: 1 addition & 0 deletions src/dmd/globals.d
Expand Up @@ -267,6 +267,7 @@ extern (C++) struct Param
Array!bool linkswitchIsForCC;
Array!(const(char)*) libfiles;
Array!(const(char)*) dllfiles;
Array!(const(char)*) frameworks;
const(char)[] deffile;
const(char)[] resfile;
const(char)[] exefile;
Expand Down
1 change: 1 addition & 0 deletions src/dmd/globals.h
Expand Up @@ -236,6 +236,7 @@ struct Param
Array<bool> linkswitchIsForCC;
Array<const char *> libfiles;
Array<const char *> dllfiles;
Array<const char *> frameworks;
DString deffile;
DString resfile;
DString exefile;
Expand Down
1 change: 1 addition & 0 deletions src/dmd/id.d
Expand Up @@ -322,6 +322,7 @@ immutable Msgtable[] msgtable =
// For pragma's
{ "Pinline", "inline" },
{ "lib" },
{ "framework"},
{ "linkerDirective" },
{ "mangle" },
{ "msg" },
Expand Down
8 changes: 8 additions & 0 deletions src/dmd/json.d
Expand Up @@ -931,6 +931,14 @@ public:
}
arrayEnd();

propertyStart("frameworks");
arrayStart();
foreach (framework; global.params.frameworks)
{
item(framework.toDString);
}
arrayEnd();

propertyStart("ddocFiles");
arrayStart();
foreach (ddocFile; global.params.ddocfiles)
Expand Down
11 changes: 10 additions & 1 deletion src/dmd/link.d
Expand Up @@ -639,7 +639,9 @@ public int runLINK()
* 4. libraries specified by pragma(lib), which were appended
* to global.params.libfiles. These are prefixed with "-l"
* 5. dynamic libraries passed to the command line (global.params.dllfiles)
* 6. standard libraries.
* 6. frameworks specified by pragma(framework), which were appended
* to the global.params.frameworks as -framework FRAMEWORK_NAME
* 7. standard libraries.
*/

// STEP 1
Expand Down Expand Up @@ -698,6 +700,13 @@ public int runLINK()
}

// STEP 6
foreach (framework; global.params.frameworks)
{
argv.push("-framework");
argv.push(mem.xstrdup(framework));
}

// STEP 7
/* D runtime libraries must go after user specified libraries
* passed with -l.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/dmd/toobj.d
Expand Up @@ -754,6 +754,24 @@ void toObjFile(Dsymbol ds, bool multiobj)
global.params.libfiles.push(name);
}
}
else if (pd.ident == Id.framework)
{
assert(pd.args && pd.args.dim == 1);
printf("got a framework\n");
Expression e = (*pd.args)[0];

assert(e.op == TOK.string_);

StringExp se = cast(StringExp)e;
char *name = cast(char *)mem.xmalloc(se.numberOfCodeUnits() + 1);
se.writeTo(name, true);

/* Append the framework name to the list to be passed
* to the linker.
*/
global.params.frameworks.push(name);

}
else if (pd.ident == Id.startaddress)
{
assert(pd.args && pd.args.dim == 1);
Expand Down
1 change: 1 addition & 0 deletions test/compilable/extra-files/json2.out
Expand Up @@ -5,6 +5,7 @@
"cwd": "VALUE_REMOVED_FOR_TEST",
"ddocFiles": [],
"defFile": null,
"frameworks": [],
"importPaths": [
"compilable",
"../../druntime/import",
Expand Down
24 changes: 24 additions & 0 deletions test/runnable/test2968.d
@@ -0,0 +1,24 @@
// DISABLED: win linux freebsd dragonflybsd netbsd

pragma(framework, "CoreFoundation");

struct __CFArray; //try to call some CF functions with arrays
alias CFArrayRef = __CFArray*;
alias CFIndex = long;

extern(C) CFArrayRef CFArrayCreate(void* allocator, const void** values, long numValues, void* cbs);
extern(C) CFIndex CFArrayGetCount(CFArrayRef theArray);
extern(C) const(void *) CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);

void main()
{

ulong[5] array = [1,2,3,4,5];
auto cfa = CFArrayCreate(null, cast(void**)array.ptr, array.length, null);
const length = CFArrayGetCount(cfa);
assert(length == array.length);
foreach (i, x; array)
{
assert(x == cast(ulong) CFArrayGetValueAtIndex(cfa, i));
Copy link
Contributor

Choose a reason for hiding this comment

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

You’re storing int not ulong on the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am? The array is declared as ulong[5] above

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I was only looking at the array literal. My bad.

}
}