Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c08ec9fd
Kaydet (Commit)
c08ec9fd
authored
Eki 06, 2010
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Create a subfunction for PySys_SetArgvEx()
Create sys_update_path() static function. Do nothing if argc==0.
üst
7980eaa9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
78 deletions
+94
-78
sysmodule.c
Python/sysmodule.c
+94
-78
No files found.
Python/sysmodule.c
Dosyayı görüntüle @
c08ec9fd
...
...
@@ -1685,106 +1685,122 @@ _wrealpath(const wchar_t *path, wchar_t *resolved_path)
#define _HAVE_SCRIPT_ARGUMENT(argc, argv) \
(argc > 0 && argv0 != NULL && \
wcscmp(argv0, L"-c") != 0 && wcscmp(argv0, L"-m") != 0)
void
PySys_SetArgvEx
(
int
argc
,
wchar_t
**
argv
,
int
updatepath
)
static
void
sys_update_path
(
int
argc
,
wchar_t
**
argv
)
{
wchar_t
*
argv0
;
wchar_t
*
p
=
NULL
;
Py_ssize_t
n
=
0
;
PyObject
*
a
;
PyObject
*
path
;
#ifdef HAVE_READLINK
extern
int
_Py_wreadlink
(
const
wchar_t
*
,
wchar_t
*
,
size_t
);
wchar_t
link
[
MAXPATHLEN
+
1
];
wchar_t
argv0copy
[
2
*
MAXPATHLEN
+
1
];
int
nr
=
0
;
#endif
#if defined(HAVE_REALPATH)
wchar_t
fullpath
[
MAXPATHLEN
];
#elif defined(MS_WINDOWS) && !defined(MS_WINCE)
wchar_t
fullpath
[
MAX_PATH
];
#endif
PyObject
*
av
=
makeargvobject
(
argc
,
argv
);
PyObject
*
path
=
PySys_GetObject
(
"path"
);
if
(
av
==
NULL
)
Py_FatalError
(
"no mem for sys.argv"
);
if
(
PySys_SetObject
(
"argv"
,
av
)
!=
0
)
Py_FatalError
(
"can't assign sys.argv"
);
if
(
updatepath
&&
path
!=
NULL
)
{
wchar_t
*
argv0
=
argv
[
0
];
wchar_t
*
p
=
NULL
;
Py_ssize_t
n
=
0
;
PyObject
*
a
;
extern
int
_Py_wreadlink
(
const
wchar_t
*
,
wchar_t
*
,
size_t
);
path
=
PySys_GetObject
(
"path"
);
if
(
path
==
NULL
)
return
;
if
(
argc
==
0
)
return
;
argv0
=
argv
[
0
];
#ifdef HAVE_READLINK
wchar_t
link
[
MAXPATHLEN
+
1
];
wchar_t
argv0copy
[
2
*
MAXPATHLEN
+
1
];
int
nr
=
0
;
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
nr
=
_Py_wreadlink
(
argv0
,
link
,
MAXPATHLEN
);
if
(
nr
>
0
)
{
/* It's a symlink */
link
[
nr
]
=
'\0'
;
if
(
link
[
0
]
==
SEP
)
argv0
=
link
;
/* Link to absolute path */
else
if
(
wcschr
(
link
,
SEP
)
==
NULL
)
;
/* Link without path */
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
nr
=
_Py_wreadlink
(
argv0
,
link
,
MAXPATHLEN
);
if
(
nr
>
0
)
{
/* It's a symlink */
link
[
nr
]
=
'\0'
;
if
(
link
[
0
]
==
SEP
)
argv0
=
link
;
/* Link to absolute path */
else
if
(
wcschr
(
link
,
SEP
)
==
NULL
)
;
/* Link without path */
else
{
/* Must join(dirname(argv0), link) */
wchar_t
*
q
=
wcsrchr
(
argv0
,
SEP
);
if
(
q
==
NULL
)
argv0
=
link
;
/* argv0 without path */
else
{
/* Must join(dirname(argv0), link) */
wchar_t
*
q
=
wcsrchr
(
argv0
,
SEP
);
if
(
q
==
NULL
)
argv0
=
link
;
/* argv0 without path */
else
{
/* Must make a copy */
wcscpy
(
argv0copy
,
argv0
);
q
=
wcsrchr
(
argv0copy
,
SEP
);
wcscpy
(
q
+
1
,
link
);
argv0
=
argv0copy
;
}
/* Must make a copy */
wcscpy
(
argv0copy
,
argv0
);
q
=
wcsrchr
(
argv0copy
,
SEP
);
wcscpy
(
q
+
1
,
link
);
argv0
=
argv0copy
;
}
}
}
#endif
/* HAVE_READLINK */
#if SEP == '\\'
/* Special case for MS filename syntax */
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
{
wchar_t
*
q
;
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
{
wchar_t
*
q
;
#if defined(MS_WINDOWS) && !defined(MS_WINCE)
/* This code here replaces the first element in argv with the full
path that it represents. Under CE, there are no relative paths so
the argument must be the full path anyway. */
wchar_t
*
ptemp
;
if
(
GetFullPathNameW
(
argv0
,
sizeof
(
fullpath
)
/
sizeof
(
fullpath
[
0
]),
fullpath
,
&
ptemp
))
{
argv0
=
fullpath
;
}
/* This code here replaces the first element in argv with the full
path that it represents. Under CE, there are no relative paths so
the argument must be the full path anyway. */
wchar_t
*
ptemp
;
if
(
GetFullPathNameW
(
argv0
,
sizeof
(
fullpath
)
/
sizeof
(
fullpath
[
0
]),
fullpath
,
&
ptemp
))
{
argv0
=
fullpath
;
}
#endif
p
=
wcsrchr
(
argv0
,
SEP
);
/* Test for alternate separator */
q
=
wcsrchr
(
p
?
p
:
argv0
,
'/'
);
if
(
q
!=
NULL
)
p
=
q
;
if
(
p
!=
NULL
)
{
n
=
p
+
1
-
argv0
;
if
(
n
>
1
&&
p
[
-
1
]
!=
':'
)
n
--
;
/* Drop trailing separator */
}
p
=
wcsrchr
(
argv0
,
SEP
);
/* Test for alternate separator */
q
=
wcsrchr
(
p
?
p
:
argv0
,
'/'
);
if
(
q
!=
NULL
)
p
=
q
;
if
(
p
!=
NULL
)
{
n
=
p
+
1
-
argv0
;
if
(
n
>
1
&&
p
[
-
1
]
!=
':'
)
n
--
;
/* Drop trailing separator */
}
}
#else
/* All other filename syntaxes */
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
{
if
(
_HAVE_SCRIPT_ARGUMENT
(
argc
,
argv
))
{
#if defined(HAVE_REALPATH)
if
(
_wrealpath
(
argv0
,
fullpath
))
{
argv0
=
fullpath
;
}
#endif
p
=
wcsrchr
(
argv0
,
SEP
);
if
(
_wrealpath
(
argv0
,
fullpath
))
{
argv0
=
fullpath
;
}
if
(
p
!=
NULL
)
{
n
=
p
+
1
-
argv0
;
#endif
p
=
wcsrchr
(
argv0
,
SEP
);
}
if
(
p
!=
NULL
)
{
n
=
p
+
1
-
argv0
;
#if SEP == '/'
/* Special case for Unix filename syntax */
if
(
n
>
1
)
n
--
;
/* Drop trailing separator */
if
(
n
>
1
)
n
--
;
/* Drop trailing separator */
#endif
/* Unix */
}
#endif
/* All others */
a
=
PyUnicode_FromWideChar
(
argv0
,
n
);
if
(
a
==
NULL
)
Py_FatalError
(
"no mem for sys.path insertion"
);
if
(
PyList_Insert
(
path
,
0
,
a
)
<
0
)
Py_FatalError
(
"sys.path.insert(0) failed"
);
Py_DECREF
(
a
);
}
#endif
/* All others */
a
=
PyUnicode_FromWideChar
(
argv0
,
n
);
if
(
a
==
NULL
)
Py_FatalError
(
"no mem for sys.path insertion"
);
if
(
PyList_Insert
(
path
,
0
,
a
)
<
0
)
Py_FatalError
(
"sys.path.insert(0) failed"
);
Py_DECREF
(
a
);
}
void
PySys_SetArgvEx
(
int
argc
,
wchar_t
**
argv
,
int
updatepath
)
{
PyObject
*
av
=
makeargvobject
(
argc
,
argv
);
if
(
av
==
NULL
)
Py_FatalError
(
"no mem for sys.argv"
);
if
(
PySys_SetObject
(
"argv"
,
av
)
!=
0
)
Py_FatalError
(
"can't assign sys.argv"
);
Py_DECREF
(
av
);
if
(
updatepath
)
sys_update_path
(
argc
,
argv
);
}
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment