Re: goto skips declaration of variable

2014-08-18 Thread ollie via Digitalmars-d-learn
On Mon, 18 Aug 2014 13:51:12 +, nrgyzer wrote:

 When I try to compile this sample application I'm getting the 
 following error:
 
 sample.d(7): Error: goto skips declaration of variable 
 sample.main.__ctmp1344 at sample.d(9)
 

http://dlang.org/changelog.html#disable_goto_skips_init

First item in D2.065 Changelog for language changes :
  1. Goto jumps now cannot skip variable declarations


Help with array maniipulation

2014-02-04 Thread ollie
I have a C Struct:

   typedef struct
   {
   enum LibRaw_image_formats type; 
   ushort  height,
   width,
   colors,
   bits;
   unsigned int  data_size; 
   unsigned char data[1]; 
   }libraw_processed_image_t;

with a D version:

   struct libraw_processed_image_t
   {
   LibRaw_image_formatstype; 
   ushort  height,
   width,
   colors,
   bits;
   uintdata_size; 
   ubyte[1]data; 
   }

libraw_dcraw_make_mem_thumb() returns a pointer to this struct.
I need to create a char[] from the data and data_size members,
ideally without copying, to send to GdkPixbufLoader.write(char[]).

If I do this:
   libraw_processed_image_t *img;
   img = libraw_dcraw_make_mem_thumb();
   char[] buf = cast(char[]) img.data[];
   GdkPixbufLoader.write(buf); // Runtime error

buf.ptr == img.data.ptr and length of both arrays is 1.
If I try:
   buf.length = img.data_size;
buf is reallocated.

Any suggestions to make buf.ptr == img.data.ptr and
buf.length = img.data_size?

Thanks
ollie


Re: Help with array maniipulation

2014-02-04 Thread ollie
On Tue, 04 Feb 2014 11:16:00 -0800, Ali Çehreli wrote:


 Is that the C extension where the last array in a struct can have more 
 elements than its size? That will be a problem in D.

yes it is.

  int[] D_slice = C_array[0 .. C_array_number_of_elements];

Thank you, that gives me what I was looking for. I thought I had tried
something like that. Too many moving parts with threads and context
changes to call GDK/GTK functions make things very precarious. I am
still getting an access violation, but your help has moved me a step
nearer a solution.

Thanks,
ollie


Re: Server is not active?

2013-09-29 Thread ollie
On Sun, 29 Sep 2013 03:47:27 +0200, wagtail wrote:

 When my server and client are on the same machine,these succeed.
 If I try communicating with other machine via global network,it do not
 work.
 IP of my server which you say above should set to server side?

When you instantiate your InternetAddress class, set it to the assigned
IP of your server machine.

It's starting to look like more of a network configuration problem and
not a D.learn problem. I'd rather not pollute this forum with those
type of issues. Good luck.


Re: Server is not active?

2013-09-28 Thread ollie
On Sat, 28 Sep 2013 08:42:16 +0200, wagtail wrote:

 I tried rewriting code with using ADDR_ANY, but do not work...

Ali Çehreli posted some examples in the D.learn group earlier.
He creates the socket then uses its member functions to setup
the connection, but it should work either way.

Try something like this:

auto inet = new InternetAddress(port);

The constructor for class InternetAddress will set addr to ADDR_ANY.
This should work if your server and client are on the same machine.
Otherwise you need to set the address to the IP of your server.

Would need some basic compilable code to know for sure how to make
that work in your situation.


Re: Server is not active?

2013-09-27 Thread ollie
On Fri, 27 Sep 2013 03:22:32 +0200, wagtail wrote:

 A part of code shown below.
 
 /++ Server main()
 /
  ushort port = 9876;
 
   auto inet = new InternetAddress(0.0.0.0,port);
   Socket server = new TcpSocket(inet.addressFamily());
 
   bool flag = true;
 
   server.bind(inet);
   server.listen(255);

Is there any particular reason to use 0.0.0.0 creating your 
InternetAddress?  I think it should be the ip of your server
or just send port and ADDR_ANY will be used.

From Wikipedia:

In the Internet Protocol version 4 the address 0.0.0.0 is a non-routable 
meta-address used to designate an invalid, unknown or non applicable 
target.


Re: How/why can toStringz() and toUTFz() be used as properties?

2013-04-26 Thread ollie
On Fri, 26 Apr 2013 09:31:54 +0200, Trey Brisbane wrote:

 I need to understand this, as I wish to write a function toWinStr() that
 can be used in the same way which will accept any string type, and,
 based on something like version(Unicode) and const-ness, output a WinAPI
 LPSTR, LPCSTR, LPWSTR or LPCWSTR as appropriate.
 Is such a thing possible?

You might want to look at std.windows.charset. You'll find the following 
functions:

const(char)* toMBSz(in char[] s, uint codePage = 0)
string fromMBSz(immutable(char)* s, int codePage = 0)

These might work for you or you may be able to expand on them.


Re: std.net.curl is not working?

2013-04-26 Thread ollie
On Fri, 26 Apr 2013 19:25:16 +0200, mab wrote:

 undefined reference to `curl_global_init'
 undefined reference to `curl_global_cleanup'

