Float values are wrong in union

2016-08-21 Thread stunaep via Digitalmars-d-learn
I made a union to convert between int bits and floats, but the 
values are coming out wrong sometimes. This is working without 
issue in other languages so I'm really stumped. Here's an example:



union test { int i; float f; }
test t = { i : 0x7fb0};
float t2 = t.f;//int bits 0x7fb0 as float
test t3 = { f : t2 };
writefln("%x", t3.i);//prints 7ff0 NOT 0x7fb0


Re: Does D have object wrappers for primitives?

2016-07-29 Thread stunaep via Digitalmars-d-learn

On Friday, 29 July 2016 at 20:25:16 UTC, Cauterite wrote:

On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote:
I have some java code I need to convert and at one point it 
uses an Object[] array to store various ints, longs, and 
strings. Java has built in Integer and Long classes that wrap 
the primitives in an object and strings are already objects.


No, but with a template you could easily make your own:

class Boxed(T) {
T _v;
alias _v this;
this(in T v) immutable {_v = v;};
};

auto i = new Boxed!int(6);


Thank you. This is just what I needed. I am curious though as to 
why this doesn't work with strings. It would work if I removed 
immutable from the Boxed constructor but I thought strings were 
immutable. I get a compiler error 'not callable using a mutable 
object'. Even marking a string with the immutable keyword has the 
same result.


Does D have object wrappers for primitives?

2016-07-29 Thread stunaep via Digitalmars-d-learn
I have some java code I need to convert and at one point it uses 
an Object[] array to store various ints, longs, and strings. Java 
has built in Integer and Long classes that wrap the primitives in 
an object and strings are already objects.


Re: How to search for an enum by values and why enum items aren't unique

2016-07-27 Thread stunaep via Digitalmars-d-learn

On Wednesday, 27 July 2016 at 15:32:59 UTC, Meta wrote:

On Wednesday, 27 July 2016 at 13:59:54 UTC, stunaep wrote:
So how would I make a function that takes an enum and an id as 
a parameter and returns a member in the enum? I tried for 
quite some time to do this but it wont let me pass Test as a 
parameter unless I use templates. I finally came up with this 
but it wont let me return null when there's nothing found



E findEnumMember(E)(int id) if (is(E == enum)) {
auto found = [EnumMembers!E].find!(a => a.id == id)();
if(!found.empty)
return found.front;
else
...What do I return? null gives error
}


If you're going to do it like this your only real options are 
to return a Nullable!E or throw an exception if the id isn't 
found.


I tried Nullable!E earlier and it didnt work. I dont need it to 
be done like this, it just has to be done someway. I'm asking for 
help because that's the only way I could think of.


Re: How to search for an enum by values and why enum items aren't unique

2016-07-27 Thread stunaep via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 05:45:21 UTC, Jonathan M Davis 
wrote:
On Wednesday, July 20, 2016 04:03:23 stunaep via 
Digitalmars-d-learn wrote:

How can I search for an enum by its values? For example I have

>struct TestTraits {
>
> int value1;
> string value2;
>
>}
>
>enum Test : TestTraits {
>
> TEST = TestTraits(1, "test1"),
> TESTING = TestTraits(5, "test5")
>
>}

and I have the int 5 and need to find TESTING with it.

In java I would create a SearchableEnum interface, make all 
searchable enums implement it and use this method to find them.


>public static  T find(T[] vals, int
>id) {
>
> for (T val : vals) {
>
> if (id == val.getId()) {
>
> return val;
>
> }
>
> }
> return null;
>
>}

But the way enums work in D doesn't seem to permit this.


If you want the list of members in an enum, then use 
std.traits.EnumMembers and you'll get a compile-time list of 
them. It can be made into a runtime list by being put into an 
array literal.


For instance, if we take std.datetime.Month, we can look for 
the enum with the value 10 in it like so.


auto found = [EnumMembers!Month].find(10);
assert(found = [Month.oct, Month.nov, Month.dec]);

So, if you had your TestTraits struct as the type for an enum, 
you could do something like


auto found = [EnumMembers!TestTraits].find!(a => a.value1 == 
5)();

if(found.empty)
{
// there is no TestTraits which matches
}
else
{
// found.front is the match
}

And why on earth are different enum items with the same values 
equal to each other? Say I have an enum called DrawableShape


Because they have the same value. The fact that they're enums 
doesn't change how they're compared. That's determined by what 
type they are. All you're really getting with an enum is a list 
of named constants that are grouped together which implicitly 
convert to their base type but which are not converted to 
implicitly from their base type. The only stuff that's going to 
treat an enum member differently from any other value of that 
type is something that specifically operates on enums - e.g. by 
taking the enum type explicitly, or because it has is(T == 
enum) and does something different for enums (quite a few 
traits do that in std.traits), or because it uses a final 
switch. Most code is just going to treat them like any other 
value of the enum's base type. They aren't magically treated as 
unique in some way just because they're in an enum.


