How to realize isSortedRange?

2014-08-20 Thread Alexandr Druzhinin via Digitalmars-d-learn
I need to ensure that range passed to function is SortedRange to use 
binary search. I did something like:


static if(!__traits(compiles,
{
ElementType!(typeof(data)) element;
auto d = data.trisect(element);
}
)) assert(0, DataRange shall be SortedRange);

It works for me, but in fact it checks if the type of 'data' have 
'trisect' method and conception of SortedRange is something more than 
having 'trisect' method.
	I remember there is(?) some way to get general type of template (i.e. 
SortedRange instead of SortedRange!int), but can not find it.


Re: How to realize isSortedRange?

2014-08-20 Thread Alexandr Druzhinin via Digitalmars-d-learn

Thank you!


extern (C++, N) is it implemented?

2014-08-06 Thread Alexandr Druzhinin via Digitalmars-d-learn

This dlang.org/cpp_interface.html says I can do the following

// c++
namespace N {
void someCppFunction();
}

// d
extern (C++, N) void someCppFunction();

but this http://dpaste.dzfl.pl/e2242263e1dc says I can't

Is this feature implemented?


Re: extern (C++, N) is it implemented?

2014-08-06 Thread Alexandr Druzhinin via Digitalmars-d-learn

06.08.2014 10:54, Dicebot пишет:

On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote:

This dlang.org/cpp_interface.html says I can do the following

// c++
namespace N {
void someCppFunction();
}

// d
extern (C++, N) void someCppFunction();

but this http://dpaste.dzfl.pl/e2242263e1dc says I can't

Is this feature implemented?


Should be in upcoming release.


Ok. Hope it will )


[std.c.stdlib] (malloc(something) is null) or (malloc(something) == 0)?

2014-05-20 Thread Alexandr Druzhinin via Digitalmars-d-learn

In D code I do
void* data = GC.malloc(...);
if(data is null)
...

In C code I do
void* data = malloc(...);
if(data == null)
...

What to do when in D code I have
void* data = std.c.stdlib.malloc(...);
if(data ?) // is null vs == 0


Re: opCmp and unittest as a nested function

2014-04-09 Thread Alexandr Druzhinin

09.04.2014 13:45, bearophile пишет:

Alexandr Druzhinin:


http://dpaste.dzfl.pl/f7364d416cb2
Error appeared when I defined opCmp and now I can't understand what's
the reason of the error. Why does tween need access to unittest?


Try to use static struct instead of a struct.

Bye,
bearophile

Thank you! It works. But where can I read about this issue?


Re: opCmp and unittest as a nested function

2014-04-09 Thread Alexandr Druzhinin

09.04.2014 13:55, bearophile пишет:

And you need to use opEquals:

unittest {
 static struct Point2D {
 double x, y;

 bool opEquals(const Point2D rhs) const {
 return false;
 }
 }

 auto p2d0 = Point2D(0, 0);
 auto p2d1 = Point2D(1, 0);

 assert(tween(p2d0, p2d1, 1 / 3.0) == Point2D(1 / 3.0, 0));
}


opEquals/onHash/opCmp are minefields. I don't know why the D compiler
doesn't add a large amount of errors and warnings to turns this
minefield in something a bit safer.

It would be very nice.


Also use std.math.feqrel to compare floating point values.

Thanks!


Bye,
bearophile




Re: opCmp and unittest as a nested function

2014-04-09 Thread Alexandr Druzhinin

09.04.2014 14:13, bearophile пишет:

Reading about this issue is not good. What you can read about is how
unittests are implemented in D (as functions) and what's the difference
between static structs and nonstatic ones when they are defined inside a
function.

Bye,
bearophile
I guess I should read how tepmlates work. Tween needs access to 
unittest.Point2D to be instanciated but Point2D is local?


Re: opCmp and unittest as a nested function

2014-04-09 Thread Alexandr Druzhinin

09.04.2014 15:19, bearophile пишет:

Alexandr Druzhinin:


I guess I should read how tepmlates work.


No templates are involved in this code.

Bye,
bearophile
I mean that nested struct Point2D has additional pointer to frame and 
when compiler tries to instantiate template function 'tweet' it can't do 
it because in general it doesn't know about this additinal pointer to 
frame? And making it static I make it a general structure without 
additions and in this case compiler manages to instantiate 'tweet'?


Re: GtkD - how to install

2013-12-23 Thread Alexandr Druzhinin

Show your package.json file and the project structure.


Re: Dub and what it does

2013-12-23 Thread Alexandr Druzhinin

23.12.2013 15:04, Russel Winder пишет:

For my (very) early stage GtkD program, my SCons script (using all
source at once) generates a 6MB executable that works. Dub appears to
think that it is creating a .a archive and create 142MB of it. So how to
create an executable with Dub?

I statically build GtkD application using dub and it gives me binary 
about 14 Mb in debug mode and stripped binary is about 8 or 6 Mb. But I 
built GtkD separately and link against it using the following package.json:


{
name: renderer,
targetType: library,
versions: [
Derelict3,
gl3n,
],
libs: [
gtkd-2,
gtkdgl-2,
dl,
DerelictGL3,
DerelictUtil,
DerelictFI,
gl3n,
glamour,
curl,
],
importPaths: [
~/.dub/packages/gtk-d-master/src,
~/.dub/packages/gtk-d-master/srcgl,
~/.dub/packages/derelict-gl3-master/source,
~/.dub/packages/derelict-fi-master/source,
~/.dub/packages/derelict-util-1.0.0/source,
~/.dub/packages/gl3n-master/,
~/.dub/packages/glamour/,
],
configurations: [
{
name: test,
targetType: executable,
sourcePaths: [test],
}
]
}

So it's a hack, but it works for me - I have fast compilation at least.
I did the following - fetched packages I need, built every package using 
dub and copied libs to /usr/local/lib - probably it's better to use path 
to libs instead of copying.


Re: GtkD - how to install

2013-12-23 Thread Alexandr Druzhinin

23.12.2013 19:19, DLang Beginner пишет:

On Monday, 23 December 2013 at 10:08:09 UTC, Alexandr Druzhinin wrote:

Show your package.json file and the project structure.


https://www.dropbox.com/s/l3wwm84w85h5su2/dlang-gtk1.png
https://www.dropbox.com/s/9vs4r9l3lvdw2y1/dlang-gtk2.png

You shouldn't create your app inside gtkd structure. Try the following:
cd
mkdir test
cd test
dub init
copy ~/Desktop/gtkd/source/app.d ./source/
copy ~/Desktop/gtkd/package.json .
dub

and show what will happen


Re: GtkD - how to install

2013-12-23 Thread Alexandr Druzhinin

23.12.2013 22:52, DLang Beginner пишет:

On Monday, 23 December 2013 at 13:50:29 UTC, Alexandr Druzhinin wrote:

You shouldn't create your app inside gtkd structure. Try the following:
cd
mkdir test
cd test
dub init
copy ~/Desktop/gtkd/source/app.d ./source/
copy ~/Desktop/gtkd/package.json .
dub

and show what will happen


Yeah, that worked! Application successfully compiled. But when I try
start it, I'm getting another error because I don't have libgdkglext-3.0
library.

object.Exception@../../.dub/packages/gtk-d-master/src/gtkc/Loader.d(127): 
Library
load failed: libgdkglext-3.0.so.0
Either build this libraries like me or try to change dependency in 
package.json:

gtk-d: ~master = gtk-d:gtkd: ~master
You get error because your app try to use opengl extention for gtk, but 
this extension isn't provided by default for gtk3. I solved this problem 
for me, but I spent much time and frankly can't remember my steps. But 
if you don't need opengl you can use only subpackage of gtkd as I write 
above.


Re: GtkD - how to install

2013-12-23 Thread Alexandr Druzhinin

23.12.2013 23:50, DLang Beginner пишет:

On Monday, 23 December 2013 at 16:20:24 UTC, Alexandr Druzhinin wrote:

23.12.2013 22:52, DLang Beginner пишет:
Either build this libraries like me or try to change dependency in
package.json:
gtk-d: ~master = gtk-d:gtkd: ~master
You get error because your app try to use opengl extention for gtk,
but this extension isn't provided by default for gtk3. I solved this
problem for me, but I spent much time and frankly can't remember my
steps. But if you don't need opengl you can use only subpackage of
gtkd as I write above.


OH YES! No, I don't need OpenGL, so I changed dependency and it works
fine! Thank you so much!

I 3 D and it's community. :)

You're welcome!


