Re: scope(exit) and Ctrl-C

2017-12-02 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-02 02:26, Adam D. Ruppe wrote:

But this is intentional - there is no generic, reliable, cross-platform 
way of handling it natively. So you need to know the system and code it 
yourself. Not super hard but does take a bit of effort in your code.


Since the "scope" block is not executed, does that also mean that the 
runtime is not shutdown? If that's the case, does it make sense to have 
a generic signal handler in druntime that aborts the application and 
shuts down the druntime in a graceful way?


--
/Jacob Carlborg


Re: scope(exit) and Ctrl-C

2017-12-02 Thread Patrick Schluter via Digitalmars-d-learn

On Saturday, 2 December 2017 at 04:49:26 UTC, H. S. Teoh wrote:
On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via 
Digitalmars-d-learn wrote:

[...]


Signal handlers can potentially be invoked while inside a 
non-reentrant libc or OS function, so trying to do anything 
that (indirectly or otherwise) calls that function will cause 
havoc to your program.  Also, while the signal handler is 
running, some (all?) further signals may be blocked, meaning 
that your program might miss an important signal if your sig 
handler takes too long to run.  Furthermore, the signal may 
have happened in the middle of your own code, so race 
conditions may apply (e.g. if you're modifying global data in 
both).


[...]


On Linux you can use signalfd() for that, but nice trick if you 
want Posix portability.


Re: Windows Share Path

2017-12-02 Thread codephantom via Digitalmars-d-learn

On Saturday, 2 December 2017 at 07:48:14 UTC, Vino wrote:


Even tried with the below code, it works manually but not via 
Windows scheduler with option "Run whether user is logged on or 
not"




Are you using appropriate credentials in the scheduled task?



Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 07:48:14 +, Vino wrote:

> On Saturday, 2 December 2017 at 05:08:27 UTC, Vino wrote:
>> Hi All,
>>
>>   Request your help, I have samll program which validates the
>> file path, the script run perfectly when i run it manually, but if i
>> run it via windows task scheduler i am getting "Invalid File Path
>>  or Path do not Exist", The path is a windows share, Even tried
>> to add the net path as "server\\share$\\BACKUP" for the parameter
>> "p" in the below code but no luck, the same error.
>>
>> Even tried to call this program via .bat script not luck same error
>>
>> Windows .BAT program @echo off cd D:\DScript start /D D:\DScript /B
>> /WAIT D:\DScript\TestDir.exe exit
>>
>> Program import std.stdio;
>> import std.file;
>> import std.path;
>> import std.system;
>>
>> void main()
>> {
>>  version (Windows) { auto p = "N:\\\BACKUP";
>>   if (!p.isValidPath && !p.strip.isValidFilename || !p.exists )
>> { writeln("Invalid File Path (", p, ") or Path do not Exist"); }
>>   else { writeln("File Exist":, p); }
>> }
>>   }
>>
>> From,
>> Vino.B
> 
> Even tried with the below code, it works manually but not via Windows
> scheduler with option "Run whether user is logged on or not"
> 
> Program:
> import std.stdio;
> import std.file;
> import std.path;
> import std.string;
> import std.process;
> 
> void main()
> {
> auto result =
> execute(["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\
\powershell.exe",
> "-command", "New-PSDrive -Name", "R", "-PSProvider FileSystem -Root",
> "bp1xeuss005-f05.bp.com\\ea_sap_basis2$", "-Persist"]);
> auto p = "R:\\BACKUP";
> if (!p.isValidPath && !p.strip.isValidFilename || !p.exists ) {
> writeln("Invalid File Path (", p, ") or Path do not Exist"); }
> else { writeln("File Exist :", p); }
> 
> }
> From,
> Vino.B

FYI: The backquote gives you a WYSIWYG string: `c:\windows\system32`, 
which is incredibly useful for Windows paths.


I don't have a network share available to test with, but:

Are you running with elevated privileges in the scheduled task? If so, do 
you run as admin when trying manually? If you mount the share as a user, 
I'm wondering if the task can't access it running in another context.

