MCPcopy Create free account
hub / github.com/Singular/Singular / sync_contexts

Function sync_contexts

Singular/dyn_modules/pyobject/pyobject.cc:662–698  ·  view source on GitHub ↗

getting stuff from python to Singular namespace

Source from the content-addressed store, hash-verified

660
661/// getting stuff from python to Singular namespace
662void sync_contexts()
663{
664 PyRun_SimpleString("_SINGULAR_NEW = modules['__main__'].__dict__.copy()");
665
666 PythonObject newElts = python_eval("[(_k, _e) \
667 for (_k, _e) in _SINGULAR_NEW.iteritems() \
668 if _k not in _SINGULAR_IMPORTED or not _SINGULAR_IMPORTED[_k] is _e]");
669
670 long len = newElts.size();
671 for (long idx = 0; idx < len; ++idx)
672 {
673 long i = 0;
674 char* name = newElts[idx][i].str();
675 if (name && (*name != '\0') && (*name != '_'))
676 {
677 Py_XDECREF(get_current_definition(name));
678 i = 1;
679 newElts[idx][i].import_as(name);
680 }
681
682 }
683
684 PythonObject deletedElts =
685 python_eval("list(set(_SINGULAR_IMPORTED.iterkeys()) - \
686 set(_SINGULAR_NEW.iterkeys()))");
687 len = deletedElts.size();
688
689 for (long idx = 0; idx < len; ++idx)
690 {
691 char* name = deletedElts[idx].str();
692 if (name && (*name != '\0') && (*name != '_'))
693 killid(name, &IDROOT);
694 }
695
696 PyRun_SimpleString("_SINGULAR_IMPORTED =_SINGULAR_NEW");
697 PyRun_SimpleString("del _SINGULAR_NEW");
698}
699
700
701

Callers 3

check_contextMethod · 0.85
python_runFunction · 0.85
python_importFunction · 0.85

Calls 6

python_evalFunction · 0.85
get_current_definitionFunction · 0.85
killidFunction · 0.85
import_asMethod · 0.80
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected