Just in case anyone has any ideas, I get this in OS X as expected:
Macintosh-2:mio russellallen$ Self -port 4000 -headless Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )
but I get this in Linux (Fedora 19):
[self@messaging ~]$ ./selfvm -port 4000 -headless Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )
Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?
Russell
OK, to partially answer my own question:
GNU getopt, which is used on Linux, changes the order of argv as a side effect:
http://man7.org/linux/man-pages/man3/getopt.3.html
"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."
OS X uses a BSD getopt which is sane.
As Wikipedia says ( https://en.wikipedia.org/wiki/Getopt ) :
"getopt is a system dependent function. The implementation of getopt in GNU C Library does permute the contents of the argument vector as it scans, so that eventually all the non-option arguments are at the end. On the contrary, the implementation of getopt in BSD C Library does not permute the argument vector and returns -1 if it encounters a non-option argument."
The Self VM uses getopt to parse the VM options, then passes the arguments onto the Self world via argv. So on OSX it is normal argv, on Linux it is argv as altered by getopt:
In shell.cpp:
OS::opterr= 0; // disable printed warning about unrecognized options while(opt_i= OS::optind, (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) { if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options switch(c) { case 'F': etc ...
// save remaining args for Self-level access prog_argc= argc; prog_argv= argv;
So my next question is, what is the best way to fix this so that _CommandLine returns the arguments in proper order on Linux?
Russell
On 1 Feb 2014, at 9:55 pm, Russell Allen mail@russell-allen.com wrote:
Just in case anyone has any ideas, I get this in OS X as expected:
Macintosh-2:mio russellallen$ Self -port 4000 -headless Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )
but I get this in Linux (Fedora 19):
[self@messaging ~]$ ./selfvm -port 4000 -headless Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )
Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?
Russell
Get a Mac? :)
- David Sent from my iPhone, tap tap
On Feb 1, 2014, at 5:26 PM, Russell Allen mail@russell-allen.com wrote:
OK, to partially answer my own question:
GNU getopt, which is used on Linux, changes the order of argv as a side effect:
http://man7.org/linux/man-pages/man3/getopt.3.html
"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."
OS X uses a BSD getopt which is sane.
As Wikipedia says ( https://en.wikipedia.org/wiki/Getopt ) :
"getopt is a system dependent function. The implementation of getopt in GNU C Library does permute the contents of the argument vector as it scans, so that eventually all the non-option arguments are at the end. On the contrary, the implementation of getopt in BSD C Library does not permute the argument vector and returns -1 if it encounters a non-option argument."
The Self VM uses getopt to parse the VM options, then passes the arguments onto the Self world via argv. So on OSX it is normal argv, on Linux it is argv as altered by getopt:
In shell.cpp:
OS::opterr= 0; // disable printed warning about unrecognized options while(opt_i= OS::optind, (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) { if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options switch(c) { case 'F': etc ...
// save remaining args for Self-level access prog_argc= argc; prog_argv= argv;
So my next question is, what is the best way to fix this so that _CommandLine returns the arguments in proper order on Linux?
Russell
On 1 Feb 2014, at 9:55 pm, Russell Allen mail@russell-allen.com wrote:
Just in case anyone has any ideas, I get this in OS X as expected:
Macintosh-2:mio russellallen$ Self -port 4000 -headless Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )
but I get this in Linux (Fedora 19):
[self@messaging ~]$ ./selfvm -port 4000 -headless Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )
Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?
Russell
Self cannot run on Mac alone, but needs every platform including Sun. To coin a phrase.
Anyway did simplest fix I could think of and put in getoptfix branch:
https://github.com/russellallen/self/commit/e9892acfdfc319648bf9e73d484b3bf3...
This works for me. If there are no suggested improvements, I'll merge into the mainline.
Russell
On 2 Feb 2014, at 1:49 pm, David Ungar ungar@me.com wrote:
Get a Mac? :)
- David
Sent from my iPhone, tap tap
On Feb 1, 2014, at 5:26 PM, Russell Allen mail@russell-allen.com wrote:
OK, to partially answer my own question:
GNU getopt, which is used on Linux, changes the order of argv as a side effect:
http://man7.org/linux/man-pages/man3/getopt.3.html
"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."
OS X uses a BSD getopt which is sane.
As Wikipedia says ( https://en.wikipedia.org/wiki/Getopt ) :
"getopt is a system dependent function. The implementation of getopt in GNU C Library does permute the contents of the argument vector as it scans, so that eventually all the non-option arguments are at the end. On the contrary, the implementation of getopt in BSD C Library does not permute the argument vector and returns -1 if it encounters a non-option argument."
The Self VM uses getopt to parse the VM options, then passes the arguments onto the Self world via argv. So on OSX it is normal argv, on Linux it is argv as altered by getopt:
In shell.cpp:
OS::opterr= 0; // disable printed warning about unrecognized options while(opt_i= OS::optind, (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) { if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options switch(c) { case 'F': etc ...
// save remaining args for Self-level access prog_argc= argc; prog_argv= argv;
So my next question is, what is the best way to fix this so that _CommandLine returns the arguments in proper order on Linux?
Russell
On 1 Feb 2014, at 9:55 pm, Russell Allen mail@russell-allen.com wrote:
Just in case anyone has any ideas, I get this in OS X as expected:
Macintosh-2:mio russellallen$ Self -port 4000 -headless Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )
but I get this in Linux (Fedora 19):
[self@messaging ~]$ ./selfvm -port 4000 -headless Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000) Copyright 1989-2003: The Self Group (type _Credits for credits)
for I386: LogVMMessages = true for I386: PrintScriptName = true for I386: Inline = true for I386: SICDeferUncommonBranches = false (not implemented) for I386: SICReplaceOnStack = false (not implemented) for I386: SaveOutgoingArgumentsOfPatchedFrames = true VM# _CommandLine <0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )
Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?
Russell
self-interest@lists.selflanguage.org