Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
gcc-python-plugin/gcc-python-closure.c at master · HackLinux/gcc-python-plugin · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
HackLinux
/
gcc-python-plugin
Public
forked from
davidmalcolm/gcc-python-plugin
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
gcc-python-plugin
/
gcc-python-closure.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
157 lines (127 loc) · 3.83 KB
master
Breadcrumbs
gcc-python-plugin
/
gcc-python-closure.c
Copy path
Top
File metadata and controls
Code
Blame
157 lines (127 loc) · 3.83 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
152
153
154
155
156
157
/*
Copyright 2011 David Malcolm <dmalcolm@redhat.com>
Copyright 2011 Red Hat, Inc.
This is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#include
<Python.h>
#include
<gcc-plugin.h>
#include
"gcc-python-closure.h"
#include
"gcc-python.h"
#include
"function.h"
#include
"gcc-c-api/gcc-function.h"
struct
callback_closure
*
PyGcc_closure_new_generic
(
PyObject
*
callback
,
PyObject
*
extraargs
,
PyObject
*
kwargs
)
{
struct
callback_closure
*
closure
;
assert
(
callback
);
/* extraargs can be NULL
kwargs can also be NULL */
closure
=
PyMem_New
(
struct
callback_closure
,
1
);
if
(!
closure
) {
return
NULL
;
}
closure
->
callback
=
callback
;
Py_INCREF
(
callback
);
// FIXME: we may want to pass in the event enum as well as the user-supplied extraargs
if
(
extraargs
) {
/* Hold a reference to the extraargs for when we register it with the
callback: */
closure
->
extraargs
=
extraargs
;
Py_INCREF
(
extraargs
);
}
else
{
closure
->
extraargs
=
PyTuple_New
(
0
);
if
(!
closure
->
extraargs
) {
return
NULL
;
// singleton, so can't happen, really
}
}
closure
->
kwargs
=
kwargs
;
if
(
kwargs
) {
Py_INCREF
(
kwargs
);
}
closure
->
event
=
(
enum
plugin_event
)
GCC_PYTHON_PLUGIN_BAD_EVENT
;
return
closure
;
}
struct
callback_closure
*
PyGcc_Closure_NewForPluginEvent
(
PyObject
*
callback
,
PyObject
*
extraargs
,
PyObject
*
kwargs
,
enum
plugin_event
event
)
{
struct
callback_closure
*
closure
=
PyGcc_closure_new_generic
(
callback
,
extraargs
,
kwargs
);
if
(
closure
) {
closure
->
event
=
event
;
}
return
closure
;
}
PyObject
*
PyGcc_Closure_MakeArgs
(
struct
callback_closure
*
closure
,
int
add_cfun
,
PyObject
*
wrapped_gcc_data
)
{
PyObject
*
args
=
NULL
;
PyObject
*
cfun_obj
=
NULL
;
int
i
;
assert
(
closure
);
/* wrapped_gcc_data can be NULL if there isn't one for this kind of callback */
assert
(
closure
->
extraargs
);
assert
(
PyTuple_Check
(
closure
->
extraargs
));
if
(
wrapped_gcc_data
) {
/*
Equivalent to either:
args = (gcc_data, cfun, ) + extraargs
or:
args = (gcc_data, ) + extraargs
*/
args
=
PyTuple_New
((
add_cfun
?
2
:
1
)
+
PyTuple_Size
(
closure
->
extraargs
));
if
(!
args
) {
goto
error
;
}
if
(
add_cfun
) {
cfun_obj
=
PyGccFunction_New
(
gcc_get_current_function
());
if
(!
cfun_obj
) {
goto
error
;
}
}
PyTuple_SetItem
(
args
,
0
,
wrapped_gcc_data
);
if
(
add_cfun
) {
PyTuple_SetItem
(
args
,
1
,
cfun_obj
);
}
Py_INCREF
(
wrapped_gcc_data
);
for
(
i
=
0
;
i
<
PyTuple_Size
(
closure
->
extraargs
);
i
++
) {
PyObject
*
item
=
PyTuple_GetItem
(
closure
->
extraargs
,
i
);
PyTuple_SetItem
(
args
,
i
+
(
add_cfun
?
2
:
1
),
item
);
Py_INCREF
(
item
);
}
return
args
;
}
else
{
/* Just reuse closure's extraargs tuple */
Py_INCREF
(
closure
->
extraargs
);
return
closure
->
extraargs
;
}
error
:
Py_XDECREF
(
args
);
Py_XDECREF
(
cfun_obj
);
return
NULL
;
}
void
PyGcc_closure_free
(
struct
callback_closure
*
closure
)
{
assert
(
closure
);
Py_XDECREF
(
closure
->
callback
);
Py_XDECREF
(
closure
->
extraargs
);
Py_XDECREF
(
closure
->
kwargs
);
PyMem_Free
(
closure
);
}
/*
PEP-7
Local variables:
c-basic-offset: 4
indent-tabs-mode: nil
End:
*/
You can’t perform that action at this time.