Re: SQLite3 and threads

2015-03-01 Thread Vitalie Colosov via Digitalmars-d-learn

Now it all makes sense. Thank you.
Maybe it would make also some sense if I would have gotten some 
kind of exception trying to access the variable which was not 
populated by the running thread, instead of successfully getting 
empty string... so this would be observed easily during the 
testing, but perhaps there are some reasons for it being 
implemented the way it is, will keep learning.


Re: Why rbtree.length isn't const?

2015-03-01 Thread drug via Digitalmars-d-learn

On 26.02.2015 18:44, Steven Schveighoffer wrote:

Please submit an issue. http://issues.dlang.org

-Steve


Done: https://issues.dlang.org/show_bug.cgi?id=14234


Re: Invoking MAGO debugger

2015-03-01 Thread Vadim Lopatin via Digitalmars-d-learn

On Thursday, 26 February 2015 at 18:37:17 UTC, michaelc37 wrote:
On Thursday, 26 February 2015 at 10:20:31 UTC, Vadim Lopatin 
wrote:

Hello!

I'm trying to integrate MAGO into DlangIDE.

I can easy create instance of MAGO DebugEngine, but having 
problems with obtaining of IDebugPort which is needed for 
invoking of LaunchSuspended.
It looks like to get IDebugPort, I need IDebugCoreServer2 
instance.

Does anybody know how to do it?
Normally, it's being created by VisualStudio AFAIK.


Best regards,
   Vadim


I once remember pulling out my hair trying todo the same in 
order to get it to work with a monodevelop win32 debugger addon.


It resulted in a writing new clr wrapper with a different 
exposed interface

https://github.com/aBothe/MagoWrapper

e.g. of how the debugee was was launched here:
https://github.com/aBothe/MagoWrapper/blob/master/DebugEngine/MagoWrapper/NativeDebugger.cpp


Thank you a lot!

BTW, it's not clear what license in used for MagoWrapper.
In readme, it's said that it's under GPL2, but everywhere in 
source code I see Apache license.


Re: SQLite3 and threads

2015-03-01 Thread Ali Çehreli via Digitalmars-d-learn

On 03/01/2015 09:47 PM, Vitalie Colosov wrote:

> global variable

A module-scope variable is thread-local by-default. Every thread will 
have a copy of that variable.


If you want to share data, you must define it as 'shared' (or __gshared).

> which was populated in main() function

In that case only the main thread's variable would be initialized. 
Shared variables should be initialized in 'shared static this()' scopes.


Ali



Re: SQLite3 and threads

2015-03-01 Thread Vitalie Colosov via Digitalmars-d-learn
After some analysis, it looks like related to the code parts 
which I have omitted "for simplicity", and in particular - I was 
creating the query using global variable which was populated in 
main() function. It appears that when I spawn the function, it 
does not see the value of the global variable, thus, the query 
was not correct which made it execute full scan of table and 
never completed (table is huge).
I am checking more if anything like this is already documented 
anywhere.


SQLite3 and threads

2015-03-01 Thread Vitalie Colosov via Digitalmars-d-learn

Hi,

I am not able to query SQLite3 database files using threads; 
without threads it is working fine.
I tried both etc.c.sqlite3 and d2sqlite3, and both seem to be 
facing the same issue:
They stuck when executing a select query (using sqlite3_exec(...) 
for etc.c.sqlite3 or using RowCache(db.execute(...)) in case of 
d2sqlite3).
Since d2sqlite3 is a wrapper for native sqlite3, I think it faces 
the same limitation which native sqlite does, so next lines will 
describe native SQLite3 code.


---
This works fine (non-relevant code and validations are omitted 
for simplicity)

---
import etc.c.sqlite3,...
...
extern(C) int myCallback(void *a_parm, int argc, char **argv, 
char **column)

{
	 printf("%s\n", argv[1] ? argv[1] : "NULL");	// this prints 
first column of each row, all is well

 return 0;
}
void querySQLite(string dbName)
{
sqlite3* db;
auto ret = sqlite3_open(toStringz(dbName), &db);
string query = "SELECT * FROM my_table";
sqlite3_exec(db,toStringz(query),&myCallback,null,null);
sqlite3_close(db);
}
void main()
{
querySQLite("db1.sl3");
querySQLite("db2.sl3");
	...// in fact, here is a foreach loop which is calling 
querySQLite with about 30 database files

querySQLite("db30.sl3");  
}

---
However, if I change main function to spawn querySQLite, instead 
of calling it in sequence from the main thread,

then "myCallback()" is not executed.
void main()
{
spawn(&querySQLite,"db1.sl3");
spawn(&querySQLite,"db2.sl3");
...
spawn(&querySQLite,"db30.sl3");
}
It is stuck inside this line in querySQLite():

