Re: Versioned extern?

2011-07-23 Thread Brad Roberts
On Saturday, July 23, 2011 8:35:39 PM, Nick Sabalausky wrote:
> Is there a way to have a section of code be extern(C) on one OS and 
> extern(Windows) on another OS, without resorting making the code in question 
> a mixin?
> 
> These doesn't appear to work:
> 
> --
> version(Windows)
> {
> enum callingConvention = "Windows";
> }
> else
> {
> enum callingConvention = "C";
> }
> 
> extern(mixin(callingConvention ))
> {
> /+ ...code here... +/
> }
> --
> version(Windows)
> {
> extern(Windows):
> }
> else
> {
> extern(C):
> }
> 
> /+ ...code here... +/
> 
> extern(D):
> --

That specific pair of extern types with that specific set of versions 
--> extern(System)


Versioned extern?

2011-07-23 Thread Nick Sabalausky
Is there a way to have a section of code be extern(C) on one OS and 
extern(Windows) on another OS, without resorting making the code in question 
a mixin?

These doesn't appear to work:

--
version(Windows)
{
enum callingConvention = "Windows";
}
else
{
enum callingConvention = "C";
}

extern(mixin(callingConvention ))
{
/+ ...code here... +/
}
--
version(Windows)
{
extern(Windows):
}
else
{
extern(C):
}

/+ ...code here... +/

extern(D):
--






Re: How to get stack trace on Windows?

2011-07-23 Thread Nick Sabalausky
"Dmitry Olshansky"  wrote in message 
news:j0boln$1l4i$1...@digitalmars.com...
> On 22.07.2011 15:02, Nick Sabalausky wrote:
>> "Dmitry Olshansky"  wrote in message
>> news:j0bgt7$176q$1...@digitalmars.com...
>>> Last time I've seen stack trace it was due to this command:
>>>
>>> dmd -debug -g ...
>>>
>> I was already using -debug and -g. No function names.
>>
> Now that's wierd, since I definitely see them. Another thing to try is 
> rebuild dmd/druntime/phobos from latest git, at least it's a setup I have 
> right now it works (though I'm on Win7 x64).
>

Just tried that. Still no names :( Just the addresses as before.




Re: Building DMD from git

2011-07-23 Thread Nick Sabalausky
"Jonathan M Davis"  wrote in message 
news:mailman.1890.1311472074.14074.digitalmars-d-le...@puremagic.com...
>
> It can't find object_.d. It means that the path to druntime (and probably 
> the
> path to phobos as well) is screwed up. Your dmd.conf (or sc.ini I guess, 
> since
> you appear to be on Windows) needs to be fixed to have the correct paths.
>

Heh, turns out the problem was something I glossed over in my listing of 
what I did.

When I created sc.ini, I created it in the main current directory (ie, the 
same directory that contains the "dmd", "druntime" and "phobos" 
subdirectories). Then I gave sc.ini to DMD with:

> copy sc.ini dmd\bin

And then ran dmd from the current directory. So DMD picked up ./sc.ini 
instead of ./dmd/bin/sc.ini. And of course, since the paths in sc.ini are 
given relative to sc.ini itself, that's what screwed it up.

Boy, three time-consuming dumbass mistakes in two days. I'm really on a roll 
here... ;)




Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread Tyro[a.c.edwards]

On 7/23/2011 7:49 PM, bearophile wrote:

Tyro[a.c.edwards]:


[3] imagelist.d(22): Error: class
dfl.imagelist.ImageList.ImageCollection use of
dfl.imagelist.ImageList.ImageCollection.ListWrapArray!(Image,_images,_adding,_added,_blankListCallback,_removed,false,false,false).insert(int
index, Image value) hidden by ImageCollection is deprecated

Now I know I can bypass this with the -d switch but I'm more interested
in fixing the problem than bypassing it.


There is a trick based on explicit alias to avoid those errors. I'd like the 
idea of using this alias to be present in that error message...

Bye,
bearophile


Please do share. I thought the concept explicit alias simply requires me 
to do his:


alias ListWrapArray LWA;
mixin LWA!(Image, _images,
_adding, _added,
_blankListCallback!(Image), _removed,
false, false, false);

This did not work... resulted in the same error. On closer look it seems 
the actual problem is not the template but the definition of "insert" 
therein. It is being hidden by the definition of insert in ImageCollection.


ImageCollection definition:

void insert(int index, Image img)
{
if(index >= _images.length)
{
add(img);
}
else
{
assert(0, "Must add images to the end of the image 
list");
}
}

ListWrapArray definition:

void insert(int index, TValue value)
{
_insert(index, value);
}

In the end it turns out to be the same problem as one and two. Any 
suggestion on how to deal with these correctly? I can resolve this 
particular error by renaming the function to "Insert" in 
ImageCollection. But even though it appeases the compiler, is that the 
correct solution? Is there something else that I'm not taking into 
consideration? How do I fix the other two since there is no way to 
rename opApply and opCmp that I'm aware of?


Thanks


Re: Building DMD from git

2011-07-23 Thread Jonathan M Davis
On Saturday 23 July 2011 20:23:16 Nick Sabalausky wrote:
> Ok, this is probably some stupid little issue, but I'm getting "object.d:
> Error: module object is in file 'object.d' which cannot be read" when I try
> to use a DMD I build from git. Here's how I'm building it all:
> 
> -
> 
> [DMC is already installed and on the PATH]
> 
> >git clone https://github.com/D-Programming-Language/dmd.git
> >git clone https://github.com/D-Programming-Language/druntime.git
> >git clone https://github.com/D-Programming-Language/phobos.git
> >mkdir dmd\bin
> >mkdir dmd\lib
> >SET PATH={current_dir}\dmd\bin;%PATH%
> 
> [edit dmd\src\win32.mak and change the stupid  "CC=\dm\bin\dmc" to "CC=dmc"]
> 
> [create a specially-adjusted dmd\bin\sc.ini]
> 
> >type dmd\bin\sc.ini
> 
> [Version]
> version=7.51 Build 020
> 
> [Environment]
> LIB="%@P%\..\lib";\dm\lib
> DFLAGS="-I%@P%\..\..\phobos" "-I%@P%\..\..\druntime\import"
> LINKCMD=%@P%\link.exe
> 
> >cd dmd\src
> >make -fwin32.mak
> >cd ..\..
> >copy dmd\src\dmd.exe dmd\bin
> >cd druntime
> >make -fwin32.mak
> >cd ..
> >copy druntime\lib\druntime.lib dmd\lib
> >cd phobos
> >make -fwin32.mak
> >cd ..
> >copy phobos\phobos.lib dmd\lib
> >type test.d
> 
> import std.stdio;
> void main()
> {
> writeln("Hello");
> }
> 
> >dmd test.d
> 
> DMD v2.055 DEBUG
> object.d: Error: module object is in file 'object.d' which cannot be read
> import path[0] = .\..\..\phobos
> import path[1] = .\..\..\druntime\import

It can't find object_.d. It means that the path to druntime (and probably the 
path to phobos as well) is screwed up. Your dmd.conf (or sc.ini I guess, since 
you appear to be on Windows) needs to be fixed to have the correct paths.

- Jonathan M Davis


Building DMD from git

2011-07-23 Thread Nick Sabalausky
Ok, this is probably some stupid little issue, but I'm getting "object.d: 
Error: module object is in file 'object.d' which cannot be read" when I try 
to use a DMD I build from git. Here's how I'm building it all:

-

[DMC is already installed and on the PATH]

>git clone https://github.com/D-Programming-Language/dmd.git
>git clone https://github.com/D-Programming-Language/druntime.git
>git clone https://github.com/D-Programming-Language/phobos.git
>mkdir dmd\bin
>mkdir dmd\lib
>SET PATH={current_dir}\dmd\bin;%PATH%

[edit dmd\src\win32.mak and change the stupid  "CC=\dm\bin\dmc" to "CC=dmc"]

[create a specially-adjusted dmd\bin\sc.ini]

>type dmd\bin\sc.ini
[Version]
version=7.51 Build 020

[Environment]
LIB="%@P%\..\lib";\dm\lib
DFLAGS="-I%@P%\..\..\phobos" "-I%@P%\..\..\druntime\import"
LINKCMD=%@P%\link.exe

>cd dmd\src
>make -fwin32.mak
>cd ..\..
>copy dmd\src\dmd.exe dmd\bin
>cd druntime
>make -fwin32.mak
>cd ..
>copy druntime\lib\druntime.lib dmd\lib
>cd phobos
>make -fwin32.mak
>cd ..
>copy phobos\phobos.lib dmd\lib
>type test.d
import std.stdio;
void main()
{
writeln("Hello");
}

>dmd test.d
DMD v2.055 DEBUG
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = .\..\..\phobos
import path[1] = .\..\..\druntime\import





How do I call super or object.opAssign for classes?

2011-07-23 Thread Andrej Mitrovic
class Foo
{
void opAssign(int bar)
{
}
}

void main()
{
auto foo = new Foo;
foo = null;
}

test.d(17): Error: function test.Foo.opAssign (int bar) is not
callable using argument types (void*)
test.d(17): Error: cannot implicitly convert expression (null) of type
void* to int

I just wanted to implement one opAssign method for assigning a
specific type, but now I've ran into the issue that assigning class
objects to null doesn't work anymore.. :/


Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread Jesse Phillips
On Sat, 23 Jul 2011 10:51:35 -0400, bearophile wrote:

> Jesse Phillips:
> 
>> It is not fixed there, it is missing a number of changes. This is one
>> of them and I'm confused on since I thought override was supposed to,
>> well override.
> 
> I think we are talking about two different things: overriding and
> overloading.
> 
> Bye,
> bearophile

Ok, I got it. The problem is not overriding ALL the opEquals functions in 
the child class. I.e. you must override all overloaded functions when 
overriding one function.


Very strange linker error

2011-07-23 Thread Mafi
I'm trying to rebuild my projects with new dmd and after fixing some 
minor issues in my code I get the following:


Warning: As of Phobos 2.054, std.file.listDir has been scheduled for 
deprecation in August 2011. Please use std.file.dirEntries instead.


OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
obj\main.obj(main)  Offset 35B56H Record Type 00C3
 Error 1: Previous Definition Different : _D5mysdl5input8Joystick6__ctorM
--- errorlevel 1

So I went to http://www.digitalmars.com/d/2.0/abi.html (which I by the 
wy couldn't find on d-p-l.org) and it seems to be an incorrect mangling 
because there's no 'type' after M but maybe it's a special case for the 
constructor.


So looked for mysdl.input.Joystick.this(...). The struct (!) Joystick in 
input.d has two constructors:


public this(SDL_Joystick* somePtr) {
this.joyptr = somePtr;
}

public this(int index)
in {
assert(index >= 0);
assert(index < Joystick.getCount());
} body {
this(SDL_JoystickOpen(index));
}

No overlaping. So I went dumping all my object files and I found that 
dmd generated this strange sambol in input.obj twice. So it's not 
optlink's fault but dmd's!


I'd really like to solve this problem because otherwise this would be 
second release in a row that I can't use.

The worst thing is I don't even now any ugly workaround. :(

Mafi


Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread bearophile
Jesse Phillips:

> It is not fixed there, it is missing a number of changes. This is one of 
> them and I'm confused on since I thought override was supposed to, well 
> override.

I think we are talking about two different things: overriding and overloading.

Bye,
bearophile


Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread Jesse Phillips
On Sat, 23 Jul 2011 08:34:27 +0200, Andrej Mitrovic wrote:

> I'm not sure about the issue, but just in case it's not known the newest
> DFL seems to be hosted on github: https://github.com/Rayerd/dfl
> 
> It might have those issues fixed, unless this is where you've cloned
> from, in which case sorry for the noise.

It is not fixed there, it is missing a number of changes. This is one of 
them and I'm confused on since I thought override was supposed to, well 
override.


Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread bearophile
Tyro[a.c.edwards]:

> [3] imagelist.d(22): Error: class 
> dfl.imagelist.ImageList.ImageCollection use of 
> dfl.imagelist.ImageList.ImageCollection.ListWrapArray!(Image,_images,_adding,_added,_blankListCallback,_removed,false,false,false).insert(int
>  
> index, Image value) hidden by ImageCollection is deprecated
> 
> Now I know I can bypass this with the -d switch but I'm more interested 
> in fixing the problem than bypassing it.

There is a trick based on explicit alias to avoid those errors. I'd like the 
idea of using this alias to be present in that error message...

Bye,
bearophile


Re: Reference counting questions

2011-07-23 Thread Johannes Pfau
Jesse Phillips wrote:
>I don't really think stdio is the place to see modern D ref counting.
>The container class has an Array which is built to use RefCounted. I
>had tried my and at explaining how to use it: http://stackoverflow.com/
>questions/4632355/making-a-reference-counted-object-in-d-using-
>refcountedt/4635050#4635050
>
>I'm not really sure if all the details have been worked out. Hopefully
>I explained it correctly and that it gives you an idea of how to make
>ref counting work.

Totally overlooked a 'small' problem with RefCounted: It can't work for
cairoD ;-) In cairo the c handle is already reference-counted, so I
should use cairo_*_[de]reference(ptr) instead of my own counter, but
that can't be done with RefCounted. I think I'll have to adapt the
RefCounted implementation for cairoD.

But I can still use RefCounted in other projects.

BTW: RefCounted also uses std.algorithm.swap in it's opAssign. Still
wondering what that's supposed to do.
-- 
Johannes Pfau



Re: Why is a static struct's dtor called at the exit of a function?

2011-07-23 Thread Jonathan M Davis
On Saturday 23 July 2011 11:28:07 Andrej Mitrovic wrote:
> Ok, so pure does the job, didn't know.

There are two requirements for a function to be pure:

1. Any functions that it calls must be pure.

2. It cannot access any static or global variables unless they're immutable or 
they're const value types (essentially, they can't access any static or global 
variables which could ever be changed over the course of the program).

So, if a function is pure, it can't access a global variable like in your 
example. Now, in addition to that, if a pure function's arguments can be 
determined to be guaranteed to be unchanged when the function is call, then 
that function is strongly pure, and additional calls to it with the same 
arguments in the same expression can be optimized out. At the moment, that 
means that the function's parameters must all either be immutable or 
implicitly convertible to mutable, but there are cases where the compiler 
could conceivably optimize it with just const (e.g. if an immutable variable 
is passed to a function where the parameter is const).

So, the primary thing that you get out of pure in the general case (since so 
many functions can be weakly pure but not strongly pure) is that you have the 
guarantee that it doesn't access global variables whose state is at all 
mutable.

- Jonathan M Davis


Re: Why is a static struct's dtor called at the exit of a function?

2011-07-23 Thread Andrej Mitrovic
Ok, so pure does the job, didn't know.


Re: How does one correct shadowing (hidden by) errors?

2011-07-23 Thread Andrej Mitrovic
I'm not sure about the issue, but just in case it's not known the
newest DFL seems to be hosted on github: https://github.com/Rayerd/dfl

It might have those issues fixed, unless this is where you've cloned
from, in which case sorry for the noise.


Re: Why is a static struct's dtor called at the exit of a function?

2011-07-23 Thread Jonathan M Davis
On Saturday 23 July 2011 08:52:28 Andrej Mitrovic wrote:
> What are the current semantics of static struct definitions in module
> scope? It doesn't seem to have any effect. I was thinking about this:
> 
> module test;
> 
> int z;
> 
> static struct Foo
> {
> void foo()
> {
> z = 5;  // maybe make this an error if the struct definition is
> static? }
> }
> 
> Maybe it could be useful as protection against modifying globals.

static only affects what can be accessed when it's on something that's nested. 
It affects member functions (which are nested in a class or struct), making it 
so that it can't access the surrounding class or struct. The same goes with 
nested structs and classes. When used on a function, struct, or class inside 
of a function, it makes it so that that nested function, struct, or class 
cannot access the scope of the function that it's in. It _never_ has any effect 
on global variables, and it _never_ affects _anything_ at module scope.

The struct above isn't nested in anything, so static makes no sense for it. 
And if you tried to make it so that it so that its functions then couldn't 
acces the module's scope, that would be completely inconsistent with 
everything else. The only time that a function cannot access a variable at 
module scope is when that function is pure. You're essentially suggesting that 
static be used to do pure's job in this case.

- Jonathan M Davis


Re: Need OMF MySQL lib that actually f^*&^ works...

2011-07-23 Thread Andrej Mitrovic
This is what you should use for C long and unsigned long:

import core.stdc.config;
c_long;
c_ulong;


Re: Reference counting questions

2011-07-23 Thread Johannes Pfau
Jesse Phillips wrote:
>I don't really think stdio is the place to see modern D ref counting.
>The container class has an Array which is built to use RefCounted. I
>had tried my and at explaining how to use it: http://stackoverflow.com/
>questions/4632355/making-a-reference-counted-object-in-d-using-
>refcountedt/4635050#4635050
>
>I'm not really sure if all the details have been worked out. Hopefully
>I explained it correctly and that it gives you an idea of how to make
>ref counting work.

