static void MergePyGlobalsWithContext(PyObject* globals, KObjectRef context) { // Avoid compiler warnings PyObject *items = PyObject_CallMethod(globals, (char*) "items", NULL); if (items == NULL) return; PyObject *iterator = PyObject_GetIter(items); if (iterator == NULL) return; PyObject *item; while ((item = PyIter_Next(iterator))) { PyObject* k = PyTuple_GetItem(item, 0); PyObject* v = PyTuple_GetItem(item, 1); std::string sk = PythonUtils::ToString(k); if (sk.find("__") != 0) { KValueRef newValue = PythonUtils::ToKrollValue(v); KValueRef existingValue = context->Get(sk.c_str()); if (!newValue->Equals(existingValue)) { context->Set(sk.c_str(), newValue); } } Py_DECREF(item); } }