Re: stream readf keeps producing bus error on DMD 2.046 on OS X 10.5.8

2010-07-08 Thread Ali Çehreli

RedZone wrote:

Hi,

I've been trying to use readf to read some basic text from a file... I found,
though, that readf kept producing inexplicable bus errors.  I simplified my
code and tried to use readf on just a plain character array.  No change.
Here's the code:

import std.stdio;
//import std.file;
import std.stream;

void main()
{
string s1;
int i;
string s2;
string s3;

char[] s0 = "a 5 bc e".dup;
auto stream = new TArrayStream!(char[])(s0);

stream.readf("%s %d %s %s ", &s1, &i, &s2, &s3);
writefln("%s %d %s %s", s1, i, s2, s3);

}


It doesn't matter how I change the input or what I use as the stream, readf
produces this bus error.  Compiling in release mode doesn't help either.  What
am I doing wrong?

I'm using DMD 2.046 on Mac OS X 10.5.8.


Reading into char arrays and dropping the format string works (tried 
with dmd 2.047):


char[] s1;
int i;
char[] s2;
char[] s3;

char[] s0 = "a 5 bc e".dup;
auto s = new TArrayStream!(char[])(s0);

s.readf(&s1, &i, &s2, &s3);

I hear that the streams will be (are?) deprecated. There will be 
std.stdio.readf which will be in the next dmd release.


Ali


Re: Any special linking for _NSGetExecutablePath on OSX?

2010-07-08 Thread Justin Spahr-Summers
On Thu, 8 Jul 2010 19:24:52 -0400, Nick Sabalausky  wrote:
> 
> I need to use OSX's _NSGetExecutablePath, and I've declared it:
> 
> extern(C) int _NSGetExecutablePath(char* buf, uint* bufsize);
> 
> I don't have access to a OSX box to test it on ATM, so I need to know: Is 
> there anything I need to tell the linker (like, anything special I need to 
> explicitly link in) in order to get that to work, or should it "just work"? 
> (ie, is whatever library is needed for that already linked by default?)

I haven't used the function before, but after looking it up really 
quickly, that declaration looks good to go. Since it's part of the 
dynamic linker, I can't imagine that a library would have to be linked 
in for it to work.


Any special linking for _NSGetExecutablePath on OSX?

2010-07-08 Thread Nick Sabalausky
I need to use OSX's _NSGetExecutablePath, and I've declared it:

extern(C) int _NSGetExecutablePath(char* buf, uint* bufsize);

I don't have access to a OSX box to test it on ATM, so I need to know: Is 
there anything I need to tell the linker (like, anything special I need to 
explicitly link in) in order to get that to work, or should it "just work"? 
(ie, is whatever library is needed for that already linked by default?)




stream readf keeps producing bus error on DMD 2.046 on OS X 10.5.8

2010-07-08 Thread RedZone
Hi,

I've been trying to use readf to read some basic text from a file... I found,
though, that readf kept producing inexplicable bus errors.  I simplified my
code and tried to use readf on just a plain character array.  No change.
Here's the code:

import std.stdio;
//import std.file;
import std.stream;

void main()
{
string s1;
int i;
string s2;
string s3;

char[] s0 = "a 5 bc e".dup;
auto stream = new TArrayStream!(char[])(s0);

stream.readf("%s %d %s %s ", &s1, &i, &s2, &s3);
writefln("%s %d %s %s", s1, i, s2, s3);

}


It doesn't matter how I change the input or what I use as the stream, readf
produces this bus error.  Compiling in release mode doesn't help either.  What
am I doing wrong?

I'm using DMD 2.046 on Mac OS X 10.5.8.


Re: Mixing operations with signed and unsigned types

2010-07-08 Thread Jérôme M. Berger
Stewart Gordon wrote:
> Ellery Newcomer wrote:
>> On 07/06/2010 07:05 PM, Stewart Gordon wrote:
> 
>>> Just using uint, of course!
>>
>> For enforcing a non-negative constraint, that is brain damaged.
>> Semantically, the two are very different.
> 
> So effectively, the edit wars would be between people thinking at cross
> purposes.
> 
> I guess it would be interesting to see how many libraries are using
> unsigned types wherever the value is semantically unsigned, and how many
> are using signed types for such values (maybe with a few exceptions when
> there's a specific reason).
> 
I used to use unsigned types wherever the value is semantically
unsigned, but I am in the process of changing to signed everywhere
possible because of the brain dead way mixed operations are handled
(in C, but D would be the same).

Jerome
-- 
mailto:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr



signature.asc
Description: OpenPGP digital signature


Re: Mixing operations with signed and unsigned types

2010-07-08 Thread Stewart Gordon

Ellery Newcomer wrote:

On 07/06/2010 07:05 PM, Stewart Gordon wrote:



Just using uint, of course!


For enforcing a non-negative constraint, that is brain damaged. 
Semantically, the two are very different.


So effectively, the edit wars would be between people thinking at cross 
purposes.


I guess it would be interesting to see how many libraries are using 
unsigned types wherever the value is semantically unsigned, and how many 
are using signed types for such values (maybe with a few exceptions when 
there's a specific reason).



int i;
assert(i >= 0);

says i can cross the 0 boundary, but it's an error if it does, i.e. 
programmer doesn't need to be perfect because it *does get caught* 
(extreme instances notwithstanding).


Or equivalently,

uint i;
assert (i <= cast(uint) int.max);


uint i;

says i cannot cross the 0 boundary, but it isn't an error if it does. 
programmer needs to be perfect and error doesn't get caught (unless what 
you're using it for can do appropriate bounds checking).


Or the wrapping round is an intended feature of what you're using it for.


Comparison - how do you mean?

Stewart.


Mmmph. Just signed/unsigned, I guess (I was thinking foggily that 
comparison intrinsically involves subtraction or something like that)


But whether subtraction for comparison works doesn't depend on whether 
the legal ranges of the source values are signed or unsigned, at least 
as long as they're both the same.


What it does depend on is whether the subtraction is performed in more 
bits than the number required to represent the legal range.


Stewart.


Re: std.pattern.. templated publisher subscriber pattern, adding events to collections

2010-07-08 Thread BLS

@ Dmitry
Thanks for all the feedback Dmitry. Seems that we have similar projects 
in mind :) (maybe we can talk about the GUI project.. mine is similar to 
win32++ at http://sourceforge.net/projects/win32-framework/)



However : Like you I would prefer to use something like ..

void delegate(const ref message) CallBack;
CallBack[] cb;
@Jakob
Adding some delegates to our list (D dyn. array) like in C# is a piece 
of cake..


But keep in  mind that we also need  removeObserver() in order to 
implement the Observer pattern.  And removing makes the difference.


The question is now :
How do we identify our Observer object in order to remove..
possible solutions :

1) passing the object instance to the mixin template. (as shown in my 
code) adding of course a : toHash() method.

2)
adding a GUID to the delegate..
3)
...

Dmitry, I think

YOUR :

final class Observable(Cont){
Cont cont;
//here goes your current Publisher stuff
//...
alias Cont!ElementType T;
static if(__traits(compiles,cont.insert(T.init)))//some such ...
need to test if it has this method

SOLUTION

is very hackish. (Beside, like IsForwardRange!R )

IMHO a mixin template is a more clean solution.

BUT this requires that container/collection classes are not final.

Well, even for final classes there is still the option to implement a 
decorator pattern! But the decorator pattern makes code quite unreadable...


However, ATM I am thinking about how we can you use std.concurrent 
message passing stuff...


Finally
Would be nice if we can write a few LOC together! ??
bjoern
PS> Sure the Publisher/Observable mixin has to work for structs too.