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
f3250b0b
Kaydet (Commit)
f3250b0b
authored
Eki 12, 2004
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Before this turns into an unreadable mess, follow PEP 7 by using
hard tab indents in C code.
üst
25b38c89
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
57 deletions
+82
-57
_subprocess.c
PC/_subprocess.c
+82
-57
No files found.
PC/_subprocess.c
Dosyayı görüntüle @
f3250b0b
...
@@ -71,7 +71,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
...
@@ -71,7 +71,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
{
{
HANDLE
handle
;
HANDLE
handle
;
if
(
!
PyArg_ParseTuple
(
args
,
":Detach"
))
if
(
!
PyArg_ParseTuple
(
args
,
":Detach"
))
return
NULL
;
return
NULL
;
handle
=
self
->
handle
;
handle
=
self
->
handle
;
...
@@ -85,7 +85,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
...
@@ -85,7 +85,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
static
PyObject
*
static
PyObject
*
sp_handle_close
(
sp_handle_object
*
self
,
PyObject
*
args
)
sp_handle_close
(
sp_handle_object
*
self
,
PyObject
*
args
)
{
{
if
(
!
PyArg_ParseTuple
(
args
,
":Close"
))
if
(
!
PyArg_ParseTuple
(
args
,
":Close"
))
return
NULL
;
return
NULL
;
if
(
self
->
handle
!=
INVALID_HANDLE_VALUE
)
{
if
(
self
->
handle
!=
INVALID_HANDLE_VALUE
)
{
...
@@ -130,7 +130,7 @@ statichere PyTypeObject sp_handle_type = {
...
@@ -130,7 +130,7 @@ statichere PyTypeObject sp_handle_type = {
"_subprocess_handle"
,
sizeof
(
sp_handle_object
),
0
,
"_subprocess_handle"
,
sizeof
(
sp_handle_object
),
0
,
(
destructor
)
sp_handle_dealloc
,
/*tp_dealloc*/
(
destructor
)
sp_handle_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_print*/
(
getattrfunc
)
sp_handle_getattr
,
/*tp_getattr*/
(
getattrfunc
)
sp_handle_getattr
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_setattr*/
0
,
/*tp_compare*/
0
,
/*tp_compare*/
0
,
/*tp_repr*/
0
,
/*tp_repr*/
...
@@ -147,9 +147,9 @@ static PyObject *
...
@@ -147,9 +147,9 @@ static PyObject *
sp_GetStdHandle
(
PyObject
*
self
,
PyObject
*
args
)
sp_GetStdHandle
(
PyObject
*
self
,
PyObject
*
args
)
{
{
HANDLE
handle
;
HANDLE
handle
;
int
std_handle
;
int
std_handle
;
if
(
!
PyArg_ParseTuple
(
args
,
"i:GetStdHandle"
,
&
std_handle
))
if
(
!
PyArg_ParseTuple
(
args
,
"i:GetStdHandle"
,
&
std_handle
))
return
NULL
;
return
NULL
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
...
@@ -159,7 +159,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
...
@@ -159,7 +159,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
if
(
handle
==
INVALID_HANDLE_VALUE
)
if
(
handle
==
INVALID_HANDLE_VALUE
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
if
(
!
handle
)
{
if
(
!
handle
)
{
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
}
}
...
@@ -171,7 +171,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
...
@@ -171,7 +171,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
static
PyObject
*
static
PyObject
*
sp_GetCurrentProcess
(
PyObject
*
self
,
PyObject
*
args
)
sp_GetCurrentProcess
(
PyObject
*
self
,
PyObject
*
args
)
{
{
if
(
!
PyArg_ParseTuple
(
args
,
":GetCurrentProcess"
))
if
(
!
PyArg_ParseTuple
(
args
,
":GetCurrentProcess"
))
return
NULL
;
return
NULL
;
return
sp_handle_new
(
GetCurrentProcess
());
return
sp_handle_new
(
GetCurrentProcess
());
...
@@ -189,21 +189,29 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
...
@@ -189,21 +189,29 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
int
desired_access
;
int
desired_access
;
int
inherit_handle
;
int
inherit_handle
;
int
options
=
0
;
int
options
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"lllii|i:DuplicateHandle"
,
&
source_process_handle
,
&
source_handle
,
if
(
!
PyArg_ParseTuple
(
args
,
"lllii|i:DuplicateHandle"
,
&
source_process_handle
,
&
source_handle
,
&
target_process_handle
,
&
target_process_handle
,
&
desired_access
,
&
inherit_handle
,
&
options
))
&
desired_access
,
&
inherit_handle
,
&
options
))
return
NULL
;
return
NULL
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
result
=
DuplicateHandle
(
result
=
DuplicateHandle
(
(
HANDLE
)
source_process_handle
,
(
HANDLE
)
source_handle
,
(
HANDLE
)
source_process_handle
,
(
HANDLE
)
target_process_handle
,
&
target_handle
,
desired_access
,
(
HANDLE
)
source_handle
,
inherit_handle
,
options
(
HANDLE
)
target_process_handle
,
&
target_handle
,
desired_access
,
inherit_handle
,
options
);
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
if
(
!
result
)
if
(
!
result
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
sp_handle_new
(
target_handle
);
return
sp_handle_new
(
target_handle
);
...
@@ -218,19 +226,19 @@ sp_CreatePipe(PyObject* self, PyObject* args)
...
@@ -218,19 +226,19 @@ sp_CreatePipe(PyObject* self, PyObject* args)
PyObject
*
pipe_attributes
;
/* ignored */
PyObject
*
pipe_attributes
;
/* ignored */
int
size
;
int
size
;
if
(
!
PyArg_ParseTuple
(
args
,
"Oi:CreatePipe"
,
&
pipe_attributes
,
&
size
))
if
(
!
PyArg_ParseTuple
(
args
,
"Oi:CreatePipe"
,
&
pipe_attributes
,
&
size
))
return
NULL
;
return
NULL
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
result
=
CreatePipe
(
&
read_pipe
,
&
write_pipe
,
NULL
,
size
);
result
=
CreatePipe
(
&
read_pipe
,
&
write_pipe
,
NULL
,
size
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
if
(
!
result
)
if
(
!
result
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
Py_BuildValue
(
return
Py_BuildValue
(
"NN"
,
sp_handle_new
(
read_pipe
),
sp_handle_new
(
write_pipe
)
"NN"
,
sp_handle_new
(
read_pipe
),
sp_handle_new
(
write_pipe
));
);
}
}
/* helpers for createprocess */
/* helpers for createprocess */
...
@@ -239,8 +247,9 @@ static int
...
@@ -239,8 +247,9 @@ static int
getint
(
PyObject
*
obj
,
char
*
name
)
getint
(
PyObject
*
obj
,
char
*
name
)
{
{
PyObject
*
value
;
PyObject
*
value
;
value
=
PyObject_GetAttrString
(
obj
,
name
);
value
=
PyObject_GetAttrString
(
obj
,
name
);
if
(
!
value
)
{
if
(
!
value
)
{
PyErr_Clear
();
/* FIXME: propagate error? */
PyErr_Clear
();
/* FIXME: propagate error? */
return
0
;
return
0
;
}
}
...
@@ -251,8 +260,9 @@ static HANDLE
...
@@ -251,8 +260,9 @@ static HANDLE
gethandle
(
PyObject
*
obj
,
char
*
name
)
gethandle
(
PyObject
*
obj
,
char
*
name
)
{
{
sp_handle_object
*
value
;
sp_handle_object
*
value
;
value
=
(
sp_handle_object
*
)
PyObject_GetAttrString
(
obj
,
name
);
value
=
(
sp_handle_object
*
)
PyObject_GetAttrString
(
obj
,
name
);
if
(
!
value
)
{
if
(
!
value
)
{
PyErr_Clear
();
/* FIXME: propagate error? */
PyErr_Clear
();
/* FIXME: propagate error? */
return
NULL
;
return
NULL
;
}
}
...
@@ -271,11 +281,9 @@ getenvironment(PyObject* environment)
...
@@ -271,11 +281,9 @@ getenvironment(PyObject* environment)
char
*
p
;
char
*
p
;
/* convert environment dictionary to windows enviroment string */
/* convert environment dictionary to windows enviroment string */
if
(
!
PyMapping_Check
(
environment
))
{
if
(
!
PyMapping_Check
(
environment
))
{
PyErr_SetString
(
PyErr_SetString
(
PyExc_TypeError
,
"environment must be dictionary or None"
PyExc_TypeError
,
"environment must be dictionary or None"
);
);
return
NULL
;
return
NULL
;
}
}
...
@@ -287,7 +295,7 @@ getenvironment(PyObject* environment)
...
@@ -287,7 +295,7 @@ getenvironment(PyObject* environment)
goto
error
;
goto
error
;
out
=
PyString_FromStringAndSize
(
NULL
,
2048
);
out
=
PyString_FromStringAndSize
(
NULL
,
2048
);
if
(
!
out
)
if
(
!
out
)
goto
error
;
goto
error
;
p
=
PyString_AS_STRING
(
out
);
p
=
PyString_AS_STRING
(
out
);
...
@@ -296,34 +304,38 @@ getenvironment(PyObject* environment)
...
@@ -296,34 +304,38 @@ getenvironment(PyObject* environment)
int
ksize
,
vsize
,
totalsize
;
int
ksize
,
vsize
,
totalsize
;
PyObject
*
key
=
PyList_GET_ITEM
(
keys
,
i
);
PyObject
*
key
=
PyList_GET_ITEM
(
keys
,
i
);
PyObject
*
value
=
PyList_GET_ITEM
(
values
,
i
);
PyObject
*
value
=
PyList_GET_ITEM
(
values
,
i
);
if
(
!
PyString_Check
(
key
)
||
!
PyString_Check
(
value
))
{
PyErr_SetString
(
if
(
!
PyString_Check
(
key
)
||
!
PyString_Check
(
value
))
{
PyExc_TypeError
,
"environment can only contain strings"
PyErr_SetString
(
PyExc_TypeError
,
);
"environment can only contain strings"
);
goto
error
;
goto
error
;
}
}
ksize
=
PyString_GET_SIZE
(
key
);
ksize
=
PyString_GET_SIZE
(
key
);
vsize
=
PyString_GET_SIZE
(
value
);
vsize
=
PyString_GET_SIZE
(
value
);
totalsize
=
(
p
-
PyString_AS_STRING
(
out
))
+
ksize
+
1
+
vsize
+
1
+
1
;
totalsize
=
(
p
-
PyString_AS_STRING
(
out
))
+
ksize
+
1
+
vsize
+
1
+
1
;
if
(
totalsize
>
PyString_GET_SIZE
(
out
))
{
if
(
totalsize
>
PyString_GET_SIZE
(
out
))
{
int
offset
=
p
-
PyString_AS_STRING
(
out
);
int
offset
=
p
-
PyString_AS_STRING
(
out
);
_PyString_Resize
(
&
out
,
totalsize
+
1024
);
_PyString_Resize
(
&
out
,
totalsize
+
1024
);
p
=
PyString_AS_STRING
(
out
)
+
offset
;
p
=
PyString_AS_STRING
(
out
)
+
offset
;
}
}
memcpy
(
p
,
PyString_AS_STRING
(
key
),
ksize
);
p
+=
ksize
;
*
p
++
=
'='
;
memcpy
(
p
,
PyString_AS_STRING
(
key
),
ksize
);
memcpy
(
p
,
PyString_AS_STRING
(
value
),
vsize
);
p
+=
vsize
;
*
p
++
=
'\0'
;
p
+=
ksize
;
*
p
++
=
'='
;
memcpy
(
p
,
PyString_AS_STRING
(
value
),
vsize
);
p
+=
vsize
;
*
p
++
=
'\0'
;
}
}
/* add trailing null byte */
/* add trailing null byte */
*
p
++
=
'\0'
;
*
p
++
=
'\0'
;
_PyString_Resize
(
&
out
,
p
-
PyString_AS_STRING
(
out
));
_PyString_Resize
(
&
out
,
p
-
PyString_AS_STRING
(
out
));
/* PyObject_Print(out, stdout, 0); */
/* PyObject_Print(out, stdout, 0); */
return
out
;
return
out
;
error:
error:
Py_XDECREF
(
out
);
Py_XDECREF
(
out
);
Py_XDECREF
(
keys
);
Py_XDECREF
(
keys
);
Py_XDECREF
(
values
);
Py_XDECREF
(
values
);
...
@@ -347,11 +359,17 @@ sp_CreateProcess(PyObject* self, PyObject* args)
...
@@ -347,11 +359,17 @@ sp_CreateProcess(PyObject* self, PyObject* args)
PyObject
*
env_mapping
;
PyObject
*
env_mapping
;
char
*
current_directory
;
char
*
current_directory
;
PyObject
*
startup_info
;
PyObject
*
startup_info
;
if
(
!
PyArg_ParseTuple
(
args
,
"zzOOiiOzO:CreateProcess"
,
&
application_name
,
&
command_line
,
if
(
!
PyArg_ParseTuple
(
args
,
"zzOOiiOzO:CreateProcess"
,
&
process_attributes
,
&
thread_attributes
,
&
application_name
,
&
inherit_handles
,
&
creation_flags
,
&
command_line
,
&
env_mapping
,
&
current_directory
,
&
startup_info
))
&
process_attributes
,
&
thread_attributes
,
&
inherit_handles
,
&
creation_flags
,
&
env_mapping
,
&
current_directory
,
&
startup_info
))
return
NULL
;
return
NULL
;
ZeroMemory
(
&
si
,
sizeof
(
si
));
ZeroMemory
(
&
si
,
sizeof
(
si
));
...
@@ -367,27 +385,33 @@ sp_CreateProcess(PyObject* self, PyObject* args)
...
@@ -367,27 +385,33 @@ sp_CreateProcess(PyObject* self, PyObject* args)
environment
=
NULL
;
environment
=
NULL
;
else
{
else
{
environment
=
getenvironment
(
env_mapping
);
environment
=
getenvironment
(
env_mapping
);
if
(
!
environment
)
if
(
!
environment
)
return
NULL
;
return
NULL
;
}
}
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
result
=
CreateProcess
(
result
=
CreateProcess
(
application_name
,
application_name
,
command_line
,
NULL
,
NULL
,
inherit_handles
,
command_line
,
creation_flags
,
environment
?
PyString_AS_STRING
(
environment
)
:
NULL
,
NULL
,
current_directory
,
&
si
,
&
pi
NULL
,
);
inherit_handles
,
creation_flags
,
environment
?
PyString_AS_STRING
(
environment
)
:
NULL
,
current_directory
,
&
si
,
&
pi
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
Py_XDECREF
(
environment
);
Py_XDECREF
(
environment
);
if
(
!
result
)
if
(
!
result
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
Py_BuildValue
(
return
Py_BuildValue
(
"NNii"
,
"NNii"
,
sp_handle_new
(
pi
.
hProcess
),
sp_handle_new
(
pi
.
hThread
),
sp_handle_new
(
pi
.
hProcess
),
pi
.
dwProcessId
,
pi
.
dwThreadId
sp_handle_new
(
pi
.
hThread
),
);
pi
.
dwProcessId
,
pi
.
dwThreadId
);
}
}
static
PyObject
*
static
PyObject
*
...
@@ -397,12 +421,12 @@ sp_GetExitCodeProcess(PyObject* self, PyObject* args)
...
@@ -397,12 +421,12 @@ sp_GetExitCodeProcess(PyObject* self, PyObject* args)
BOOL
result
;
BOOL
result
;
long
process
;
long
process
;
if
(
!
PyArg_ParseTuple
(
args
,
"l:GetExitCodeProcess"
,
&
process
))
if
(
!
PyArg_ParseTuple
(
args
,
"l:GetExitCodeProcess"
,
&
process
))
return
NULL
;
return
NULL
;
result
=
GetExitCodeProcess
((
HANDLE
)
process
,
&
exit_code
);
result
=
GetExitCodeProcess
((
HANDLE
)
process
,
&
exit_code
);
if
(
!
result
)
if
(
!
result
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyInt_FromLong
(
exit_code
);
return
PyInt_FromLong
(
exit_code
);
...
@@ -415,8 +439,9 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
...
@@ -415,8 +439,9 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
long
handle
;
long
handle
;
int
milliseconds
;
int
milliseconds
;
if
(
!
PyArg_ParseTuple
(
args
,
"li:WaitForSingleObject"
,
if
(
!
PyArg_ParseTuple
(
args
,
"li:WaitForSingleObject"
,
&
handle
,
&
milliseconds
))
&
handle
,
&
milliseconds
))
return
NULL
;
return
NULL
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
...
@@ -432,7 +457,7 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
...
@@ -432,7 +457,7 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
static
PyObject
*
static
PyObject
*
sp_GetVersion
(
PyObject
*
self
,
PyObject
*
args
)
sp_GetVersion
(
PyObject
*
self
,
PyObject
*
args
)
{
{
if
(
!
PyArg_ParseTuple
(
args
,
":GetVersion"
))
if
(
!
PyArg_ParseTuple
(
args
,
":GetVersion"
))
return
NULL
;
return
NULL
;
return
PyInt_FromLong
((
int
)
GetVersion
());
return
PyInt_FromLong
((
int
)
GetVersion
());
...
@@ -445,13 +470,13 @@ sp_GetModuleFileName(PyObject* self, PyObject* args)
...
@@ -445,13 +470,13 @@ sp_GetModuleFileName(PyObject* self, PyObject* args)
long
module
;
long
module
;
TCHAR
filename
[
MAX_PATH
];
TCHAR
filename
[
MAX_PATH
];
if
(
!
PyArg_ParseTuple
(
args
,
"l:GetModuleFileName"
,
&
module
))
if
(
!
PyArg_ParseTuple
(
args
,
"l:GetModuleFileName"
,
&
module
))
return
NULL
;
return
NULL
;
result
=
GetModuleFileName
((
HMODULE
)
module
,
filename
,
MAX_PATH
);
result
=
GetModuleFileName
((
HMODULE
)
module
,
filename
,
MAX_PATH
);
filename
[
MAX_PATH
-
1
]
=
'\0'
;
filename
[
MAX_PATH
-
1
]
=
'\0'
;
if
(
!
result
)
if
(
!
result
)
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyErr_SetFromWindowsErr
(
GetLastError
());
return
PyString_FromString
(
filename
);
return
PyString_FromString
(
filename
);
...
...
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