Re: const char* or const(char)* when porting C headers?

2013-12-22 Thread Alexandr Druzhinin

22.12.2013 11:06, Alexandr Druzhinin пишет:

22.12.2013 07:47, Gary Willoughby пишет:

When porting C headers which include function declarations with using
char* types. Is it best to use const char* or const(char)* as the type
in the D declaration?

C vs D
const char* == const(char)*
const char const* == const char*

Yes, the last line should be
const char * const == const char*
thanks to Benjamin

IIRC in D qualificator is applied to the right part of statement if 
there is no the parantheses and to part inside the parantheses if they 
exists. Important thing is that in D qualificators are transitive. It 
makes type system more robust (from POV immutability), but doesn't 
complete it, sadly.


Re: const char* or const(char)* when porting C headers?

2013-12-21 Thread Alexandr Druzhinin

22.12.2013 07:47, Gary Willoughby пишет:

When porting C headers which include function declarations with using
char* types. Is it best to use const char* or const(char)* as the type
in the D declaration?

C vs D
const char* == const(char)*
const char const* == const char*


selective import

2013-12-05 Thread Alexandr Druzhinin

Hi all.
How to use use selective imports more effectively? I have two modules 
foo and bar:


module foo;

class Foo {}

module bar;

import foo: Foo;

class Bar
{
private Foo foo_;
this(Foo foo)
{
foo_ = foo;
}
}

Now I add module baz that use both modules above. How to import foo and 
bar - everything or only 'the topmost' one, bar?


module baz;

import bar: Bar;
import foo: Foo;

or

import bar: Bar, Foo; // also in bar import of foo.Foo should be public 
of course


I don't see difference, but it doesn't mean it doesn't exist. What do 
you think about it?


Re: selective import

2013-12-05 Thread Alexandr Druzhinin

05.12.2013 20:34, Dicebot пишет:

On Thursday, 5 December 2013 at 11:17:18 UTC, Alexandr Druzhinin wrote:

I don't see difference, but it doesn't mean it doesn't exist. What do
you think about it?


It depends on how bar uses foo. You should do public import of symbols
from foo if they are required to interact with bar public API. If foo is
only used as part of internal implementation, it should be kept private
and both modules imported explicitly.
Third module uses both Bar and Foo. So I should either import every 
module individually, or import Bar only but Bar should publicly import 
Foo - that's the question.


Re: selective import

2013-12-05 Thread Alexandr Druzhinin

05.12.2013 20:43, Dicebot пишет:


It does not matter what third module uses, it is purely about relation
between foo and bar. If foo symbols are not necessary part of public bar
API, third module will import both. If they are, bar will import foo
publicly. Pretty simple.


I realized.


Re: shared phobos 2.064, ubuntu 12.04

2013-11-29 Thread Alexandr Druzhinin

29.11.2013 21:58, Jordi Sayol пишет:

El 29/11/13 07:55, Alexandr Druzhinin ha escrit:

I recompile old project with dmd 2.064 and get the runtime error:
Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.64':
 The module 'std.path' is already defined in 'bin64/workstation-x86-sdl_64'.
How can I avoid this `collision`?



This is a known issue: https://d.puremagic.com/issues/show_bug.cgi?id=11543

The only workaround I know is to link against static phobos library.

Thank for info. But linking with static version causes libcurl linking 
troubles... :(


shared phobos 2.064, ubuntu 12.04

2013-11-28 Thread Alexandr Druzhinin

I recompile old project with dmd 2.064 and get the runtime error:
Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.64':
The module 'std.path' is already defined in 
'bin64/workstation-x86-sdl_64'.
How can I avoid this `collision`?


Re: genetically modified slices - is it possible?

2013-11-16 Thread Alexandr Druzhinin

16.11.2013 18:38, Jonathan M Davis пишет:


Well, if you want to get a slice which refers to the same thing as that slice
but includes elements which are in what is being sliced but which aren't in
that slice, you can only get the slice that you want be reslicing whatever the
slices came from. So, that means that you have to have a range which refers to
all of the elements that you want your target range to refer to and possibly
more and then either slice that range to exactly the elements that you want or
pop off elements until you get the range that you want. Doing that generally
requires knowing how many elements to pop off or the indices to slice, which
basically means that you have to keep track of indices.

In general, it doesn't work very well to increase a range so that it covers
more elements. They're designed to be reduced, not increased, and so the more
D way of doing things with ranges essentially goes against what you're
trying to do, forcing you to come at the problem from a different angle. And in
this case, it sounds like that probably means keeping track of indices.

- Jonathan M Davis

Thanks for reply. It shows that there are different tools for different 
jobs and I should use appropriate tool for specific job.


genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin
I'd like to get slice that's consist of begining one other slice and end 
of yet another slice (all slices belong to the same array of course). Is 
it possible? With iterators it's simple, but I can't manage do it with 
slices.

http://dpaste.dzfl.pl/443cd4a1


Re: genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin

15.11.2013 22:09, Adam D. Ruppe пишет:

You could make it work like this:

auto slice3 = array[
 slice1.length + (slice1.ptr - array.ptr)
 ..
 (slice2.ptr - array.ptr)];


Since the slices all start into array somewhere, subtracting the
pointers gives their start index.

Thank you very much! I forget about .ptr.
What about ranges in general? They haven't .ptr.


Re: genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin

15.11.2013 22:13, bearophile пишет:

Alexandr Druzhinin:

A simple solution is to keep two indexes, and use them to find the
slices when you need them.
I did it the first. But then I decided to make it more D-ish and 
stumbled upon the issue. Wasn't it wrong decision and would be better to 
stay with indices?


Object construction and this

2013-11-10 Thread Alexandr Druzhinin

Could somebody explain why this http://dpaste.dzfl.pl/248262b9 return this:
Foo:
7FBFD59A50
7FBFD59A80
Bar:
7FBFD59A58
7FBFD59A88
Why this value in ctor is different from this value out of ctor if ctor 
gets an argument?


Re: Object construction and this

2013-11-10 Thread Alexandr Druzhinin

10.11.2013 23:22, Benjamin Thaut пишет:

Am 10.11.2013 17:06, schrieb Alexandr Druzhinin:

Because in D Classes are reference types. That means the code you wrote
is equivalent to the following C++ source:

class Foo
{
public:
   Foo(Object* o)
   {
 printf(%x\n, this); // print a Foo**
   }
}

class Bar
{
public:
   Bar()
   {
 printf(%x\n, this); // print a Bar**
   }
}

void main()
{
   Object* o = new Object;
   Foo* foo = new Foo(o);
   printf(%x\n, foo); // print a Foo**

   Bar* bar = new Bar();
   printf(%x\n, bar); // print a Bar**
}

My best guess would be that you wanted to pass this instead of this
to writeln as weel as bar instead of bar etc.

Kind Regards
Benjamin Thaut
Yes, of course I should pass this instead of this, thanks. I was 
looking for bug in wrong place - and using  let me hope I found it. :)

But kind people didn't let me get up on the wrong way. Thanks!


casting issue

2013-10-24 Thread Alexandr Druzhinin

May I cast like:

struct Point
{
float x, y, z;
float r, g, b, a;
}

Point[] points;

void foo(float[] float_array) {};

foo(cast(float[]) points); // is it safe?

May be more elegant way do express this exists?

Thanks


Re: casting issue

2013-10-24 Thread Alexandr Druzhinin

25.10.2013 02:08, Adam D. Ruppe пишет:

On Thursday, 24 October 2013 at 17:59:03 UTC, Alexandr Druzhinin wrote:

foo(cast(float[]) points); // is it safe?


Two options would be to make the points itself be a float[] with the
names just properties into the index:

struct Point {
  float[7] data;
  ref float x() { return data[0]; }
  ref float y() { return data[1]; }
  // etc etc etc
}

then to use it, just pass point.data[] instead of casting.

Or you could also do a union:

struct Point {
union {
   float[7] data;
   struct {
  float x,y,z,r,g,b,a;
   }
}
}

and again, pass point.data[] instead of casting it, while continuing to
use the other members normally.

These are both well defined so are less likely to break than the cast.
I thought to use union, but using struct with properties is good to 
know. Thanks for sharing!


Re: Changing elements during foreach

2013-10-21 Thread Alexandr Druzhinin

21.10.2013 17:31, Krzysztof Ciebiera пишет:

Is the following compiler behavior consistent with language specification?

import std.stdio;

void main()
{
 int a[][] = [[1,2,3]];
 foreach(x; a)
 {
 x[0] = 0;
 x ~= 4;
 }
 writeln(a);
}

