init.cc (11988:665cd5f8b52b) init.cc (11990:5fad911cc326)
1/*
2 * Copyright (c) 2012, 2017 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 113 unchanged lines hidden (view full) ---

122 return false;
123 }
124
125 Py_DECREF(result);
126 return true;
127}
128
129/*
1/*
2 * Copyright (c) 2012, 2017 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 113 unchanged lines hidden (view full) ---

122 return false;
123 }
124
125 Py_DECREF(result);
126 return true;
127}
128
129/*
130 * Load and initialize all of the python parts of M5, including Swig
131 * and the embedded module importer.
130 * Load and initialize all of the python parts of M5.
132 */
133int
134EmbeddedPython::initAll()
135{
136 // Load the importer module
137 PyObject *code = importer->getCode();
138 importerModule = PyImport_ExecCodeModule(PyCC("importer"), code);
139 if (!importerModule) {

--- 7 unchanged lines hidden (view full) ---

147 list<EmbeddedPython *>::iterator end = getList().end();
148 for (; i != end; ++i)
149 if (!(*i)->addModule())
150 return 1;
151
152 return 0;
153}
154
131 */
132int
133EmbeddedPython::initAll()
134{
135 // Load the importer module
136 PyObject *code = importer->getCode();
137 importerModule = PyImport_ExecCodeModule(PyCC("importer"), code);
138 if (!importerModule) {

--- 7 unchanged lines hidden (view full) ---

146 list<EmbeddedPython *>::iterator end = getList().end();
147 for (; i != end; ++i)
148 if (!(*i)->addModule())
149 return 1;
150
151 return 0;
152}
153
155EmbeddedSwig::EmbeddedSwig(void (*init_func)(), const string& _context)
156 : initFunc(init_func), context(_context)
157{
158 getList().push_back(this);
159}
160
161list<EmbeddedSwig *> &
162EmbeddedSwig::getList()
163{
164 static list<EmbeddedSwig *> the_list;
165 return the_list;
166}
167
168void
169EmbeddedSwig::initAll()
170{
171 char* old_context = _Py_PackageContext;
172 // initialize SWIG modules. initFunc() is autogenerated and calls
173 // all of the individual swig initialization functions.
174 for (auto i : getList()) {
175 // to ensure that the loaded modules are placed in the right
176 // package we have to be a bit unorthodox and directly
177 // manipulate the package context since swig simply calls
178 // Py_InitModule with nothing but the module name of the
179 // wrapper
180 char* cstr = new char[i->context.size() + 1];
181 strcpy(cstr, i->context.c_str());
182 _Py_PackageContext = cstr;
183 i->initFunc();
184 delete[] cstr;
185 }
186 _Py_PackageContext = old_context;
187}
188
189EmbeddedPyBind::EmbeddedPyBind(const char *_name,
190 void (*init_func)(py::module &),
191 const char *_base)
192 : initFunc(init_func), registered(false), name(_name), base(_base)
193{
194 getMap()[_name] = this;
195}
196

--- 63 unchanged lines hidden (view full) ---

260 }
261 }
262 }
263}
264
265int
266initM5Python()
267{
154EmbeddedPyBind::EmbeddedPyBind(const char *_name,
155 void (*init_func)(py::module &),
156 const char *_base)
157 : initFunc(init_func), registered(false), name(_name), base(_base)
158{
159 getMap()[_name] = this;
160}
161

--- 63 unchanged lines hidden (view full) ---

225 }
226 }
227 }
228}
229
230int
231initM5Python()
232{
268 EmbeddedSwig::initAll();
269 EmbeddedPyBind::initAll();
270 return EmbeddedPython::initAll();
271}
272
273/*
274 * Make the commands array weak so that they can be overridden (used
275 * by unit tests to specify a different python main function.
276 */

--- 58 unchanged lines hidden ---
233 EmbeddedPyBind::initAll();
234 return EmbeddedPython::initAll();
235}
236
237/*
238 * Make the commands array weak so that they can be overridden (used
239 * by unit tests to specify a different python main function.
240 */

--- 58 unchanged lines hidden ---