View previous topic :: View next topic |
Author |
Message |
uw
Joined: 10 Feb 2005 Posts: 4
|
Posted: Thu Feb 10, 2005 12:25 pm Post subject: some questions |
|
|
Mango seems to be a great library. Thank you for a flashing example of a really usefull D library, Kris.
However I've got one pretty important question. It seems examples(though I tried only 'servlets') do run only when linked for 'console' subsystem. When they are linked for 'windows', they silently quit. Even when it is console, if run(in hidden window and output is redirected) from another process which is 'windows' the only output is "Error : Access Violation" . Have you any clues what causes such strange behaviour?
Is there any easy way to completely suppress console output? Though I'm not sure it will really help.
By the way I noticed some pretty weird asm code in ByteSwap.d. No offence, but have you heard of bswap instruction? Its spec is bswap r32 and it takes exactly 1 tick. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 1:01 pm Post subject: |
|
|
You're welcome!
Thanks for posting this issue -- I'll look into it. When you say 'linked for windows', what does that mean exactly? And which version of windows are you running?
And thanks for the "bswap" note. I must admit to not having written much x86 assembler since the 386 ... definately a bit rusty
Do you wanna' patch ByteSwap.d ? If so, add your name to the header and email the file to me.
Cheers!
- kris |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 1:18 pm Post subject: Re: some questions |
|
|
uw wrote: | Is there any easy way to completely suppress console output? |
If you're talking about servlets.d, then yes, you can control all output. That example uses mango.log for its output. Therefore, you can reconfigure the logger to send the content elsewhere, or configure the 'level' of logging to inhibit unwanted output (or turn it off completely). Looks like servlets.exe uses INFO and TRACE logging, so you could set the logging level to ERROR instead, via mainLogger.setLevel() in the main() function.
Or better; use http://127.0.0.1/admin/logger in your browser to control the log settings of servlets.exe while it is running ... |
|
Back to top |
|
|
uw
Joined: 10 Feb 2005 Posts: 4
|
Posted: Thu Feb 10, 2005 2:01 pm Post subject: |
|
|
kris wrote: | Thanks for posting this issue -- I'll look into it. When you say 'linked for windows', what does that mean exactly? And which version of windows are you running? |
PE header contains 'subsystem' field, which can be one of the following:
NATIVE, CONSOLE, WINDOWS(WINDOWS GUI to be more precise), POSIX, WINDOWSCE.
Linker allows to specify subsystem, DMD allows passing parameters to linker. I'm not completely sure whether I got it correct(I'm more used to microsoft's linker), but to specify WINDOWS GUI subsystem you need to pass -L/SUB:WIN. With most other console apps this works just fine, moreover their console io can still be redirected. With Mango examples it doesn't work at all, no matter what subsystem specified.
Here's 'Redirector' code, it's C# however(compile with /target:winexe).
Code: |
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
class Redirector
{
public static void Main(string[] args)
{
StringBuilder argStr = new StringBuilder("");
for (int i = 2; i < args.Length; i++) argStr.Append(args[i]);
if (args.Length < 2)
{
MessageBox.Show("At least two arguments required!","Error!",MessageBoxButtons.OK);
return;
}
ProcessStartInfo pi = new ProcessStartInfo(args[0], argStr.ToString());
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process pr = Process.Start(pi);
string outputText = pr.StandardOutput.ReadToEnd();
pr.WaitForExit();
FileStream output = new FileStream(args[1], FileMode.Create);
StreamWriter sw = new StreamWriter(output);
sw.Write(outputText);
sw.Close();
output.Close();
}
};
|
I am running XP(pre-SP1 or SP1, I don't exactly remember ). I believe though it has no correlation with described behaviour.
kris wrote: | Do you wanna' patch ByteSwap.d ? If so, add your name to the header and email the file to me. |
OK. |
|
Back to top |
|
|
uw
Joined: 10 Feb 2005 Posts: 4
|
Posted: Thu Feb 10, 2005 2:13 pm Post subject: Re: some questions |
|
|
It doesn't get to the point at which I can control log settings. It immediately exits with access violation. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 3:11 pm Post subject: Re: some questions |
|
|
uw wrote: |
It doesn't get to the point at which I can control log settings. It immediately exits with access violation. |
Doh!
I'm guessing that GetStdHandle() is returning a null (for whatever reason) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getstdhandle.asp
The relevant code is in mango.io.FileConduit, and looks like this:
Code: | private void _reopen (FileDevice device)
{
static const DWORD[] id = [
cast(DWORD) -10,
cast(DWORD) -11,
cast(DWORD) -12
];
handle = GetStdHandle (id[device.id]);
} |
Shame on me for not having an out{} contract or an assert there Can you add one, to ensure this is indeed the issue? I would, but don't have the necessary tools at hand (.Net etc).
- Kris |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 3:15 pm Post subject: |
|
|
uw wrote: | Linker allows to specify subsystem, DMD allows passing parameters to linker. I'm not completely sure whether I got it correct(I'm more used to microsoft's linker), but to specify WINDOWS GUI subsystem you need to pass -L/SUB:WIN. With most other console apps this works just fine, moreover their console io can still be redirected. With Mango examples it doesn't work at all, no matter what subsystem specified.
I am running XP(pre-SP1 or SP1, I don't exactly remember ). I believe though it has no correlation with described behaviour. |
Gotcha -- thanks. Wanted to check the O/S wasn't Win95 or somthing |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 3:25 pm Post subject: |
|
|
The plot thickens ...
The output to the console is actually via stderr, not stdout. I wonder if that has something to do with this? You might try the lineio.exe example, which uses stdout instead -- to see if that has the same bogus behavior?
- Kris
p.s. lineio.exe looks for a file called "test.txt" in the local directory, so you'll probably have to create one with some content in it. Silly example, I know. |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Thu Feb 10, 2005 3:56 pm Post subject: |
|
|
To make the test.txt in the lineio.exe directory, I just did something like this:
copy lineio.d test.txt
Quck fix! |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Thu Feb 10, 2005 9:39 pm Post subject: Re: some questions |
|
|
uw wrote: |
By the way I noticed some pretty weird asm code in ByteSwap.d. No offence, but have you heard of bswap instruction? Its spec is bswap r32 and it takes exactly 1 tick. |
The compiler will likely output that instruction on systems that support it when you call std.intrinsic.bswap. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 10:39 pm Post subject: Re: some questions |
|
|
aldacron wrote: | The compiler will likely output that instruction on systems that support it when you call std.intrinsic.bswap. |
It's a hair trickier that that, since ByteSwap currently supports flipping up to 10 bytes. Otherwise, the intrinsics would have been pretty handy.
Thanks for pointing it out though ... |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 10, 2005 10:41 pm Post subject: |
|
|
JJR wrote: | Quck fix! |
I checked in a somewhat less constrained lineio.d example. Use it to print itself ... |
|
Back to top |
|
|
uw
Joined: 10 Feb 2005 Posts: 4
|
Posted: Fri Feb 11, 2005 4:12 am Post subject: |
|
|
Redirecting stderr finally made servlets example working in GUI mode, however this is workaround, not a real solution.
Yes, GetStdHandle returns null, when no redirection is done and app is running in gui mode. However, this is normal behaviour, it should not result in access violation or even exception.
For example:
Code: |
import std.c.windows.windows;
void main()
{
for(int i = 0; i < 1000000; i++)
printf("is there stdout?\n");
Sleep(10000);
}
|
This works brilliantly, when compiled with -L/SUB:WIN(check task manager).
lineio fails immediately after first output to stdout is made, when its compiled with the very same flag.
If the following code is placed before while(line.get) ..., it will work, if after it fails.
Code: |
FileConduit fcc = new FileConduit("testout.txt",FileStyle.ReadWriteCreate);
fcc.copy(new FilePath("test.txt"));
|
|
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Fri Feb 11, 2005 11:08 am Post subject: |
|
|
uw wrote: | Redirecting stderr finally made servlets example working in GUI mode, however this is workaround, not a real solution.
Yes, GetStdHandle returns null, when no redirection is done and app is running in gui mode. However, this is normal behaviour, it should not result in access violation or even exception |
Thanks much, uw. I'll change it such that a null Stdio handle sends content to the bit-bucket instead. Do you know what's supposed to happen with stdin? We should fix that also.
- Kris |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Fri Feb 11, 2005 1:28 pm Post subject: |
|
|
I'm curious. If you're using GUI mode with dmd, how are you setting up WinMain? Are you following the instructions at http://www.digitalmars.com/d/windows.html in which you must set up the gc first?
I don't know if /not/ doing so would cause the probelms described. But it's probably good to clarify that first since the biggest difference between a console app and a GUI app is that pre-initialization is done for you by dmd in the console app.
- John R. |
|
Back to top |
|
|
|