- Jonathan M Davis


So how would I make a function that takes an enum and an id as a 
parameter and returns a member in the enum? I tried for quite 
some time to do this but it wont let me pass Test as a parameter 
unless I use templates. I finally came up with this but it wont 
let me return null when there's nothing found



E findEnumMember(E)(int id) if (is(E == enum)) {
auto found = [EnumMembers!E].find!(a => a.id == id)();
if(!found.empty)
return found.front;
else
...What do I return? null gives error
}


Re: How to search for an enum by values and why enum items aren't unique

2016-07-20 Thread stunaep via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 05:45:21 UTC, Jonathan M Davis 
wrote:
On Wednesday, July 20, 2016 04:03:23 stunaep via 
Digitalmars-d-learn wrote:

[...]


If you want the list of members in an enum, then use 
std.traits.EnumMembers and you'll get a compile-time list of 
them. It can be made into a runtime list by being put into an 
array literal.


[...]


Coming from Java I've learned to love enums that are separate 
objects, that can store multiple values, and that can have 
methods that can be in their scope. Seems to me like there's no 
reason to even use enums in D. What's the point when just making 
a constant would do the same exact thing?


How to search for an enum by values and why enum items aren't unique

2016-07-19 Thread stunaep via Digitalmars-d-learn

How can I search for an enum by its values? For example I have

struct TestTraits {
int value1;
string value2;
}

enum Test : TestTraits {
TEST = TestTraits(1, "test1"),
TESTING = TestTraits(5, "test5")
}


and I have the int 5 and need to find TESTING with it.

In java I would create a SearchableEnum interface, make all 
searchable enums implement it and use this method to find them.
public static  T find(T[] vals, int 
id) {

for (T val : vals) {
if (id == val.getId()) {
return val;
}
}
return null;
}

But the way enums work in D doesn't seem to permit this.

And why on earth are different enum items with the same values 
equal to each other? Say I have an enum called DrawableShape



struct DrawableShapeTraits {
bool useAlpha;
int sideCount;
}

enum DrawableShape : DrawableShapeTraits {
RECTANGLE = DrawableShapeTraits(true, 4),
DIAMOND = DrawableShapeTraits(true, 4),
}


Now say I have some code that does this


if(shape == DrawableShape.DIAMOND)
... render a diamond
else if(shape == DrawableShape.RECTANGLE)
... render a rectangle


Now even if shape is a DrawableShape.RECTANGLE it's going to 
render a DrawableShape.DIAMOND unless I add a dummy value to 
differentiate them.


DlangUI FileDialog not working

2016-05-03 Thread stunaep via Digitalmars-d-learn
FileDialog is showing a blank white window for me. Only tested on 
windows 7 so far, but if I run dmledit, the filedialog on there 
works fine. It's weird because I am using almost exactly the same 
code.


Here is what it looks like
http://i.imgur.com/qslu7tJ.png

handleAction code:


   case ProgramActions.FolderOpen:
UIString caption;
   caption = "OPEN_DIR"c;
   FileDialog dlg = createFileDialog(caption, 
true);
   dlg.dialogResult = delegate(Dialog dlg, 
const Action result) {

   if (result.id == ACTION_OPEN.id) {
   string filename = result.stringParam;
   //TODO
   }
   };
   dlg.show();
   return true;

   case ProgramActions.FileOpen:
UIString caption;
   caption = "FILE_OPEN"c;
   FileDialog dlg = createFileDialog(caption, 
false);
   
dlg.addFilter(FileFilterEntry(UIString("D_FILES"c), "*.d"));
   
dlg.addFilter(FileFilterEntry(UIString("ALL_FILES"c), "*.*"));
   dlg.dialogResult = delegate(Dialog dlg, 
const Action result) {

   if (result.id == ACTION_OPEN.id) {
   string filename = result.stringParam;
   //TODO
   }
   };
   dlg.show();
   return true;


Here is my createFileDialog

   FileDialog createFileDialog(UIString caption, bool folder, 
bool fileMustExist = true) {

   uint flags = DialogFlag.Modal | DialogFlag.Resizable;
   if (fileMustExist)
   flags |= FileDialogFlag.FileMustExist;
   if (folder)
   flags |= FileDialogFlag.SelectDirectory;
   FileDialog dlg = new FileDialog(caption, window, null, 
flags);

   //dlg.filetypeIcons[""] = "";
   return dlg;
   }


also have this in handleActionStateRequest:


   if (!_currentBackgroundOperation)
   a.state = ACTION_STATE_ENABLED;
   else
   a.state = ACTION_STATE_DISABLE;


Re: DlangUI MouseEvent mouse delta

2016-04-26 Thread stunaep via Digitalmars-d-learn

I am currently handling it like this:


current = e.pos();
xdelta = current.x - previous.x;
ydelta = current.y - previous.y;
previous = current;

I'm just wondering if there is a built in solution that I missed.



DlangUI MouseEvent mouse delta

2016-04-26 Thread stunaep via Digitalmars-d-learn
I am trying to know how much the mouse moves when clicking down 
on a certain widget, but I can't figure out how. I noticed only a 
mouse wheel delta property and nothing for the mouse pointer x,y 
deltas since the click. I am looking to do something such as


if(e.lbutton().isDown() && !e.rbutton().isDown()) {
pitch -= e.dy();
}


Re: DlangUI translations

2016-04-24 Thread stunaep via Digitalmars-d-learn

On Sunday, 24 April 2016 at 04:49:36 UTC, thedeemon wrote:

On Saturday, 23 April 2016 at 15:44:22 UTC, stunaep wrote:
I am wondering how to use other languages and how to NOT use 
other languages.


Did you see example1 from examples folder in dlangui? It has 
two languages and allows switching at runtime via menu.


But I don't know how to change the language for ui components 
such as buttons and text. And the most important thing is 
removing "UNTRANSLATED: " from items in my list.


DlangUI translations

2016-04-23 Thread stunaep via Digitalmars-d-learn
I am wondering how to use other languages and how to NOT use 
other languages. I have all of the UI of my program translated to 
Russian, and I have the languages loading from the resource 
files, but I have no idea how to switch the language to Russian. 
Also, when adding file names to a StringListWidget, it shows 
"UNTRANSLATED: " before every file name, which needs to be 
removed.


Re: Dlang UI - making widget extend to the bounds of the window

2016-04-19 Thread stunaep via Digitalmars-d-learn

On Monday, 18 April 2016 at 07:50:28 UTC, Vadim Lopatin wrote:

On Monday, 18 April 2016 at 07:06:43 UTC, Vadim Lopatin wrote:
In TableLayout there is a bug #113 which prevents extending of 
table layout content to parent size.


For other widgets FILL_PARENT should work ok.


Issue #113 is fixed today in v0.8.8


Спасибо за помощь! Всё работает как задумано!


Re: Dlang UI - making widget extend to the bounds of the window

2016-04-16 Thread stunaep via Digitalmars-d-learn

On Saturday, 16 April 2016 at 08:20:33 UTC, stunaep wrote:

On Friday, 15 April 2016 at 10:33:35 UTC, Vadim Lopatin wrote:

[...]


I am doing that. I think it has to do with my high dpi because 
I'm using a 4k monitor.


If I use Modal window flag:

[...]

http://i.imgur.com/FJgPq8U.png

If I use resizable:

[...]

http://i.imgur.com/PsPwoSN.jpg


Actually, that is with the opengl area set to a specific size. 
Here is using fill:


