View previous topic :: View next topic |
Author |
Message |
BobDobbs
Joined: 03 Oct 2006 Posts: 6
|
Posted: Mon Dec 11, 2006 11:39 pm Post subject: dmd .177 breaks an implicit cast in wgl.d |
|
|
line 117 of wgl.d
void *func = wglGetProcAddress(funcName);
throws an error about implicitly casting from char[] to char*
changing the line to
void *func = wglGetProcAddress(cast(char*)funcName);
seems to fix it so far as my code compiles once again.
However I'm not sure if this will in some bizarre way break other things you've done.
Either way I wanted to bring it to your attention if you didn't already know.
(wasn't sure where you'd see it so I figured the forums would be good a place as any)
Cheers. |
|
Back to top |
|
|
Crispy
Joined: 26 Nov 2005 Posts: 67
|
Posted: Tue Dec 12, 2006 10:12 pm Post subject: |
|
|
In general, to convert from D-style strings (char[]) to C-style strings (char*) you should call std.string.toStringz(). Casting directly may work, but if the string isn't already null-terminated you may end up passing garbage at the end of the string. (toStringz just adds a null terminator and then casts to char*.) |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sun Dec 17, 2006 6:15 pm Post subject: Re: dmd .177 breaks an implicit cast in wgl.d |
|
|
BobDobbs wrote: | line 117 of wgl.d
void *func = wglGetProcAddress(funcName);
throws an error about implicitly casting from char[] to char*
changing the line to
void *func = wglGetProcAddress(cast(char*)funcName);
seems to fix it so far as my code compiles once again.
However I'm not sure if this will in some bizarre way break other things you've done.
Either way I wanted to bring it to your attention if you didn't already know.
(wasn't sure where you'd see it so I figured the forums would be good a place as any)
Cheers. |
Thanks. This is a side-effect of the new "feature" of DMD that eliminates implicit conversion from arrays to pointers (a feature I think is silly, but I'm in the minority there). I'll have to go through and update all cases in Derelict where this is going on. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
Bradley Smith
Joined: 20 Jun 2006 Posts: 60
|
Posted: Mon Dec 18, 2006 2:00 am Post subject: |
|
|
Here is a patch for subversion revision 201.
Code: | Index: DerelictGL/derelict/opengl/wgl.d
===================================================================
--- DerelictGL/derelict/opengl/wgl.d (revision 201)
+++ DerelictGL/derelict/opengl/wgl.d (working copy)
@@ -40,6 +40,7 @@
import derelict.util.loader;
import derelict.util.exception;
import std.c.windows.windows;
+ import std.string;
}
//------------------------------------------------------------------------------
@@ -114,7 +115,7 @@
package void wglBindFunc(void **ptr, char[] funcName, SharedLib lib)
{
- void *func = wglGetProcAddress(funcName);
+ void *func = wglGetProcAddress(toStringz(funcName));
if(!func)
Derelict_HandleMissingProc(lib.name, funcName);
else
Index: DerelictSDLMixer/derelict/sdl/mixer.d
===================================================================
--- DerelictSDLMixer/derelict/sdl/mixer.d (revision 201)
+++ DerelictSDLMixer/derelict/sdl/mixer.d (working copy)
@@ -40,6 +40,7 @@
import derelict.sdl.sdlversion;
import derelict.sdl.error;
import derelict.util.loader;
+ import std.string;
}
//==============================================================================
@@ -119,7 +120,7 @@
// FIXME: Need to append \0 to file?
Mix_Chunk* Mix_LoadWAV(char[] file)
{
- return Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1);
+ return Mix_LoadWAV_RW(SDL_RWFromFile(toStringz(file), toStringz("rb")), 1);
}
int Mix_PlayChannel(int channel, Mix_Chunk* chunk, int loops)
|
|
|
Back to top |
|
|
ToadChild
Joined: 18 Dec 2006 Posts: 1
|
Posted: Mon Dec 18, 2006 10:58 pm Post subject: |
|
|
This also affects buildme.d
Code: |
Index: buildme.d
===================================================================
--- buildme.d (revision 201)
+++ buildme.d (working copy)
@@ -7,6 +7,7 @@
import std.c.process;
import std.file;
import std.path;
+ import std.string;
}
// build configurations
@@ -131,7 +132,7 @@
{
// execute the system delete command on all of the library files in the lib dir
writefln("Deleting all libraries in Derelict's lib directory...");
- system(delCmd ~ "lib" ~ sep ~ "*" ~ libExt);
+ system(toStringz(delCmd ~ "lib" ~ sep ~ "*" ~ libExt));
writefln("Finished!\n\n");
}
@@ -220,16 +221,16 @@
// call out to build with the name of the temporary build response file as an arg
writefln("Building package...");
- int ret = system(buildName ~ " @temp");
+ int ret = system(toStringz(buildName ~ " @temp"));
if(ret != 0)
{
writefln("\n\n " ~ packageName ~ " failed to build.\n");
- version(Windows) system("pause");
+ version(Windows) system(toStringz("pause"));
}
// delete the temporary build response file
writefln("Deleting temporary build response file...\n\n");
- system(delCmd ~ tempBrf);
+ system(toStringz(delCmd ~ tempBrf));
}
|
|
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Thu Dec 21, 2006 3:34 am Post subject: |
|
|
Thanks, guys. Both patches have been applied. I had to do it manually as the patcher bitched at me with a different error for each of them, so let me know if I goofed anything. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
Deewiant
Joined: 26 Dec 2005 Posts: 21 Location: Finland
|
Posted: Fri Dec 22, 2006 1:55 pm Post subject: |
|
|
Not a goof of yours, but in the patch: toStringz on string literals is redundant, as they are already zero terminated. (See "C's printf() and strings" at http://digitalmars.com/d/arrays.html )
I'd change at least toStringz("pause") and toStringz("rb") to just "pause" and "rb".
It's up to you whether to change toStringz(buildName ~ " @temp") - in its current form it will be zero terminated anyway, since a 0 follows from the " @temp" literal, but there is a variable, buildName, involved, so if the code is ever changed to a form where the string literal doesn't come last it will break. Personally, I'd go for the slight optimisation, removing the toStringz() and putting a warning comment nearby. |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Fri Dec 22, 2006 2:56 pm Post subject: |
|
|
Deewiant wrote: | Not a goof of yours, but in the patch: toStringz on string literals is redundant, as they are already zero terminated. (See "C's printf() and strings" at http://digitalmars.com/d/arrays.html ) |
Right, but I assumed the toStringz call in this case was just a way to convert to char* so I left it as is.
Quote: |
I'd change at least toStringz("pause") and toStringz("rb") to just "pause" and "rb". |
That's actually the original code. The problem was that constant string are of type char[], but the function call takes a char* since it's a C API. DMD no longer allows implicit conversion from char[] to char*.
I'm not really up to speed on the implications yet. Would cast(char*)"rb" work? Or perhaps "rb".ptr?
Quote: | It's up to you whether to change toStringz(buildName ~ " @temp") - in its current form it will be zero terminated anyway, since a 0 follows from the " @temp" literal, but there is a variable, buildName, involved, so if the code is ever changed to a form where the string literal doesn't come last it will break. Personally, I'd go for the slight optimisation, removing the toStringz() and putting a warning comment nearby. |
It's not like this is critical code, so calling toStringz on everything really isn't an issue. I don't have any problem leaving it. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
Deewiant
Joined: 26 Dec 2005 Posts: 21 Location: Finland
|
Posted: Sun Dec 24, 2006 6:27 am Post subject: |
|
|
Right, of course "rb" doesn't convert to char* automatically - my bad. "rb".ptr is probably the most idiomatic way of doing it. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|