I understand why thw program could output [1,2,3] (like in C++ without
) or [0,2,3,4] (python, C++ ref). But [0,2,3]? It was unpleasant surprise.

It's expected.
foreach(ref x; a) == C++ with 
but without ref you get the first element of a - i.e. [1, 2, 3] then set 
x[0] = 0 so you get [0, 2, 3]. But when you append 4 you append it to 
local copy of x - because there is no 'ref'. So your local copy of x 
became [0, 2, 3, 4] but when scope is gone you get unmodified copy of a 
with old array [0, 2, 3]. Changing the first element without ref 
possible because you modify inner array which is reference itself.


Re: Changing elements during foreach

2013-10-21 Thread Alexandr Druzhinin

21.10.2013 17:55, Krzysztof Ciebiera пишет:

On Monday, 21 October 2013 at 10:41:38 UTC, Alexandr Druzhinin wrote:

21.10.2013 17:31, Krzysztof Ciebiera пишет:

void main()
{
int a[][] = [[1,2,3]];
foreach(x; a)
{
x[0] = 0;
x ~= 4;
}
writeln(a);
}
...
) or [0,2,3,4] (python, C++ ref). But [0,2,3]? It was unpleasant
surprise.

It's expected.
foreach(ref x; a) == C++ with 
but without ref you get the first element of a - i.e. [1, 2, 3] then
set x[0] = 0 so you get [0, 2, 3]. But when you append 4 you append it
to local copy of x - because there is no 'ref'.


So, when exactly my local copy of data should be created? Now it is
created during appending element to an array (when I switch instructions
order, first append x ~= 4, then set x[0] to 0, as a result I get
[1,2,3]). Maybe I should get a warning (like when hiding variable from
outer scope)?
If you switch instruction order you create local copy and then set x[0] 
in local copy so original is unchanged. But local copy creating depends 
on several thing and happens not every appending in general. Your way is 
not D-ish one. What do you want to do?


Re: unsigned interger overflow

2013-10-02 Thread Alexandr Druzhinin

02.10.2013 12:41, Jonathan M Davis пишет:

On Wednesday, October 02, 2013 12:32:24 Alexandr Druzhinin wrote:

Is it safe to replace code:

uint index;
// do something
index++;
if(index == index.max)
index = index.init;

by the following code
uint index;
// do something
index++; /// I use unsigned int so uint.max changed to 0 automagically


Well, not quite. Your first one skips uint.max. It goes from uint.max - 1 to 0,
whereas the second one goes from uint.max to 0. So, they're subtly different.
But yes, incrementing the maximum value of an unsigned integral type is
guaranteed to wrap around to 0. Signed integers are of course another matter
entirely, but it's guaranteed to work with unsigned integers.

- Jonathan M Davis


Thanks for clarification.


code formatting issue

2013-10-02 Thread Alexandr Druzhinin

I'm curious what is the best way to code like this:

//  request_id  zoom  x y pathurl
auto msg = receiveOnly!(size_t, zoom, uint, uint, string, string)();

or like this

auto msg = receiveOnly!(
typeof(request_id),
typeof(zoom),
typeof(x),
typeof(y),
typeof(path),
typeof(url)
)();

Or may be I'm worrying about nonsense and better I'd start thinking 
about more useful things? :)


Re: code formatting issue

2013-10-02 Thread Alexandr Druzhinin

02.10.2013 22:47, bearophile пишет:


It's often a good idea to use typeof to keep the code more DRY and safer.



I'm sure keeping the code dry and clean is very good idea, but using 
typeof is rather verbose and just is unusual and verbose a little bit.



Another possible solution is to put the variables in some kind of tuple,
take its types and use them with a trailing [] to pass them all to
receiveOnly.

Bye,
bearophile


Something like this:

alias Tuple!(
typeof(request_id),
typeof(zoom),
typeof(x),
typeof(y),
typeof(path),
typeof(url)
) TileDescription;

// wait for tile descripton to process
auto msg = receiveOnly!TileDescription();

? I didn't understand about trailing []


unsigned interger overflow

2013-10-01 Thread Alexandr Druzhinin

Is it safe to replace code:

uint index;
// do something
index++;
if(index == index.max)
index = index.init;

by the following code
uint index;
// do something
index++; /// I use unsigned int so uint.max changed to 0 automagically

Thanks in advance



curl linux

2013-09-28 Thread Alexandr Druzhinin
I use curl in my application. If I link it with -lcurl - symbols are 
undefined (libcurl3 installed), if I link with -lphobos2 - it links. So 
curl is linked with libphobos2.so? But what to do if I need static 
linking? (ubuntu 12.04 x86_64, dmd 2.063.2)


Throwable catching

2013-09-28 Thread Alexandr Druzhinin
catching Throwable is wrong. But is it wrong if I used it in separate 
thread to prevent thread dying like:


static void run()
{
while(true)
{
try
{
/// do work
...

// interacting with parent
auto msg = receiveTimeout(dur!msecs(1),
(string command)
{
/// process command from parent
if(some_condition_is_true)
break; // finish
   // execution
}
);
}
catch(Throwable t)
{
/// some diagnostic message
}
}
}

...

auto child = spawn(run);

...

?


Re: Throwable catching

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 15:50, Jonathan M Davis пишет:


It's just as wrong to catch Throwable there is at is anywhere. If you do that
you'll catch Errors, and Errors are _supposed_ to kill your program. They
indicate that something bad enough has occurred that it's better to terminate
your program than continue.

So, yes, what you're doing will keep the thread from dying, but if you get an
Error, you want to shut your program down, not try and keep it running. So,
maybe catching Throwable would make sense if you had to then tell the other
thread to terminate, but should rethrow the Throwable afterwards and let the
thread die.

- Jonathan M Davis

Just to clear - in my case child thread processes parent commands like a 
worker and every loop iteration isn't correlated with others before and 
after so I thought that just new iteration resets bad application state 
caused by Error - I was wrong?


Re: curl linux

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 17:06, Jordi Sayol пишет:

On 28/09/13 10:28, Alexandr Druzhinin wrote:

I use curl in my application. If I link it with -lcurl - symbols are undefined 
(libcurl3 installed), if I link with -lphobos2 - it links. So curl is linked 
with libphobos2.so? But what to do if I need static linking? (ubuntu 12.04 
x86_64, dmd 2.063.2)



To link against libcurl (-lcurl) you need to install libcurl development files. On Ubuntu, install one of 
these three packages: libcurl4-openssl-dev, libcurl4-gnutls-dev or 
libcurl4-nss-dev.

For libcurl static linking you should link against all libraries that libcurl 
depends on.

Thank you for info. I have installed libcurl4-gnutls-dev - the same 
happens, symbols are undefined. But with -lphobos2 it links... Why 
linker don't find these symbols if libs are installed? Should I pass to 
linker some additional info in this case?


Re: Throwable catching

2013-09-28 Thread Alexandr Druzhinin

Thank you for info! I will redesign.


Re: curl linux

2013-09-28 Thread Alexandr Druzhinin

28.09.2013 20:14, Jordi Sayol пишет:


Can I see your full command line please?
$ dmd -lcurl 


I use dub, but I did rdmd version:
rdmd --build-only -I/home/drug/.dub/packages/derelict-master/import 
-I/home/drug/.dub/packages/glamour-master -version=Derelict3 
-version=gl3n -I/home/drug/.dub/packages/gl3n-master/ 
-I/home/drug/3rdparties/cairoD/src 
-I/home/drug/.dub/packages/arsd-master -version=CAIRO_HAS_PNG_FUNCTIONS 
-L-lphobos2 -L-L/home/drug/3rdparties/cairoD -L-lcairoD -L-lcairo -L-ldl 
-ofbin/geoviewer src/app.d


