Re: druntime investigation troubles

2012-05-23 Thread Jacob Carlborg

On 2012-05-23 21:58, Steven Schveighoffer wrote:


+1

dmain2 has that "magic runtime" feel where you look at it and are so
confused that you are afraid to touch anything :P

-Steve


I previously made a pull request and tried to fix code duplication in 
dmain2.d. Unfortunately some test case failed, I'm going to look into it 
again.


--
/Jacob Carlborg


Re: D under Linux Mint

2012-05-23 Thread Jordi Sayol
Al 23/05/12 23:46, En/na snow ha escrit:
> Hello, Ive tried to install D under Linux and followed the steps
> described on . this page http://dlang.org/dmd-linux.html . I
> checked all folders after every step and everything is where it
> should be. In the secound step I did both, adding dmd to the PATH
> and copied the executables into the lib folder. If I type dmd
> into the console, I get back all infos about D, so this is
> already working. But if I try to run a simple Hello world program
> like this:
> 
> import std.stdio;
> 
> void main() {
> writeln("Hallo Welt");
> }
> 
> I get the following error:
> object.d: Error: module object is in file 'object.d' which cannot
> be read
> import path[0] = /usr/local/bin/../../src/phobos
> import path[1] = /usr/local/bin/../../src/druntime/import
> 
> 
> My DMD folder is in the home directory and the dmd.config
> contains this:
> [Environment]
> 
> DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
> -L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
> -L--export-dynamic
> 
> I already tried to compile the program with geany and the
> console. In the console i trid to compile it as: dmd hello.d and
> dmd -c hello.d. But everywhere I get the same errors
> 
> 
> 

In Linux Mint you can install deb packages from http://dlang.org/download.html

32-bit: http://ftp.digitalmars.com/dmd_2.059-0_i386.deb

64-bit: http://ftp.digitalmars.com/dmd_2.059-0_amd64.deb

They work out of the box.

-- 
Jordi Sayol


Re: D under Linux Mint

2012-05-23 Thread jerro

On Wednesday, 23 May 2012 at 21:46:24 UTC, snow wrote:

Hello, Ive tried to install D under Linux and followed the steps
described on . this page http://dlang.org/dmd-linux.html . I
checked all folders after every step and everything is where it
should be. In the secound step I did both, adding dmd to the 
PATH

and copied the executables into the lib folder. If I type dmd
into the console, I get back all infos about D, so this is
already working. But if I try to run a simple Hello world 
program

like this:

import std.stdio;

void main() {
writeln("Hallo Welt");
}

I get the following error:
object.d: Error: module object is in file 'object.d' which 
cannot

be read
import path[0] = /usr/local/bin/../../src/phobos
import path[1] = /usr/local/bin/../../src/druntime/import


My DMD folder is in the home directory and the dmd.config
contains this:
[Environment]

DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
-L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
-L--export-dynamic

I already tried to compile the program with geany and the
console. In the console i trid to compile it as: dmd hello.d and
dmd -c hello.d. But everywhere I get the same errors


Do you have a copy of dmd executable and dmd.conf in 
/usr/local/bin, by any chance? That would explain this:



import path[0] = /usr/local/bin/../../src/phobos
import path[1] = /usr/local/bin/../../src/druntime/import


Re: D under Linux Mint

2012-05-23 Thread Jonathan M Davis
On Wednesday, May 23, 2012 23:46:23 snow wrote:
> Hello, Ive tried to install D under Linux and followed the steps
> described on . this page http://dlang.org/dmd-linux.html . I
> checked all folders after every step and everything is where it
> should be. In the secound step I did both, adding dmd to the PATH
> and copied the executables into the lib folder. If I type dmd
> into the console, I get back all infos about D, so this is
> already working. But if I try to run a simple Hello world program
> like this:
> 
> import std.stdio;
> 
> void main() {
> writeln("Hallo Welt");
> }
> 
> I get the following error:
> object.d: Error: module object is in file 'object.d' which cannot
> be read
> import path[0] = /usr/local/bin/../../src/phobos
> import path[1] = /usr/local/bin/../../src/druntime/import
> 
> 
> My DMD folder is in the home directory and the dmd.config
> contains this:
> [Environment]
> 
> DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
> -L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
> -L--export-dynamic
> 
> I already tried to compile the program with geany and the
> console. In the console i trid to compile it as: dmd hello.d and
> dmd -c hello.d. But everywhere I get the same errors

Well, is Phobos found in /usr/local/bin/../../src/phobos (i.e. 
/usr/src/phobos)? I'm assuming not. You need to fix the dmd.conf that you use 
so that it points to where the source files actually are. So, 
%@P%/../../src/phobos needs to be changed to 
/path/to/where/phobos/src/is/whatever/that/might/be. The same goes for 
druntime and the lib64 and lib32 directories (which should be the paths to 
where libphobos.a is).