Window window = Platform.instance.createWindow("DlangUI OpenGL 
Example", null, WindowFlag.Modal, 1250, 1250);

http://i.imgur.com/exAyjI0.png

   Window window = Platform.instance.createWindow("DlangUI 
OpenGL Example", null, WindowFlag.Resizable, 1250, 1250);

http://i.imgur.com/R7oxBa0.jpg

http://pastebin.com/qqbfQLvN


Re: Dlang UI - making widget extend to the bounds of the window

2016-04-16 Thread stunaep via Digitalmars-d-learn
And no matter what window size I put when using Modal or 
Fullscreen, it always shows that same sized window


Re: Dlang UI - making widget extend to the bounds of the window

2016-04-16 Thread stunaep via Digitalmars-d-learn

On Friday, 15 April 2016 at 10:33:35 UTC, Vadim Lopatin wrote:

On Friday, 15 April 2016 at 00:58:58 UTC, stunaep wrote:
I'm trying to make a gui program with dlangui, but no matter 
what I do, I cannot get widgets to fill the whole window. The 
window is resizable so I cannot just set the widths to static 
numbers.


No layoutWidth and layoutHeight set:
http://i.imgur.com/UySt30K.png

layoutWidth/Height set to fill (left widget width 300):
http://i.imgur.com/76tMIFz.png

I need these widgets to extend the width of the window because 
it is resizable

http://i.imgur.com/PiL7Y7f.png

You can see this also on DlangUI ML editor:
  fill:
http://i.imgur.com/t9DsASt.png

  wrap:
http://i.imgur.com/FoTS69g.png


  arbitrary number:
http://i.imgur.com/voiYTWZ.png


For parent VerticalLayout, set layoutWidth: fill too

VerticalLayout {
id: main;
layoutWidth: fill;
VerticalLayout {
layoutWidth: fill;
TextWidget { text: "test"; layoutWidth: fill }
}
}


I am doing that. I think it has to do with my high dpi because 
I'm using a 4k monitor.


If I use Modal window flag:
Window window = Platform.instance.createWindow("DlangUI OpenGL 
Example", null, WindowFlag.Modal, 800, 700);

http://i.imgur.com/FJgPq8U.png

If I use resizable:
Window window = Platform.instance.createWindow("DlangUI OpenGL 
Example", null, WindowFlag.Resizable, 800, 700);

http://i.imgur.com/PsPwoSN.jpg



Dlang UI - making widget extend to the bounds of the window

2016-04-14 Thread stunaep via Digitalmars-d-learn
I'm trying to make a gui program with dlangui, but no matter what 
I do, I cannot get widgets to fill the whole window. The window 
is resizable so I cannot just set the widths to static numbers.


No layoutWidth and layoutHeight set:
http://i.imgur.com/UySt30K.png

layoutWidth/Height set to fill (left widget width 300):
http://i.imgur.com/76tMIFz.png

I need these widgets to extend the width of the window because it 
is resizable

http://i.imgur.com/PiL7Y7f.png

You can see this also on DlangUI ML editor:
  fill:
http://i.imgur.com/t9DsASt.png

  wrap:
http://i.imgur.com/FoTS69g.png


  arbitrary number:
http://i.imgur.com/voiYTWZ.png


Re: overriding methods

2016-04-05 Thread stunaep via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:42:33 UTC, Adam D. Ruppe wrote:

On Tuesday, 5 April 2016 at 18:38:43 UTC, stunaep wrote:
I get a deprecation warning with @Override, but I was unable 
to find the proper way to do it.


What error message exactly are you getting and on what code?

Both styles you put there should work equally well.


I had no error on the examples I posted, only when using 
@Override previously. It just says to use override attribute 
instead of @Override


source\game\client.d(8,20): Deprecation: implicitly overriding 
base class method game.GameWindow.startThread with 
game.client.Client.startThread deprecated; add 'override' 
attribute

source\game\client.d(7,3): Error: undefined identifier 'Override'


overriding methods

2016-04-05 Thread stunaep via Digitalmars-d-learn
I get a deprecation warning with @Override, but I was unable to 
find the proper way to do it.

Am I meant to add override before the method like this?

override public void startThread(Thread t, int pri) {
   ...
}

Am I meant to wrap the entire method in override { } like this?

override {
   public void startThread(Thread t, int pri) {
   ...
   }
}


Both of them compile, so I'm wondering which to use. Is override 
{} supposed to be for adding multiple methods inside to avoid 
writing override before each method, or is putting override in 
front of the method without brackets just wrong?




Re: Decompressing bzip2

2016-04-04 Thread stunaep via Digitalmars-d-learn

On Monday, 4 April 2016 at 08:26:07 UTC, Thomas Brix Larsen wrote:

On Sunday, 3 April 2016 at 02:03:29 UTC, stunaep wrote:
I am trying to use the bzip2 bindings that are available on 
code.dlang.org/packages, but I am having a really hard time 
using it due to the pointers. It needs to be an array once 
it's decompressed.


Here is what I have:

import std.stdio;
import bzlib;

void main(string[] args)
{

   File f = File("./test.bz2");
   ubyte[] data = new ubyte[f.size];
  f.rawRead(data);
   writeln(data);

   ubyte* output;
   uint avail_out;
   bz_stream* stream = new bz_stream();
   stream.avail_out = avail_out;
   stream.next_out = output;

   int init_error = BZ2_bzDecompressInit(stream, 0, 0);
   int bzipresult = BZ2_bzDecompress(stream);

   stream.avail_in = cast(uint) data.length;
   stream.next_in = cast(ubyte*) data;

   bzipresult = BZ2_bzDecompress(stream);
   int read = stream.total_out_lo32;
   BZ2_bzDecompressEnd(stream);
   delete stream;
   writeln(output);
}


It's not working at all so any help would be very much 
appreciated.


You need to allocate the output array:

import std.stdio;
import bzlib;

void main(string[] args)
{
File f = File("./test.bz2");
auto data = new ubyte[](f.size);
f.rawRead(data);
writeln(data);

auto output = new ubyte[](4096);
scope stream = new bz_stream();
stream.avail_out = cast(uint)output.length;
stream.next_out = output.ptr;

int init_error = BZ2_bzDecompressInit(stream, 0, 0);
int bzipresult = BZ2_bzDecompress(stream);

stream.avail_in = cast(uint)data.length;
stream.next_in = data.ptr;

bzipresult = BZ2_bzDecompress(stream);
int read = stream.total_out_lo32;
BZ2_bzDecompressEnd(stream);
writeln(output);
}


Can you please explain what the scope keyword does and if there 
is any benefit to using

"new byte[](size)" over "new byte[size]" with a 1D array?


string to uppercase

2016-04-02 Thread stunaep via Digitalmars-d-learn
Is there any easy way to convert a string to uppercase? I tried 
s.asUpperCase, but it returns a ToCaserImpl, not a string, and it 
cant be cast to string. I also tried toUpper but it wasnt working 
with strings


Decompressing bzip2

2016-04-02 Thread stunaep via Digitalmars-d-learn
I am trying to use the bzip2 bindings that are available on 
code.dlang.org/packages, but I am having a really hard time using 
it due to the pointers. It needs to be an array once it's 
decompressed.


Here is what I have:

import std.stdio;
import bzlib;

void main(string[] args)
{

   File f = File("./test.bz2");
   ubyte[] data = new ubyte[f.size];
  f.rawRead(data);
   writeln(data);

   ubyte* output;
   uint avail_out;
   bz_stream* stream = new bz_stream();
   stream.avail_out = avail_out;
   stream.next_out = output;

   int init_error = BZ2_bzDecompressInit(stream, 0, 0);
   int bzipresult = BZ2_bzDecompress(stream);

   stream.avail_in = cast(uint) data.length;
   stream.next_in = cast(ubyte*) data;

   bzipresult = BZ2_bzDecompress(stream);
   int read = stream.total_out_lo32;
   BZ2_bzDecompressEnd(stream);
   delete stream;
   writeln(output);
}


It's not working at all so any help would be very much 
appreciated.




Re: Something wrong with GC

2016-03-22 Thread stunaep via Digitalmars-d-learn

On Monday, 21 March 2016 at 07:55:39 UTC, thedeemon wrote:

On Sunday, 20 March 2016 at 07:49:17 UTC, stunaep wrote:
The gc throws invalid memory errors if I use Arrays from 
std.container.


Those arrays are for RAII-style deterministic memory release, 
they shouldn't be freely mixed with GC-allocated things. What 
happens here is while initializing Array sees it got some GC-ed 
value type (strings), so it tells GC to look after those 
strings. When your program ends runtime does a GC cycle, finds 
your Test object, calls its destructor that calls Array 
destructor that tries to tell GC not to look at its data 
anymore. But during a GC cycle it's currently illegal to call 
such GC methods, so it throws an error.
Moral of this story: try not to store "managed" (collected by 
GC) types in Array and/or try not to have Arrays inside 
"managed" objects. If Test was a struct instead of a class, it 
would work fine.


So what am I do to? Any other language can do such a thing so 
trivially... I also run into the same problem with 
emsi_containers TreeMap. It is imperative that I can store data 
such as



public class Example1 {

private File file;

public this(File f) {
this.file = f;  
}
}


or


public class Example2 {

private int one;
private int two;

public this(int one, int two) {
this.one = one;
this.two = two;
}
}


in a tree map and list of some sort. Neither of the above work 
whether they are classes or structs and it's starting to become 
quite bothersome...




Something wrong with GC

2016-03-20 Thread stunaep via Digitalmars-d-learn
The gc throws invalid memory errors if I use Arrays from 
std.container.

For example, this throws an InvalidMemoryOperationError:

import std.stdio;
import std.container;

void main() {
new Test();
}

class Test {

private Array!string test = Array!string();

this() {
test.insert("test");
writeln(test[0]);
}
}


and here's the stack trace

	testt.exe!app.onInvalidMemoryOperationError( void* _param_0 ) 
Line 21	D


testt.exe!_D2gc2gc2GC134__T9runLockedS57_D2gc2gc2GC11removeRangeMFNbNiPvZ2goFNbNiPS2gc2gc3GcxPvZvS19_D2gc2gc9otherTimelS19_D2gc2gc9numOtherslTPS2gc2gc3GcxTPvZ9runLockedMFNbNiKPS2gc2gc3GcxKPvZv()
 + 0x52 bytes D
testt.exe!_D2gc2gc2GC11removeRangeMFNbNiPvZv() + 0x29 bytes D
testt.exe!gc_removeRange() + 0x21 bytes D
	testt.exe!_D4core6memory2GC11removeRangeFNbNixPvZv() + 0xd 
bytes	D

testt.exe!std.container.array.Array!string.Array.Payload.~this() Line 
229 + 0x1f bytes  D

testt.exe!object._destructRecurse!(std.container.array.Array!string.Array.Payload)._destructRecurse(
 std.container.array.Array!string.Array.Payload* s ) Line 2409 + 0xd bytes  D

testt.exe!object.destroy!(std.container.array.Array!string.Array.Payload).destroy(
 std.container.array.Array!string.Array.Payload* obj ) Line 2778 + 0xd bytes  D

testt.exe!std.typecons.RefCounted!(std.container.array.Array!string.Array.Payload,
 cast(RefCountedAutoInitialize)0).RefCounted.~this() Line 4864 + 0x10 bytes   D
	testt.exe!std.container.array.Array!string.Array.~this() Line 
198 + 0x15 bytes	D

testt.exe!app.Test.~this() Line 10 + 0x19 bytes D
testt.exe!rt_finalize2() + 0xb8 bytes   D
testt.exe!rt_finalizeFromGC() + 0x24 bytes  D
testt.exe!_D2gc2gc3Gcx5sweepMFNbZm() + 0x3a3 bytes  D
testt.exe!_D2gc2gc3Gcx11fullcollectMFNbbZm() + 0x57a bytes  D

testt.exe!_D2gc2gc2GC86__T9runLockedS56_D2gc2gc2GC18fullCollectNoStackMFNbZ2goFNbPS2gc2gc3GcxZmTPS2gc2gc3GcxZ9runLockedMFNbKPS2gc2gc3GcxZm()
 + 0x72 bytes   D
	testt.exe!_D2gc2gc2GC18fullCollectNoStackMFNbZv() + 0x11 
bytes	D

testt.exe!gc_term() + 0x14 bytesD
testt.exe!rt_term() + 0x9e bytesD
	testt.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv() 
+ 0x4d bytes	D

testt.exe!_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv() + 
0x6f bytesD
testt.exe!_d_run_main() + 0x419 bytes   D
	testt.exe!__entrypoint.main( int argc, char** argv ) + 0x22 
bytes	D

testt.exe!__tmainCRTStartup() Line 255 + 0x12 bytes D
kernel32.dll!76cd59cd   
ntdll.dll!76f0b891  


Not sure what to do here


Tracing InvalidMemoryOperationError

2016-03-15 Thread stunaep via Digitalmars-d-learn
I need to find the source of this InvalidMemoryOperationError. I 
tried loading the project in visuald but it wont break on the 
error.

I also tried adding

extern(C) void onInvalidMemoryOperationError(void*) {
  asm { int 3; }
}


building with


dub build --build=debug --arch=x86_64


and then using gdb, but it says "(no debugging symbols found)" 
and does this



(gdb) r
Starting program: program.exe
[New Thread 8144.0xf00]
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00013f7a5f99 in ?? ()
(gdb) where
#0  0x00013f7a5f99 in ?? ()
Backtrace stopped: previous frame identical to this frame 
(corrupt stack?)


Re: std.stdio.File.seek error

2016-03-14 Thread stunaep via Digitalmars-d-learn

On Monday, 14 March 2016 at 13:33:36 UTC, Mike Parker wrote:

On Monday, 14 March 2016 at 09:57:19 UTC, stunaep wrote:

It looks like _fseeki64 is in the nightly build but not dmd 
2.070.2; However, the nightly build says std.stdio and 
std.conv are deprecated and I cant use them.


I think you may be misinterpreting the error message. There was 
a change recently in how imports are handled in certain cases 
and that may be what you're seeing. What exactly is the error 
message?


I'm on my phone but I think It said something like
Deprecation: module std.stdio not accessible from here. Try 
import static std.stdio


Re: std.stdio.File.seek error

2016-03-14 Thread stunaep via Digitalmars-d-learn

On Monday, 14 March 2016 at 07:15:01 UTC, Nicholas Wilson wrote:

On Monday, 14 March 2016 at 05:24:48 UTC, stunaep wrote:
On Monday, 14 March 2016 at 03:07:05 UTC, Nicholas Wilson 
wrote:

[...]


I'm currently on windows 7. The code you gave me prints 022. 
It's weird because it always tries to convert longs to ints 
and I think that is weird because the function uses a c_long.

[...]


It wont even compile if I try giving it a long

[...]


I also tried giving it a c_long, but this line

[...]

gives this error for some reason...

[...]


It's like c_longs are not longs at all...


c_long maps to the target long which evidently is not 64-bit on 
win7

meaning you can't seek longer than int.max.
 if you cant't find _fseeki64 try looking in the windows 
section.

Glad you got it working on arch.

Nic


It looks like _fseeki64 is in the nightly build but not dmd 
2.070.2; However, the nightly build says std.stdio and std.conv 
are deprecated and I cant use them.


Re: std.stdio.File.seek error

2016-03-14 Thread stunaep via Digitalmars-d-learn
Just tested it on arch linux 64 bit and it works with no problem 
seeking to positions over 2^31-1


Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn
It seems my lacking knowledge of C has gotten the best of me and 
longs in C only have a signed int range? It looks like in C, 
fseeko() is needed on linux and _fseeki64() is needed on windows, 
but I dont see either of these in stdc.stdio.





Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Monday, 14 March 2016 at 03:07:05 UTC, Nicholas Wilson wrote:

On Monday, 14 March 2016 at 00:12:46 UTC, stunaep wrote:
On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson 
wrote:

[...]


I'm on 64 bit but it needs to work on both. It works for 
anything between 0 and 2147483647.



[...]


that throws an error before reaching f.tell()


[...]


Also, seeking relative to the current position throws the same 
error as in the original post if it's over max signed int.



[...]


Hmm. If you're getting an errno exception ( as opposed to a 
conv) I really don't
think that theres anything you can do about it, as its a 
problem with the C standard

lib. What OS/version are you running?

what does the equivalent in C give you.
i.e.

FILE* f = fopen(...,"r");
fseek(f,0,SEEK_END);
printf("%ld",ftell(f));
printf("%d",errno);


I'm currently on windows 7. The code you gave me prints 022. It's 
weird because it always tries to convert longs to ints and I 
think that is weird because the function uses a c_long.

int fseek(FILE* stream, c_long offset, int whence)


It wont even compile if I try giving it a long
Error: function core.stdc.stdio.fseek (shared(_iobuf)* stream, 
int offset, int whence) is not callable using argument types 
(shared(_iobuf)*, long, int)


I also tried giving it a c_long, but this line

c_long test = 2147483649;

gives this error for some reason...
Error: cannot implicitly convert expression (2147483649L) of 
type long to int


It's like c_longs are not longs at all...


Re: std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Sunday, 13 March 2016 at 12:21:11 UTC, Nicholas Wilson wrote:

On Sunday, 13 March 2016 at 10:32:41 UTC, stunaep wrote:
I have a very large file I need to read data from at certain 
positions, but I have run into this error
std.conv.ConvOverflowException@std\conv.d(1328): Conversion 
positive overflow
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so it 
must be able to read data at positions that high.


are you on a 32 or 64 bit system?
You could try 2 or more consecutive relative seeks in place of 
an absolute seek.

i.e.
File f = ... ;
f.seek(173445340 , SEEK_SET);
f.seek(173445340 , SEEK_REL);
also what does
f.seek(0,SEEK_END);
writeln(f.tell());
print?


I'm on 64 bit but it needs to work on both. It works for anything 
between 0 and 2147483647.



f.seek(0,SEEK_END);
writeln(f.tell());


that throws an error before reaching f.tell()

std.exception.ErrnoException@std\stdio.d(920): Could not seek 
in file `./file.dat' (Invalid argument)


0x00013FE67868 in @safe bool 
std.exception.errnoEnforce!(bool, "std\stdio.d", 
920uL).errnoEnforce(bool, lazy immutable(char)[])
0x00013FE4E7D3 in @trusted void std.stdio.File.seek(long, 
int)


Also, seeking relative to the current position throws the same 
error as in the original post if it's over max signed int.



f.seek(2147483647, SEEK_SET);
writeln(f.tell()); // prints 2147483647
f.seek(4, SEEK_CUR); // throws error


std.stdio.File.seek error

2016-03-13 Thread stunaep via Digitalmars-d-learn
I have a very large file I need to read data from at certain 
positions, but I have run into this error
std.conv.ConvOverflowException@std\conv.d(1328): Conversion 
positive overflow
when seeking to 6346890680. Seeking to smaller values such as 
3580720 work with no problem. The file is well over 8GB, so it 
must be able to read data at positions that high.


Re: Is there a sorted map?

2016-03-13 Thread stunaep via Digitalmars-d-learn

On Sunday, 13 March 2016 at 08:33:43 UTC, Jonathan M Davis wrote:
On Sunday, March 13, 2016 02:35:27 stunaep via 
Digitalmars-d-learn wrote:

[...]


The closest that we have in Phobos at the moment is 
RedBlackTree in std.container. Its API is geared towards sets, 
not maps, but you can get it to work as a map if you define the 
comparison functions appropriately. Red-black trees are 
typically used for both sets and maps, so using RedBlackTree in 
that manner is pretty normal from an implementation 
perspective, but there's no question that what we really need 
is a wrapper around it that provides a map API, since it's not 
terribly user-friendly to use the set API for a map, much as it 
works.


[...]


Wow, thanks!


Is there a sorted map?

2016-03-12 Thread stunaep via Digitalmars-d-learn
Is there any sorted map in D? I need a map and I need to be able 
to get the highest key in the map. In java I would use a TreeMap 
and use map.lastKey(), but since associative arrays are not 
sorted that would be O(n). I know about RedBlackTree, but that's 
a set and it must be a map.


Re: BZ2 library

2016-03-12 Thread stunaep via Digitalmars-d-learn

On Saturday, 12 March 2016 at 10:10:44 UTC, Basile B. wrote:

On Saturday, 12 March 2016 at 09:53:36 UTC, stunaep wrote:

[...]


"dflags" : ["lib\\libbzip2.lib"] is only if you want to compile 
as 32 bit AND in OMF, so the -m32mscoff switch must NOT be set 
(I see that someone else explained you how to compile using the 
coff object format, which is not the same thing as I've 
explained before)


so in the config you should have something like that

"configurations" :
[
{
  "name" : "win32omf",
  "dflags" : ["lib\\omf32\\libbzip2.lib"] // made with dmc 
or converted

},
{
  "name" : "win64coff",
  "dflags" : ["lib\\coff64\\libbzip2.lib", "-m64"] // made 
with gcc

},
]


Thanks for that. The other issue I had was solved because I wasnt 
using runtime library /MT when compiling the .lib.


Re: BZ2 library

2016-03-12 Thread stunaep via Digitalmars-d-learn

On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:

 [...]


On Saturday, 12 March 2016 at 09:04:08 UTC, stunaep wrote:

On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:

[...]


If I do "dflags" : ["lib/libbzip2.lib"] as Basile B. suggested 
instead of pragma, I get the same error on x86_64 as I do on x86


I think "dflags" : ["lib/libbzip2.lib"] is not loading anything 
at all because the same thing happens if I delete the lib file


Re: BZ2 library

2016-03-12 Thread stunaep via Digitalmars-d-learn

On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:

[...]


If I do "dflags" : ["lib/libbzip2.lib"] as Basile B. suggested 
instead of pragma, I get the same error on x86_64 as I do on x86


Re: BZ2 library

2016-03-11 Thread stunaep via Digitalmars-d-learn

On Saturday, 12 March 2016 at 06:07:25 UTC, Mike Parker wrote:

[...]


I used visual studio 2013 to build the libraries

With dflag -m64 and dub flag --arch=x86_64, this happens


Running: dub build --arch=x86_64

## Warning for package rsdlib ##

The following compiler flags have been specified in the 
package description
file. They are handled by DUB and direct use in packages is 
discouraged.
Alternatively, you can set the DFLAGS environment variable to 
pass custom flags

to the compiler, or use one of the suggestions below:

-m64: Use --arch=x86/--arch=x86_64 to specify the target 
architecture


Performing "debug" build using dmd for x86_64.
rsdlib ~master: building configuration "application"...
Linking...
MSVCRT.lib(MSVCR120.dll) : error LNK2005: exit already 
defined in LIBCMT.lib(crt0dat.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: free already 
defined in LIBCMT.lib(free.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: malloc already 
defined in LIBCMT.lib(malloc.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: __iob_func already 
defined in LIBCMT.lib(_file.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: fclose already 
defined in LIBCMT.lib(fclose.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: ferror already 
defined in LIBCMT.lib(feoferr.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: fflush already 
defined in LIBCMT.lib(fflush.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: fprintf already 
defined in LIBCMT.lib(fprintf.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: fread already 
defined in LIBCMT.lib(fread.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: fwrite already 
defined in LIBCMT.lib(fwrite.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: ungetc already 
defined in LIBCMT.lib(ungetc.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: isdigit already 
defined in LIBCMT.lib(_ctype.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: _fdopen already 
defined in LIBCMT.lib(fdopen.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: _fileno already 
defined in LIBCMT.lib(fileno.obj)
MSVCRT.lib(MSVCR120.dll) : error LNK2005: _setmode already 
defined in LIBCMT.lib(setmode.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with 
use of other libs; use /NODEFAULTLIB:library

.dub\build\application-debug-windows-x86_64-dmd_2070-F2AB32EEAA78A29A3AA6010749D38D4A\rsdlib.exe : fatal error LNK1169: one or more multiply defined symbols found

--- errorlevel 1169
dmd failed with exit code 1169.




and with dflag -m32mscoff, this happens

Performing "debug" build using dmd for x86.
rsdlib ~master: building configuration "application"...
Linking...
rsdlib.obj : error LNK2019: unresolved external symbol 
_BZ2_bzDecompressInit referenced in function 
_D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container
rsdlib.obj : error LNK2019: unresolved external symbol 
_BZ2_bzDecompress referenced in function 
_D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container
rsdlib.obj : error LNK2019: unresolved external symbol 
_BZ2_bzDecompressEnd referenced in function 
_D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container

.dub\build\application-debug-windows-x86-dmd_2070-E301E842F2B5FA1A3A9D79D8EE34C4E8\rsdlib.exe : fatal error LNK1120: 3 unresolved externals

--- errorlevel 1120
dmd failed with exit code 1120.


BZ2 library

2016-03-11 Thread stunaep via Digitalmars-d-learn
I'm really having a hard time using bzp (and later I need gzip 
and lzma).


So I added this bzip2 D interface to my DUB dependencies
"dependencies" : {
"bzip2": "~>0.1.0"
}

I downloaded the bzip2 source code and compiled it for windows 
32bit (will 64 bit work with dmd2?). Then I used coffimplib.exe 
to convert the .lib file from coff to omf. From there I added 
this code:

pragma(lib, "libbzip2OMF.lib");

Now when I run the program it terminates with exit code 
-1073741515 and will not print or do anything written in the 
program. Am I doing the right things? This is the first time I've 
ever done this and I was unable to find any useful help on this 
subject, so some help would be very much appreciated. Thanks.