If I change -L-lphobos2 на -L-lcurl I get:
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticCtor34FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticCtor34FZv+0xf): 
undefined reference to `curl_global_init'
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl.o): In function 
`_D3std3net4curl4Curl19_sharedStaticDtor35FZv':
std/net/curl.d:(.text._D3std3net4curl4Curl19_sharedStaticDtor35FZv+0x5): 
undefined reference to `curl_global_cleanup'
/usr/lib/x86_64-linux-gnu/libphobos2.a(curl_144c_140.o): In function 
`_D3std3net4curl4HTTP4Impl6__dtorMFZv':
std/net/curl.d:(.text._D3std3net4curl4HTTP4Impl6__dtorMFZv+0x19): 
undefined reference to `curl_slist_free_all'

...

and so on. That is in this case I have static linking but curl symbols 
are not definded somehow.


Re: non virtual interfaces

2013-09-20 Thread Alexandr Druzhinin

20.09.2013 12:45, Ali Çehreli пишет:

On 09/19/2013 10:31 PM, Alexandr Druzhinin wrote:

  if I use protected instead of private in interface like:

private member functions are non-virtual.
But I just use code example from TDPL russian edition. And TDPL says 
clearly that (un)transmogrify() are private and CardboardBox _maynot_ 
make (un)transmogrify() non-private - this is highlighted as compiler 
support of NVI idiom. Is it wrong example, I guess?


  interface Transmogrifier
  {
   final void thereAndBack()
   {
   transmogrify();
   untransmogrify();
   }
 
   protected:
   void transmogrify();
   void untransmogrify();
  }

If they were non-virtual (i.e. private), the calls to transmogrify() and
untransmogrify() from thereAndBack() would be bound to
Transmogrifier.transmogrify and Transmogrifier.untransmogrify at compile
time. That happens and the linker cannot find their definitions.

I see. Thanks, I understand it now better


  class CardboardBox: Transmogrifier
  {
   override protected void transmogrify() { }
   override void untransmogrify() {}
  }

  it compiles, but why does compiler permit making untransmogrify() be
  public?

It is up to CardboardBox to decide whether untransmogrify() is public or
not. Note that untransmogrify() is still protected when objects are used
through the Transmogrifier interface. However, when an object is known
to be a CardboardBox so that it is being used through the CardboardBox
interface, it is not bound to be a Transmogrifier at that point. Yes,
CardboardBox inherits from Transmogrifier but it is CardboardBox's
interface that is being used at that point so it decides.
Thanks again. So there is no compiler support for NVI idiom? Because if 
CardboardBox may define its own (un)transmogrify() - TDPL says it 
possible only if (un)transmogrify() have other signatures.


  How can I prohibit this? May be it just unrealized yet?

You cannot prohibit from Transmogrifier.

Ali


Unfortunately I tried to use NVI for it namely.


Re: non virtual interfaces

2013-09-20 Thread Alexandr Druzhinin

20.09.2013 23:09, Jonathan M Davis пишет:

You can use NVI with classes just fine just so long as you use protected rather
than private, but making it private there won't work either, because private
is never virtual (and it wouldn't really help you any if it were, because
while the base class private function might not be callable, the derived class
one would still be callable by the derived class, so trying to prevent the
virtual function in NVI from ever being called outside of the base class is
broken in the first place - including in C++ where it was originally devised).
What NVI helps with is making it so that the public function being called as
part of the API is non-virtual, allowing you to do stuff before and after the
hidden virtual function being called, but the derived classes can still call
their implementation of the hidden, virtual function.

- Jonathan M Davis


I see. Thanks for clarifying.


non virtual interfaces

2013-09-19 Thread Alexandr Druzhinin

Hello all.

I try to use NVI and failed with a snippet from TDPL:

interface Transmogrifier
{
final void thereAndBack()
{
transmogrify();
untransmogrify();
}

private:
void transmogrify();
void untransmogrify();
}

class CardboardBox: Transmogrifier
{
override private void transmogrify() { }
override void untransmogrify() {}
}

int main()
{
auto cb = new CardboardBox();
return 0;
}

doesn't compile with log info:
src/test.d(16): Error: function test.CardboardBox.transmogrify cannot 
override a non-virtual function
src/test.d(17): Error: function test.CardboardBox.untransmogrify does 
not override any function, did you mean to override 
'test.Transmogrifier.untransmogrify'?


It rather well differs from what I expected reading TDPL. Something is 
changed very much or I just missed something?


Re: non virtual interfaces

2013-09-19 Thread Alexandr Druzhinin

if I use protected instead of private in interface like:
interface Transmogrifier
{
final void thereAndBack()
{
transmogrify();
untransmogrify();
}

protected:
void transmogrify();
void untransmogrify();
}

class CardboardBox: Transmogrifier
{
override protected void transmogrify() { }
override void untransmogrify() {}
}

int main()
{
auto cb = new CardboardBox();
return 0;
}

it compiles, but why does compiler permit making untransmogrify() be 
public? How can I prohibit this? May be it just unrealized yet?


Re: may gc free malloced memory?

2013-09-12 Thread Alexandr Druzhinin

12.09.2013 14:45, Rene Zwanenburg пишет:

On Thursday, 12 September 2013 at 05:59:33 UTC, monarch_dodra
wrote:

On Thursday, 12 September 2013 at 05:36:31 UTC, Alexandr Druzhinin wrote:

Some C function malloc-ed memory. This memory should be freeed much
later. I don't want to manually call C function to free this memory
in some point later, so may I in some way ask gc to free this memory
using something like addRoot(for instance) or else or the true way is
to copy malloc-ed memory to gc-allocated memory and free malloc-ed
memory at once? Like:

ubyte data* = cfunction_allocates_memory();
auto gcmemory = data[0..length(data)];
cfunction_frees_memory(data);
// work with gcmemory only

or

ubyte data* = cfunction_allocates_memory();
GC.someUnknownToMeFunction(data); // now gc will control this memory


No.

Only free can be used with malloc. The memory comes from distinct pools.

Another option could be to use GC.malloc, and memcpy your old mmory
into your new memory, free the old memory, and use your new block.
GC.malloc, as the name suggests, is a malloc, but done by the GC.


You could also use some kind of helper class. Perhaps Phobos has
a facility for this, but to illustrate the idea:
http://dpaste.dzfl.pl/805a61c0

However note that the memory isn't guaranteed to be freed this
way. Only if the GC heap gets full and the collector runs.
Ok. I just think that copying from one pool to another is excessive and 
may be there is a some way to avoid it.

Thanks for the answers!


may gc free malloced memory?

2013-09-11 Thread Alexandr Druzhinin
Some C function malloc-ed memory. This memory should be freeed much 
later. I don't want to manually call C function to free this memory in 
some point later, so may I in some way ask gc to free this memory using 
something like addRoot(for instance) or else or the true way is to copy 
malloc-ed memory to gc-allocated memory and free malloc-ed memory at 
once? Like:


ubyte data* = cfunction_allocates_memory();
auto gcmemory = data[0..length(data)];
cfunction_frees_memory(data);
// work with gcmemory only

or

ubyte data* = cfunction_allocates_memory();
GC.someUnknownToMeFunction(data); // now gc will control this memory


TDPL, std.concurrency and OwnerFailed

2013-09-03 Thread Alexandr Druzhinin

Hello
I try to get known if daughter thread finished its work using 
OwnerFailed exception catching like TDPL says, but std.concurrency has 
no such symbol. So, something changed. Can somebody help me with this 
case - finding if a child thread finished/terminated?
I know about spawnLinked, but I want to get known about child state when 
sending, not receiving, because in the last case I don't know what of 
linked child threads is terminated.


Re: TDPL, std.concurrency and OwnerFailed

2013-09-03 Thread Alexandr Druzhinin

04.09.2013 0:58, Ali Çehreli пишет:

One way is, the child can send a special message (even the exception
itself) when it terminates:

// ... at the worker ...
 try {
 // ...

 } catch (shared(Exception) exc) {
 owner.send(exc);
 }},

This implies some protocol, at least simplest, but hand-made, 
non-standard protocol - I'd like to avoid this if possible and use 
standart ways

Beware though: There has been problems with disappearing workers even
with that code. The reason is, the code above does not catch Errors.
However, if it did catch by Error (or, more generally by Throwable),
then in theory, it shouldn't trust program state sufficiently to be able
to send a message to the owner.
But if after catching Throwable and sending a message to the parent I 
stop the worker - I won't be needed to trust a worker state, because it 
won't be used more? Or again I need some protocol to avoid this case?


  I know about spawnLinked, but I want to get known about child state when
  sending, not receiving, because in the last case I don't know what of
  linked child threads is terminated.

I don't think it is a complete solution: Even if you think the child is
healthy when you send the message, it may terminate right after
receiving it.
You're absolutely right. So, ultimately I need some communication 
protocol. It would be very nice if phobos has something like message 
pattern in zeromq.


Re: How do you profile your apps under windows?

2013-08-11 Thread Alexandr Druzhinin

10.08.2013 00:59, H. S. Teoh пишет:

On Fri, Aug 09, 2013 at 11:39:41PM +0700, Alexandr Druzhinin wrote:

-profile switch doesn't work for me (nothing happens), so I'm
curious how to profile?


You've to run your program first. It will create a bunch of extra files
in your current working directory that contains the profile results.


T

Of course I run the program first. When the program was simpler it 
worked fine. But at the some moment I tried to profile it again but 
there were no profile results generated. More over now my app just hangs 
up after finishing (my code) execution somewhere in druntime kingdom.
To try gprof I installed ubuntu 12.04 (newer versions didn't install 
from flushdisk) and also installed gdc-4.8 (native gdc-4.6 doesn't 
compile my code) from a package (compiling gdc from source fails, 
playing with configure options just wasted several hours of my spare 
time) and even build my app and became exciting that now I would get 
opportunity to profile using gprof but my app just crashed with dumping 
without any informative message. I tried to use gdb (I'm a noob with it) 
and found that it crashed somewhere about exit from static ctors - I'm 
not sure I interpreted gdb output correctly.
So now I have a choice - to wait when good and smart guys solve these 
problems either with dmd -profile or gdc code generating and try to work 
around myself - probably gdc codegen isn't the real reason. Here I'm 
sitting and making decision what to do further...
But nevertheless thanks to all who made the universe more beautiful and 
handy by means of D language and its infrastructure! Thank you guys!


Re: How do you profile your apps under windows?

2013-08-11 Thread Alexandr Druzhinin

10.08.2013 01:30, Gary Willoughby пишет:

On Friday, 9 August 2013 at 16:39:41 UTC, Alexandr Druzhinin wrote:

-profile switch doesn't work for me (nothing happens), so I'm curious
how to profile?


I had the same problem on Linux where -profile didn't seem to produce
anything. I had a program which ran an infinite loop running as a
daemon. When compiled and run using -profile i'd let it run for a bit
then kill it and nothing was produced. After much head scratching i
implemented a timer in the program that only ran in debug mode and after
the timer expired i raised an assert fail:

 assert(false);

This exited the program and produced the trace file which i could then
examine. I guess killing the process also killed the profiler and so
never gave me the report.
Tried this approach but the app hangs up somewhere in druntime code 
after my code execution finished.


How do you profile your apps under windows?

2013-08-09 Thread Alexandr Druzhinin
-profile switch doesn't work for me (nothing happens), so I'm curious 
how to profile?


Re: Exception isn't thrown as expected

2013-06-04 Thread Alexandr Druzhinin

31.05.2013 8:56, Alexandr Druzhinin пишет:

Hello
I have code like this:

class SomeClass {
ubyte[] data_;

...

 auto getObjectType() const {
 if(data_ is null) {
 writeln(throwing);
 throw new Exception(Here the exception should be thrown!);
 }
 KeyHeaderHelper value_header;
 value_header.ptr_ = cast(ubyte*) data_.ptr;
 return value_header.object_type;
 }
}

When data_ is null the application just prints throwing and hangs up
without an exception throwing. I don't know how to handle this. May be I
did something wrong? If so then what?


Rephrase my question - I have a function getObjectType, that throws an 
exception. Unittest is ok. But in more complex use case, this function 
doesn't throw exception and just hangs up. If I brace the function call 
by try/catch then an exception is throw again. But I guess exception 
have to be thrown in any case.


Re: Exception isn't thrown as expected

2013-06-04 Thread Alexandr Druzhinin

04.06.2013 19:18, Alexandr Druzhinin пишет:

31.05.2013 8:56, Alexandr Druzhinin пишет:

Hello
I have code like this:

class SomeClass {
ubyte[] data_;

...

 auto getObjectType() const {
 if(data_ is null) {
 writeln(throwing);
 throw new Exception(Here the exception should be thrown!);
 }
 KeyHeaderHelper value_header;
 value_header.ptr_ = cast(ubyte*) data_.ptr;
 return value_header.object_type;
 }
}

When data_ is null the application just prints throwing and hangs up
without an exception throwing. I don't know how to handle this. May be I
did something wrong? If so then what?


Rephrase my question - I have a function getObjectType, that throws an
exception. Unittest is ok. But in more complex use case, this function
doesn't throw exception and just hangs up. If I brace the function call
by try/catch then an exception is throw again. But I guess exception
have to be thrown in any case.

Oh, no.. If I do

...
try {
auto foo =  some_class_instance.getObjectType();
}
catch(Throwable t) {
writeln(t.msg); // print exception, no hanging
throw t;// hangs again
}
...
all happens in the main thread.


Re: Exception isn't thrown as expected

2013-06-03 Thread Alexandr Druzhinin

03.06.2013 12:26, Ali Çehreli пишет:

On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote:

  I found that after calling
  std.concurrency.spawn() template - exceptions stop throwing, but if I
  add little delay in beginning of spawned thread about 100 ms - it'd
  works again and exceptions would be thrown again... :(

Is the exception thrown by a child thread? If so, perhaps that is
causing the child to terminate. Also, the parent cannot catch a child's
exception automatically.

Ali

no, the main thread do it. But even if child thread throws an exception, 
should it print some diagnostic message to clear that it crashed or no? 
Because my app just hangs up and nothing more, no message, no 
complaints, nothing.


Exception isn't thrown as expected

2013-05-30 Thread Alexandr Druzhinin

Hello
I have code like this:

class SomeClass {
ubyte[] data_;

...

auto getObjectType() const {
if(data_ is null) {
writeln(throwing);
throw new Exception(Here the exception should be thrown!);
}
KeyHeaderHelper value_header;
value_header.ptr_ = cast(ubyte*) data_.ptr;
return value_header.object_type;
}
}

When data_ is null the application just prints throwing and hangs up 
without an exception throwing. I don't know how to handle this. May be I 
did something wrong? If so then what?


Re: Exception isn't thrown as expected

2013-05-30 Thread Alexandr Druzhinin

31.05.2013 8:59, Adam D. Ruppe пишет:

three questions come to mind:

1) what operating system and 32 bit or 64 bit?
2) what D compiler?
3) are you sure you didn't catch the exception somewhere up the chain
and silence the message that way?

1) win7 64
2) dmd 32
3) I don't catch explicitly. To ensure it isn't catch some way 
implicitly I just throw Exception without condition and it is thrown as 
expected

auto getObjectType() const {
throw new Exception(Here the exception should be thrown!); // 
works as expected

KeyHeaderHelper value_header;
value_header.ptr_ = cast(ubyte*) data_.ptr;
return value_header.object_type; // if data isn't null it hangs 
up here

}

moreover, when I provide data_ always have some length, the application 
starts hangin at return operator. I've met something like this behaviour 
(I mean silent hanging up) earlier working with std.concurrency, but I 
found some workaround. Now I dont know what to do.


Re: Exception isn't thrown as expected

2013-05-30 Thread Alexandr Druzhinin

31.05.2013 10:49, Marco Leise пишет:


The code that you haven't shown reads:

   int main(string[] args) {
   SomeClass c;
   auto t = c.getObjectType();
   return 0;
   }

You have to fix that!

You mean I didn't initialize c? If even so, it should throw an 
exception, no hanging, I think. Nevertheless, a class instance is 
correct. I'll try to reduce code.


Re: Can't find GLU symbols when compiling SimpleGL.d found in GtkD/demos

2013-05-19 Thread Alexandr Druzhinin

Try this http://gtkd.org/Downloads/GtkDGL.zip



Re: GtkD HelloWorld app crashes with exception

2013-05-18 Thread Alexandr Druzhinin

18.05.2013 14:53, Enjoys Math пишет:

I re-installed DMD 2.062 and now it's a compiler error:

-- Build started: Project: ConsoleApp3, Configuration: Debug Win32
--
Building Debug\ConsoleApp3.exe...
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(glib)
  Error 42: Symbol Undefined _D3std3utf10decodeImplFNaNePxakKkZw (pure
@trusted dchar std.utf.decodeImpl(const(char)*, uint, ref uint))
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(glib)
  Error 42: Symbol Undefined
_D6object9Exception6__ctorMFAyaAyakC6object9ThrowableZC9Exception
(Exception object.Exception.__ctor(immutable(char)[], immutable(char)[],
uint, object.Throwable))
Building Debug\ConsoleApp3.exe failed!
Details saved as
file://C:\home\Dropbox\Dev\AudioSynth\Tests\ConsoleApp3\ConsoleApp3\Debug\ConsoleApp3.buildlog.html

Try to rebuild GtkD if you re-installed dmd. Check if Gtk path is the 
first in path because can be other application with different version of Gtk


Re: GtkD HelloWorld app crashes with exception

2013-05-18 Thread Alexandr Druzhinin

18.05.2013 15:34, Enjoys Math пишет:


And the errors are:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(ObjectG)
  Error 42: Symbol Undefined _D4core6memory2GC7addRootFxPvZv (void
core.memory.GC.addRoot(const(void*)))
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(ObjectG)
  Error 42: Symbol Undefined _D4core6memory2GC10removeRootFxPvZv (void
core.memory.GC.removeRoot(const(void*)))
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(glib)
  Error 42: Symbol Undefined
_D4core6memory2GC6qallocFkkZS4core6memory8BlkInfo_ (core.memory.BlkInfo_
core.memory.GC.qalloc(uint, uint))
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(glib)
  Error 42: Symbol Undefined _D4core6memory2GC6extendFPvkkZk (uint
core.memory.GC.extend(void*, uint, uint))
C:\D\dmd2\windows\bin\..\lib\GtkD.lib(glib)
  Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi (pure nothrow int
core.bitop.bsr(uint))
Building Debug\WindowsApp2.exe failed!
Your compiler is installed incorrectly and can not find phobos  of 
appropriate version. Check it once again. In your case this error should 
appear with any other example. Check it too, if you want.


Re: GtkD HelloWorld app crashes with exception

2013-05-18 Thread Alexandr Druzhinin

18.05.2013 16:17, Enjoys Math пишет:

Then upon continuing I get an infinitely repeating

Unhandled exception at 0x in WindowsApp2.exe: 0xC005:
Access violation reading location 0x.

message box popping up.
Did you check that path to Gtk runtime binaries is the first? I guess 
there is some other application in your path variable that is using 
different zlib1.dll and when you run your app it load incorrect version 
that results in what you get. Check you path once again.


Re: GtkD HelloWorld app crashes with exception

2013-05-17 Thread Alexandr Druzhinin

18.05.2013 9:52, Enjoys Math пишет:

I'm on Windows 7 64-bit and using DMD2, compiling a regular 32-bit
windows app using Visual D New Project  Windows App and replacing
winmain.d with the code below:


 ...


I'm using GtkD-2.2.0 from here:
https://code.google.com/p/gtkd-packages/downloads/list

and also the 32-bit runtime from there.

The output when I click Start Debugging in Visual D is to display a
stdout window with some text (that I can't read since it's too fast.
I've tried setting breakpoints to no avail), no window is ever
displayed.  Then in Visual D the output log shows:

code
First-chance exception at 0x76c6c41f in WindowsApp1.exe: 0xE0440001:
0xe0440001.
The program '[3848] WindowsApp1.exe: Native' has exited with code 1 (0x1).
/code

Thank you for any suggestions.
Works fine on my box. You have problem with gtk installation. But I 
can't specify what's the reason - I downloaded previous binaries. Also I 
recommend you to experiment with paths - check it out.


Compiler error

2013-05-06 Thread Alexandr Druzhinin

during building I get:
Assertion failure: 'alignment  0  !(alignment  (alignment - 1))' on 
line 239

 in file 'struct.c'

abnormal program termination

what should I do to help us to catch this?


Re: Compiler error

2013-05-06 Thread Alexandr Druzhinin

07.05.2013 0:39, Maxim Fomin пишет:

On Monday, 6 May 2013 at 16:37:18 UTC, Alexandr Druzhinin wrote:

during building I get:
Assertion failure: 'alignment  0  !(alignment  (alignment - 1))'
on line 239
 in file 'struct.c'

abnormal program termination

what should I do to help us to catch this?


1) search or report to bugzilla
2) debug dmd
3) fix sources
4) prepare pull request
Честно сказать, я не в курсе как искать в багзилле - все баги такие 
разные. Думал, тут все за меня сейчас решат. ;) Понял, будем работать...


Re: Compiler error

2013-05-06 Thread Alexandr Druzhinin

07.05.2013 8:55, Alexandr Druzhinin пишет:

07.05.2013 1:40, Maxim Fomin пишет:

On Monday, 6 May 2013 at 17:48:58 UTC, Alexandr Druzhinin wrote:

07.05.2013 0:39, Maxim Fomin пишет:

On Monday, 6 May 2013 at 16:37:18 UTC, Alexandr Druzhinin wrote:

during building I get:
Assertion failure: 'alignment  0  !(alignment  (alignment - 1))'
on line 239
in file 'struct.c'

abnormal program termination

what should I do to help us to catch this?


1) search or report to bugzilla
2) debug dmd
3) fix sources
4) prepare pull request

Честно сказать, я не в курсе как искать в багзилле - все баги такие
разные. Думал, тут все за меня сейчас решат. ;) Понял, будем работать...


понятно :)

Issue 8612 and 8710 looks like your case. Please post there your reduced
code.

http://d.puremagic.com/issues/show_bug.cgi?id=8612

it looks like 8612 but unfortunatly I found that the error appearance
depends on command line arguments - if I compile the file with reduced
code without other files of the project it compiles, but with the files
- it fails. :(
I forgot to mention that the these other files don't need for the 
reduced code compiling, but nevertheless bug is affected by these files.


[GtkD] How to connect to notify::active signal?

2013-05-03 Thread Alexandr Druzhinin
I need to connect to notify::active signal for Switch widget to 
process changing of its state. The guides say I shouldn't use onActivate 
signal, but notify:active. But I didn't find a way to do it. Can 
somebody help with it?


Re: [GtkD] How to connect to notify::active signal?

2013-05-03 Thread Alexandr Druzhinin

04.05.2013 1:18, Mike Wey пишет:

On 05/03/2013 06:30 PM, Alexandr Druzhinin wrote:

I need to connect to notify::active signal for Switch widget to
process changing of its state. The guides say I shouldn't use onActivate
signal, but notify:active. But I didn't find a way to do it. Can
somebody help with it?


Are you referring to gtk.Switch ?


yes, gtk.Switch
if I connect to activate signal by means addOnActivate nothing works. 
Documentation says I should use notify::active event (it belongs to 
ObjectG, as I understand?), but I cannot find a way to connect to this 
signal by means of GtkD.


[GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

How to use GtkD with Glade? Is some tutorial available?
I spent some time trying to use Glade to build non-trivial application, 
but I do it very inproductive, so I'd like to get some help or I'm 
afraid it will be lasting for years...
For example, if somebody would upload some example of Gtk application, 
that built with glade and has several typical widgets and signal 
handlers - it may help very much.


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 6:12, Carlos пишет:


Normally the example looks for builderTest.glade in the directory
where the binary is.

There one in the GtkD git
https://github.com/gtkd-developers/GtkD/blob/master/demos/builder/builderTest.glade


You can also specify a different glade file on the commandline, the
example code tries to access a wiget named window1 if it's not
pressent in the glade file it will print No window? and exit.


I can't believe an hour has passed so easy.

How do I specify the doferent glade ?, During compilation ?
if you mean glade file with different name then answer is yes. but if 
you just want to use another glade file with the same name then answer 
is no. this different glade file should has window widget with name 
window1 but with the rest no other restrictions exist. with glade you 
can create more complex application easer and after debugging build 
glade file into your application.


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 0:43, Mike Wey пишет:


There is an small example distributed with GtkD:
https://github.com/gtkd-developers/GtkD/blob/master/demos/builder/builderTest.d



Oops, didn't see.


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 7:24, Alexandr Druzhinin пишет:


I can't believe an hour has passed so easy.

How do I specify the doferent glade ?, During compilation ?

if you mean glade file with different name then answer is yes. but if
you just want to use another glade file with the same name then answer
is no. this different glade file should has window widget with name
window1 but with the rest no other restrictions exist. with glade you
can create more complex application easer and after debugging build
glade file into your application.

I was totally wrong - didn't look at code before :(
The right answer to your question is you can specify your own glade file 
into command line as second argument like this:

builder /path/to/your/glade/file/your.glade
it will be enough


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 7:55, Carlos пишет:


Sorry if this was too wild but this is what I can do at the moment since
I don't see a gladeText program which I believe is required for this
action I did my guess.

code:

dmd builderTest.d $(pkg-config --cflags --libs gtkd-2) builder
~/Documents/Glade/builderTest.glade

gives error :

Error: unrecognized file extension glade

-

gtkD samples give error but I'm not using the same software from
developers I'll try to install by purge all gtkD programs installed by
no and trying make install again. Then check if the samples compile
right.

first build application:
dmd builderTest.d $(pkg-config --cflags --libs gtkd-2)

then run it:
builder ~/Documents/Glade/builderTest.glade


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 0:43, Mike Wey пишет:

On 05/02/2013 03:58 PM, Alexandr Druzhinin wrote:

How to use GtkD with Glade? Is some tutorial available?
I spent some time trying to use Glade to build non-trivial application,
but I do it very inproductive, so I'd like to get some help or I'm
afraid it will be lasting for years...
For example, if somebody would upload some example of Gtk application,
that built with glade and has several typical widgets and signal
handlers - it may help very much.


There is an small example distributed with GtkD:
https://github.com/gtkd-developers/GtkD/blob/master/demos/builder/builderTest.d


won't it be better to have the simple template to hide cast() using 
Builder.getObject():


auto getObjectAs(T)(Builder b, string object_name) {
return cast(T) b.getObject(object_name);
}
?


Re: [GtkD] How to use Glade?

2013-05-02 Thread Alexandr Druzhinin

03.05.2013 8:29, Carlos пишет:


I got it working now. I'm using the sample code and I made another
layout with Glade for GTK+3 and saved it with the same name, so when I
compile the file is called and I get the UI I wanted.


SO now next step is to learn the signals part, Right ?

right. and it's very very simpler than in plain C


Re: does GtkD (win7) support opengl?

2013-04-28 Thread Alexandr Druzhinin
developers version of GtkD solves my problem. but GtkD 2.1.1 from 
download page doesn't. May be remove it from there to avoid such problems?


Re: does GtkD (win7) support opengl?

2013-04-28 Thread Alexandr Druzhinin

28.04.2013 20:26, Mike Wey пишет:

On 04/28/2013 01:04 PM, Alexandr Druzhinin wrote:

developers version of GtkD solves my problem. but GtkD 2.1.1 from
download page doesn't. May be remove it from there to avoid such
problems?


Does it also draw the triangle properly for you?

yes, it works out of box as expected. Exception is that after window 
resizing drawGL() function isn't called and I need to call it explicitly 
in resize() - don't know is it intended or it is some failure.


Re: does GtkD (win7) support opengl?

2013-04-27 Thread Alexandr Druzhinin

27.04.2013 0:57, Mike Wey пишет:


Should be working now.


Yes, 32bit binary works well (didn't run 64bit). Thank you very much!


Re: does GtkD (win7) support opengl?

2013-04-25 Thread Alexandr Druzhinin

24.04.2013 4:02, Mike Wey пишет:

I don't think it's the line number. I think i may have this error on my
machine once, but not since then. And i can't reproduce it.

Could I ask you to build SimpleGL demo, check it works and send binary 
to me? It can help me in solving my trouble.

Thank in advance.


Re: does GtkD (win7) support opengl?

2013-04-25 Thread Alexandr Druzhinin

26.04.2013 3:45, Mike Wey пишет:


http://gtkd.org/Downloads/SimpleGL.zip

After updating dmd the demo no longer draws the triangle, i still need
to figure out why.


Link is broken


Re: does GtkD (win7) support opengl?

2013-04-23 Thread Alexandr Druzhinin

10.04.2013 3:48, Mike Wey пишет:


I was able to build gtkglext3 on windows, and i've uploaded a zip file
containing the dll's.

http://gtkd.org/Downloads/GtkDGL.zip

I've also included the static libs for GtkDGL and for 32bits windows two
import libraries for opengl and glu, for win64 these are included in the
Windows SDK.


Thank you very much, Mike!
now I have a little time to try gtk again and your help lets me build my 
SimpleGL demo. But I was forced use my own version of GtkDGL - your' 
doesn't work. I built it simple just running this from srcgl folder:

cd glgdk
dmd -lib -ofGlGdk.lib GLConfig.d GLContext.d GLdInit.d GLDrawable.d 
GLDrawableIF.d GLDrawableT.d GLQuery.d GLWindow.d -I.. -I..\..\src

cd ..

cd glgtk
dmd -lib -ofGlGtk.lib GLCapability.d GLtInit.d GLWidget.d -I.. -I..\..\src
cd ..

cd gtkglc
dmd -lib -ofGtkGlc.lib gl.d glgdk.d glgdktypes.d glgtk.d glgtktypes.d 
glu.d -I.. -I..\..\src

cd ..

it created three other libs and these I linked against.
Also I was forced to rename:
libgdkglext-3.0-0.dll to libgdkglext-win32-3.0-0.dll
libgtkglext-3.0-0.dll to libgtkglext-win32-3.0-0.dll
Now simplegl building and running but failed with the following:

(SimpleGL.exe:4668): GLib-GObject-WARNING **: cannot register existing 
type `GdkGLConfig'