- Jonathan M Davis


Re: D under Linux Mint

2012-05-23 Thread Kevin Cox
On May 23, 2012 5:48 PM, "snow"  wrote:
>
> Hello, Ive tried to install D under Linux and followed the steps
> described on . this page http://dlang.org/dmd-linux.html . I
> checked all folders after every step and everything is where it
> should be. In the secound step I did both, adding dmd to the PATH
> and copied the executables into the lib folder. If I type dmd
> into the console, I get back all infos about D, so this is
> already working. But if I try to run a simple Hello world program
> like this:
>
> import std.stdio;
>
> void main() {
>writeln("Hallo Welt");
>}
>
> I get the following error:
> object.d: Error: module object is in file 'object.d' which cannot
> be read
> import path[0] = /usr/local/bin/../../src/phobos
> import path[1] = /usr/local/bin/../../src/druntime/import
>
>
> My DMD folder is in the home directory and the dmd.config
> contains this:
> [Environment]
>
> DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
> -L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
> -L--export-dynamic
>
> I already tried to compile the program with geany and the
> console. In the console i trid to compile it as: dmd hello.d and
> dmd -c hello.d. But everywhere I get the same errors
>
>

It appears that dmd can't find the library files.  IIRC object.d is part of
the runtime.  Check the paths in the error message and try to ensure
necessary files are found.


D under Linux Mint

2012-05-23 Thread snow

Hello, Ive tried to install D under Linux and followed the steps
described on . this page http://dlang.org/dmd-linux.html . I
checked all folders after every step and everything is where it
should be. In the secound step I did both, adding dmd to the PATH
and copied the executables into the lib folder. If I type dmd
into the console, I get back all infos about D, so this is
already working. But if I try to run a simple Hello world program
like this:

import std.stdio;

void main() {
writeln("Hallo Welt");
}

I get the following error:
object.d: Error: module object is in file 'object.d' which cannot
be read
import path[0] = /usr/local/bin/../../src/phobos
import path[1] = /usr/local/bin/../../src/druntime/import


My DMD folder is in the home directory and the dmd.config
contains this:
[Environment]

DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
-L-L%@P%/../lib64 -L-L%@P%/../lib32 -L--no-warn-search-mismatch
-L--export-dynamic

I already tried to compile the program with geany and the
console. In the console i trid to compile it as: dmd hello.d and
dmd -c hello.d. But everywhere I get the same errors




Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Paul


This works, though it's ugly:


foreach(line; uniS.splitLines()) {
   transcode(line, latinS);
   fout.writeln((cast(char[]) latinS));
}

The Latin1String type, at the storage level, is a ubyte[]. By 
casting to char[], you can get a similar-to-string thing that 
writeln() can handle.


Graham


Awesome!  What a lesson! Thannk you!

So if anyone is following this thread heres my code now.  This 
reads a text file(encoded in Latin1 which is basic ascii with 
extended ascii codes), allows D to work with it in unicode, and 
then spits it back out as Latin1.


I wonder about the speed between this method and Era's home-spun 
solution?


import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
auto fout = File("out.txt","w");
auto latinS = cast(Latin1String) read("in.txt");
string uniS;
transcode(latinS, uniS);
foreach(line; uniS.splitLines()){
   transcode(line, latinS);
   fout.writeln((cast(char[]) latinS));
}
}


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Paul


The safest way is probably to read it as binary data (i.e. 
byte[]), then
do the conversion into UTF8, then process it, and finally 
convert it

back to latin-1 (in binary form) and output it.

D assumes Unicode internally; if you try to read a Latin-1 file 
as
char[], you may be running into some implicit UTF conversions 
that are

corrupting the data. Best use byte[] for reading/writing, and do
conversions to/from UTF-8 internally for processing.


T


You mean something like Era has done in the first reply?

If that is so I have to say I'm really surprized.  To write D so 
it natively expects and outputs unicode is one thing but not 
making a clean simple way to read extended ASCII chars (i.e. 
Latin1) and write them back out seems like an oversight.


I think I'm (actually Graham) is close.
Thanks for your feedback HS.


Re: std.range.put?

2012-05-23 Thread Steven Schveighoffer

On Mon, 21 May 2012 07:26:32 -0400, simendsjo  wrote:


Shouldn't the following work?

import std.range;
import std.stdio;

void main() {
 int[] a;
 a.reserve(10);
 //a.put(1); // Attempting to fetch the front of an empty array of  
int

 a.length = 1;
 writeln(a.length); // 1
 a.put(2);
 writeln(a.length); // 0 - what?
 writeln(a); // [] - come on!

OK, here is why:

put(R, v) has three modus operandi:

1. R is an input range with an lvalue front().
2. R is a function/delegate that accepts a v
3. R implements the method put(v)

slices fit into category one.  In this case, guess what happens?

R.front = v;
R.popFront();

Why?  Think of R as a *buffer* that is *pre-allocated* and needs to be  
filled.  This is what put is trying to do.


What you want is std.array.Appender, which defines the method put, which  
*appends* data to the end instead of overwriting it.



 char[] b;
 //b.put('a'); // range.d(615): Error: static assert  "Cannot put a  
char into a char[]"

}


This is just phobos being its usual nasty self claiming that char[] is not  
an array of char, but actually a range of dchar.  If I only had a nickel  
every time someone ran into this "feature"... I'd probably have about $5  
by now ;)  It's one of the worst designs of Phobos.


-Steve


Re: unsynchronized access to primitive variables

2012-05-23 Thread Steven Schveighoffer

On Sat, 19 May 2012 04:16:39 -0400, luka8088  wrote:


Hello to all,

I would like to know if D guarantees that access to primitive variable  
is atomic ?


I was looking for any source of information that says anything about  
unsynchronized access to primitive variables. What I want to know is if  
it is possible (in any way and any OS / hardware) for the following code  
to output anything other then 1 or 2:


import std.stdio;
import core.thread;

void main () {
   int value = 1;
   (new Thread({ value = 2; })).start();
   writeln(value);
}

Thanks !


It depends on hardware architecture.  loads and stores of word sizes are  
generally atomic.  A better (more portable) version would be to make value  
size_t or ptrdiff_t, which should mimic CPU word size.


In very crude multithreading apps, I rely on this all the time.  But you  
have to be careful not to change the value in more than one thread, or you  
are subject to racing.


-Steve


Re: druntime investigation troubles

2012-05-23 Thread Steven Schveighoffer

On Wed, 23 May 2012 15:46:16 -0400, Jacob Carlborg  wrote:


On 2012-05-23 19:32, Denis Shelomovskij wrote:


What call have you found in "_d_criticalenter"?

By the way, `_STI_critical_init` is called before C main (uncomment
printf's and check), so it is definitely called not by druntime.



"_STI_critical_init" is called here:

*  
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical_.d#L149


*  
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical.c#L124


*  
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L364


Found another one:

*  
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L255


I assume, and hope, that only one of these are actually called. That's  
why I said all this is a big mess.


The last one is only called if the runtime is manually initialized, i.e.  
via C using the "rt_init" function. Which is stupid, "rt_init" should be  
called from the C main function as well. There's unnecessary code  
duplication here.




+1

dmain2 has that "magic runtime" feel where you look at it and are so  
confused that you are afraid to touch anything :P


-Steve


Re: druntime investigation troubles

2012-05-23 Thread Jacob Carlborg

On 2012-05-23 19:32, Denis Shelomovskij wrote:


What call have you found in "_d_criticalenter"?

By the way, `_STI_critical_init` is called before C main (uncomment
printf's and check), so it is definitely called not by druntime.



"_STI_critical_init" is called here:

* 
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical_.d#L149


* 
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical.c#L124


* 
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L364


Found another one:

* 
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L255


I assume, and hope, that only one of these are actually called. That's 
why I said all this is a big mess.


The last one is only called if the runtime is manually initialized, i.e. 
via C using the "rt_init" function. Which is stupid, "rt_init" should be 
called from the C main function as well. There's unnecessary code 
duplication here.


--
/Jacob Carlborg


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Graham Fawcett

On Wednesday, 23 May 2012 at 19:09:29 UTC, Paul wrote:

On Wednesday, 23 May 2012 at 19:01:53 UTC, Graham Fawcett wrote:

On Wednesday, 23 May 2012 at 18:43:04 UTC, Paul wrote:
On Wednesday, 23 May 2012 at 18:04:56 UTC, Graham Fawcett 
wrote:

On Wednesday, 23 May 2012 at 15:48:20 UTC, Paul wrote:
On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett 
wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes 
(e.g. degree symdol). Depending on how I read the file in 
and what I do with it the error shows up at different 
points.  I'm pretty sure it all boils down to the these 
extended ascii codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 
8859-1 file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
auto latin = cast(Latin1String) read("/tmp/hi.8859");
string s;
transcode(latin, s);
writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  
I does help me read and process text.  But when I go to 
print it out I have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
auto fout = File("out.txt","w");
auto latinS = cast(Latin1String) read("in.txt");
string uniS;
transcode(latinS, uniS);
foreach(line; uniS.splitLines()){
   transcode(line, latinS);
   fout.writeln(line);
   fout.writeln(latinS);
}
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, 
cast(immutable(Latin1Char))70]


If I print the Unicode string I get an extra weird 
character.
If I print the Unicode string retranslated to Latin1, it 
get weird pseudo-code.

Can you help?


I tried the program and it seemed to work for me.

What program are you using to read "out.txt"? Are you sure 
it supports UTF-8, and knows to open the file as UTF-8? 
(This looks suspiciously like a tool's attempt to 
misinterpret a UTF-8 string as Latin-1.)


If you're on a Unix system, what does "file in.txt out.txt" 
report?


Graham


Hmmm.  I'm not communicating well.
I want to read and write ASCII.  The only reason I'm 
converting to Unicode is because D needs it (as I understand).


Yes if I open °F in notepad++ and tell notepad++ that it 
is UTF-8, it shows °F.


I want to:
1) Read an ascii file that may have codes above 127.
2) Convert to unicode so D funcs like .splitLines() can work 
with it.
3) Convert back to ascii so that stuff like °F writes out as 
it was read in.


