On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote:
That worked but now I have a more convoluted case: a C array of
pointers to int pointers, e.g.,
int **xs[] = {x1, x2, 0};
int *x1[] = {x1a, 0};
int *x2[] = {x2a, x2b, 0};
...
int x2a[] = { 1, 3, 5, 0};
Only the first line is exposed (and
On Wednesday, 14 March 2018 at 02:17:57 UTC, Adam D. Ruppe wrote:
The type system would *like* to know, certainly for correct
range errors, but if you declare it as the wrong length and use
the .ptr, it still works like it does in C:
extern(C) __gshared extern char*[1] files; // still works
On Wednesday, 4 July 2018 at 01:58:15 UTC, Seb wrote:
So just add the declaration to your D file:
---
extern(C) void myCfunction(FILE* stream);
---
I do have a similar declaration in D. It appears the problem is
that the C program I'm trying to convert passes stdout as the
argument and the
The subject basically says it all. The C function uses the
argument to call fprintf and also passes it to other functions
where it's used to call fileno, fprintf or putc.
On Wednesday, 4 July 2018 at 02:16:00 UTC, Seb wrote:
Hmm, calling e.g. fprintf with stdout should just work:
---
void main()
{
import core.stdc.stdio;
fprintf(stdout, "Hello %s", "world".ptr);
}
---
Could you maybe provide your whole code?
This short test program shows the error:
On Monday, 15 January 2018 at 02:28:29 UTC, Matthias Klumpp wrote:
In any case, please don't start another Postgres library and
consider contributing to one of the existing ones, so that we
maybe have one really awesome, 100% complete library at some
point.
If, on the other hand, your goal
On Saturday, 20 January 2018 at 04:54:47 UTC, Adam D. Ruppe wrote:
Same as above. The general pattern is:
C_Type[] name = new C_Type[](requested_size);
// pass as `name.ptr`. This becomes a C_Type*
Thanks, Adam. Perhaps something like this ought to make its way
into the "D for C Programmers"
On Saturday, 13 January 2018 at 10:10:41 UTC, Jacob Carlborg
wrote:
There's a native D library, ddb [1], for connecting to
Postgres. Then you don't have to worry about null-terminated
strings.
There are several D libraries that I would consider "native":
derelict-pq, dpq, dpq2 and ddb. The
I'm trying to learn how to use D to connect (and send queries) to
Postgres, i.e., libpq in C. Postgres has three families of
connection functions: PQsetdbLogin which takes multiple
individual arguments (all as const char *), PQconnectdb which
takes a single connection string (which Postgres
Going beyond the connection, there are various other libpq
functions that use a similar pattern of values passed using
multiple parallel C arrays, e.g.,
PGresult *PQexecParams(PGconn *conn,
const char *command,
int nParams,
On Saturday, 13 January 2018 at 04:26:06 UTC, Adam D. Ruppe wrote:
If and only if the values are known at compile time, you can do:
const char** keywords = ["hostaddr".ptr, "port".ptr,
"dbname".ptr, null].ptr;
or even do it inline:
PQconnectdbParams(["hostaddr".ptr, "port".ptr,
An example test program that I'm using to learn D to C
interfacing (specifically calling the libpq library) has a call
to a C function declared as follows:
void PQprint(FILE *fout, /* output stream */
const PGresult *res,
const PQprintOpt *po);
Hello everybody!
Last week end I found this post (
https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ ) on the Blog and thought to myself awesome.
So I built the library and everything went smooth. Thanks for the
effort of all the involved people who made that
On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote:
Hi Joe,
/SNIP
On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote:
[...]
The FuncDeclaration node contains all the information for that.
For example, you can access fd.parent to see if the function is
declared at top-level (in
On Thursday, 22 February 2018 at 02:41:30 UTC, Steven
Schveighoffer wrote:
On 2/21/18 7:30 PM, SrMordred wrote:
But with a slice negative indexes are never allowed, even on
a pointer.
youd have to do
(c-1)[0 .. 1];
Nice!
Thank you both!
In D Slice article it says "You can even use
On Thursday, 22 February 2018 at 13:44:51 UTC, RazvanN wrote:
On Thursday, 22 February 2018 at 13:21:04 UTC, joe wrote:
[...]
Indeed, @Stefan is right. The ParseTimeVisitor only contains
information available at parse time. If you are interested in
the parent you have 2 options: either (1)
On Monday, 12 February 2018 at 08:47:58 UTC, RazvanN wrote:
Hi Joe,
I suggest you watch this video which explains how the parse
time visitors work: https://www.youtube.com/watch?v=tK072jcoWv4
.
On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote:
[...]
The FuncDeclaration node
On Thursday, 22 February 2018 at 14:53:11 UTC, Seb wrote:
On Tuesday, 6 February 2018 at 12:03:06 UTC, joe wrote:
Hello everybody!
Last week end I found this post (
https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/ ) on the Blog and thought to myself awesome.
On Wednesday, 15 August 2018 at 06:39:50 UTC, Mike Parker wrote:
String literals are implicitly convertible to const(char)* and
are guaranteed to be nul-terminated like a C string, so this
works:
[...]
Does that help?
Yes, indeed. I think I possibly read about literal strings being
I'm attempting a piecemeal conversion of some C programs. I've
converted a few that depend on C modules that are in a library
and now I'm sort of in the middle of converting those C modules.
One of them has an array of strings, i.e., array of char*, which
most easily translated to D's
On Wednesday, 15 August 2018 at 01:56:34 UTC, Mike Parker wrote:
The correct thing to do is to keep the original C function
signatures in the converted code, i.e. don't change char* to
string[]. And don't use anything from Phobos internally that
requires linking. In other words, treat your
Hello All!
I've been trying every possible combination and cannot get
anything working. (>_<)
This is I think the closest I've got, I think the problem may be
with the 3 argument. I'm not sure how to join the Multicast IP
membership?
(this code currently does not work - throws error:
On Saturday, 13 January 2018 at 05:28:17 UTC, Joe wrote:
Going beyond the connection, there are various other libpq
functions that use a similar pattern of values passed using
multiple parallel C arrays, e.g.,
PGresult *PQexecParams(PGconn *conn,
const char *command,
I'm getting a compiler error in a qsort() call as follows:
qsort(recs, num_recs, (Record *).sizeof, compar);
Record is a struct, recs is a fixed array of pointers to Record's
and num_recs is a size_t that holds the number of valid records.
compar is this:
int compar(const void *p1,
On Monday, 12 March 2018 at 01:45:54 UTC, Adam D. Ruppe wrote:
I just reformatted it but now the difference should be visible:
`extern(C)` is missing on your callback.
The scope things might make a difference too, but I know for
sure extern(C) is necessary on your callback function.
I saw
On Sunday, 11 March 2018 at 23:26:04 UTC, Stefan Koch wrote:
You have to pass a pointer to the function.
Otherwise it'll be a parenthsis-less call.
use : qsort(recs, num_recs, (Record *).sizeof, );
After passing a pointer, getting some other error messages, I
changed the call to
On Monday, 12 March 2018 at 03:13:08 UTC, Seb wrote:
Out of interest: I wonder what's your usecase for using qsort.
Or in other words: why you can't use the high-level
std.algorithm.sorting.sort?
This is only temporary. I will be using
std.algorithm.sorting.sort. I was converting a C program
What is the correct way to declare and access storage managed by
C?
For example, say a C module defines an array of filenames, e.g.,
char *files[] = { "one", "two", "three", 0};
The C header of course declares this as:
extern char *files[];
The way to declare it in a D module appears to be:
I'm trying to build a very simple library. For now it just has a
single class, constructor, destructor and one method. I added a
unit test right after the method, declared the targetType to be
"library" and a buildType of "unittest" (with options
"unittests", "debugMode", "debugInfo"). When I
On Wednesday, 28 March 2018 at 03:07:23 UTC, Jonathan M Davis
wrote:
Run
dub test
The problem is that an executable needs a main, and a library
doesn't have one, whereas when you're testing a library, you
need an executable. So, a main must be inserted - e.g. with the
-main flag to dmd.
On Monday, 12 March 2018 at 03:50:42 UTC, Joe wrote:
On Monday, 12 March 2018 at 03:13:08 UTC, Seb wrote:
Out of interest: I wonder what's your usecase for using qsort.
Or in other words: why you can't use the high-level
std.algorithm.sorting.sort?
This is only temporary. I will be using
On Sunday, 18 March 2018 at 13:10:08 UTC, Dmitry Olshansky wrote:
Do this to get the usual ptr + length:
sort!((a, b) => to!string((*a).name) <
to!string((*b).name))(recs[]);
Also to!string would be computed on each compare anew. May want
to use schwartzSort to avoid that, on 10 elements
On Sunday, 18 March 2018 at 19:01:11 UTC, Joe wrote:
I managed to get it working by declaring a D dynamic array,
appending n_recs pointers to it and using it as argument to
sort. Unfortunately, I then had to copy from the dynamic array
to the fixed array in order to continue using the latter.
On Sunday, 18 March 2018 at 18:11:02 UTC, Dmitry Olshansky wrote:
Well since recs is array of pointers this looks like a null
pointer in your data.
The usual ways to fix that is either print stuff or poke around
in debugger to see if a Record* is null or .name is null.
The problem is that
I've discovered that the 'log' function as well several similar
functions are only defined as taking a real argument and
returning a real, unlike most other std.math functions, which
have triple definitions (also supporting double and float types).
This created a problem when I tried compiling
On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:
On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:
On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:
There appears to be a problem with the example at
https://tour.dlang.org/tour/en/gems/unittesting
If compiled with -unittest,
On Tuesday, 2 October 2018 at 13:24:09 UTC, Basile B. wrote:
The problem is the NaN madness.
Since several values are NaN there's this strange stuff:
void main()
{
import std.stdio;
import std.math : isNaN;
double d;
writeln(d.init);// nan
writeln(d); // nan
On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:
On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:
There appears to be a problem with the example at
https://tour.dlang.org/tour/en/gems/unittesting
If compiled with -unittest, the resulting program crashes. It
happens with ldc2 on
There appears to be a problem with the example at
https://tour.dlang.org/tour/en/gems/unittesting
If compiled with -unittest, the resulting program crashes. It
happens with ldc2 on Linux but it can also be seen if you click
on "Export" and run it with dmd -unittest.
On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote:
That worked but now I have a more convoluted case: a C array of
pointers to int pointers, e.g.,
int **xs[] = {x1, x2, 0};
int *x1[] = {x1a, 0};
int *x2[] = {x2a, x2b, 0};
...
int x2a[] = { 1, 3, 5, 0};
Only the first line is exposed (and
On Tuesday, 18 September 2018 at 13:47:50 UTC, Atila Neves wrote:
On Tuesday, 18 September 2018 at 02:39:39 UTC, Joe wrote:
The second type is like that shown above. The first is a
simpler array of pointers to int, e.g.,
int *yp = {2, 4, 0};
int *yq = {10, 12, 0};
This is valid C in the
On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote:
On Friday, 15 September 2023 at 15:27:00 UTC, Vino wrote:
On Friday, 15 September 2023 at 02:25:09 UTC, Joe wrote:
On Thursday, 14 September 2023 at 14:21:09 UTC, Vino wrote:
[...]
A pointer is a type that points to something. It's
On Thursday, 14 September 2023 at 14:21:09 UTC, Vino wrote:
Hi All,
Request your help to guide me in understanding about
pointers, the below code works,I have few question which i need
your help for better understanding.
Questions:1
```
char[] invalid = (cast(char*)malloc(char.sizeof *
On Monday, 18 September 2023 at 02:49:37 UTC, vino wrote:
On Sunday, 17 September 2023 at 18:28:36 UTC, Joe wrote:
On Friday, 15 September 2023 at 16:55:34 UTC, Vino wrote:
[...]
[...]
char[] invalid = (cast(char*)malloc(char.sizeof *
len))[0..len];
This is not the way to go about it.
I'm using download(url, filename) to download files in vibe.d.
The issue is that I do not know when the download is finished or
errors. There is a callback for the streaming side but not for
the file download.
On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin
wrote:
On 23.09.23 14:07, j...@bloow.edu wrote:
I'm using download(url, filename) to download files in vibe.d.
The issue is that I do not know when the download is finished
or errors. There is a callback for the streaming side
For absolutely no reason I started getting this error.
Last night I compiled the project and it worked just fine. This
morning I made a single insignificant change and tried to compile
and got that error. Only possible thing is that for some reason
some change in updating the compiler may
On Saturday, 23 September 2023 at 15:09:13 UTC, Elias wrote:
On Saturday, 23 September 2023 at 12:07:38 UTC, Joe wrote:
I'm using download(url, filename) to download files in vibe.d.
The issue is that I do not know when the download is finished
or errors. There is a callback for the streaming
On Sunday, 24 September 2023 at 12:59:57 UTC, Steven
Schveighoffer wrote:
On Sunday, 24 September 2023 at 10:00:31 UTC, Joe wrote:
For absolutely no reason I started getting this error.
Last night I compiled the project and it worked just fine.
This morning I made a single insignificant
I use
foreach(s; taskPool.parallel(files, numParallel))
{ L(s); } // L(s) represents the work to be done.
to download files from the internet.
Everything works. The issue is this:
the foreach will download 8 files at once. BUT it will not start
the next batch of 8 *until* ALL of the previous
On Wednesday, 23 August 2023 at 14:43:33 UTC, Sergey wrote:
On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote:
I use
foreach(s; taskPool.parallel(files, numParallel))
{ L(s); } // L(s) represents the work to be done.
If you make for example that L function return “ok” in case
file
On Wednesday, 23 August 2023 at 14:43:33 UTC, Sergey wrote:
On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote:
I use
foreach(s; taskPool.parallel(files, numParallel))
{ L(s); } // L(s) represents the work to be done.
If you make for example that L function return “ok” in case
file
On Friday, 25 August 2023 at 21:31:37 UTC, Ali Çehreli wrote:
On 8/25/23 14:27, j...@bloow.edu wrote:
> "A work unit is a set of consecutive elements of range to be
processed
> by a worker thread between communication with any other
thread. The
> number of elements processed per work unit is
On Friday, 25 August 2023 at 21:43:26 UTC, Adam D Ruppe wrote:
On Wednesday, 23 August 2023 at 13:03:36 UTC, Joe wrote:
to download files from the internet.
Are they particularly big files? You might consider using one
of the other libs that does it all in one thread. (i ask about
size cuz
On Monday, 28 August 2023 at 10:33:15 UTC, Christian Köstlin
wrote:
On 26.08.23 05:39, j...@bloow.edu wrote:
On Friday, 25 August 2023 at 21:31:37 UTC, Ali Çehreli wrote:
On 8/25/23 14:27, j...@bloow.edu wrote:
> "A work unit is a set of consecutive elements of range to be
processed
> by a
On Monday, 28 August 2023 at 22:43:56 UTC, Ali Çehreli wrote:
On 8/28/23 15:37, j...@bloow.edu wrote:
> Basically everything is hard coded to use totalCPU's
parallel() is a function that dispatches to a default TaskPool
object, which uses totalCPUs. It's convenient but as you say,
not all
On Monday, 13 March 2023 at 13:58:29 UTC, Adam D Ruppe wrote:
I'm not particularly interested in defending dub - i consider
it a useless piece of crap that I only suffer through cuz some
users demanded it
For the record, I wasn't trying to attack dub (or dfmt). I was
more interested in
On Monday, 13 March 2023 at 12:56:57 UTC, Bradley Chatha wrote:
For better or for worse we're stuck with dub as the standard
package manager + build tool one-in-all for most of our open
source libraries.
Yeah, it seems like it's *only* for libraries (and a few
single-exe utilities). Looking
On Monday, 13 March 2023 at 13:32:04 UTC, Mike Parker wrote:
The package registry is full of libraries, yes. That's what
it's primarily for. There aren't a lot of executables uploaded
there because they're usually better distributed in other ways.
But plenty of people are using dub to build
Let's say we have two classes, A and B. The latter has a dynamic
array of X and type X has an add() method that can be used to
append elements (of type C, another struct) to X's own dynamic
array of C. So it's something like the following:
```d
struct C {}
struct X { C[] cs;
void add(C c)
Thanks, Ali.
On Friday, 3 March 2023 at 18:09:01 UTC, Ali Çehreli wrote:
Think may be due to D not having reference variables. Sometimes
one needs to use pointers.
Ah! I'm about five chapters away from Pointers ;-).
Actually, I had tried changing B.x1() to:
`ref X x1() { return [0]; }`
How does one really use atomics in D?
shared string[int] AA;
AA[s[2]].atomicStore(s[1]);
causes a hangup.
If I just assign it "works":
AA[s[2]] = s[1];
I've had similar issues where:
atomicOp!"+="(X[Y],1);
fails and I have to use
X[Y].atomicStore(1);
or
??? Surely there there is a
one liner library solution for this?
I have a program that spawns a thread for debugging information
and uses the keyboard input which allows me to display the
information.
If I use getchar or readline then it blocks the
On Wednesday, 27 December 2023 at 13:27:53 UTC, Adam D Ruppe
wrote:
On Wednesday, 27 December 2023 at 05:07:04 UTC, Joe wrote:
??? Surely there there is
a one liner library solution for this?
It is not one line because it needs a bit of setup (and
64 matches
Mail list logo