init.cc (10453:d0365cc3d05f) | init.cc (11548:91f58918a76a) |
---|---|
1/* 2 * Copyright (c) 2012 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 --- 134 unchanged lines hidden (view full) --- 143 list<EmbeddedPython *>::iterator end = getList().end(); 144 for (; i != end; ++i) 145 if (!(*i)->addModule()) 146 return 1; 147 148 return 0; 149} 150 | 1/* 2 * Copyright (c) 2012 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 --- 134 unchanged lines hidden (view full) --- 143 list<EmbeddedPython *>::iterator end = getList().end(); 144 for (; i != end; ++i) 145 if (!(*i)->addModule()) 146 return 1; 147 148 return 0; 149} 150 |
151EmbeddedSwig::EmbeddedSwig(void (*init_func)()) 152 : initFunc(init_func) | 151EmbeddedSwig::EmbeddedSwig(void (*init_func)(), const string& _context) 152 : initFunc(init_func), context(_context) |
153{ 154 getList().push_back(this); 155} 156 157list<EmbeddedSwig *> & 158EmbeddedSwig::getList() 159{ 160 static list<EmbeddedSwig *> the_list; 161 return the_list; 162} 163 164void 165EmbeddedSwig::initAll() 166{ | 153{ 154 getList().push_back(this); 155} 156 157list<EmbeddedSwig *> & 158EmbeddedSwig::getList() 159{ 160 static list<EmbeddedSwig *> the_list; 161 return the_list; 162} 163 164void 165EmbeddedSwig::initAll() 166{ |
167 // initialize SWIG modules. initSwig() is autogenerated and calls | 167 char* old_context = _Py_PackageContext; 168 // initialize SWIG modules. initFunc() is autogenerated and calls |
168 // all of the individual swig initialization functions. | 169 // all of the individual swig initialization functions. |
169 list<EmbeddedSwig *>::iterator i = getList().begin(); 170 list<EmbeddedSwig *>::iterator end = getList().end(); 171 for (; i != end; ++i) 172 (*i)->initFunc(); | 170 for (auto i : getList()) { 171 // to ensure that the loaded modules are placed in the right 172 // package we have to be a bit unorthodox and directly 173 // manipulate the package context since swig simply calls 174 // Py_InitModule with nothing but the module name of the 175 // wrapper 176 char* cstr = new char[i->context.size() + 1]; 177 strcpy(cstr, i->context.c_str()); 178 _Py_PackageContext = cstr; 179 i->initFunc(); 180 delete[] cstr; 181 } 182 _Py_PackageContext = old_context; |
173} 174 175int 176initM5Python() 177{ 178 EmbeddedSwig::initAll(); 179 return EmbeddedPython::initAll(); 180} --- 63 unchanged lines hidden --- | 183} 184 185int 186initM5Python() 187{ 188 EmbeddedSwig::initAll(); 189 return EmbeddedPython::initAll(); 190} --- 63 unchanged lines hidden --- |