If I open in.txt and out.txt in an ascii editor, °F should 
look the same in both files with the editor encoding the 
files as ANSI/ASCII.  I thought my program was doing just 
that.

Thanks for your assistance.


To make sure we're on the same page -- ASCII is a 7-bit 
encoding, and any character above 127 is by definition not an 
ASCII character. At that point we're talking about an encoding 
other than ASCII, such as UTF-8 or Latin-1.


If you're reading a file that has bytes > 127, you really have 
no choice but to specify (assume?) an encoding, Latin-1 for 
example. There's no guarantee your input file is Latin-1, 
though, and garbage-in will result in garbage-out.


So I think what you're trying to do is

1. read a Latin-1 file, into unicode (internally in D)
2. do splitLines(), etc., generating some result
3. Convert the result back to latin-1, and output it.

Is that right?
Graham


Exactly.


This works, though it's ugly:


foreach(line; uniS.splitLines()) {
   transcode(line, latinS);
   fout.writeln((cast(char[]) latinS));
}

The Latin1String type, at the storage level, is a ubyte[]. By 
casting to char[], you can get a similar-to-string thing that 
writeln() can handle.


Graham



Re: Simplified socket creation and handling

2012-05-23 Thread Jarl André

On Wednesday, 23 May 2012 at 13:39:09 UTC, Jarl André wrote:

On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always 
need control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level 
control, try a ListeningConnectionManager. To see how it's 
used, look at the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop the 
server), but it is very nice in _easily_ starting up, with 
_zero_ config.


NMS


Thanks. It looks like a good option.

As it turns out I am very interested in having complete control 
of what type of service I am creating, so a library limiting me 
in some ways are not an option. On the other hand, I have 
investigated the listener example and have found out that I 
needed to generalize it a bit. Make a few interfaces, some 
implementations and my initial goal is to have end user code 
look excactly like QuickServers in Java. Why? Because sometimes 
you need simple command servers, lets say for polling an email 
or checking hardware status on a server and report it back, not 
worrying about blocking and async or whatever about sockets.


Another great advantage of making a "QuickServer" library is 
that its inner content can be replaced in the future without 
the end users knowing about. I have come far in the library 
making, but need some help understanding std.socket:


1.a. What is SocketSet and why do I need to pass it to 
Socket.select?
1.b. I only want to accept new sockets and I think its too much 
code for that


Even if questions is stupid please comment/correct me.


And here it comes:

https://github.com/jarlah/d2-simple-socket-server

This is my object oriented contribution to the problem.

Based on closed/open principe, in that expansion is done by 
adding new classes and not modifying the existing code.


Comments are appreciated.


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread H. S. Teoh
On Wed, May 23, 2012 at 09:09:27PM +0200, Paul wrote:
> On Wednesday, 23 May 2012 at 19:01:53 UTC, Graham Fawcett wrote:
[...]
> >So I think what you're trying to do is
> >
> >1. read a Latin-1 file, into unicode (internally in D)
> >2. do splitLines(), etc., generating some result
> >3. Convert the result back to latin-1, and output it.
> >
> >Is that right?
> >Graham
> 
> Exactly.

The safest way is probably to read it as binary data (i.e. byte[]), then
do the conversion into UTF8, then process it, and finally convert it
back to latin-1 (in binary form) and output it.

D assumes Unicode internally; if you try to read a Latin-1 file as
char[], you may be running into some implicit UTF conversions that are
corrupting the data. Best use byte[] for reading/writing, and do
conversions to/from UTF-8 internally for processing.


