@@ -20,32 +20,15 @@ limitations under the License.
2020#include " dsAssert.hh"
2121#include " GetGlobalParameter.hh"
2222
23- // #include <iostream>
2423
25- Interpreter::Interpreter () // : interp_(nullptr)
24+ Interpreter::Interpreter ()
2625{
2726}
2827
2928Interpreter::~Interpreter ()
3029{
3130}
3231
33- #if 0
34- /* for now run in main intepreter*/
35- bool Interpreter::RunCommand(const std::string &command, const std::vector<std::string> &arguments)
36- {
37- // PyObject *interp_ = reinterpret_cast<PyObject *>(GetMainInterpreter());
38-
39- std::vector<ObjectHolder> objs(arguments.size() + 1);
40- objs[0] = ObjectHolder(command);
41- for (size_t i = 0; i < arguments.size(); ++i)
42- {
43- objs[i + 1] = ObjectHolder(arguments[i]);
44- }
45- return RunCommand(objs);
46- }
47- #endif
48-
4932namespace
5033{
5134PyObject *GetGlobalDictionary ()
@@ -125,13 +108,13 @@ ObjectHolder CreateTuple(std::vector<ObjectHolder> &objects, size_t beg, size_t
125108 for (size_t i = 0 ; i < len; ++i)
126109 {
127110 PyObject *p = reinterpret_cast <PyObject *>(objects[beg + i].GetObject ());
111+ // PyTuple_SetItem steals a reference
128112 Py_INCREF (p);
129113 PyTuple_SetItem (args, i, p);
130114 }
131115 return ret;
132116}
133117
134- // /// Check for duplicates!
135118ObjectHolder CreateDictionary (const std::vector<std::pair<std::string, ObjectHolder> > &objects)
136119{
137120 ObjectHolder ret;
@@ -141,7 +124,8 @@ ObjectHolder CreateDictionary(const std::vector<std::pair<std::string, ObjectHol
141124 {
142125 const std::string &key = objects[i].first ;
143126 const PyObject *obj = reinterpret_cast <const PyObject *>((objects[i].second ).GetObject ());
144- Py_INCREF (const_cast <PyObject *>(obj));
127+ // PyDict_SetItemString does not steal a reference
128+ // Py_INCREF(const_cast<PyObject *>(obj));
145129 PyDict_SetItemString (args, key.c_str (), const_cast <PyObject *>(obj));
146130 }
147131 return ret;
@@ -175,7 +159,6 @@ bool Interpreter::RunCommand(ObjectHolder &procedure, std::vector<ObjectHolder>
175159 return ret;
176160 }
177161
178- // // This really can't fail
179162 ObjectHolder args = CreateTuple (objects, 0 , objects.size ());
180163
181164 PyErr_Clear ();
@@ -194,41 +177,6 @@ bool Interpreter::RunCommand(ObjectHolder &procedure, std::vector<ObjectHolder>
194177 return ret;
195178}
196179
197- #if 0
198- bool Interpreter::RunCommand(std::vector<ObjectHolder> &objects)
199- {
200- bool ret = false;
201- error_string_.clear();
202-
203- std::string commandname = objects[0].GetString();
204-
205- ObjectHolder command_object = GetCommandFromInterpreter(commandname, error_string_);
206- if (!error_string_.empty())
207- {
208- ret = false;
209- return ret;
210- }
211-
212- //// This really can't fail
213- ObjectHolder args = CreateTuple(objects, 1, objects.size() - 1);
214-
215- PyErr_Clear();
216- PyObject *robj = PyObject_Call(reinterpret_cast<PyObject *>(command_object.GetObject()), reinterpret_cast<PyObject *>(args.GetObject()), nullptr);
217- result_ = ObjectHolder(robj);
218- if (robj)
219- {
220- ret = true;
221- }
222- else
223- {
224- ret = false;
225- ProcessError(commandname, error_string_);
226- }
227-
228- return ret;
229- }
230- #endif
231-
232180bool Interpreter::RunInternalCommand (const std::string &commandname, const std::vector<std::pair<std::string, ObjectHolder> > &arguments)
233181{
234182 std::string newname;
@@ -238,7 +186,6 @@ bool Interpreter::RunInternalCommand(const std::string &commandname, const std::
238186 return RunCommand (newname, arguments);
239187}
240188
241- // TODO: pass command directly as function reference from python
242189bool Interpreter::RunCommand (const std::string &commandname, const std::vector<std::pair<std::string, ObjectHolder> > &arguments)
243190{
244191 bool ret = false ;
@@ -273,24 +220,6 @@ bool Interpreter::RunCommand(const std::string &commandname, const std::vector<s
273220}
274221
275222
276- #if 0
277- bool Interpreter::RunCommand(const std::string &commandString)
278- {
279- error_string_.clear();
280- PyErr_Clear();
281- PyObject *globals = GetGlobalDictionary();
282- PyObject *res = PyRun_String(commandString.c_str(), Py_file_input, globals, globals);
283- result_ = ObjectHolder(res);
284-
285- if (!res)
286- {
287- ProcessError(commandString, error_string_);
288- }
289-
290- return (res != nullptr);
291- }
292- #endif
293-
294223std::string Interpreter::GetVariable (const std::string &name)
295224{
296225 std::string ret;
0 commit comments