FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Modules/_testcapi/function.c at 3.15 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.5k
(2.5k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Modules
/
_testcapi
/
function.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
151 lines (128 loc) · 3.66 KB
Breadcrumbs
cpython
/
Modules
/
_testcapi
/
function.c
Copy path
File metadata and controls
151 lines (128 loc) · 3.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include
"parts.h"
#include
"util.h"
static
PyObject
*
function_get_code
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
code
=
PyFunction_GetCode
(
func
);
if
(
code
!=
NULL
) {
return
Py_NewRef
(
code
);
}
else
{
return
NULL
;
}
}
static
PyObject
*
function_get_globals
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
globals
=
PyFunction_GetGlobals
(
func
);
if
(
globals
!=
NULL
) {
return
Py_NewRef
(
globals
);
}
else
{
return
NULL
;
}
}
static
PyObject
*
function_get_module
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
module
=
PyFunction_GetModule
(
func
);
if
(
module
!=
NULL
) {
return
Py_NewRef
(
module
);
}
else
{
return
NULL
;
}
}
static
PyObject
*
function_get_defaults
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
defaults
=
PyFunction_GetDefaults
(
func
);
if
(
defaults
!=
NULL
) {
return
Py_NewRef
(
defaults
);
}
else
if
(
PyErr_Occurred
()) {
return
NULL
;
}
else
{
Py_RETURN_NONE
;
// This can happen when `defaults` are set to `None`
}
}
static
PyObject
*
function_set_defaults
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
func
=
NULL
,
*
defaults
=
NULL
;
if
(!
PyArg_ParseTuple
(
args
,
"OO"
,
&
func
,
&
defaults
)) {
return
NULL
;
}
int
result
=
PyFunction_SetDefaults
(
func
,
defaults
);
if
(
result
==
-1
)
return
NULL
;
Py_RETURN_NONE
;
}
static
PyObject
*
function_get_kw_defaults
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
defaults
=
PyFunction_GetKwDefaults
(
func
);
if
(
defaults
!=
NULL
) {
return
Py_NewRef
(
defaults
);
}
else
if
(
PyErr_Occurred
()) {
return
NULL
;
}
else
{
Py_RETURN_NONE
;
// This can happen when `kwdefaults` are set to `None`
}
}
static
PyObject
*
function_set_kw_defaults
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
func
=
NULL
,
*
defaults
=
NULL
;
if
(!
PyArg_ParseTuple
(
args
,
"OO"
,
&
func
,
&
defaults
)) {
return
NULL
;
}
int
result
=
PyFunction_SetKwDefaults
(
func
,
defaults
);
if
(
result
==
-1
)
return
NULL
;
Py_RETURN_NONE
;
}
static
PyObject
*
function_get_closure
(
PyObject
*
self
,
PyObject
*
func
)
{
PyObject
*
closure
=
PyFunction_GetClosure
(
func
);
if
(
closure
!=
NULL
) {
return
Py_NewRef
(
closure
);
}
else
if
(
PyErr_Occurred
()) {
return
NULL
;
}
else
{
Py_RETURN_NONE
;
// This can happen when `closure` is set to `None`
}
}
static
PyObject
*
function_set_closure
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
func
=
NULL
,
*
closure
=
NULL
;
if
(!
PyArg_ParseTuple
(
args
,
"OO"
,
&
func
,
&
closure
)) {
return
NULL
;
}
int
result
=
PyFunction_SetClosure
(
func
,
closure
);
if
(
result
==
-1
) {
return
NULL
;
}
Py_RETURN_NONE
;
}
static
PyObject
*
function_get_annotations
(
PyObject
*
self
,
PyObject
*
func
)
{
return
Py_XNewRef
(
PyFunction_GetAnnotations
(
func
));
}
static
PyMethodDef
test_methods
[]
=
{
{
"function_get_code"
,
function_get_code
,
METH_O
,
NULL
},
{
"function_get_globals"
,
function_get_globals
,
METH_O
,
NULL
},
{
"function_get_module"
,
function_get_module
,
METH_O
,
NULL
},
{
"function_get_defaults"
,
function_get_defaults
,
METH_O
,
NULL
},
{
"function_set_defaults"
,
function_set_defaults
,
METH_VARARGS
,
NULL
},
{
"function_get_kw_defaults"
,
function_get_kw_defaults
,
METH_O
,
NULL
},
{
"function_set_kw_defaults"
,
function_set_kw_defaults
,
METH_VARARGS
,
NULL
},
{
"function_get_closure"
,
function_get_closure
,
METH_O
,
NULL
},
{
"function_set_closure"
,
function_set_closure
,
METH_VARARGS
,
NULL
},
{
"function_get_annotations"
,
function_get_annotations
,
METH_O
,
NULL
},
{
NULL
},
};
int
_PyTestCapi_Init_Function
(
PyObject
*
m
)
{
return
PyModule_AddFunctions
(
m
,
test_methods
);
}
Back
|
FazBrowse Home
|
New Git URL