T

-- 
Doubt is a self-fulfilling prophecy.


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Paul

On Wednesday, 23 May 2012 at 19:01:53 UTC, Graham Fawcett wrote:

On Wednesday, 23 May 2012 at 18:43:04 UTC, Paul wrote:
On Wednesday, 23 May 2012 at 18:04:56 UTC, Graham Fawcett 
wrote:

On Wednesday, 23 May 2012 at 15:48:20 UTC, Paul wrote:

On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes 
(e.g. degree symdol). Depending on how I read the file in 
and what I do with it the error shows up at different 
points.  I'm pretty sure it all boils down to the these 
extended ascii codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 
8859-1 file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
auto latin = cast(Latin1String) read("/tmp/hi.8859");
string s;
transcode(latin, s);
writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  I 
does help me read and process text.  But when I go to print 
it out I have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
 auto fout = File("out.txt","w");
 auto latinS = cast(Latin1String) read("in.txt");
 string uniS;
 transcode(latinS, uniS);
 foreach(line; uniS.splitLines()){
transcode(line, latinS);
fout.writeln(line);
fout.writeln(latinS);
 }
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, 
cast(immutable(Latin1Char))70]


If I print the Unicode string I get an extra weird character.
If I print the Unicode string retranslated to Latin1, it get 
weird pseudo-code.

Can you help?


I tried the program and it seemed to work for me.

What program are you using to read "out.txt"? Are you sure it 
supports UTF-8, and knows to open the file as UTF-8? (This 
looks suspiciously like a tool's attempt to misinterpret a 
UTF-8 string as Latin-1.)


If you're on a Unix system, what does "file in.txt out.txt" 
report?


Graham


Hmmm.  I'm not communicating well.
I want to read and write ASCII.  The only reason I'm 
converting to Unicode is because D needs it (as I understand).


Yes if I open °F in notepad++ and tell notepad++ that it is 
UTF-8, it shows °F.


I want to:
1) Read an ascii file that may have codes above 127.
2) Convert to unicode so D funcs like .splitLines() can work 
with it.
3) Convert back to ascii so that stuff like °F writes out as 
it was read in.


If I open in.txt and out.txt in an ascii editor, °F should 
look the same in both files with the editor encoding the files 
as ANSI/ASCII.  I thought my program was doing just that.

Thanks for your assistance.


To make sure we're on the same page -- ASCII is a 7-bit 
encoding, and any character above 127 is by definition not an 
ASCII character. At that point we're talking about an encoding 
other than ASCII, such as UTF-8 or Latin-1.


If you're reading a file that has bytes > 127, you really have 
no choice but to specify (assume?) an encoding, Latin-1 for 
example. There's no guarantee your input file is Latin-1, 
though, and garbage-in will result in garbage-out.


So I think what you're trying to do is

1. read a Latin-1 file, into unicode (internally in D)
2. do splitLines(), etc., generating some result
3. Convert the result back to latin-1, and output it.

Is that right?
Graham


Exactly.


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Graham Fawcett

On Wednesday, 23 May 2012 at 18:43:04 UTC, Paul wrote:

On Wednesday, 23 May 2012 at 18:04:56 UTC, Graham Fawcett wrote:

On Wednesday, 23 May 2012 at 15:48:20 UTC, Paul wrote:

On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes 
(e.g. degree symdol). Depending on how I read the file in 
and what I do with it the error shows up at different 
points.  I'm pretty sure it all boils down to the these 
extended ascii codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 8859-1 
file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
 auto latin = cast(Latin1String) read("/tmp/hi.8859");
 string s;
 transcode(latin, s);
 writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  I 
does help me read and process text.  But when I go to print 
it out I have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
  auto fout = File("out.txt","w");
  auto latinS = cast(Latin1String) read("in.txt");
  string uniS;
  transcode(latinS, uniS);
  foreach(line; uniS.splitLines()){
 transcode(line, latinS);
 fout.writeln(line);
 fout.writeln(latinS);
  }
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, 
cast(immutable(Latin1Char))70]


If I print the Unicode string I get an extra weird character.
 If I print the Unicode string retranslated to Latin1, it get 
weird pseudo-code.

Can you help?


I tried the program and it seemed to work for me.

What program are you using to read "out.txt"? Are you sure it 
supports UTF-8, and knows to open the file as UTF-8? (This 
looks suspiciously like a tool's attempt to misinterpret a 
UTF-8 string as Latin-1.)


If you're on a Unix system, what does "file in.txt out.txt" 
report?


Graham


Hmmm.  I'm not communicating well.
I want to read and write ASCII.  The only reason I'm converting 
to Unicode is because D needs it (as I understand).


