[Patches] [ python-Patches-457892 ] sys module feature patch - modify_argv()
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 02 Sep 2001 19:15:50 -0700
Patches item #457892, was opened at 2001-09-02 19:15
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=457892&group_id=5470
Category: core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dave Cinege (dcinege)
Assigned to: Nobody/Anonymous (nobody)
Summary: sys module feature patch - modify_argv()
Initial Comment:
sys module feature patch - modify_argv()
Feature enhancment patch to sys module.
(Python/sysmodule.c)
modify_argv(string,[start],[amount])
Modify the absolute argv (process listing) elements
of the python process.
NOTE: You may wish view the thread
of the python mailing list below.
It's been mentioned a more appropreate place for
this might be the posix module. (However I still think
sys is the right place) I'm willing to implement this
as the core team desires, if it is to be included.
Subject: [PATCH] sys.modify_argv()
Date: Fri, 24 Aug 2001 22:19:34 -0400
To: Python <python-list@python.org>
keywords: modify argv change process listing argv[0]
ps output
This patch adds a new feature to the sys module,
modify_argv().
As you might have guessed this allows one to change
to absolute
argv values of the python process itself. (It is of
great wonder
to me why this functionality is not already
available...)
I have intentionally left the patch with minimal
sanity
checking. Ignorance of detail could lead to dangerous
results. Stronger bountries may be desirable in a
final
implementation.
The patch is against Python 2.1.1. Adding this
function to another
module or placing it in your own module should be a
trvial task.
It is self contained using Py_GetArgcArgv() to grab
the location
of argv, already present in the python core.
This patch has been submitted for inclusion into core
python.
Documentation on it's use is in the patch itself.
I hereby place this code into the public domain.
'Diesel' Dave 'Kill a Cop' Cinege
-----------------------------------------------------
Subject: Re: [PATCH] sys.modify_argv()
Date: Fri, 24 Aug 2001 23:53:04 -0400
To: Ignacio Vazquez-Abrams <ignacio@openservices.net>
CC: Python <python-list@python.org>
> Instead of making a whole new function for this,
why not add write
capability
> to sys.argv?
Why I didn't do this:
1) From what I've looked at, the current sys code
would change
dramatically as it's already dealing in copies of
argv initialized
at python startup, and not by accessing
Py_GetArgcArgv() dynamically.
What I did is less intrusive and portable outside of
sys.
2) Even though one clears the absolute argv, you
probably still want
it's values available internally. Thus clearing the
sys.argv copies
adds a layer of complexity that is really unneeded
and probably undesirable.
3) It's not yet exactly clear (to me) to what extent
you can alter argv
and not impeed portability. This is probably reason
enough to segregate this
functionality. (On linux it stacks argv elements
concurrently in memory and
it's safe to use that total space anyway you want.
Who knows
how other OS's deal with it...)
4) sys.argv[0] == argv[1]. How do we get to the real
argv[0] in a
sane way? sys.argv[-1] Might break old code as the
current implementation
ignores negatives and uses absolute values. Also
making process
listing follow sys.agrv assignment might break old
code. And then
we have to deal with the lengths of the orginial argv
elements again...
This is the first time I've ever even looked at the
python source,
and am hardly close to being a python guru myself.
There might be
a better solution then what I've done, though I've
tried to put a bit
of thought into it. At least this patch is usable by
people
now and will hopefully lead to SOME sort of standard
argv modification
support in the near future.
Dave
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=457892&group_id=5470