You could try in the batch file, either adding
```
net use N: \\server\share\BACKUP /USER:  
```

prior to running the exe (and "net delete" afterword), or try
"pushd \\server\share\BACKUP" to access the path (and make it the current 
working directory). Use "popd \\server\share\BACKUP" at the end of the 
script.

Source: https://blog.adrianbanks.co.uk/windows/2007/03/08/accessing-
network-file-shares-from-a-command-prompt.html


Re: Windows Share Path

2017-12-02 Thread Vino via Digitalmars-d-learn

On Saturday, 2 December 2017 at 13:05:37 UTC, rjframe wrote:

On Sat, 02 Dec 2017 07:48:14 +, Vino wrote:


On Saturday, 2 December 2017 at 05:08:27 UTC, Vino wrote:

[...]


Even tried with the below code, it works manually but not via 
Windows scheduler with option "Run whether user is logged on 
or not"


Program:
import std.stdio;
import std.file;
import std.path;
import std.string;
import std.process;

void main()
{
auto result =
execute(["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\

\powershell.exe",
"-command", "New-PSDrive -Name", "R", "-PSProvider FileSystem 
-Root",

"bp1xeuss005-f05.bp.com\\ea_sap_basis2$", "-Persist"]);
auto p = "R:\\BACKUP";
if (!p.isValidPath && !p.strip.isValidFilename || !p.exists ) {
writeln("Invalid File Path (", p, ") or Path do not Exist"); }
else { writeln("File Exist :", p); }

}
From,
Vino.B


FYI: The backquote gives you a WYSIWYG string: 
`c:\windows\system32`, which is incredibly useful for Windows 
paths.



I don't have a network share available to test with, but:

Are you running with elevated privileges in the scheduled task? 
If so, do you run as admin when trying manually? If you mount 
the share as a user, I'm wondering if the task can't access it 
running in another context.


You could try in the batch file, either adding
```
net use N: \\server\share\BACKUP /USER:  
```

prior to running the exe (and "net delete" afterword), or try
"pushd \\server\share\BACKUP" to access the path (and make it 
the current
working directory). Use "popd \\server\share\BACKUP" at the end 
of the

script.

Source: 
https://blog.adrianbanks.co.uk/windows/2007/03/08/accessing- 
network-file-shares-from-a-command-prompt.html


Hi,

  The script is schedule using a domain user id(domain\user id), 
and the windows share are mapped using the same user id /password 
and ran the scheduled task by login with the same domain user(Not 
Administrator) , the script executes fine when run manually and 
executes fine when scheduled with option "Run when user is logged 
in" , but the same is not running when schedule with option "Run 
whether user is logged in or not". The domain id is added to the 
Administrator Group and the Security policy "Logon as Batch user" 
is assigned. The domain id has the Full access to the Network 
share.


From,
Vino.B






Re: Windows Share Path

2017-12-02 Thread Vino via Digitalmars-d-learn

On Saturday, 2 December 2017 at 14:16:17 UTC, Vino wrote:

On Saturday, 2 December 2017 at 13:05:37 UTC, rjframe wrote:

[...]


Hi,

  The script is schedule using a domain user id(domain\user 
id), and the windows share are mapped using the same user id 
/password and ran the scheduled task by login with the same 
domain user(Not Administrator) , the script executes fine when 
run manually and executes fine when scheduled with option "Run 
when user is logged in" , but the same is not running when 
schedule with option "Run whether user is logged in or not". 
The domain id is added to the Administrator Group and the 
Security policy "Logon as Batch user" is assigned. The domain 
id has the Full access to the Network share.


From,
Vino.B

Hi,
  Even tried the Option "Run with Highest Privilege" but no luck. 
and also tried with option "Configure for : Windows Vista , 
Windows Server 2008"


From,
Vino.B


Re: Windows Share Path

2017-12-02 Thread rjframe via Digitalmars-d-learn
On Sat, 02 Dec 2017 14:16:17 +, Vino wrote:

> Hi,
> 
>The script is schedule using a domain user id(domain\user id),
> and the windows share are mapped using the same user id /password and
> ran the scheduled task by login with the same domain user(Not
> Administrator) , the script executes fine when run manually and executes
> fine when scheduled with option "Run when user is logged in" , but the
> same is not running when schedule with option "Run whether user is
> logged in or not". The domain id is added to the Administrator Group and
> the Security policy "Logon as Batch user"
> is assigned. The domain id has the Full access to the Network share.
> 
> From,
> Vino.B

Is storing the password allowed by your local security policy? (gpedit on 
the local machine: Computer Configuration > Windows Settings > Security 
Settings > Local Policies > Security Options > Network access: Do not 
allow storage of passwords and credentials for network authentication)

Other than that, I'm out of ideas; this should be a slow week at work so I 
might be able to try later.

Note that running "whether logged on or not" will run in interactive mode 
so your `writeln`s won't output anywhere; you'd need to log to a file. But 
it shouldn't restrict network access.

--Ryan


Re: Instructions to build DMD from source don't work (anymore) here

2017-12-02 Thread Joakim via Digitalmars-d-learn

On Thursday, 30 November 2017 at 08:38:15 UTC, Basile B. wrote:
Hi, I've recently switched from a linux distribution to another 
(F27). During the last 2 years i used a script to build DMD, 
unfortunately i forgot to include it in my backup. Initially i 
thought "No problem, there's the instructions in the wiki, it's 
more or less about calling make with a couple of option". In 
theory only...


make -fposix.mak gives me


[basile@pc1 dmd]$ make -f posix.mak
make -C src -f posix.mak
make[1] : on entre dans le répertoire 
« /home/basile/dev/repos/dlang/dmd/src »

no cpu specified, assuming X86
 (CC)  ROOT_OBJS  ddmd/root/newdelete.c
c++ -c -o../generated/linux/release/64/newdelete.o 
-Wno-deprecated -Wstrict-
aliasing -fno-exceptions -fno-rtti -D__pascal= -DMARS=1 
-DTARGET_LINUX=1 -
DDM_TARGET_CPU_X86=1 -m64 -fPIC -std=gnu++98 -Iddmd/root -MMD 
-MF ../generated/linux/release/64/newdelete.deps 
ddmd/root/newdelete.c

cc1plus: désolé, pas implémenté: mode 64 bits pas compilé


According to Google Translate, this means your C++ compiler 
doesn't support 64-bit mode.  Not sure why, since the Makefile is 
only compiling in 64-bit after checking that's what your kernel 
is, with uname -m.


Ddoc - No Documentation

2017-12-02 Thread Tony via Digitalmars-d-learn

Wondering what the rationale is for this:

https://dlang.org/spec/ddoc.html#no_documentation

No Documentation

No documentation is generated for the following constructs, even 
if they have a documentation comment:


Invariants
Postblits
Destructors
Static constructors and static destructors
Class info, type info, and module info


Re: Ddoc - No Documentation

2017-12-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 03, 2017 00:14:10 Tony via Digitalmars-d-learn wrote:
> Wondering what the rationale is for this:
>
> https://dlang.org/spec/ddoc.html#no_documentation
>
> No Documentation
>
> No documentation is generated for the following constructs, even
> if they have a documentation comment:
>
> Invariants
> Postblits
> Destructors
> Static constructors and static destructors
> Class info, type info, and module info