(SimpleGL.exe:4668): GLib-CRITICAL **: g_once_init_leave: assertion 
`result != 0' failed


(SimpleGL.exe:4668): GtkGLExt-CRITICAL **: gtk_widget_set_gl_capability: 
assertion `GDK_IS_GL_CONFIG (glconfig)' failed

object.Error: Access Violation

0x0059ADDC
0x0059AC67
0x77B1B459 in LdrRemoveLoadAsDataTable
0x77B1B42B in LdrRemoveLoadAsDataTable
0x77AD0133 in KiUserExceptionDispatcher
0x004E5E73
0x665228B6 in gtk_main_do_event
0x6860BBCC in g_slice_free1
0x63A45E36 in g_closure_invoke
0x77AEE0F2 in RtlAllocateHeap

I think it relevant to Gtk, not GtkD, but it would be very nice if you 
could help with it too. Google says nothing about it and simplegl.d has 
only 150 lines, where should I look for 4668th line?


Re: Calculation differences between Debug and Release mode

2013-04-13 Thread Alexandr Druzhinin
I'm not sure, but I suspect this is because of 80-bit intermediary float 
point operation result. Its precision too excessive and gives us this 
inexpectible result. But when you use an intermediary variable this 
exessive intermediary result is rounded properly and you get what you 
expect. See here - http://d.puremagic.com/issues/show_bug.cgi?id=6531. 
The reason is:

float a, b, c, d, foo;
foo = a + b / c;
if (d  foo) { // you compare two float value
} else {
}
but:
if (d  (a + b / c)) { // you compare float value and 80bit value and 
sometimes the result won't be what you expected

} else {
}

in your case in release mode compiler may do some optimization and do 
not round value properly but using temp you force do proper rounding


Re: is it bug?

2013-04-10 Thread Alexandr Druzhinin

05.04.2013 1:26, Ali Çehreli пишет:


I was wrong. What I found is just a workaround. Created a bug for iota:

   http://d.puremagic.com/issues/show_bug.cgi?id=9877

The following program fails when compiled with -m32:

import std.range;

void main()
{
 float st = 0.000;
 float step = 12.038554191589355;
 float en = 999.200012207031250;

 iota(st, en, step);
}

Ali


Ali, please, take a look at this http://dpaste.dzfl.pl/44e64eb0
it's code of ctor of iota float point specialization. And it's strange 
for me, that pastEnd and (start + count * step) have the same value, but 
give different comparing results.


Re: is it bug?

2013-04-10 Thread Alexandr Druzhinin

11.04.2013 12:13, Alexandr Druzhinin пишет:

Ali, please, take a look at this http://dpaste.dzfl.pl/44e64eb0
it's code of ctor of iota float point specialization. And it's strange
for me, that pastEnd and (start + count * step) have the same value, but
give different comparing results.