Thanks, I think I understand how to use RefCounted now.
But it still leaves this issue:
Is it possible to add explicit de-referencing to allow a global
struct / struct in class to be manually dereferenced?

And it adds a new one:
RefCounted calls addRange
https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L2304
if the _store size is >= size_t (In fact, as _store already has a size_t
for count, addRange will always get called?). This means even if I only
want RefCounting for a simple C handle, addRange will be called.

I don't understand the use of malloc & free in
RefCounted. If addRange is called anyway, why not just use GC.malloc
and GC.free?

One more thing: The removeRange call uses a different condition:

if (hasIndirections!T && RefCounted._store)
GC.removeRange(RefCounted._store);

if (sz >= size_t.sizeof && p.ptr)
GC.addRange(p.ptr, sz);

Now say, I store a  single byte, wouldn't addRange get called but
removeRange not?
-- 
Johannes Pfau



Re: Need OMF MySQL lib that actually f^*&^ works...

2011-07-23 Thread Nick Sabalausky
"Nick Sabalausky"  wrote in message 
news:j0dqhg$2cvs$1...@digitalmars.com...
> "Nick Sabalausky"  wrote in message 
> news:j0b4r1$icb$1...@digitalmars.com...
>> Anyone have a known-working Windows OMF library for MySQL? Static or 
>> dynamic, I don't care. I've tried fucking everything and I can't get the 
>> dang thing to work. Static was a total no-go. With dynamic, using implib 
>> I got it to link, but calling any of it resulted in an Access Violation. 
>> Using coffimplib, best I could do had one linker error, a missing 
>> "_mysql_real_connect". This was all with "Connector/C" v6.0.2. I'd have 
>> tried an older version, 5.x, but 6.0.2 is the only version that seems to 
>> still exist.
>>
>
> Goddamnnit, I think the whole problem was that stupid linking with a C 
> "long" issue...
>
> The function mysql_real_connect takes a long, and it's the only part of 
> the MySQL interface being used that takes a long. No idea why it still 
> worked on Linux, but fingers crossed that a DDMD-style C bridge will fix 
> it...
>

Ok, yea, it was a C long issue with the bindings, although I ended up not 
needing a C bridge. Apparently, C's "int" and "long" are both 32-bit on a 
32-bit system (Also apparent: it's been a very long time since I used 
C/C++...) Screwy C...

Once I changed the "ulong" param in the D binding for mysql_real_connect to 
"uint", the instructions at ( 
http://www.wikiservice.at/d/wiki.cgi?DatabaseBindings#MySQL ) suddenly 
worked like a charm. I'm now connected to my MySQL DB from D. Whoohoo!

I still have no idea why it seemed to work fine on Linux without that 
change, but at the moment I don't particularly give a crap...





Re: Need OMF MySQL lib that actually f^*&^ works...

2011-07-23 Thread Nick Sabalausky
"Nick Sabalausky"  wrote in message 
news:j0b4r1$icb$1...@digitalmars.com...
> Anyone have a known-working Windows OMF library for MySQL? Static or 
> dynamic, I don't care. I've tried fucking everything and I can't get the 
> dang thing to work. Static was a total no-go. With dynamic, using implib I 
> got it to link, but calling any of it resulted in an Access Violation. 
> Using coffimplib, best I could do had one linker error, a missing 
> "_mysql_real_connect". This was all with "Connector/C" v6.0.2. I'd have 
> tried an older version, 5.x, but 6.0.2 is the only version that seems to 
> still exist.
>

Goddamnnit, I think the whole problem was that stupid linking with a C 
"long" issue...

The function mysql_real_connect takes a long, and it's the only part of the 
MySQL interface being used that takes a long. No idea why it still worked on 
Linux, but fingers crossed that a DDMD-style C bridge will fix it...




Re: Why is a static struct's dtor called at the exit of a function?

2011-07-23 Thread Andrej Mitrovic
Filed with a simplified test case:
http://d.puremagic.com/issues/show_bug.cgi?id=6364


Re: Why is a static struct's dtor called at the exit of a function?

2011-07-23 Thread Andrej Mitrovic
What are the current semantics of static struct definitions in module
scope? It doesn't seem to have any effect. I was thinking about this:

module test;

int z;

static struct Foo
{
void foo()
{
z = 5;  // maybe make this an error if the struct definition is static?
}
}

Maybe it could be useful as protection against modifying globals.