sqlite3_exec(db,toStringz(query),&myCallback,null,null);

If I comment it, the flow continues and returns fine from all 
spawn-ed functions, so it is definitely something wrong in this 
line.

---

I think I am missing some kind of thread locking code in 
querySQLite() - since it is working with C code I think it needs 
more attention.


I tried to compile SQLite with different multithreading options, 
but that did not help.


Any advice is much appreciated.

Using dmd.2.066.1.linux
RedHat 5 64bit
Compiled using dmd
sqlite-amalgamation-3080803

Thanks,
Vitalie


Re: The site engine written in D

2015-03-01 Thread Dennis Ritchie via Digitalmars-d-learn

On Monday, 2 March 2015 at 00:06:26 UTC, Ali Çehreli wrote:

Do you mean vibe.d?

  http://vibed.org/


I was referring to the software engine written using the vibe.d.
http://vibed.org/ written using the vibe.d?


Re: The site engine written in D

2015-03-01 Thread Ali Çehreli via Digitalmars-d-learn

On 03/01/2015 03:03 PM, Dennis Ritchie wrote:

Prompt, please, where can I find the software engine written in D?


Do you mean vibe.d?

  http://vibed.org/

Ali



The site engine written in D

2015-03-01 Thread Dennis Ritchie via Digitalmars-d-learn

Prompt, please, where can I find the software engine written in D?


Re: Does static ctor/dtor of struct behave differently in 2.067-b2?

2015-03-01 Thread amber via Digitalmars-d-learn

On Saturday, 28 February 2015 at 03:26:17 UTC, ketmar wrote:

On Fri, 27 Feb 2015 23:58:16 +, amber wrote:


On Friday, 27 February 2015 at 23:50:51 UTC, amber wrote:

Hi All,

[snip]

Thanks, amber


[edited subject]

Sorry I should add that I'm talking about static ctor/dtor of 
struct.


The bug I see with 2.067-b2 is this:

1. static this() {} called and static fields of struct are 
initialised

2. app runs, static fields are initialised.
3. static ~this() {} called and static fields of struct are NOT
initialised.


In step 3 with 2.066.1 all the static fields of struct are 
still

initialised, as expected, and my app shuts down cleanly.


is your struct GC-allocated? and can you provide dustmited code 
or

something we can play with?


Hi ketmar, thanks for replying.

I think I have figured out what was happening.

DMD 2.067 spins up 5 threads when running the unittests and DMD 
2.066.1 only uses one thread. This change exposed a bug in the 
static ctor which I've now fixed.


Thanks,
amber


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Ha, i found
std.windows.syserror: WindowsException, wenforce;


Re: ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Thans guys!

wenforce not sutable - error code is lost.
may be, i will use modified wenforce, wich throws ErrnoException.


Re: ErrnoException in Windows

2015-03-01 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 1 March 2015 at 16:39:29 UTC, novice2 wrote:

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2


Here's the right way to do this:

// test.d //
import std.c.windows.windows;
import std.string : toStringz;
import std.windows.syserror : wenforce;

void main ()
{
auto handle = CreateFileA(toStringz("nonexisting"),
GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
null);
wenforce(handle != INVALID_HANDLE_VALUE, "CreateFileA");
}


See std.windows.syserror for more information.


Re: ErrnoException in Windows

2015-03-01 Thread ketmar via Digitalmars-d-learn
On Sun, 01 Mar 2015 16:39:27 +, novice2 wrote:

> Could you, please, help me to understand, why code:

'cause winapi functions never sets `errno`. `errno` is a libc feature, 
and winapi knows nothing about libc. besides, `GetLastError()` is not 
required to return correct errno codes.

so you have to either use libc funcions, or translate `GetLastError()` 
codes to errno manually.

signature.asc
Description: PGP signature


ErrnoException in Windows

2015-03-01 Thread novice2 via Digitalmars-d-learn

Could you, please, help me to understand, why code:


import std.c.windows.windows;
import std.exception: ErrnoException;
import std.stdio: writefln;
import std.string: toStringz;

void main ()
{
  CreateFileA(toStringz("nonexisting file name"), GENERIC_READ, 
FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 
null);

  auto ex = new ErrnoException("CreateFileA");
  writefln("ex.errno=%d, ex.msg=%s, lasterror=%d", ex.errno, 
ex.msg, GetLastError());

}


prints:
ex.errno=0, ex.msg=CreateFileA (No error), lasterror=2

I wanted it will be:
ex.errno=2, ex.msg=CreateFileA (File not found), lasterror=2