it fixes bug (I guess) http://dpaste.dzfl.pl/b9577e70


is it bug?

2013-04-04 Thread Alexandr Druzhinin
on win7 64 bits using dmd 2.062 32 bits this code http://dpaste.dzfl.pl 
/6cca43b5 failed with assert failure: 
core.exception.AssertError@std.range(5288): Assertion failure
but on ubuntu 12.04 64 bits, dmd 2.062 64 bit it compiles and works 
rather well. May be I missed something important with it?


Re: is it bug?

2013-04-04 Thread Alexandr Druzhinin

04.04.2013 21:24, Ali Çehreli пишет:

On 04/04/2013 06:27 AM, Alexandr Druzhinin wrote:

on win7 64 bits using dmd 2.062 32 bits this code http://dpaste.dzfl.pl
/6cca43b5 failed with assert failure:
core.exception.AssertError@std.range(5288): Assertion failure
but on ubuntu 12.04 64 bits, dmd 2.062 64 bit it compiles and works
rather well. May be I missed something important with it?


The problem is reproducible on Linux as well if you compile with -m32.

The following assert fails in range.d:

   assert(start + count * step = end);

start: 0
count: 83
step: 12.0386
end: 999.2

Even though count * step is seemingly 999.2 as well, due to the inexact
nature of floating point calculations the assertion is false.