These functions are defined in libcurl. Make sure you have installed 
libcurl if it wasn't installed as a dependency for curl.


Re: GtkD DLL issues

2013-04-23 Thread ollie
 Then it's indeed picing up the copy of zlib1.dll installed with the
 Intel WiFi tools instead of the one installed with Gtk+.
 
 But i don't know what could be done about that.

Try opening a command prompt (cmd.exe) and setting the path of the gtk 
runtime before the Intel Wifi tools.

set PATH=C:\Path\To\GtkRuntime\bin;%PATH%

This will use the gtk runtime zlib1.dll first.  If that works and doesn't 
mess up your intel wifi program, you can make that a global path setting.


Question about wchar[]

2013-02-04 Thread ollie
I am using wchar[] and find the usage clunky. Am I doing something wrong?

Example:
// Compiler complains that wchar[] != immutable(char)[]
wchar[] wstr = This is a wchar[];

// Compiler accepts this
wchar[] wstr = This is a wchar[]w.dup;

// Compiler accepts this
wchar[] wstr;
wstr ~= This is a wchar[];

If the compiler knows the type in the last example with concatenation, 
shouldn't it be able to figure that out in the first example.

I am using windows and DMD HEAD.

Thanks,
ollie


Re: Question about wchar[]

2013-02-04 Thread ollie
On Mon, 04 Feb 2013 13:28:43 -0500, Steven Schveighoffer wrote:

 On Mon, 04 Feb 2013 13:13:22 -0500, ollie ol...@home.net wrote:
 
 wchar[] wstr = This is a wchar[];
 
 It's not so much the wchar vs. char, but the mutable vs. immutable. It
 could be argued that the message should say wchar[] != wstring
 instead.

I am aware of the immutable/mutable issue.  My intention was a mutable 
string.

 Right, because you are duplicating the string onto the heap, and making
 it mutable.

I thought druntime always created dynamic arrays on the heap and returned 
a slice.

 // Compiler accepts this wchar[] wstr;
 wstr ~= This is a wchar[];

 No, because the first example does not involve heap allocation, just
 straight assignment.
 
 Appending involves concatenation, and making a copy of the original, so
 it is safe to do so.

What is the storage (heap/stack) of straight assignment if this were a 
local variable.  Or do you mean that This is a wchar[] was already 
created on the heap as an immutable(wchar)[] then assigned to wstr.

Thanks for your replies Steven and Ali,

ollie


Re: Question about wchar[]

2013-02-04 Thread ollie
On Mon, 04 Feb 2013 15:09:06 -0500, Steven Schveighoffer wrote:

 On Mon, 04 Feb 2013 14:45:02 -0500, ollie ol...@home.net wrote:
 
 What is the storage (heap/stack) of straight assignment if this were
 a local variable.  Or do you mean that This is a wchar[] was already
 created on the heap as an immutable(wchar)[] then assigned to wstr.
 
 The string is actually stored in code, not on the heap.  When you
 assign, you get a pointer right into code (ROM).
 

I seem to remember that now (had a brain fart).

Thank you Jonathan and Steven for your help.

ollie


Re: dynamic arrays of immutable question: Are the elements actually mutable

2013-01-09 Thread ollie
On Wed, 09 Jan 2013 14:38:13 +0100, monarch_dodra wrote:

 On Wednesday, 9 January 2013 at 12:38:13 UTC, Jonathan M Davis wrote:

 When you append to array, the elements being added are in untyped
 memory. So,
 no mutation of immutable anything is going on at all.
 
 Ok, I guess that makes sense.
 

Newbie answer and question to follow.

The area of memory after .length to .capacity is not defined (untyped) in 
the D spec.  It is a trick used by the compiler to not slow down appends 
with repetitive memory allocations.  I believe that since the memory has 
been allocated for an array of a certain type, the extra capacity memory 
should be of that type until the array and its slices have been 
deallocated by druntime.

My question is about immutable and casting in general.  I've heard Walter 
say of immutable, Turtles all the way down..  If say I have a plug-in  
system with a defined interface and I pass it an immutable array (ie 
immutable(int)[]) then it uses a cast to mutate, that seems to defeat the 
purpose of immutable.  When the plug-in returns, I now have an immutable 
array that has been mutated.  Is this how immutable and casting are 
supposed to work?  


Re: error with reading file name

2012-12-06 Thread ollie
On Thu, 06 Dec 2012 16:52:20 +0100, Suliman wrote:

 I am trying to create simple app that would read user input and open
 file with such name, but every time when I run it's crash with error
 
 std.file.FileException@std\file.d(294): \1.txt
 

After a call to readln, the string returned has termination characters 
that need to be stripped off.

import std.stdio;
import std.file;

void main()
{
string name = readln();

while(name[$-1] == '\x0a' || name[$-1] == '\x0d')
name.length -= 1;

if(name.exists)
writeln(name,  exists!);
else
{
writeln(name,  doesn't exists!);
return;
}

auto filearray = cast(char[]) read(name);
writeln(\n, filearray);
}