Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Jeremy DeHaan via Digitalmars-d-learn
I'll be trying to narrow it down even more tomorrow, but I was hoping somone here might have some insight into this weird issue I am having. I have a dynamic array of shorts that I had been trying to append to (capturing sound data). I kept getting a segfault when doing the append, and have

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Jeremy DeHaan via Digitalmars-d-learn
I should also mention that this is on Linux. I haven't tried on OSX or Windows yet.

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Paul via Digitalmars-d-learn
On Saturday, 13 December 2014 at 08:59:19 UTC, Jeremy DeHaan wrote: for(int i = 0; isamples.length; ++i) m_samples.length +=1; You are testing i against an ever-increasing limit aren't you, so it's an infinite loop.

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Jeremy DeHaan via Digitalmars-d-learn
On Saturday, 13 December 2014 at 09:24:51 UTC, Paul wrote: On Saturday, 13 December 2014 at 08:59:19 UTC, Jeremy DeHaan wrote: for(int i = 0; isamples.length; ++i) m_samples.length +=1; You are testing i against an ever-increasing limit aren't you, so it's an infinite

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Artem Tarasov via Digitalmars-d-learn
On Saturday, 13 December 2014 at 09:24:51 UTC, Paul wrote: You are testing i against an ever-increasing limit aren't you, so it's an infinite loop. Read more carefully. samples is unmodified, it's m_samples whose length is changed.

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Artem Tarasov via Digitalmars-d-learn
On Saturday, 13 December 2014 at 08:59:19 UTC, Jeremy DeHaan wrote: I'll be trying to narrow it down even more tomorrow, but I was hoping somone here might have some insight into this weird issue I am having. Could you upload the code to somewhere? With only a small snippet, it's hard to get

Re: The package feature is ignored when the file name is package.di

2014-12-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 13, 2014 02:34:21 Jeremy DeHaan via Digitalmars-d-learn wrote: Is this on purpose? Granted, I almost never use interface files, but I had a whim to use them for what I was working on today. Everything worked fine when I renamed the file to package.d, but apparently

Re: std.array oddness

2014-12-13 Thread bearophile via Digitalmars-d-learn
ketmar: no, you are using `.byLine` incorrectly. ;-) `.byLine` reuses it's internal buffer for each line, so you have to copy that buffer. A simple solution is to use byLineCopy (that unfortunately should have been the default behavior since the beginning). Bye, bearophile

repack ubyte[] to use only 7 bits