Yes if I open °F in notepad++ and tell notepad++ that it is 
UTF-8, it shows °F.


I want to:
1) Read an ascii file that may have codes above 127.
2) Convert to unicode so D funcs like .splitLines() can work 
with it.
3) Convert back to ascii so that stuff like °F writes out as 
it was read in.


If I open in.txt and out.txt in an ascii editor, °F should 
look the same in both files with the editor encoding the files 
as ANSI/ASCII.  I thought my program was doing just that.

Thanks for your assistance.


To make sure we're on the same page -- ASCII is a 7-bit encoding, 
and any character above 127 is by definition not an ASCII 
character. At that point we're talking about an encoding other 
than ASCII, such as UTF-8 or Latin-1.


If you're reading a file that has bytes > 127, you really have no 
choice but to specify (assume?) an encoding, Latin-1 for example. 
There's no guarantee your input file is Latin-1, though, and 
garbage-in will result in garbage-out.


So I think what you're trying to do is

1. read a Latin-1 file, into unicode (internally in D)
2. do splitLines(), etc., generating some result
3. Convert the result back to latin-1, and output it.

Is that right?
Graham




Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Paul

On Wednesday, 23 May 2012 at 18:04:56 UTC, Graham Fawcett wrote:

On Wednesday, 23 May 2012 at 15:48:20 UTC, Paul wrote:

On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes 
(e.g. degree symdol). Depending on how I read the file in 
and what I do with it the error shows up at different 
points.  I'm pretty sure it all boils down to the these 
extended ascii codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 8859-1 
file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
  auto latin = cast(Latin1String) read("/tmp/hi.8859");
  string s;
  transcode(latin, s);
  writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  I 
does help me read and process text.  But when I go to print it 
out I have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
   auto fout = File("out.txt","w");
   auto latinS = cast(Latin1String) read("in.txt");
   string uniS;
   transcode(latinS, uniS);
   foreach(line; uniS.splitLines()){
  transcode(line, latinS);
  fout.writeln(line);
  fout.writeln(latinS);
   }
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, cast(immutable(Latin1Char))70]

If I print the Unicode string I get an extra weird character.  
If I print the Unicode string retranslated to Latin1, it get 
weird pseudo-code.

Can you help?


I tried the program and it seemed to work for me.

What program are you using to read "out.txt"? Are you sure it 
supports UTF-8, and knows to open the file as UTF-8? (This 
looks suspiciously like a tool's attempt to misinterpret a 
UTF-8 string as Latin-1.)


If you're on a Unix system, what does "file in.txt out.txt" 
report?


Graham


Hmmm.  I'm not communicating well.
I want to read and write ASCII.  The only reason I'm converting 
to Unicode is because D needs it (as I understand).


Yes if I open °F in notepad++ and tell notepad++ that it is 
UTF-8, it shows °F.


I want to:
1) Read an ascii file that may have codes above 127.
2) Convert to unicode so D funcs like .splitLines() can work with 
it.
3) Convert back to ascii so that stuff like °F writes out as it 
was read in.


If I open in.txt and out.txt in an ascii editor, °F should look 
the same in both files with the editor encoding the files as 
ANSI/ASCII.  I thought my program was doing just that.

Thanks for your assistance.


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Graham Fawcett

On Wednesday, 23 May 2012 at 15:48:20 UTC, Paul wrote:

On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes (e.g. 
degree symdol). Depending on how I read the file in and what 
I do with it the error shows up at different points.  I'm 
pretty sure it all boils down to the these extended ascii 
codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 8859-1 
file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
   auto latin = cast(Latin1String) read("/tmp/hi.8859");
   string s;
   transcode(latin, s);
   writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  I 
does help me read and process text.  But when I go to print it 
out I have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
auto fout = File("out.txt","w");
auto latinS = cast(Latin1String) read("in.txt");
string uniS;
transcode(latinS, uniS);
foreach(line; uniS.splitLines()){
   transcode(line, latinS);
   fout.writeln(line);
   fout.writeln(latinS);
}
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, cast(immutable(Latin1Char))70]

If I print the Unicode string I get an extra weird character.  
If I print the Unicode string retranslated to Latin1, it get 
weird pseudo-code.

Can you help?


I tried the program and it seemed to work for me.

What program are you using to read "out.txt"? Are you sure it 
supports UTF-8, and knows to open the file as UTF-8? (This looks 
suspiciously like a tool's attempt to misinterpret a UTF-8 string 
as Latin-1.)


If you're on a Unix system, what does "file in.txt out.txt" 
report?


Graham



OPTLINK : Error 63: DOSNEWSIZE Error ?

