How to create library with exported functions
Hi! I am make a yet another attempt to create an interface to PostgreSQL from the D: https://github.com/denizzzka/dpq2 I can not understand how do I compile it into a library and create .di headers file. Currently, "make debug" uses dmd -lib and creates libpq.di file, but its file contains only few strings from main() Plz help!
Re: How to create library with exported functions
(sorry for my English) Hi! I am make a yet another attempt to create an interface to PostgreSQL from the D: https://github.com/denizzzka/dpq2 I can not understand how do a compile it into a library and create .di headers file. Currently, "make debug" uses dmd -lib and creates libpq.di file, but this file contains only few strings from main() As far as I understand it, in libdpq2.di should be automatically added functions what are available from the library. But they are not.
Re: How to create library with exported functions
I tried to add: export { /* module code except imports*/} but nothing has changed.
Re: How to create library with exported functions
On Friday, 5 October 2012 at 09:15:36 UTC, denizzzka wrote: I tried to add: export { /* module code except imports*/} but nothing has changed. libdpq2.di have a comment on top: // D import file generated from 'unittests_main.d' why only from unittests_main.d? Build command is: dmd libpq.di connection.d query.d answer.d unittests_main.d -L-lpq -L-lcom_err -w -d -Hflibdpq2.di -oflibdpq2 -g -debug -lib which includes 5 source files.
Re: How to create library with exported functions
solved! problem was in -Hf compiler switch
How to create immutable struct?
I am have struct with constructor: immutable struct Cell { ... } And I trying to create instance of this struct: immutable (Cell)* s = new Cell( v, s); compiler returns error: Error: cannot implicitly convert expression (new Cell(v,s)) of type Cell* to immutable(Cell)* How to pass immutable to new?
Re: How to create immutable struct?
I should just create immutable constructor :-)
version(debug)
Why version(assert){ int i = 1; } else { int k = 1; } causes error: Error: identifier or integer expected, not assert ? This is bug or feature? http://dlang.org/version.html says what it is correct code, because "assert" in the list of "Predefined Version Identifiers" How I can solve this problem by other way?
Re: version(debug)
huh, text should be from upper letter: Assert, Debug
Re: version(debug)
Strange, when you write to the forum then you solve problem immediately by yourself :-) Thx for fast answers!
Re: version(debug)
On Saturday, 6 October 2012 at 18:15:49 UTC, Andrej Mitrovic wrote: On 10/6/12, denizzzka <4deni...@gmail.com> wrote: This is bug or feature? http://dlang.org/version.html says what it is correct code, because "assert" in the list of "Predefined Version Identifiers" I think that must be a typo on the website. Use version(debug) instead. No, debug also don't works. Debug and Assert works fine
Re: version(debug)
On Saturday, 6 October 2012 at 19:16:26 UTC, Jonathan M Davis wrote: On Saturday, October 06, 2012 20:42:01 Alex Rønne Petersen wrote: version (assert) is a very recent addition to the compiler and is not in 2.060. Which would probably explain why it's not working for him, since presumably, he's not building the compiler himself, but then it really shouldn't be up on the website yet. - Jonathan M Davis I am on dmd 2.060 debug {} else {} was not obvious for me - I thought that debug is a kind of qualifer.
Re: connect to an SQL Server database
On Saturday, 6 October 2012 at 12:35:05 UTC, Minas wrote: Is there a library that I can use to connect to an SQL Server database? (I need to use it on both linux and windows). I am write one for PostgreSQL right now: https://github.com/denizzzka/dpq2
Re: connect to an SQL Server database
On Saturday, 6 October 2012 at 22:08:48 UTC, denizzzka wrote: On Saturday, 6 October 2012 at 12:35:05 UTC, Minas wrote: Is there a library that I can use to connect to an SQL Server database? (I need to use it on both linux and windows). I am write one for PostgreSQL right now: Ops, it turns SQL Server is a *Microsoft* SQL Server
Re: version(debug)
On Sunday, 7 October 2012 at 01:20:49 UTC, Jonathan M Davis wrote: On Saturday, October 06, 2012 23:49:23 denizzzka wrote: I am on dmd 2.060 debug {} else {} was not obvious for me - I thought that debug is a kind of qualifer. I wouldn't expect you to try either version(debug) or debug {} without seeing them in the docs or in TDPL. I suppose that I can see why you would try version(debug), but it's not listed in the docs. There isn't really a debug version of anything in D. What debug {} does is it's compiled in when -debug is compiled in, and that can be used in conjunction with -release if you want to. So talking about debug vs release in D is likely to get very confusing. Rather -debug enables debug blocks which are intended for inserting debug code, _not_ code which is meant for non- release builds. It looks like version(assert) (which I guess is only in the github version right now) will effectively correspond to not having -release, but if there's ever a compiler flag which specifically enables or disables assertions instead of -release (which does more than just disable assertions - e.g. it disables bounds checking in non-@safe code), then it won't actually be guaranteed to not be there if -release isn't there. It's close enough though I guess, particularly when the type of stuff that you specifically do in non-release code is typically the kind of stuff that you want done with assertions are enabled and probably wouldn't want enable if assertions were turned off, even if that were to somehow happen without -release. I've got a situation that debug information should be placed into the class via the constructor. Therefore, when used -debug constructor has another arguments list, and its need debug {} else {} for ctor calling. In any case, -debug and debug{} should be explained in the docs somewhere. It's certainly not the sort of thing that I would expect you to magically know. Yes.
Best way to store postgresql's "numeric" type in D?
It is up to 131072 digits before the decimal point; up to 16383 digits after the decimal point.
Re: Is there a thread safe single linked list?
or dynamic array with this methods
Re: Is there a thread safe single linked list?
Thanks for answer! After investigation came to the conclusion that here is needed not synchronized-based solution. I am need compare-and-swap single linked list because it will be used in callback proc from C, and it cannot be throwable, but synchronized contains throwable _d_monitorenter and_d_monitorexit. I would be grateful if someone share singly linked list based on cas()
Re: Is there a thread safe single linked list?
I would be grateful if someone share singly linked list based on cas() Ok, this is a good opportunity to learn how to write such by oneself :-)
Re: Is there a thread safe single linked list?
On Friday, 12 October 2012 at 23:30:39 UTC, Sean Kelly wrote: I would be grateful if someone share singly linked list based on cas() There's a sample Stack and SList implementation in the concurrency chapter: http://www.informit.com/articles/printerfriendly.aspx?p=1609144 Of course, I read this article. I think that SList is not the same thing as FIFO list - get the first entry in the queue and get queue entry by numerical order are two different things in multithreaded environment, right? I think its necessary to implement "primitives" like a CASN from article "A Pratial Multi-Word Compare-and-Swap Operation" (by Timothy L. Harris, Keir Fraser and Ian A. Pratt.) This titanic challenge as I see it, but sooner or later it will have to do. Then we will be able to create various thread safe structures.
Re: Is there a thread safe single linked list?
Not that the "titanic" but the authors, probably, have used Java and another type of cas result returns.
how to create a local copy of shared pointer?
void main() { struct S { int payload; } S* s = new shared (S); // Why this is a illegal? } Error: cannot implicitly convert expression (new shared(S)) of type shared(S)* to S*
Re: how to create a local copy of shared pointer?
On Monday, 15 October 2012 at 15:27:03 UTC, thedeemon wrote: On Monday, 15 October 2012 at 15:15:57 UTC, denizzzka wrote: S* s = new shared (S); // Why this is a illegal? Error: cannot implicitly convert expression (new shared(S)) of type shared(S)* to S* Because shared(S) and S are different types. Either declare s as shared too or use a cast. Why it was made in the language? This can be a safe automatic conversion I think.
Re: how to create a local copy of shared pointer?
Thanks!
synchronization + nothrow
How I can synchronize changing of array in the functions with nothrow? Handmade spinlock or something better?
How to start new command with arguments, pass data to its stdin read its output?
Something like execv() but with stdin/stdout?
Re: How to start new command with arguments, pass data to its stdin read its output?
On Tuesday, 23 October 2012 at 11:34:35 UTC, denizzzka wrote: Something like execv() but with stdin/stdout? Something like popen(), not execv().
Re: How to start new command with arguments, pass data to its stdin read its output?
On Tuesday, 23 October 2012 at 12:19:08 UTC, Adam D. Ruppe wrote: On Tuesday, 23 October 2012 at 11:34:35 UTC, denizzzka wrote: Something like execv() but with stdin/stdout? If you're on linux i have a little file that might help: http://arsdnet.net/dcode/exec.d int exec( string program, string[] args = null, string input = null, string* output = null, string* error = null, string[] environment = null); Thanks! It is suitable for my case. I think something like this should be in the standard library.
UTF-8 strings and endianness
Hi! How to convert D's string to big endian? How to convert to D's string from big endian?
Re: UTF-8 strings and endianness
On Monday, 29 October 2012 at 15:22:39 UTC, Adam D. Ruppe wrote: UTF-8 isn't affected by endianness. Ok, thanks!
Re: UTF-8 strings and endianness
On Monday, 29 October 2012 at 15:46:43 UTC, Jordi Sayol wrote: Al 29/10/12 16:17, En/na denizzzka ha escrit: Hi! How to convert D's string to big endian? How to convert to D's string from big endian? UTF-8 is always big emdian. Yes. (I thought that the problem in this place but the problem was different.)
Re: UTF-8 strings and endianness
On Monday, 29 October 2012 at 15:46:43 UTC, Jordi Sayol wrote: Al 29/10/12 16:17, En/na denizzzka ha escrit: Hi! How to convert D's string to big endian? How to convert to D's string from big endian? UTF-8 is always big emdian. oops, what? Q: Is the UTF-8 encoding scheme the same irrespective of whether the underlying processor is little endian or big endian? A: Yes. Since UTF-8 is interpreted as a sequence of bytes, there is no endian problem as there is for encoding forms that use 16-bit or 32-bit code units. Where a BOM is used with UTF-8, it is only used as an ecoding signature to distinguish UTF-8 from other encodings — it has nothing to do with byte order.
How to place char* of stringZ to ubyte[]?
immutable ubyte[] valueBin = cast(immutable(ubyte[])) toStringz(s); // s is string type Error: e2ir: cannot cast toStringz(s) of type immutable(char)* to type immutable(ubyte[])
Re: How to place char* of stringZ to ubyte[]?
On Monday, 29 October 2012 at 17:51:56 UTC, bearophile wrote: denizzzka: immutable ubyte[] valueBin = cast(immutable(ubyte[])) toStringz(s); // s is string type Error: e2ir: cannot cast toStringz(s) of type immutable(char)* to type immutable(ubyte[]) One way to do it: import std.stdio; void main() { string s = "hello"; auto valueBin = cast(immutable ubyte[])s.dup; writeln(valueBin); } But what are you trying to do? I am trying to send to remote host utf8 text with zero byte at end (required by protocol) But sending function accepts only ubyte[]
Re: How to place char* of stringZ to ubyte[]?
On Monday, 29 October 2012 at 18:50:58 UTC, bearophile wrote: denizzzka: I am trying to send to remote host utf8 text with zero byte at end (required by protocol) What if your UTF8 string coming from D already contains several zeros? Incredible situation because it is text-based protocol toStringz(s) returns a pointer, so you can't cast a pointer (that doesn't know the length the buffer it points to) to an array. You have to tell it the length in some way. One way is to slice the pointer, another solution is to append a '\0' and then cast it to an immutable array. Two solutions: import std.stdio, std.string; void main() { string s = "hello"; auto valueBin1 = cast(immutable ubyte[])(s ~ '\0'); writeln(valueBin1); auto valueBin2 = cast(immutable ubyte[])(s.toStringz()[0 .. s.length + 1]); writeln(valueBin2); } I am concerned about the extra allocations of temp arrays. here is it, or not? compiler optimizes it? In my case it does not matter but for the future I would like to know how it can be implemented without overhead. If you have to do this more than two or three times it's better to write a little function to do it, to avoid bugs. Even better is to define with strong typing the type of such nil-terminated array of bytes, to avoid other mistakes. This used to be possible in D with typedef. Now one a little clumsy way to do it is to use a struct with "alias this". This is just a sketch: Yes, already implemented similar. struct BytesBuf { this(string s) { this.data = cast(typeof(data))(s ~ '\0'); } byte[] data = [0]; Why not "byte[] data;" ? alias this = data; // new syntax What difference between this syntax and "alias Something this"? } void main() { import std.stdio; string s = "hello"; auto valueBin3 = BytesBuf(s); writeln(valueBin3); }
Re: Vibe: I found the problem, but don't know how to fix it
On Thursday, 1 November 2012 at 18:25:22 UTC, Lubos Pintes wrote: Hi, Some time ago I reported on D.Anounce, that Vibe apps are not working on my system, they failed with an exception. So I diagnosed a bit and found the following: There is a folder on my system C:\Users\pintes\AppData\Local\Temp\.rdmd\source which contains some DLLs needed for successful run. But the app.exe generated by rdmd is, in one concrete case in the folder C:\Users\pintes\AppData\Local\Temp\.rdmd\rdmd-app.d-7203ADE98B25A99E6D0DEF46E9812990 After I manually moved the app.exe from the previous folder with crazy name to the source folder, everything worked. Hi! You can report this problem to Vibe community forum (without signup): http://news.rejectedsoftware.com/groups/rejectedsoftware.vibed/
How to add n items to TypeTuple?
For example, adding 3 strings to type tuple t: foreach( i; 0..2 ) alias TypeTuple!( t, string ) t; // this is wrong code and result should be: TypeTuple!( string, string, string );
Re: How to add n items to TypeTuple?
Great! Thanks!
Re: What is PostgreSQL driver is most stable?
On Wednesday, 15 March 2017 at 08:54:59 UTC, Paolo Invernizzi wrote: I'm curious: ddb does not support yet arbitrary precision numbers [1], does dpq support them? Does Dlang supports them?
dub dustmite: Initial test fails
Hi! I have a code with segfault. I decided to try to take advantage with dub dustmite: $ dub dustmite ~/ssd/pgator_dustmite0 --program-status=139 -- --config=my_pgator.conf --debug=true WARNING: A deprecated branch based version specification is used for the dependency vibe-d-postgresql. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead. Copy package 'pgator' to destination folder... Copy package 'vibe-d-postgresql' to destination folder... Copy package 'dpq2' to destination folder... Copy package 'derelict-pq' to destination folder... Copy package 'derelict-util' to destination folder... Copy package 'vibe-d' to destination folder... Copy package 'libasync' to destination folder... Copy package 'memutils' to destination folder... Copy package 'libev' to destination folder... Copy package 'libevent' to destination folder... Copy package 'openssl' to destination folder... Executing dustmite... None => No object.Exception@DustMite/dustmite.d(243): Initial test fails but if I try to run already compiled binary it is successfully core dumps: $ ./pgator --config=my_pgator.conf --debug=true; echo $? 2016-02-23T18:07:00.748:package.d:_sharedStaticCtor6:9 DerelictPQ loading... 2016-02-23T18:07:00.748:package.d:_sharedStaticCtor6:16 ...DerelictPQ loading finished 2016-02-23T18:07:00.750:package.d:connectionFactory:50 creating new connection 2016-02-23T18:07:00.750:package.d:connectionFactory:54 new connection is started 2016-02-23T18:07:00.750:package.d:runStatementBlockingManner:126 runStatementBlockingManner 2016-02-23T18:07:00.750:package.d:doQuery:66 get connection from a pool 2016-02-23T18:07:00.753:package.d:doQuery:90 doesQuery() call 2016-02-23T18:07:00.753:package.d:__lambda5:140 consumeInput() 2016-02-23T18:07:00.753:package.d:__lambda5:145 getResult() 2016-02-23T18:07:00.753:package.d:__lambda5:145 getResult() 2016-02-23T18:07:00.754:app.d:main:88 found method row: "echo" "SELECT $1::text as echoed" ["value_for_echo"] false 2016-02-23T18:07:00.754:app.d:main:137 Method echo loaded. Content: Method("echo", "SELECT $1::text as echoed", ["value_for_echo"], false) 2016-02-23T18:07:00.754:app.d:main:88 found method row: "echo2" "SELECT $1::text" ["value_for_echo"] NULL 2016-02-23T18:07:00.754:app.d:main:132 Value of column one_row_flag is NULL, skipping reading of method echo2 2016-02-23T18:07:00.754:app.d:main:88 found method row: "wrong_sql_statement" "wrong SQL statement" [] false 2016-02-23T18:07:00.754:app.d:main:137 Method wrong_sql_statement loaded. Content: Method("wrong_sql_statement", "wrong SQL statement", [], false) 2016-02-23T18:07:00.754:app.d:main:141 Number of methods in the table "pgator_rpc": 3, failed to load: 1 2016-02-23T18:07:00.754:app.d:__foreachbody18:148 try to prepare method wrong_sql_statement 2016-02-23T18:07:00.754:package.d:runStatementBlockingManner:126 runStatementBlockingManner 2016-02-23T18:07:00.754:package.d:doQuery:66 get connection from a pool 2016-02-23T18:07:00.754:package.d:doQuery:90 doesQuery() call 2016-02-23T18:07:00.754:package.d:__lambda5:140 consumeInput() 2016-02-23T18:07:00.754:package.d:__lambda5:145 getResult() 2016-02-23T18:07:00.754:package.d:__lambda5:145 getResult() 2016-02-23T18:07:00.755:app.d:__foreachbody18:160 ОШИБКА: ошибка синтаксиса (примерное положение: "wrong") LINE 1: wrong SQL statement ^ , skipping preparing of method wrong_sql_statement 2016-02-23T18:07:00.755:app.d:__foreachbody18:162 catched 2016-02-23T18:07:00.755:app.d:__foreachbody18:165 next Ошибка сегментирования (core dumped) 139 How how to understand why dub dustmite doesn't work for me?
Re: Can't Compile Global Semaphores?
On Monday, 27 July 2015 at 20:12:10 UTC, John Colvin wrote: Yes, but then core.sync.semaphore doesn't support being shared, so... I don't really understand how https://github.com/D-Programming-Language/druntime/blob/master/src/core/sync/semaphore.d#L356 is managing to avoid this Since that time is something cleared up? Faced with the same problem
.opAssign disabled without @disable
Hi! DMD and LDC2 complain about disabled opAssign, but I am not used @disable and depend package "gfm" also isn't uses @disable. Steps to reproduce: git clone https://github.com/denizzzka/r-tree.git cd r-tree git checkout 803eed22 dub test Fetching gfm 6.0.0 (getting selected version)... Placing gfm 6.0.0 to /home/denizzz/.dub/packages/... Generating test runner configuration '__test__library__' for 'library' (sourceLibrary). Performing "unittest" build using dmd for x86_64. gfm:math 6.0.0: building configuration "library"... r-tree ~master: building configuration "__test__library__"... source/package.d(109,31): Error: function rtree.RAMNode!(Box!(int, 2), ubyte).RAMNode.opAssign is not callable because it is annotated with @disable source/package.d(110,26): Error: function rtree.RAMNode!(Box!(int, 2), ubyte).RAMNode.opAssign is not callable because it is annotated with @disable source/package.d(330,25): Error: template instance rtree.RTree!(RAMNode!(Box!(int, 2), ubyte), true) error instantiating dmd failed with exit code 1. If I am try to add opAssign to struct RAMNode manually it is compiles. (But there is enough postblit constructor.)
Re: .opAssign disabled without @disable
On Saturday, 16 April 2016 at 11:48:56 UTC, denizzzka wrote: source/package.d(109,31): Error: function rtree.RAMNode!(Box!(int, 2), ubyte).RAMNode.opAssign is not callable because it is annotated with @disable source/package.d(110,26): Error: function rtree.RAMNode!(Box!(int, 2), ubyte).RAMNode.opAssign is not callable because it is annotated with @disable source/package.d(330,25): Error: template instance rtree.RTree!(RAMNode!(Box!(int, 2), ubyte), true) error instantiating Perhaps I should explain that struct RAMNode placed in repository above. (And it isn't contains any @disable)
Re: .opAssign disabled without @disable
On Saturday, 16 April 2016 at 15:15:18 UTC, Alex Parrill wrote: Try removing the const from this line: debug private const bool isLeafNode = false; I suspect that D is disabling whole-structure assignment since allowing it would mean that the constant `isLeafNode` could be changed. Tried - is no avail.
Re: .opAssign disabled without @disable
Tried to build small test app - is not reproduced.
Re: .opAssign disabled without @disable
On Sunday, 17 April 2016 at 06:42:39 UTC, denizzzka wrote: Tried to build small test app - is not reproduced. Also tried to reduce source: https://github.com/denizzzka/r-tree/tree/314f7f1cc1b6387915dc56dcb2d3ccbc63e19275/source In this source line 199 causes this error (https://github.com/denizzzka/r-tree/blob/314f7f1cc1b6387915dc56dcb2d3ccbc63e19275/source/package.d#L199) But if I am checkout to master and remove const from debug private const bool isLeafNode = false; It isn't fixes compiling. Second branch: I am removed const from file and add import insted of traits template function: https://github.com/denizzzka/r-tree/blob/4457025efa72a6d8a97429e09c35a3f5520c37d5/source/package.d#L26 If place this import to top of the file @disabled error is gone! Why?
Re: .opAssign disabled without @disable
As Alex Parrill says, on problem was in const member. But this is one of the problems, and after fix here still was an error. But alphaglosined found another problem! For some unknown reason here it is need to specify an empty postblit constructor. Full patch: https://github.com/denizzzka/r-tree/commit/ca9231df5a8a227aa9a8010b849e2e92a134f8a1 So, my problem is solved. But nevertheless maybe here is a problem in the compiler too.