2014-12-13 Thread Charles Hixson via Digitalmars-d-learn
Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a better way to do what this was to accomplish, but it feels as if this should be somewhere in the standard library, if I could only find it. /** Repack the data from

Re: std.array oddness

2014-12-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Dec 2014 10:01:49 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: no, you are using `.byLine` incorrectly. ;-) `.byLine` reuses it's internal buffer for each line, so you have to copy that buffer. A simple solution is to use byLineCopy (that

Re: std.bitmanip - bitshift?

2014-12-13 Thread via Digitalmars-d-learn
On Friday, 12 December 2014 at 19:35:26 UTC, Steven Schveighoffer wrote: On 12/12/14 2:17 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Dec 12, 2014 at 11:13:38AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/12/14 8:39 AM, Trollgeir wrote:

Re: repack ubyte[] to use only 7 bits

2014-12-13 Thread Manolo via Digitalmars-d-learn
On Saturday, 13 December 2014 at 10:09:27 UTC, Charles Hixson via Digitalmars-d-learn wrote: Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a better way to do what this was to accomplish, but it feels as if this

Re: repack ubyte[] to use only 7 bits

2014-12-13 Thread Manolo via Digitalmars-d-learn
On Saturday, 13 December 2014 at 11:20:21 UTC, Manolo wrote: On Saturday, 13 December 2014 at 10:09:27 UTC, Charles Hixson via Digitalmars-d-learn wrote: Is there a standard way to do this? The code below is untested, as I haven't yet written the x7to8 routine, and came up with a better way

fibers and ranges: what's wrong here?

2014-12-13 Thread zeljkog via Digitalmars-d-learn
import std.stdio, core.thread; struct Tree{ int val; Tree[] tree; } struct TreeRange{ Tree curtree; bool empty; Fiber worker; this(Tree t){ worker = new Fiber(fiberFunc); curtree = t; popFront(); } void fiberFunc(){ Tree t = curtree; Fiber.yield();

Re: std.array oddness

2014-12-13 Thread thedeemon via Digitalmars-d-learn
On Saturday, 13 December 2014 at 06:40:41 UTC, ketmar via Digitalmars-d-learn wrote: .map!a.idup That can be just .map!idup.

Re: std.array oddness

2014-12-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Dec 2014 12:07:27 + thedeemon via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Saturday, 13 December 2014 at 06:40:41 UTC, ketmar via Digitalmars-d-learn wrote: .map!a.idup That can be just .map!idup. it depends of compiler version, as `idup` was a

Re: fibers and ranges: what's wrong here?

2014-12-13 Thread Tobias Pankrath via Digitalmars-d-learn
When you assigning the worker in TreeRange, you create a delegate that captures the current TreeRange or 'this'. --- worker = new Fiber(fiberFunc); --- foreach is defined as (http://dlang.org/statement.html#ForeachStatement): --- for (auto __r = range; !__r.empty; __r.popFront()) {

Re: fibers and ranges: what's wrong here?

2014-12-13 Thread zeljkog via Digitalmars-d-learn
On 13.12.14 13:01, zeljkog wrote: void main() { auto tt = Tree(5, [Tree(7,[Tree(11), Tree(4)]), Tree(10)]); auto tr1 = TreeRange(tt); foreach(v; tr1){ writef(%2d, , v); } writeln(); for(auto r = TreeRange(tt); !r.empty; r.popFront()) writef(%2d, , r.front);

Re: fibers and ranges: what's wrong here?

2014-12-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 13 December 2014 at 12:26:49 UTC, zeljkog wrote: On 13.12.14 13:01, zeljkog wrote: void main() { auto tt = Tree(5, [Tree(7,[Tree(11), Tree(4)]), Tree(10)]); auto tr1 = TreeRange(tt); foreach(v; tr1){ writef(%2d, , v); } writeln(); for(auto r = TreeRange(tt);

Re: Segmentation fault after having a certain number of elements in an array?

2014-12-13 Thread Jeremy DeHaan via Digitalmars-d-learn
On Saturday, 13 December 2014 at 09:47:40 UTC, Artem Tarasov wrote: On Saturday, 13 December 2014 at 08:59:19 UTC, Jeremy DeHaan wrote: I'll be trying to narrow it down even more tomorrow, but I was hoping somone here might have some insight into this weird issue I am having. Could you

Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread aldanor via Digitalmars-d-learn
I'm writing bindings to a rather big C library where the return values of almost all functions indicate the possibility of an error (exception). Assuming there's a C header, foo.h with functions f1, f2, etc, I want to have a corresponding D module, foo.d which would provide the f1, f2 that

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 13 December 2014 at 16:34:42 UTC, aldanor wrote: I'm writing bindings to a rather big C library where the return values of almost all functions indicate the possibility of an error (exception). Assuming there's a C header, foo.h with functions f1, f2, etc, I want to have a

Re: scope block do not handle failure, but try-catch does

2014-12-13 Thread Suliman via Digitalmars-d-learn
If I right understand scope is not good for checking if one of function is fail. For example: string dbpass = config.getKey(dbpass); string dbpass = config.getKey(dbpass); string dbhost = config.getKey(dbhost); string dbport = config.getKey(dbport); if I will try to add scope(failure)

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread aldanor via Digitalmars-d-learn
Personally i wouldn't go this route. I would create foo.d as a C to D translation only so it can be imported and used like in C. Then i would create another module which imports this to create your new OOP API adding features and excepions, etc. This allows the best of both worlds, keep the C

Re: scope block do not handle failure, but try-catch does

2014-12-13 Thread Suliman via Digitalmars-d-learn
I reread docs and understood that scope not for such case. Next code is do what I need: try { string dbname = config.getKey(dbname); string dbpass = config.getKey(dbpass); string dbhost = config.getKey(dbhost); string dbport = config.getKey(dbport); } catch

SQLLite driver

2014-12-13 Thread Suliman via Digitalmars-d-learn
On the code.dlang.org I found SQLLite driver https://github.com/biozic/d2sqlite3 Look like it's not ready for Windows: pragma(msg, \nWARNING !!!\nDevelopped for POSIX systems only.\nNot tested on Windows.\n); I tried to add import to my project and I got next errors:

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 13 December 2014 at 19:03:42 UTC, aldanor wrote: Let's say there's a foo.d that contains raw bindings to foo.h (enums, structs, extern variables, function declarations, a whole load of stuff) -- everything but the functions is already fine but all functions need to be wrapped.

Re: repack ubyte[] to use only 7 bits

2014-12-13 Thread Manolo via Digitalmars-d-learn
On Saturday, 13 December 2014 at 19:52:33 UTC, Charles Hixson via Digitalmars-d-learn wrote: On 12/13/2014 03:20 AM, Manolo via Digitalmars-d-learn wrote: On Saturday, 13 December 2014 at 10:09:27 UTC, Charles Hixson via Digitalmars-d-learn wrote: Is there a standard way to do this? The code

Re: Are there any methods like isDestroyed or isDisposed to detect whether some object is destroyed or not?

2014-12-13 Thread Andrey Derzhavin via Digitalmars-d-learn
import std.stdio; class ObjectAType { bool ok; this() {ok = true;} } void main() { auto a = new ObjectAType; assert(a.ok); destroy(a); assert(!a.ok); // a has been destroyed. } This method of detection of collected objects is what I needed. Thanks to everybody for

All Unordered Pairs of Elements in a Range

2014-12-13 Thread Nordlöw
Is there a Phobos method/range for selecting all pairs out of a range without caring about the ordering within each pair? Example: [1,2,3] = [(1,2), (2,3), (3,1)]

Re: Wrapping multiple extern (C) declarations in a template

2014-12-13 Thread Mike Parker via Digitalmars-d-learn
On 12/14/2014 4:03 AM, aldanor wrote: However, it wouldn't be possible to retain the same function names since they've been imported to the namespace (it's then also not possible to extern them as private initially since then you won't be able to import/wrap them in a different module). Hence

Re: All Unordered Pairs of Elements in a Range

2014-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 13, 2014 at 10:24:50PM +, Nordlöw via Digitalmars-d-learn wrote: Is there a Phobos method/range for selecting all pairs out of a range without caring about the ordering within each pair? Example: [1,2,3] = [(1,2), (2,3), (3,1)] Sounds like:

Re: All Unordered Pairs of Elements in a Range

2014-12-13 Thread Nordlöw
On Saturday, 13 December 2014 at 23:08:13 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [1,2,3] = [(1,2), (2,3), (3,1)] Sounds like: https://issues.dlang.org/show_bug.cgi?id=6788 Thx.

Re: SQLLite driver

2014-12-13 Thread Rikki Cattermole via Digitalmars-d-learn
On 14/12/2014 9:21 a.m., Suliman wrote: On the code.dlang.org I found SQLLite driver https://github.com/biozic/d2sqlite3 Look like it's not ready for Windows: pragma(msg, \nWARNING !!!\nDevelopped for POSIX systems only.\nNot tested on Windows.\n); I tried to add import to my project and I

Re: std.array oddness

2014-12-13 Thread earthfront via Digitalmars-d-learn
On Saturday, 13 December 2014 at 06:40:41 UTC, ketmar via Digitalmars-d-learn wrote: auto names = File(names.txt) .byLine!(char,char)(KeepTerminator.no, ',') .map!a.idup .array; Awesome. map!idup does the trick. I had looked at the byLine doc before posting, in

Re: SQLLite driver

2014-12-13 Thread Suliman via Digitalmars-d-learn
Yes I used 2.0.65, but after updating compiler the situation did not resolved... http://www.everfall.com/paste/id.php?apd0bfs5z4eg

Re: SQLLite driver

2014-12-13 Thread Rikki Cattermole via Digitalmars-d-learn
On 14/12/2014 7:35 p.m., Suliman wrote: Yes I used 2.0.65, but after updating compiler the situation did not resolved... http://www.everfall.com/paste/id.php?apd0bfs5z4eg Ah oh, I remember this issue from 2.064 - 2.065. Definitely hasn't been upgraded.