2012-05-23 Thread ParticlePeter

Hi,

I'm getting the error mentioned in the subject. I can't find no 
reference neither to DOSNEWSIZE nor to Error 63 on the Optilink 
pages or google.

Where can I find information about this error ?
Is there a list which maps Optilink Error Numbers to Error Names ?

Cheers, ParticlePeter !


Re: druntime investigation troubles

2012-05-23 Thread Denis Shelomovskij

23.05.2012 10:21, Jacob Carlborg написал:

On 2012-05-22 23:01, Steven Schveighoffer wrote:


It looks like code that is not called on Windows. Which doesn't make
sense. It would seem that you must initialize a critical section in
order to use it.

I can't find any reference to STI_monitor in dmd, dmc, or druntime
source code, except those calls that are done for Posix only. This isn't
some closed-source mystery, I think it is just unused code.

Sean, does this make sense? Are we using uninitialized critical sections?

-Steve


I found a call now, it's in "_d_criticalenter", both in critical.c and
critical_.d.


What call have you found in "_d_criticalenter"?

By the way, `_STI_critical_init` is called before C main (uncomment 
printf's and check), so it is definitely called not by druntime.


--
Денис В. Шеломовский
Denis V. Shelomovskij


Re: Reading ASCII file with some codes above 127 (exten ascii)

2012-05-23 Thread Paul

On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:

On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
I am reading a file that has a few extended ASCII codes (e.g. 
degree symdol). Depending on how I read the file in and what I 
do with it the error shows up at different points.  I'm pretty 
sure it all boils down to the these extended ascii codes.


Can I just tell dmd that I'm reading a Latin1 or ISO 8859-1 
file?
I've messed with the std.encoding module but really can't 
figure out what I need to do.


There must be a simple solution to this.


This seems to work:


import std.stdio, std.file, std.encoding;

void main()
{
auto latin = cast(Latin1String) read("/tmp/hi.8859");
string s;
transcode(latin, s);
writeln(s);
}


Graham


I thought I was in good shape with your above suggestion.  I does 
help me read and process text.  But when I go to print it out I 
have problems.


Here is my input file:
°F

Here is my code:
import std.stdio;
import std.string;
import std.file;
import std.encoding;

// Main function
void main(){
auto fout = File("out.txt","w");
auto latinS = cast(Latin1String) read("in.txt");
string uniS;
transcode(latinS, uniS);
foreach(line; uniS.splitLines()){
   transcode(line, latinS);
   fout.writeln(line);
   fout.writeln(latinS);
}
}

Here is the output:
°F
[cast(immutable(Latin1Char))176, cast(immutable(Latin1Char))70]

If I print the Unicode string I get an extra weird character.  If 
I print the Unicode string retranslated to Latin1, it get weird 
pseudo-code.

Can you help?


Re: Sorry for posting this here. Not sure where else.

2012-05-23 Thread Roman D. Boiko

On Wednesday, 23 May 2012 at 15:29:40 UTC, Steven Schveighoffer
wrote:
You need to send an email to brad at dsource.org.  The guy who 
does this is (or was) Brad Anderson.


Depending on where you are planning to post, you may be in for 
more disappointment, many projects on dsource.org are abandoned.


-Steve


Try to login with your email/pwd. I succeeded even though didn't
get any emails.


Re: Sorry for posting this here. Not sure where else.

2012-05-23 Thread Steven Schveighoffer
On Wed, 23 May 2012 10:38:00 -0400, WhatMeWorry   
wrote:


I apologize in advance if I'm doing something stupid here. But shat's up  
with dsource.org forums?  I created a user account on 5/19/12 and got an  
email:


Welcome to  Forums

Please keep this email for your records. Your account information is as  
follows:



Username: myusername
Password: mypassword


Your account is currently inactive, the administrator of the board will  
need to activate it before you can log in. You will receive another  
email when this has occured.


Please do not forget your password as it has been encrypted in our  
database and we cannot retrieve it for you. However, should you forget  
your password you can request a new one which will be activated in the  
same way as this account.


Thank you for registering.

--
Thanks, The Management


It has been 5 days and still no replay.  Catch-22. Can't post this on  
the dsource.org site.


You need to send an email to brad at dsource.org.  The guy who does this  
is (or was) Brad Anderson.


Depending on where you are planning to post, you may be in for more  
disappointment, many projects on dsource.org are abandoned.


-Steve


Re: druntime investigation troubles

2012-05-23 Thread Jacob Carlborg

On 2012-05-23 13:31, Steven Schveighoffer wrote:

On Wed, 23 May 2012 02:21:14 -0400, Jacob Carlborg  wrote:


On 2012-05-22 23:01, Steven Schveighoffer wrote:


It looks like code that is not called on Windows. Which doesn't make
sense. It would seem that you must initialize a critical section in
order to use it.

I can't find any reference to STI_monitor in dmd, dmc, or druntime
source code, except those calls that are done for Posix only. This isn't
some closed-source mystery, I think it is just unused code.

Sean, does this make sense? Are we using uninitialized critical
sections?

-Steve


I found a call now, it's in "_d_criticalenter", both in critical.c and
critical_.d.



OK, so does this mean monitor is only used on Posix, and critical is
used only on windows? This seems a little weird. Especially since we are
still compiling monitor.c.

-Steve


No, there's a "_d_criticalenter" for Posix in critical(_).d/c which 
calls "_STI_critical_init". It seems there's a duplicate call for 
"_STI_critical_init" on Posix, in dmain2.d and in critical(_).d/c.


Also this actually looks like a big mess:

* critical_.d and critical.c contains the same code. critical_.d is used 
in the posix makefile. critical.c _and_ critical_.d is used in the win32 
makefile


* "_STI_critical_init" is implemented on both Posix and Windows, but 
it's only called on Posix


* "_STI_critical_init" is called on multiple places on Posix. In 
dmain2.d and in "_d_criticalenter".


--
/Jacob Carlborg


Sorry for posting this here. Not sure where else.

2012-05-23 Thread WhatMeWorry
I apologize in advance if I'm doing something stupid here. But 
shat's up with dsource.org forums?  I created a user account on 
5/19/12 and got an email:


Welcome to  Forums

Please keep this email for your records. Your account information 
is as follows:



Username: myusername
Password: mypassword


Your account is currently inactive, the administrator of the 
board will need to activate it before you can log in. You will 
receive another email when this has occured.


Please do not forget your password as it has been encrypted in 
our database and we cannot retrieve it for you. However, should 
you forget your password you can request a new one which will be 
activated in the same way as this account.


Thank you for registering.

--
Thanks, The Management


It has been 5 days and still no replay.  Catch-22. Can't post 
this on the dsource.org site.




Re: Simplified socket creation and handling

2012-05-23 Thread Jarl André

On Saturday, 19 May 2012 at 20:33:49 UTC, Nathan M. Swan wrote:

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a 
handler interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level control, 
try a ListeningConnectionManager. To see how it's used, look at 
the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop the 
server), but it is very nice in _easily_ starting up, with 
_zero_ config.


