Re: SegFault with HibernateD

2018-01-11 Thread Mike Parker via Digitalmars-d-learn
On Friday, 12 January 2018 at 05:24:52 UTC, Venkat wrote: I get a SegFault with the main method below which uses HibernateD . The second main method which uses ddbc just works fine. What is wrong with the first main method ? I have attached the error at the bottom although I don't think it says

Re: Voldemort type for mixin template.

2018-01-11 Thread ChangLong via Digitalmars-d-learn
On Thursday, 11 January 2018 at 21:30:43 UTC, aliak wrote: On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote: When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemor

SegFault with HibernateD

2018-01-11 Thread Venkat via Digitalmars-d-learn
I get a SegFault with the main method below which uses HibernateD . The second main method which uses ddbc just works fine. What is wrong with the first main method ? I have attached the error at the bottom although I don't think it says much. This method uses HibernateD int main() {

Re: Why is this valued zeroed?

2018-01-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 11, 2018 14:07:18 Ali Çehreli via Digitalmars-d-learn wrote: > On 01/11/2018 12:21 PM, Marc wrote: > > I stuck at this and can't figure out the reason why the value of the > > variable ds is 0 when I do this: startTime = MonoTime.currTime; > > It's not clear which of the two

__gshared as part of alias

2018-01-11 Thread Nicholas Wilson via Digitalmars-d-learn
Is there a way to make __gshared part of an alias? as in enum AddrSpace : uint { Private = 0, Global = 1, Shared = 2, Constant = 3, Generic = 4, } struct Variable(AddrSpace as, T) { T val; alias val this; } alias Global(T) = __gshared Variable!(AddrSpace.Glob

Problem with function taking variable number of arguments with -m64

2018-01-11 Thread tipdbmp via Digitalmars-d-learn
// // rdmd -m64 foo.d // module va_arg_x64_windows; void foo(void* a, void* b, void *c, void* d, ...) { import core.vararg : va_arg; import std.stdio : writeln; foreach (arg; _arguments) { if (arg == typeid(int)) { int x = va_arg!(int)(_argptr); writel

Re: Interfacing with webcam

2018-01-11 Thread thedeemon via Digitalmars-d-learn
On Thursday, 11 January 2018 at 17:02:58 UTC, Amorphorious wrote: Looking for something similar. I simply need to show the video of a camera and be able to do to basics like rotation, crop, etc. On which platform? On Windows I've successfully used DirectShow, I can show an example of working

Re: Druntime: Changing the underlying C Standard Library

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 12 January 2018 at 03:21:15 UTC, Sebastian Trent wrote: I'm writing an operating system in D for some exotic hardware. I understand the D runtime environment depends on a C stdlib being available (at compile time or run time?) both As a consequence of the hardware, I need to use ou

Druntime: Changing the underlying C Standard Library

2018-01-11 Thread Sebastian Trent via Digitalmars-d-learn
Hello, I'm writing an operating system in D for some exotic hardware. I understand the D runtime environment depends on a C stdlib being available (at compile time or run time?) As a consequence of the hardware, I need to use our own C std lib for the operating system. How can I set about di

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: $ dmd crash.d $ ./crash Nicholas Wilson is right that you can use = "" to work around it, but with strings, null is supposed to behave the same way. And this gives different (each wrong) behavior on -m32 vs -m64, which leads me to be

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread ag0aep6g via Digitalmars-d-learn
On 01/12/2018 02:45 AM, Nicholas Wilson wrote: because you don't initialise `s` in    string toString ()    {   string s;   return s;    } so it defaults to `string s = null;` thus giving a segfault. try `string s = "";` instead. A null string is a perfectly fine empty string. Prin

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 12 January 2018 at 01:45:37 UTC, Nicholas Wilson wrote: so it defaults to `string s = null;` thus giving a segfault. null and "" are basically the same for strings. that's not the problem.

Re: Rvalue references

2018-01-11 Thread Tony via Digitalmars-d-learn
On Monday, 8 January 2018 at 23:31:27 UTC, Jonathan M Davis wrote: auto foo(T)(auto ref T t) { return t; } foo(42); will result in foo being instantiated as int foo(int t) { return t; } whereas int i; foo(i); will result in foo being instantiated as int foo(ref int t) { retur

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: crash.d ``` import std.stdio; union U { float f; int i; string toString () { string s; return s; } } void main () { U u; writeln (u); } ``` $ dmd crash.d $ ./crash because you don't initialise `s` in

union/toString: crash/segfault: What's happening here?

2018-01-11 Thread kdevel via Digitalmars-d-learn
crash.d ``` import std.stdio; union U { float f; int i; string toString () { string s; return s; } } void main () { U u; writeln (u); } ``` $ dmd crash.d $ ./crash std.exception.ErrnoException@/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(2776): (Bad add

Can you introspect predicate arity and if it's an equality predicate?

2018-01-11 Thread aliak via Digitalmars-d-learn
Hi, so basically is there a way to: void func(alias pred = null, Range)(Range range) { // 1) check if pred(ElementType!Range.init, ElementType!Range.init) is equality // 2) check if isUnary!pred // 3) check if isBinary!pred } I think maybe the isUnary or isBinary may not work unless it

Re: How to move an associative array between modules?

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 11 January 2018 at 23:20:44 UTC, WhatMeWorry wrote: When I simply move the array out of main() but still in app.d, the compiler returns Error: expression ["SCRATCH":Track("scratch.wav", cast(Sound)1, 0, null),... is not a constant. Can I use "static if" or "static this()", or "mi

How to move an associative array between modules?

2018-01-11 Thread WhatMeWorry via Digitalmars-d-learn
I've built a sound.d module with lots data types, free functions (initAndOpenSound() loadSound()), and enums etc. In my main/app.d module, I've created the the following associative array: void main(string[] argv) { initAndOpenSound(); Track[string] tracks = [ "SCRATCH"

Re: Why is this valued zeroed?

2018-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 01/11/2018 12:21 PM, Marc wrote: > I stuck at this and can't figure out the reason why the value of the > variable ds is 0 when I do this: startTime = MonoTime.currTime; It's not clear which of the two statements you're talking about. >> http.onProgress = (size_t dltotal, size_t dlnow, >>

Re: calloc for std.experimental.allocator

2018-01-11 Thread MrSmith via Digitalmars-d-learn
On Thursday, 11 January 2018 at 21:09:01 UTC, Nordlöw wrote: Is there no equivalent of `calloc()` for `std.experimental.allocator`, something like Allocator.zeroAllocate(size_t numberOfElements) ? http://dpldocs.info/experimental-docs/std.experimental.allocator.makeArray.4.html

Re: Voldemort type for mixin template.

2018-01-11 Thread aliak via Digitalmars-d-learn
On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote: When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemort type ? fake code: mix template TypeX () { alias Th

calloc for std.experimental.allocator

2018-01-11 Thread Nordlöw via Digitalmars-d-learn
Is there no equivalent of `calloc()` for `std.experimental.allocator`, something like Allocator.zeroAllocate(size_t numberOfElements) ?

Re: Why is this valued zeroed?

2018-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/18 3:21 PM, Marc wrote: I stuck at this and can't figure out the reason why the value of the variable ds is 0 when I do this: startTime = MonoTime.currTime; if I remove that statement, the value of ds isn't zeroed, it has the actual number of seconds. But I can't figure out, ds is of in

Why is this valued zeroed?

2018-01-11 Thread Marc via Digitalmars-d-learn
I stuck at this and can't figure out the reason why the value of the variable ds is 0 when I do this: startTime = MonoTime.currTime; if I remove that statement, the value of ds isn't zeroed, it has the actual number of seconds. But I can't figure out, ds is of integer type and such, it is copie

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/18 12:41 PM, tipdbmp wrote: Appender is able to do this: It seems that Appender allocates its own private data: private struct Data {     size_t capacity;     Unqual!T[] arr;     bool canExtend = false; } private Data* _data; _data = new Data; But hopefully its bug free u

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread tipdbmp via Digitalmars-d-learn
Appender is able to do this: It seems that Appender allocates its own private data: private struct Data { size_t capacity; Unqual!T[] arr; bool canExtend = false; } ... private Data* _data; ... _data = new Data; But hopefully its bug free unlike what I posted (missing `T.sizeof *`

Re: How to test a DUB-based library during development?

2018-01-11 Thread jmh530 via Digitalmars-d-learn
On Thursday, 11 January 2018 at 14:59:18 UTC, DanielG wrote: Ah, thank you! I replaced: "libs-windows-x86-dmd" with: "sourceFiles-windows-x86-dmd" (and added a .lib suffix) and now everything works as expected. I see now that I was using "libs" improperly. It seems more for system-

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/18 6:21 AM, tipdbmp wrote: string push_stuff(char[] buf, int x) {     if (x == 1) {     buf ~= 'A';     buf ~= 'B';     buf ~= 'C';     return cast(string) buf[0 .. 3];     }     else {     buf ~= 'A';     buf ~= 'B';     return cast(string) buf[0 ..

Re: new int[]

2018-01-11 Thread Dukc via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 23:08:28 UTC, Luís Marques wrote: void main() { int[]* x = &[[1, 2, 3]][0]; int[]* x2 = [[1, 2, 3]].ptr; /* same */ } That's an interesting solution. I'm not sure which one I prefer, the wrapper or this one. Still... I feel like the language should just

Re: Interfacing with webcam

2018-01-11 Thread Amorphorious via Digitalmars-d-learn
On Tuesday, 30 September 2014 at 03:41:20 UTC, Kyle wrote: Hi, Has anyone successfully used D to capture images from a webcam? Something like what you can do with OpenCV or pygame's camera API? Any idea how I can do this without having to know a lot of complex stuff? Thanks! Looking for som

Re: Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Seb via Digitalmars-d-learn
On Thursday, 11 January 2018 at 13:18:47 UTC, Simen Kjærås wrote: On Thursday, 11 January 2018 at 12:32:54 UTC, Per Nordlöw wrote: Is this an ok implementation: enum bool isNogc(alias fun) = (isCallable!fun && (functionAttributes!fun &

Re: How to test a DUB-based library during development?

2018-01-11 Thread DanielG via Digitalmars-d-learn
Ah, thank you! I replaced: "libs-windows-x86-dmd" with: "sourceFiles-windows-x86-dmd" (and added a .lib suffix) and now everything works as expected. I see now that I was using "libs" improperly. It seems more for system-wide libraries / things in the library search path, not to be

Re: How to test a DUB-based library during development?

2018-01-11 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 11 January 2018 at 14:22:50 UTC, DanielG wrote: If I manually override "libs-windows-x86-dmd" in the example's dub.json, it links despite the error, but if possible I would like users of my library to not have to concern themselves with linkage issues. vibe.d seems to do it suc

Re: How to test a DUB-based library during development?

2018-01-11 Thread DanielG via Digitalmars-d-learn
Thank you very much, very helpful! I'm currently attempting the (A) suggestion, but find that dub isn't fixing up the relative path to one of the parent's prerequisite libraries. In the parent: "libs-windows-x86-dmd": ["./lib/32/dmd/SomeLibrary"] This causes a warning when building the n

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread tipdbmp via Digitalmars-d-learn
Have you checked what push_stuff actually returns with those inputs? Right, we get [0xFF, 0xFF, 'A'] and [0xFF, 0xFF]. I think the following is a pretty easy workaround though: alias usize = size_t; struct Push_Buf(T, usize stack_size) { T[stack_size] stack_buf; T[] heap_buf; usize

Re: Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 11 January 2018 at 12:32:54 UTC, Per Nordlöw wrote: Is this an ok implementation: enum bool isNogc(alias fun) = (isCallable!fun && (functionAttributes!fun & FunctionAttribute.nogc)); @safe pure nothrow @nogc unittest {

Re: How to test a DUB-based library during development?

2018-01-11 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 11 January 2018 at 12:27:27 UTC, DanielG wrote: Is there a simple example that shows how to test the library during development, before publishing (ie, before being able to add it as a dependency to another project)? I guess I'm just asking, what's the convention here? Do I creat

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 11, 2018 11:21:08 tipdbmp via Digitalmars-d-learn wrote: > string push_stuff(char[] buf, int x) { > if (x == 1) { > buf ~= 'A'; > buf ~= 'B'; > buf ~= 'C'; > return cast(string) buf[0 .. 3]; > } > else { > buf ~= 'A';

Re: Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 11 January 2018 at 12:24:36 UTC, Nordlöw wrote: How do I check whether an aggregate member function (call for a specific argument) is @nogc or not? I want to check whether Allocator.allocate(1) (for a any Allocator) is @nogc or not? Is https://dlang.org/phobos/std_traits.ht

How to test a DUB-based library during development?

2018-01-11 Thread DanielG via Digitalmars-d-learn
I want to create a library and eventually publish it via the DUB registry. Is there a simple example that shows how to test the library during development, before publishing (ie, before being able to add it as a dependency to another project)? I guess I'm just asking, what's the convention h

Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Nordlöw via Digitalmars-d-learn
How do I check whether an aggregate member function (call for a specific argument) is @nogc or not? I want to check whether Allocator.allocate(1) (for a any Allocator) is @nogc or not? Is https://dlang.org/phobos/std_traits.html#hasFunctionAttributes the way to do it?

Re: Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 11 January 2018 at 11:21:08 UTC, tipdbmp wrote: string push_stuff(char[] buf, int x) { if (x == 1) { buf ~= 'A'; buf ~= 'B'; buf ~= 'C'; return cast(string) buf[0 .. 3]; } else { buf ~= 'A'; buf ~= 'B'; return cast(s

Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread tipdbmp via Digitalmars-d-learn
string push_stuff(char[] buf, int x) { if (x == 1) { buf ~= 'A'; buf ~= 'B'; buf ~= 'C'; return cast(string) buf[0 .. 3]; } else { buf ~= 'A'; buf ~= 'B'; return cast(string) buf[0 .. 2]; } } void foo() { { char[2

Is it possible to append to a local buffer without reallocating?

2018-01-11 Thread tipdbmp via Digitalmars-d-learn
string push_stuff(char[] buf, int x) { if (x == 1) { buf ~= 'A'; buf ~= 'B'; buf ~= 'C'; return cast(string) buf[0 .. 3]; } else { buf ~= 'A'; buf ~= 'B'; return cast(string) buf[0 .. 2]; } } void foo() { { char[2

Re: Getting a Type from TypeInfo / Getting Variant Type

2018-01-11 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 11 January 2018 at 08:59:01 UTC, Chirs Forest wrote: I'm using std.variant.Variant to hold a value of unknown type (not a string, could be a numeric type or a container holding multiple numeric types). I'm trying to retrieve this value with .get!T but I need the type to do that...

Re: Getting a Type from TypeInfo / Getting Variant Type

2018-01-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 11, 2018 08:59:01 Chirs Forest via Digitalmars-d-learn wrote: > I'm using std.variant.Variant to hold a value of unknown type > (not a string, could be a numeric type or a container holding > multiple numeric types). I'm trying to retrieve this value with > .get!T but I need t

Getting a Type from TypeInfo / Getting Variant Type

2018-01-11 Thread Chirs Forest via Digitalmars-d-learn
I'm using std.variant.Variant to hold a value of unknown type (not a string, could be a numeric type or a container holding multiple numeric types). I'm trying to retrieve this value with .get!T but I need the type to do that... .type gives me TypeInfo, but that's not a type so I'm not sure how

Voldemort type for mixin template.

2018-01-11 Thread ChangLong via Digitalmars-d-learn
When I try add some sub type for struct with mixin template, seems there is no way to hidden the private type. Is there a way to hidden type from mix template like Voldemort type ? fake code: mix template TypeX () { alias This = typeof(this); static struct Unique { This* _ptr