Presumably, because they are not things that you would ever explicitly use.
The whole point of the documentation is to document what the types and
functions being documented do and how to use them. If they're not something
that you're going to explicitly use, then there really isn't anything to
document. In general, the items you listed are just implementation details
(e.g. a static constructor certainly isn't part of a public API), or they're
something that exists for types in general,  and there's nothing special to
document (e.g. all classes have a corresponding TypeInfo; there's nothing
about a specific class' TypeInfo that merits documentation, and it's not
something that's actually explicitly in the module anyway; it's all
generated by the compiler).

- Jonathan M Davis



Re: Windows Share Path

2017-12-02 Thread codephantom via Digitalmars-d-learn

On Saturday, 2 December 2017 at 14:23:48 UTC, Vino wrote:

Hi,
  Even tried the Option "Run with Highest Privilege" but no 
luck. and also tried with option "Configure for : Windows Vista 
, Windows Server 2008"


From,
Vino.B


You haven't accidently ticked the 'Do not store password' option? 
That is a common mistake. (i.e. make sure it's *not* ticked, and 
reinsert credentials).


In my 'sysadmin' days, I *refused* to use the windows scheduler. 
I didn't want something that kept changing depending on which 
version of windows you were using. I wanted consistency.


From memory, i think I installed 'system scheduler' on all my MS 
servers.


https://www.splinterware.com/tour/scheduler.html




Re: Ddoc - No Documentation

2017-12-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 3 December 2017 at 00:25:34 UTC, Jonathan M Davis 
wrote:
Presumably, because they are not things that you would ever 
explicitly use. The whole point of the documentation is to 
document what the types and functions being documented do and 
how to use them. If they're not something that you're going to 
explicitly use, then there really isn't anything to document.


Implicit use is important to understand what's going on too. My 
adrdox generator does document those... even if they don't have a 
comment, because just knowing they are there is valuable in 
understanding the type.


So your explanation might be the reason, but I disagree with it 
and I doubt I'm the only one.


Re: scope(exit) and Ctrl-C

2017-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 02, 2017 at 11:32:17AM +, Patrick Schluter via 
Digitalmars-d-learn wrote:
> On Saturday, 2 December 2017 at 04:49:26 UTC, H. S. Teoh wrote:
> > On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via
> > Digitalmars-d-learn wrote:
> > > [...]
> > 
> > Signal handlers can potentially be invoked while inside a
> > non-reentrant libc or OS function, so trying to do anything that
> > (indirectly or otherwise) calls that function will cause havoc to
> > your program.  Also, while the signal handler is running, some
> > (all?) further signals may be blocked, meaning that your program
> > might miss an important signal if your sig handler takes too long to
> > run.  Furthermore, the signal may have happened in the middle of
> > your own code, so race conditions may apply (e.g. if you're
> > modifying global data in both).
> > 
> > [...]
> 
> On Linux you can use signalfd() for that, but nice trick if you want
> Posix portability.

Ha! I've been using Linux for decades now and this is the first time I'm
aware of this function.  Should simplify my code when I'm not planning
to be Posix-portable. Thanks!


T

-- 
Heads I win, tails you lose.


Re: scope(exit) and Ctrl-C

2017-12-02 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 3 December 2017 at 02:56:38 UTC, H. S. Teoh wrote:
Ha! I've been using Linux for decades now and this is the first 
time I'm aware of this function.  Should simplify my code when 
I'm not planning to be Posix-portable. Thanks!


In the same vein, make sure you read about timerfd and eventfd 
too. They rok.


Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn

On Friday, 1 December 2017 at 18:33:09 UTC, Ali Çehreli wrote:

On 12/01/2017 07:21 AM, Steven Schveighoffer wrote:
> On 12/1/17 4:29 AM, Johan Engelen wrote:

>> (Also, I would expect "popFront" to return the element
popped, but it
>> doesn't, OK...
>
> pop removes the front element, but if getting the front
element is
> expensive (say if it's a map with a complex lambda function),
you don't
> want to execute that just so you can return it to someone who
doesn't
> care. This is why front and popFront are separate.

Yet, we're told that compilers are pretty good at eliminating 
that unused copy especially for function templates where all 
code is visible.


I assume that Steven means "copying the front element" when he 
wrote "getting the front element"? There is no need for a copy, 
because the element will be removed from the range, so we can 
move (whose cost only depends on the size of the element, 
internal pointers being disallowed by the language).
If it is expensive to actually get _to_ the front/back element 
(i.e. find its memory location), then having to do the operation 
twice is a disadvantage.


Ali: the compiler can only elide copying/moving of an unused 
return value when inlining the function. (the duty of making the 
return value move/copy is on the callee, not the caller)


Note that because front/back() and popFront/Back() are separate, 
a copy *is* needed when one wants to "pop an element off". Thus 
moveFront/Back() and popFront/Back() should be used. OK.
The fact that "pop" does something different from other 
programming languages is something important to remember when 
teaching people about D. And I think should be made clear in the 
documentation; let's add an example of how one is supposed to use 
all this in an efficient manner?


Back on topic: let's change the documentation of moveFront such 
that it is clear that it does _not_ reduce the number of elements 
in the range?


So, even though exception safety is not a common topic of D 
community, the real reason for why popFront() does not return 
the element is for strong exception safety guarantee.


Interesting point. Argh why do we allow the user to throw in move?

Regardless, separating front() from popFront() is preferable 
due to cohesion: fewer responsibilities per function, 
especially such low level ones.


This doesn't make much sense ;-)
popFrontN has more responsibility, and one gains better 
performance than simply calling popFront N times. It's similar 
here.


-Johan





Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 18:55:53 UTC, Steven Schveighoffer 
wrote:


Once you popFront a byLine range, the element that was at front 
is now possibly invalid (the buffer may be reused). So in order 
to return the line from popFront, you have to store it 
somewhere. This means allocating another buffer to hold the 
line you just returned. So the costs of doing this aren't just 
that you might do work and just throw it away, it's that you 
have this extra caching problem you didn't have before.


Cool, thanks.
Can we add points like this to the documentation?
(if not, user frustration and forum threads will keep coming 
about these things... ;-)


-Johan



How to declare immutable struct outside of try catch and reference it later

2017-12-02 Thread Fra Mecca via Digitalmars-d-learn

I have this code:
Configuration conf = void ;
try {
conf = parse_config("config.sdl");
} catch (Exception e) {
std.stdio.stderr.writeln("Error reading configuration 
file: ", e.msg);

exit(1);
}

// other code
function(value, conf);
// end

I get:
source/app.d(18,3): Error: cannot modify struct conf 
Configuration with immutable members


Is there a way to declare conf outside of the try catch block and 
use it later?

I thought void explicitly avoid inizialization.


Struct inside a class: How to get outer?

2017-12-02 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn

Is this even possible? My attempts:

class Outer {
struct Inner {
void foo() {
// Error: no property 'outer' for type 'Inner'
Outer o = this.outer;

// Error: cannot implicitly convert expression
// this of type Inner to testNested.Outer
Outer o = this;
}
}
}


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 03, 2017 05:49:54 Fra Mecca via Digitalmars-d-learn 
wrote:
> I have this code:
>  Configuration conf = void ;
>  try {
>  conf = parse_config("config.sdl");
>  } catch (Exception e) {
>  std.stdio.stderr.writeln("Error reading configuration
> file: ", e.msg);
>  exit(1);
>  }
>
> // other code
> function(value, conf);
> // end
>
> I get:
> source/app.d(18,3): Error: cannot modify struct conf
> Configuration with immutable members
>
> Is there a way to declare conf outside of the try catch block and
> use it later?
> I thought void explicitly avoid inizialization.

It's not possible to delay initialization with const or immutable variables
unless they're member variables (which then have to be initialized in a
constructor before they're used), but you can wrap the try-catch block in a
function or lambda that returns the struct so that the code is separated out
in a way that the variable is then directly initialized.

- Jonathan M Davis



Re: Struct inside a class: How to get outer?

2017-12-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 03, 2017 01:05:00 Nick Sabalausky  via Digitalmars-d-
learn wrote:
> Is this even possible? My attempts:
>
> class Outer {
>   struct Inner {
>   void foo() {
>   // Error: no property 'outer' for type 'Inner'
>   Outer o = this.outer;
>
>   // Error: cannot implicitly convert expression
>   // this of type Inner to testNested.Outer
>   Outer o = this;
>   }
>   }
> }

As I understand it, there is no outer for nested structs, only nested
classes. So, you'll either have to use a nested class or explicitly pass a
reference to the outer class to the nested struct.

- Jonathan M Davis