NMS


Thanks. It looks like a good option.

As it turns out I am very interested in having complete control 
of what type of service I am creating, so a library limiting me 
in some ways are not an option. On the other hand, I have 
investigated the listener example and have found out that I 
needed to generalize it a bit. Make a few interfaces, some 
implementations and my initial goal is to have end user code look 
excactly like QuickServers in Java. Why? Because sometimes you 
need simple command servers, lets say for polling an email or 
checking hardware status on a server and report it back, not 
worrying about blocking and async or whatever about sockets.


Another great advantage of making a "QuickServer" library is that 
its inner content can be replaced in the future without the end 
users knowing about. I have come far in the library making, but 
need some help understanding std.socket:


1.a. What is SocketSet and why do I need to pass it to 
Socket.select?
1.b. I only want to accept new sockets and I think its too much 
code for that


Even if questions is stupid please comment/correct me.


Re: druntime investigation troubles

2012-05-23 Thread Steven Schveighoffer

On Wed, 23 May 2012 02:21:14 -0400, Jacob Carlborg  wrote:


On 2012-05-22 23:01, Steven Schveighoffer wrote:


It looks like code that is not called on Windows. Which doesn't make
sense. It would seem that you must initialize a critical section in
order to use it.

I can't find any reference to STI_monitor in dmd, dmc, or druntime
source code, except those calls that are done for Posix only. This isn't
some closed-source mystery, I think it is just unused code.

Sean, does this make sense? Are we using uninitialized critical  
sections?


-Steve


I found a call now, it's in "_d_criticalenter", both in critical.c and  
critical_.d.




OK, so does this mean monitor is only used on Posix, and critical is used  
only on windows?  This seems a little weird.  Especially since we are  
still compiling monitor.c.


-Steve


Re: pure functions calling impure functions at compile-time

2012-05-23 Thread bearophile

Simen Kjaeraas:

Should this be filed as a bug, or is the plan that only pure 
functions be

ctfe-able? (or has someone already filed it, perhaps)


It's already in Bugzilla, see issue 7994 and 6169.

But I think there is a semantic hole in some of the discussions 
about this problem. Is a future compile-time JIT allowed to 
perform purity-derived optimizations in CTFE?


Bye,
bearophile