The problem seems to be in your code because your step calculation
ignores a remainder. This works:

 // OLD: step = width / factor;
 step = (width  + factor - 1) / factor;

Ali

that works, thank you very much! but provide some link to some good 
article that explains my mistake, I didn't realize it clearly


Re: is it bug?

2013-04-04 Thread Alexandr Druzhinin

05.04.2013 0:26, Ali Çehreli пишет:


I was wrong. What I found is just a workaround. Created a bug for iota:

   http://d.puremagic.com/issues/show_bug.cgi?id=9877

The following program fails when compiled with -m32:

import std.range;

void main()
{
 float st = 0.000;
 float step = 12.038554191589355;
 float en = 999.200012207031250;

 iota(st, en, step);
}

Ali


Thank you, Ali.
will be waiting it will be fixed.


Re: does GtkD (win7) support opengl?

2013-04-02 Thread Alexandr Druzhinin

02.04.2013 1:32, Jesse Phillips пишет:

Please provide your compile command, it looks like you didn't tell the
linker where to find GtkD.


cd path/to/GtkD/demos/gl/simple
dmd SimpleGL.d -I../../../src -I../../../srcgl ../../../src/GtkD.lib

without GtkD.lib there are much more undefined symbols


Re: does GtkD (win7) support opengl?

2013-04-02 Thread Alexandr Druzhinin

02.04.2013 21:38, Jesse Phillips пишет:

On Tuesday, 2 April 2013 at 06:19:23 UTC, Alexandr Druzhinin wrote:

02.04.2013 1:32, Jesse Phillips пишет:

Please provide your compile command, it looks like you didn't tell the
linker where to find GtkD.


cd path/to/GtkD/demos/gl/simple
dmd SimpleGL.d -I../../../src -I../../../srcgl ../../../src/GtkD.lib

without GtkD.lib there are much more undefined symbols


Ops I was thinking Derelict, I don't think GtkD is dynamically linked,
so you'll also need to say where gtk is.


but this is compilation error, not runtime or you mean there is another 
lib I should link against?


Re: does GtkD (win7) support opengl?

2013-04-02 Thread Alexandr Druzhinin

03.04.2013 1:08, Jesse Phillips пишет:


GtkD is only bindings for the actual GTK library, that library must be
installed to use GtkD. GtkD being using static linking (at compile time)
you need to tell the linker you want the GTK library too.

The best way to do this I don't know. The website suggest dgen to build
programs after install:
https://github.com/gtkd-developers/GtkD/wiki/Installing-on-Windows

If you were in Linux you likely would only add -L-lgtk to the compiler
command.


I'm totally agree that I need Gtk runtime - I install it before and set 
path to it properly. I build GtkD using dgen.d and link against it. But 
nevertheless I have undefined symbols and I don't know where to find 
them. Gtk application without opengl support builds very well, but 
opengl demo building fails.


Re: does GtkD (win7) support opengl?

2013-04-02 Thread Alexandr Druzhinin

03.04.2013 4:13, Mike Wey пишет:


GtkD relies on gtkglext-3 for it's openGL support it can be found here:
https://github.com/tdz/gtkglext

It currently isn't included in the Gtk-runtime installer, and as far as
i know there aren't any binaries readily available for windows.

And i haven't yet found the time to try and build it myself.


So undefined symbols may be just unported to windows part of gtkd library?


does GtkD (win7) support opengl?

2013-04-01 Thread Alexandr Druzhinin
I built GtkD following instructions from 
https://github.com/gtkd-developers/GtkD/wiki/Installing-on-Windows. Then 
I tried to build demo from demos/gl/simple/simplegl.d and failed with 
undefined symbols http://dpaste.dzfl.pl/ba0c3277
Script (dgen.d) builds the whole library and there is no separate lib to 
provide opengl (sort of gtkdgl.lib) so where can I find these undefined 
symbols to satisfy compiler?


Re: Text from the Internet page

2013-03-27 Thread Alexandr Druzhinin

27.03.2013 17:43, SaltySugar пишет:

How to get a piece of text from the Internet page with D code?
Its totally depends on context you are workin. For example you can use D 
as script and by means of wget to get the whole page and then parse it 
with sed. Also you can use curl and use D as programming language.


GC, memory leaks and 32/64 bit

2013-03-12 Thread Alexandr Druzhinin
32 bit versions (using dmd and gdc, win7/ubuntu 12.04) of my application 
always leak very fast. But 64 bit version (ubuntu 12.04 only, win7 
segfaults) works stable without any leaks. I'm curious is there some 
workaround or I have to wait for GC improvement to build 32bit version, 
without choice?


Re: gui libs

2013-02-28 Thread Alexandr Druzhinin

28.02.2013 16:35, rho пишет:

hi,
what keeps me from using d, is that there is no compilable gui lib
available. does dfl compile with the latest dmd?


DWT is compilable with the last dmd and works fine
Also GTK is available, but I didn't tested it


Re: std.concurrency.thisTid.send() feat. immutable(struct with several arrays)

2013-02-27 Thread Alexandr Druzhinin

27.02.2013 14:19, Jonathan M Davis пишет:

On Wednesday, February 27, 2013 13:19:22 Alexandr Druzhinin wrote:

This code doesn't compiles http://dpaste.dzfl.pl/706a0d12
But if you comment one of arrays it will do. I take a look at varaint.d
but can't understand why two arrays cause this error.
How can I send immutable struct that contains two or more arrays without
any serializing?


I don't exactly what's going on with your code here, but std.concurrency is
very buggy with regards to what types it will and won't accept - including
both immutable and arrays. These are just some of the reported issues:

http://d.puremagic.com/issues/show_bug.cgi?id=6585
http://d.puremagic.com/issues/show_bug.cgi?id=5538
http://d.puremagic.com/issues/show_bug.cgi?id=8853
http://d.puremagic.com/issues/show_bug.cgi?id=9122

Your problem may be one of those.

std.concurrency is fantastic as far as its basic design goes, but its
implementation still needs a fair bit of work. It generally works, but it's
fairly easy to find corner cases where it doesn't work.

- Jonathan M Davis


Thank you.
I will learn to use reported issues.


Re: Linking C and D

2013-02-27 Thread Alexandr Druzhinin

27.02.2013 23:12, monarch_dodra пишет:

I can't seem to get the executable to link correctly.

I'm using gcc and dmd on windows.

I'm building foo.c with:
gcc -c foo.c -o foo.obj

Then I build my exe with:
dmd foo.obj main.d

But I get:
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj Offset 0H Record Type 004C
  Error 138: Module or Dictionary corrupt
--- errorlevel 1

...Help ?
Under Windows I use dmc + dmd and gdc + gcc - all these combinations 
work fine. But I only tested it on simple and small files.
There is also unilink (ftp://ftp.styx.cabel.net/pub/UniLink/) - they say 
it can link together omf and coff, but I don't try it


Re: Linking C and D

2013-02-27 Thread Alexandr Druzhinin

27.02.2013 23:50, monarch_dodra пишет:


dmc seems to start choking when my font files start to reach about 15 Mo.

I suppose there's a switch somewhere, but I've never used dmc before, so
all the switches are unknown to me. I guess I'll just have to learn
(anybody know?).

If worst comes to worst, I can try to split the font files, but since
they are tool generated, I really shouldn't be touching them.


IIRC, there is such switch, but I can't remember it, may be 
http://www.digitalmars.com/ctg/sc.html#dashCapHCapP ?


std.concurrency.thisTid.send() feat. immutable(struct with several arrays)

2013-02-26 Thread Alexandr Druzhinin

This code doesn't compiles http://dpaste.dzfl.pl/706a0d12
But if you comment one of arrays it will do. I take a look at varaint.d 
but can't understand why two arrays cause this error.
How can I send immutable struct that contains two or more arrays without 
any serializing?


Re: std.concurrency.thisTid.send() feat. immutable(struct with several arrays)

2013-02-26 Thread Alexandr Druzhinin

27.02.2013 13:19, Alexandr Druzhinin пишет:

This code doesn't compiles http://dpaste.dzfl.pl/706a0d12
But if you comment one of arrays it will do. I take a look at varaint.d
but can't understand why two arrays cause this error.
How can I send immutable struct that contains two or more arrays without
any serializing?

I've done it using pointer to the structure

thisTid.send(test_var);

but using pointers isn't good practice and if somebody explain the 
reason of compiler complaining it would be great.


thank in advance


  1   2   >