Re: Is build a 64 bit version worth if I'm looking for better perfomance?

2018-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 01, 2018 22:48:08 Dr.No via Digitalmars-d-learn wrote:
> Looking for make application run fast as possible, aside
> optimization in the source code, is using 64 bit over 32 really
> worth?

That would heavily depend on the program. The big win for D code and 64-bit
that doesn't necessarily apply to other languages would be that the GC won't
end up with false pointers like it does with 32-bit code (i.e. because the
address space is small enough, when scanning, it can easily think that a
32-bit integer value is a pointer and thus not free that memory, because it
thinks that you have a pointer to it; the 64-bit address space is large
enough that that doesn't happen enough to really matter). But aside from
that, as I understand it, it's not an obvious gain one way or the other and
is really going to depend on what you're doing. In general, it's better to
match the architecture of the machine, which would almost certainly mean
64-bit at this point, but modern x86_64 machines are highly optimized for
32-bit code as well, and 64-bit programs tend to use more memory, because
stuff like pointers are twice as large (the program won't use double the
memory, because it's not like everything that gets pointed to doubles in
size - just the pointers and other types whose size depends on the size of
pointers - but you'll use more memory, which can slow things down). So, some
stuff will be faster with 32-bit and other stuff will be faster with 64-bit.

In general, at this point, talking about whether you should be writing
32-bit or 64-bit programs is kind of silly outside of Windows. Everywhere
else, you just target what the OS is running, which is probably 64-bit, and
with Windows, whether 32-bit or 64-bit is better probably has more to do
with what you're trying to do with your program than anything (e.g. whether
you have to worry about supporting folks with 32-bit Windows installs).

D in general is designed to be architecture-independent. It doesn't always
succeed at that, but most D code is going to work just fine as both 32-bit
and 64-bit (especially if auto and size_t are used properly). And it's
generally bad practice to target one or the other. As such, you can just
write your program and then see how it performs as 32-bit and how it
performs as 64-bit. If performance is then your biggest concern for choosing
32-bit or 64-bit, then you can just go with whichever performs better.
Either way, I would strongly discourage you from making it so that your
program only works as 32-bit or only works as 64-bit - not unless it's doing
something that requires enough memory that it has to be 64-bit, and most
programs don't need that.

- Jonathan M Davis



Re: Can I convert the Range returned by asUpperCase to ubyte[]?

2018-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 01, 2018 20:13:41 Dr.No via Digitalmars-d-learn wrote:
> I'm trying to do an optimization here: a hash function which
> expect a ubye[] array as argument, would just work if I cast
> string to ubyte[] but I need to convert it to upper case, so I'd
> like to do that lazily, so that the byte is converted to its
> upper case version soon as it's requested. I'm not sure if this
> possible because I think the function should also work with Range
> and not ubyte[] to work.
>
> So, adding some code example, can I convert the string to upper
> case then convert it to ubyte[] without memory allocation?
> something like this:
>
>
> import xxhash;
> import std.uni : asUpperCase;
> uint hash = xxhashOf(cast(ubyte[])(word.asUpperCase));

If you want a ubyte[], then you'd need to convert the range to char[] so
string and then do something like call representation on it to get an array
of ubytes. But at that point, using asUpperCase instead of toUpper is
pointless.

Pretty much the only way that you could avoid allocating to get a ubyte[]
would be if you did something like have a static array that you filled and
then sliced, which requires knowing ahead of time how much space you need
(or at least knowing the upper bound). At that point, you could use
asUpperCase and then put each character into the static array, and then
slice the static array. But that's a royal pain in comparison to just
allocating a dynamic array.

You'd do better to make it so that your hashing code operates on a range
rather than requiring an array of ubytes. Then you wouldn't need to allocate
or array or jump through a bunch of hoops to get a dynamic array that's a
slice of a static array or something similar.

- Jonathan M Davis



Re: How to curl!

2018-05-01 Thread ikod via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 00:04:49 UTC, IntegratedDimensions 
wrote:
On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran 
wrote:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

[...]


std.net.curl is not quite up to date when compared to the curl 
command. It is not useful any non-trivial stuff. Right now I'm 
using ikod's dlang-requests[1] and I'm quite happy with it. I 
would recommend you to try it.


[1] https://github.com/ikod/dlang-requests


Ok, first try:

Unhandled exception: object.Exception can't complete call to 
TLS_method at requests\ssl_adapter.d(248)


which says it can't find the lib. I renamed ssleay32.dll to 
libssl32.dll and it then passed. I am getting http 404 error 
though ;/


I turned off cert though, which may be the reason, I have no 
idea. Seems to be working through.


Did you try to use full path to cacert.pem?


Re: D in SUSE Enterprise Linux

2018-05-01 Thread Joakim via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 16:02:03 UTC, rikki cattermole wrote:

On 02/05/2018 3:51 AM, Vino wrote:

On Tuesday, 1 May 2018 at 15:42:38 UTC, Jonathan M Davis wrote:
On Tuesday, May 01, 2018 15:18:12 Vino via 
Digitalmars-d-learn wrote:

[...]


That sounds like your /tmp is mounted with noexec. which 
won't work with rdmd or any other program that expects to be 
able to create a file in /tmp and run it. Presumably, you'll 
need to change the settings in /etc/fstab so that /tmp is not 
mounted with noexec.


- Jonathan M Davis


Hi Jonathan,

   Yes the /tmp is mounted with noexec option , we should not 
change this option as it is a security violation so is there 
any other way we can make it work, it tried setting the tmp 
env variable to a local FS which is mounted with the noexec 
option but it did not work.


From,
Vino.B


Modify rdmd to use another directory which is more acceptable 
for your setup.


Or just set an environment variable like TMP, if you don't want 
to append the flag Jonathan gave each time, as rdmd simply calls 
std.file.tempDir:


https://dlang.org/phobos/std_file.html#.tempDir


Re: Can I convert the Range returned by asUpperCase to ubyte[]?

2018-05-01 Thread ag0aep6g via Digitalmars-d-learn

On 05/01/2018 10:13 PM, Dr.No wrote:
I'm trying to do an optimization here: a hash function which expect a 
ubye[] array as argument, would just work if I cast string to ubyte[] 
but I need to convert it to upper case, so I'd like to do that lazily, 
so that the byte is converted to its upper case version soon as it's 
requested. I'm not sure if this possible because I think the function 
should also work with Range and not ubyte[] to work.


Yup. Not possible. There's no such thing as a lazy ubyte[].


Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 23:35:42 UTC, Arun Chandrasekaran wrote:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

Trying to curl basic stuff but std.net.curl isn't cooperating:
This is one of the reasons I hate D ;/ I've spent more time 
trying to get std.net.curl to do something that just works 
from the command line.


std.net.curl is not quite up to date when compared to the curl 
command. It is not useful any non-trivial stuff. Right now I'm 
using ikod's dlang-requests[1] and I'm quite happy with it. I 
would recommend you to try it.


[1] https://github.com/ikod/dlang-requests


Ok, first try:

Unhandled exception: object.Exception can't complete call to 
TLS_method at requests\ssl_adapter.d(248)


which says it can't find the lib. I renamed ssleay32.dll to 
libssl32.dll and it then passed. I am getting http 404 error 
though ;/


I turned off cert though, which may be the reason, I have no 
idea. Seems to be working through.


Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 23:02:39 UTC, Dr.No wrote:
On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions 
wrote:

[...]

those dlls:
libeay32.dll libssl32.dll ssleay32.dll

I'm sure they would be installed with whatever

[...]


I don't think so. IIRC, when I used D+curl I needed to download 
them manutally. This is always the case with Qt. Even using 
windeployqt with   --webkit2 flag I still need to copy those 
dlls to application binary folder.



[...]



It isn't always the case if the dll is dynamic loaded, it might 
fail quietly, for example, if you deploy an Qt application with 
QWebKit missing those Open SSL dlls, an page with https 
protocol just doesn't open and didn't show any error at all. To 
find out whether some referenced dll by your executable is 
missing, people use Dependence Walker: 
http://www.dependencywalker.com/


I don't think this is the problem.

If I use get on https://www.google.com it works fine but if I use 
get on https://www.googleapis.com/youtube/v3/channels it fails


so it is site dependent.



Re: How to curl!

2018-05-01 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

Trying to curl basic stuff but std.net.curl isn't cooperating:
This is one of the reasons I hate D ;/ I've spent more time 
trying to get std.net.curl to do something that just works from 
the command line.


std.net.curl is not quite up to date when compared to the curl 
command. It is not useful any non-trivial stuff. Right now I'm 
using ikod's dlang-requests[1] and I'm quite happy with it. I 
would recommend you to try it.


[1] https://github.com/ikod/dlang-requests


Re: Is build a 64 bit version worth if I'm looking for better perfomance?

2018-05-01 Thread Uknown via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 22:48:08 UTC, Dr.No wrote:
Looking for make application run fast as possible, aside 
optimization in the source code, is using 64 bit over 32 really 
worth?


With the GC yes, since false pointers become less of an issue. 
Also you get to take full advantage of the target CPU. The vast 
majority of home computers today use 64 bit. You'll also be able 
to take advantage of more optimizations since the compiler can 
assume more features are available. But you will *probably* get 
better performance from profiling + optimizing than 32 bit -> 64 
bit.


Re: How to curl!

2018-05-01 Thread Dr.No via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 22:51:01 UTC, IntegratedDimensions 
wrote:

On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

Trying to curl basic stuff but std.net.curl isn't cooperating:

curl "https://www.googleapis.com/youtube/v3/channels"; -G -d 
part=contentDetails -d forUsername=test -d key=somekey


[...]


Just a wild guess, do you have the SSL dlls in the same folder 
as your executable or (less likely) in your PATH?



What SSL dlls?

those dlls:
libeay32.dll libssl32.dll ssleay32.dll

I'm sure they would be installed with whatever

installation uses them.


I don't think so. IIRC, when I used D+curl I needed to download 
them manutally. This is always the case with Qt. Even using 
windeployqt with   --webkit2 flag I still need to copy those dlls 
to application binary folder.


ssleay32.dll comes with dmd2 and it is in the path, if that is 
what you are talking about. If a dll was missing though and 
that was the problem then it needs to state that it is a 
missing dll rather than some other issue.



It isn't always the case if the dll is dynamic loaded, it might 
fail quietly, for example, if you deploy an Qt application with 
QWebKit missing those Open SSL dlls, an page with https protocol 
just doesn't open and didn't show any error at all. To find out 
whether some referenced dll by your executable is missing, people 
use Dependence Walker: http://www.dependencywalker.com/







Re: How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 22:08:50 UTC, Dr.No wrote:
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

Trying to curl basic stuff but std.net.curl isn't cooperating:

curl "https://www.googleapis.com/youtube/v3/channels"; -G -d 
part=contentDetails -d forUsername=test -d key=somekey


[...]


Just a wild guess, do you have the SSL dlls in the same folder 
as your executable or (less likely) in your PATH?



What SSL dlls? I'm sure they would be installed with whatever 
installation uses them.


ssleay32.dll comes with dmd2 and it is in the path, if that is 
what you are talking about. If a dll was missing though and that 
was the problem then it needs to state that it is a missing dll 
rather than some other issue.


Is build a 64 bit version worth if I'm looking for better perfomance?

2018-05-01 Thread Dr.No via Digitalmars-d-learn
Looking for make application run fast as possible, aside 
optimization in the source code, is using 64 bit over 32 really 
worth?


Re: How to curl!

2018-05-01 Thread Dr.No via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 21:57:22 UTC, IntegratedDimensions 
wrote:

Trying to curl basic stuff but std.net.curl isn't cooperating:

curl "https://www.googleapis.com/youtube/v3/channels"; -G -d 
part=contentDetails -d forUsername=test -d key=somekey


[...]


Just a wild guess, do you have the SSL dlls in the same folder as 
your executable or (less likely) in your PATH?


How to curl!

2018-05-01 Thread IntegratedDimensions via Digitalmars-d-learn

Trying to curl basic stuff but std.net.curl isn't cooperating:

curl "https://www.googleapis.com/youtube/v3/channels"; -G -d 
part=contentDetails -d forUsername=test -d key=somekey


import std.stdio;
import std.net.curl;


int main(string[] argv)
{
auto http = HTTP();
http.caInfo("cacert.pem"); // cacert.pem installed in the bin dir
http.handle.set(CurlOption.ssl_verifypeer, 1);

	auto content = 
post("https://www.googleapis.com/youtube/v3/channels";, ["part" : 
"contentDetails", "forUsername" : "test", "key" : "somekey"], 
http);



return 0;
}

I either get the error

Unhandled exception: std.net.curl.CurlException Peer certificate 
cannot be authenticated with given CA certificates on handle at 
std\net\curl.d(4343)


or, when verifypeer is 0,

Unhandled exception: std.net.curl.HTTPStatusException HTTP 
request returned status code 404 (Not Found)


But the command line version works fine. (of course, if you want 
to test you must use a valid key and youtube user name.


This is one of the reasons I hate D ;/ I've spent more time 
trying to get std.net.curl to do something that just works from 
the command line.




Pure double to string conversion

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn
Is there a way to convert a `double` to a `string` in a `pure` 
function?


I tried

@safe pure unittest
{
import std.conv : to;
const y = 3.14.to!string;
}

but it fails to compile as

`pure` function `foo.__unittest_L1_C12` cannot call impure 
function `std.conv.to!string.to!double.to`


Have anybody wrapped the corresponding C solution via, snprintf 
or gcvt in a high-level D wrapper?


Is assume `gcvt` is GNU only but that's ok with me. I assume 
`gcvt` is faster than `snprintf` in this case.


Re: Purity of delegate-style toString

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 12:03:15 UTC, ag0aep6g wrote:
By the way, you shouldn't mark toString as @trusted when `sink` 
is @system.


Thanks


Can I convert the Range returned by asUpperCase to ubyte[]?

2018-05-01 Thread Dr.No via Digitalmars-d-learn
I'm trying to do an optimization here: a hash function which 
expect a ubye[] array as argument, would just work if I cast 
string to ubyte[] but I need to convert it to upper case, so I'd 
like to do that lazily, so that the byte is converted to its 
upper case version soon as it's requested. I'm not sure if this 
possible because I think the function should also work with Range 
and not ubyte[] to work.


So, adding some code example, can I convert the string to upper 
case then convert it to ubyte[] without memory allocation? 
something like this:



import xxhash;
import std.uni : asUpperCase;
uint hash = xxhashOf(cast(ubyte[])(word.asUpperCase));


Re: Interfacing with C++ Class named Object

2018-05-01 Thread Robert M. Münch via Digitalmars-d-learn

On 2018-05-01 17:14:53 +, Robert M. Münch said:


Yes, great! Thanks. I could extend the code now. But I get a next problem:

extern (C++, b2d) {
  class AnyBase {
bool isShared();
  }

  pragma(mangle, "Object");
  class b2dObject : AnyBase {
  }

  class Image : b2dObject {
  // class Image {
uint create(int w, int h, uint pixelFormat);
  }
}

The linke complains about missing symbols:

error LNK2001: "public: virtual bool __cdecl 
b2d::AnyBase::isShared(void)" (?isShared@AnyBase@b2d@@UEBA_NXZ)
error LNK2001: "public: virtual unsigned int __cdecl 
b2d::Image::create(int,int,unsigned int)" 
(?create@Image@b2d@@UEAAIHHI@Z)


I have in my C++ link lib:

?isShared@AnyBase@b2d@@QEBA_NXZ which demangles to => public: BOOL 
__cdecl b2d::AnyBase::isShared(void)const __ptr64


So, the difference is the "virtual" specifier on the D side, while the 
C++ mangeling is missing this. I have this for many functions.


Any idea how to handle this?


Answering myself. There is a final keyword missing:

 class Image : b2dObject {
 // class Image {
   final uint create(int w, int h, uint pixelFormat);
 }

With this it's working.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Interfacing with C++ Class named Object

2018-05-01 Thread Robert M. Münch via Digitalmars-d-learn

On 2018-05-01 16:07:30 +, Timoses said:


On Tuesday, 1 May 2018 at 15:24:09 UTC, Robert M. Münch wrote:
Hi, I'm mostly doing simple C-API wrappers around C++ code to access 
thigns from D. However, I wanted to try how far I can come using C++ 
directly.


I have the following C++ code in namespace N:

class Image : public Object {
Error create(int w, int h, uint32_t p) noexcept;
}
And I have the following D code:
extern (C++, N) {
class Object {
}
class Image : public Object {
uint create(int w, int h, uint pixelFormat);
}
}
So frist problem I see is, that a C++ class names Object is pretty 
unfortunate as this is a reserved class name in D. And DMD doesn't seem 
to allow using Object inside a C++ scope (which IMO should be possible).
Am I right, that there is no chance to handle this case other than 
ranming the C++ base class?


Would `pragma(mangle, ...)` work here?
https://dlang.org/spec/pragma.html#mangle


Yes, great! Thanks. I could extend the code now. But I get a next problem:

extern (C++, b2d) {
 class AnyBase {
   bool isShared();
 }

 pragma(mangle, "Object");
 class b2dObject : AnyBase {
 }

 class Image : b2dObject {
 // class Image {
   uint create(int w, int h, uint pixelFormat);
 }
}

The linke complains about missing symbols:

error LNK2001: "public: virtual bool __cdecl 
b2d::AnyBase::isShared(void)" (?isShared@AnyBase@b2d@@UEBA_NXZ)
error LNK2001: "public: virtual unsigned int __cdecl 
b2d::Image::create(int,int,unsigned int)" 
(?create@Image@b2d@@UEAAIHHI@Z)


I have in my C++ link lib:

?isShared@AnyBase@b2d@@QEBA_NXZ which demangles to => public: BOOL 
__cdecl b2d::AnyBase::isShared(void)const __ptr64


So, the difference is the "virtual" specifier on the D side, while the 
C++ mangeling is missing this. I have this for many functions.


Any idea how to handle this?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Interfacing with C++ Class named Object

2018-05-01 Thread Timoses via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 15:24:09 UTC, Robert M. Münch wrote:
Hi, I'm mostly doing simple C-API wrappers around C++ code to 
access thigns from D. However, I wanted to try how far I can 
come using C++ directly.


I have the following C++ code in namespace N:

class Image : public Object {
Error create(int w, int h, uint32_t p) noexcept;
}
And I have the following D code:
extern (C++, N) {
 class Object {
 }
 class Image : public Object {
   uint create(int w, int h, uint pixelFormat);
 }
}
So frist problem I see is, that a C++ class names Object is 
pretty unfortunate as this is a reserved class name in D. And 
DMD doesn't seem to allow using Object inside a C++ scope 
(which IMO should be possible).
Am I right, that there is no chance to handle this case other 
than ranming the C++ base class?


Would `pragma(mangle, ...)` work here?
https://dlang.org/spec/pragma.html#mangle


Re: D in SUSE Enterprise Linux

2018-05-01 Thread rikki cattermole via Digitalmars-d-learn

On 02/05/2018 3:51 AM, Vino wrote:

On Tuesday, 1 May 2018 at 15:42:38 UTC, Jonathan M Davis wrote:

On Tuesday, May 01, 2018 15:18:12 Vino via Digitalmars-d-learn wrote:

On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:
> On 02/05/2018 2:56 AM, Vino wrote:
>> [...]
>
> Does this work?
>
> $ dmd -run foo.d

Hi Rikki,

  No, it is not working, rather getting an error, and the user i
executed is the root user. if i compile the program as dmd
 and then execute it as ./ it works
fine, so is rdmd not supported in Linux.

Error:
/tmp/dmd_runqfz3ul: Permission denied


That sounds like your /tmp is mounted with noexec. which won't work 
with rdmd or any other program that expects to be able to create a 
file in /tmp and run it. Presumably, you'll need to change the 
settings in /etc/fstab so that /tmp is not mounted with noexec.


- Jonathan M Davis


Hi Jonathan,

   Yes the /tmp is mounted with noexec option , we should not change 
this option as it is a security violation so is there any other way we 
can make it work, it tried setting the tmp env variable to a local FS 
which is mounted with the noexec option but it did not work.


From,
Vino.B


Modify rdmd to use another directory which is more acceptable for your 
setup.


Re: D in SUSE Enterprise Linux

2018-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 01, 2018 15:51:14 Vino via Digitalmars-d-learn wrote:
> On Tuesday, 1 May 2018 at 15:42:38 UTC, Jonathan M Davis wrote:
> > On Tuesday, May 01, 2018 15:18:12 Vino via Digitalmars-d-learn
> >
> > wrote:
> >> On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:
> >> > On 02/05/2018 2:56 AM, Vino wrote:
> >> >> [...]
> >> >
> >> > Does this work?
> >> >
> >> > $ dmd -run foo.d
> >>
> >> Hi Rikki,
> >>
> >>   No, it is not working, rather getting an error, and the user
> >>
> >> i
> >> executed is the root user. if i compile the program as dmd
> >>  and then execute it as ./ it works
> >> fine, so is rdmd not supported in Linux.
> >>
> >> Error:
> >> /tmp/dmd_runqfz3ul: Permission denied
> >
> > That sounds like your /tmp is mounted with noexec. which won't
> > work with rdmd or any other program that expects to be able to
> > create a file in /tmp and run it. Presumably, you'll need to
> > change the settings in /etc/fstab so that /tmp is not mounted
> > with noexec.
> >
> > - Jonathan M Davis
>
> Hi Jonathan,
>
>Yes the /tmp is mounted with noexec option , we should not
> change this option as it is a security violation so is there any
> other way we can make it work, it tried setting the tmp env
> variable to a local FS which is mounted with the noexec option
> but it did not work.

Whether it's really a security risk is up for debate, though I'm sure that
concerns over that would be why /tmp is mounted with noexec on your system.

Looking at rdmd --help, it does list a --tmpdir flag, so if you have another
directory that is not mounted noexec where you would consider it acceptable
to have temporary files be created and executed, then you can use --tmpdir
to tell rdmd to use it. So, presumably, the shebang line would then be
something like

#!/usr/bin/env rdmd --tmpdir=/some/other/tmp/dir

though I haven't tested it.

- Jonathan M Davis



Re: D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 15:42:38 UTC, Jonathan M Davis wrote:
On Tuesday, May 01, 2018 15:18:12 Vino via Digitalmars-d-learn 
wrote:

On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:
> On 02/05/2018 2:56 AM, Vino wrote:
>> [...]
>
> Does this work?
>
> $ dmd -run foo.d

Hi Rikki,

  No, it is not working, rather getting an error, and the user 
i

executed is the root user. if i compile the program as dmd
 and then execute it as ./ it works
fine, so is rdmd not supported in Linux.

Error:
/tmp/dmd_runqfz3ul: Permission denied


That sounds like your /tmp is mounted with noexec. which won't 
work with rdmd or any other program that expects to be able to 
create a file in /tmp and run it. Presumably, you'll need to 
change the settings in /etc/fstab so that /tmp is not mounted 
with noexec.


- Jonathan M Davis


Hi Jonathan,

  Yes the /tmp is mounted with noexec option , we should not 
change this option as it is a security violation so is there any 
other way we can make it work, it tried setting the tmp env 
variable to a local FS which is mounted with the noexec option 
but it did not work.


From,
Vino.B


Re: Equivalent function of timeCreated for Linux

2018-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 01, 2018 15:41:07 Vino via Digitalmars-d-learn wrote:
> Hi All,
>
>   Request your help, what is the equivalent function of
> timeCreated(Windows) for Linux. Or how do i get the file creation
> date and time in Linux using D.

AFAIK, no filesystems on Linux keep track of that information, and if they
do, you can't get at it via the normal OS API calls for getting file
information. The closest that you're likely to get was the time that the
file was last modified. The OS API call for getting information on POSIX
systems is the stat command, and as can be seen on the man page

https://linux.die.net/man/2/stat

this is the information provided on Linux:

struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_tst_mode;/* protection */
nlink_t   st_nlink;   /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev;/* device ID (if special file) */
off_t st_size;/* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
time_tst_atime;   /* time of last access */
time_tst_mtime;   /* time of last modification */
time_tst_ctime;   /* time of last status change */
};

The only fields related to time are

time_tst_atime;   /* time of last access */
time_tst_mtime;   /* time of last modification */
time_tst_ctime;   /* time of last status change */

and the file creation time is not one of them. That's why D's std.file does
not provide a way to get at the file creation time on any non-Windows
systems. Windows tracks the file creation and has calls to provide that
information, whereas POSIX systems do not. So, std.file provides that
information on Windows but not on other systems.

- Jonathan M Davis



Equivalent function of timeCreated for Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, what is the equivalent function of 
timeCreated(Windows) for Linux. Or how do i get the file creation 
date and time in Linux using D.


From,
Vino.B


Re: D in SUSE Enterprise Linux

2018-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 01, 2018 15:18:12 Vino via Digitalmars-d-learn wrote:
> On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:
> > On 02/05/2018 2:56 AM, Vino wrote:
> >> Hi All,
> >>
> >>   Request your help, trying to execute the below program in
> >>
> >> SUSE Linux but there is no output
> >>
> >>
> >> Code
> >> #!/usr/bin/env rdmd
> >> import std.stdio;
> >>
> >> void main() {
> >> writeln("Test");
> >> }
> >>
> >> DMD Version : DMD64 D Compiler v2.079.1
> >> Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm
> >>
> >> Execution 1 : rdmd   without this #!/usr/bin/env
> >> rdmd
> >> Execution 2: ./ with #!/usr/bin/env rdmd + chmod
> >> 777 
> >>
> >> Both ways there is on output
> >>
> >>
> >> From,
> >> Vino.B
> >
> > Does this work?
> >
> > $ dmd -run foo.d
>
> Hi Rikki,
>
>   No, it is not working, rather getting an error, and the user i
> executed is the root user. if i compile the program as dmd
>  and then execute it as ./ it works
> fine, so is rdmd not supported in Linux.
>
> Error:
> /tmp/dmd_runqfz3ul: Permission denied

That sounds like your /tmp is mounted with noexec. which won't work with
rdmd or any other program that expects to be able to create a file in /tmp
and run it. Presumably, you'll need to change the settings in /etc/fstab so
that /tmp is not mounted with noexec.

- Jonathan M Davis



Interfacing with C++ Class named Object

2018-05-01 Thread Robert M. Münch via Digitalmars-d-learn
Hi, I'm mostly doing simple C-API wrappers around C++ code to access 
thigns from D. However, I wanted to try how far I can come using C++ 
directly.


I have the following C++ code in namespace N:

class Image : public Object {
Error create(int w, int h, uint32_t p) noexcept;
}
And I have the following D code:
extern (C++, N) {
 class Object {
 }
 class Image : public Object {
   uint create(int w, int h, uint pixelFormat);
 }
}
So frist problem I see is, that a C++ class names Object is pretty 
unfortunate as this is a reserved class name in D. And DMD doesn't seem 
to allow using Object inside a C++ scope (which IMO should be possible).
Am I right, that there is no chance to handle this case other than 
ranming the C++ base class?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

On Tuesday, 1 May 2018 at 15:04:43 UTC, rikki cattermole wrote:

On 02/05/2018 2:56 AM, Vino wrote:

Hi All,

  Request your help, trying to execute the below program in 
SUSE Linux but there is no output



Code
#!/usr/bin/env rdmd
import std.stdio;

void main() {
writeln("Test");
}

DMD Version : DMD64 D Compiler v2.079.1
Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm

Execution 1 : rdmd   without this #!/usr/bin/env 
rdmd
Execution 2: ./ with #!/usr/bin/env rdmd + chmod 
777 


Both ways there is on output


From,
Vino.B


Does this work?

$ dmd -run foo.d


Hi Rikki,

 No, it is not working, rather getting an error, and the user i 
executed is the root user. if i compile the program as dmd 
 and then execute it as ./ it works 
fine, so is rdmd not supported in Linux.


Error:
/tmp/dmd_runqfz3ul: Permission denied

From,
Vino.B


Re: D in SUSE Enterprise Linux

2018-05-01 Thread rikki cattermole via Digitalmars-d-learn

On 02/05/2018 2:56 AM, Vino wrote:

Hi All,

  Request your help, trying to execute the below program in SUSE Linux 
but there is no output



Code
#!/usr/bin/env rdmd
import std.stdio;

void main() {
writeln("Test");
}

DMD Version : DMD64 D Compiler v2.079.1
Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm

Execution 1 : rdmd   without this #!/usr/bin/env rdmd
Execution 2: ./ with #!/usr/bin/env rdmd + chmod 777 



Both ways there is on output


From,
Vino.B


Does this work?

$ dmd -run foo.d


D in SUSE Enterprise Linux

2018-05-01 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, trying to execute the below program in SUSE 
Linux but there is no output



Code
#!/usr/bin/env rdmd
import std.stdio;

void main() {
writeln("Test");
}

DMD Version : DMD64 D Compiler v2.079.1
Package installed : dmd-2.079.1-0.openSUSE.x86_64.rpm

Execution 1 : rdmd   without this #!/usr/bin/env 
rdmd
Execution 2: ./ with #!/usr/bin/env rdmd + chmod 
777 


Both ways there is on output


From,
Vino.B


Re: Purity of delegate-style toString

2018-05-01 Thread ag0aep6g via Digitalmars-d-learn

On 05/01/2018 01:44 PM, Per Nordlöw wrote:
In which cases (if any) is it possible to make a delegate-style 
implementation of toString such as


     void toString(scope void delegate(const(char)[]) sink) const 
@trusted pure

     {
     // sink("...");
     // sink.formattedWrite!"..."(...);
     }

pure?


You have to mark `sink` as pure, too:

void toString(scope void delegate (const(char)[]) pure sink)
const @trusted pure

Then the toString method itself works, but it may not be callable by 
other code that wants to use an impure sink.


For example, `format` works, but `writeln` doesn't:


struct S
{
void toString(scope void delegate(const(char)[]) pure sink)
const @trusted pure
{
import std.format: formattedWrite;
sink("...");
sink.formattedWrite!"%s"(" ...");
}
}
void main()
{
import std.format: format;
import std.stdio: writeln;
writeln(format("%s", S())); /* Ok. Prints "... ...". */
writeln(S()); /* Nope. writeln would like to use an impure sink. */
}


By the way, you shouldn't mark toString as @trusted when `sink` is @system.


Purity of delegate-style toString

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn
In which cases (if any) is it possible to make a delegate-style 
implementation of toString such as


void toString(scope void delegate(const(char)[]) sink) const 
@trusted pure

{
// sink("...");
// sink.formattedWrite!"..."(...);
}

pure?


Re: Coding Challenges at Dconf2018: Implement Needleman–Wunsch and Smith–Waterman algorithms

2018-05-01 Thread rikki cattermole via Digitalmars-d-learn

On 01/05/2018 9:00 PM, biocyberman wrote:

On Monday, 30 April 2018 at 20:34:41 UTC, Steven Schveighoffer wrote:

On 4/30/18 2:47 PM, biocyberman wrote:

Hellow D community.

I am attending Dconf 2018 and giving a talk there on May 4. Link: 
https://dconf.org/2018/talks/le.html. It will be very interesting to 
talk about the outcome of the following challenges. If we can't have 
at least 3 solutions by three individuals by 10:00 GMT+2 May 4, I 
will have to postpone the deadline one week. Please see below for 
more details.




This should really go in announce ;)

-Steve


Thought about that too. But then I imagined the "announce" is for 
official use of the D dev team and forum admins.


It isn't.



Re: Coding Challenges at Dconf2018: Implement Needleman–Wunsch and Smith–Waterman algorithms

2018-05-01 Thread biocyberman via Digitalmars-d-learn
On Monday, 30 April 2018 at 20:34:41 UTC, Steven Schveighoffer 
wrote:

On 4/30/18 2:47 PM, biocyberman wrote:

Hellow D community.

I am attending Dconf 2018 and giving a talk there on May 4. 
Link: https://dconf.org/2018/talks/le.html. It will be very 
interesting to talk about the outcome of the following 
challenges. If we can't have at least 3 solutions by three 
individuals by 10:00 GMT+2 May 4, I will have to postpone the 
deadline one week. Please see below for more details.




This should really go in announce ;)

-Steve


Thought about that too. But then I imagined the "announce" is for 
official use of the D dev team and forum admins. These challenges 
are for learning and for fun, therefore I put them topic here. 
Anyway, I can't move this to announce now.