This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Calling built-in locals() and globals() in C++ leads to SystemError
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, Никита Сиргиенко
Priority: normal Keywords:

Created on 2018-12-19 14:54 by Никита Сиргиенко, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg332144 - (view) Author: Никита Сиргиенко (Никита Сиргиенко) Date: 2018-12-19 14:54
  Distributor ID: Ubuntu
  Description:    Ubuntu 18.04.1 LTS
  Release:        18.04
  Codename:       bionic
  Arch:           x86_64

  g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Python versions:
  Python 3.6.7-1
  Python 2.7.15rc1

  This C++ code:

    PyObject* pBuiltin = PyImport_ImportModule("builtins");
    PyObject* py_globals_fun = PyObject_GetAttrString(pBuiltin,"locals");
    PyObject* globals = PyObject_CallObject(py_globals_fun, NULL);

  produces "SystemError: frame does not exist".
  For function "globals" output is "SystemError: returned NULL without 
  setting an error". For python2 this code produces similar errors (descriptions
  of error little different).

  Another functions with arguments, like "abs", works fine.
  And calling function with optional argument, like "int", "float" 
  works with this code (with null parameter) without problem.
msg332175 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-12-20 05:41
What behavior are you expecting? If there isn't any Python code in the callback, globals() and locals() are meaningless.
msg332178 - (view) Author: Никита Сиргиенко (Никита Сиргиенко) Date: 2018-12-20 06:03
I run some Python code before this moment, so I expect, that globals variable will be a PyDictObject with results of 'globals()' command: '__name__', '__doc__', global variables, etc.
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79717
2018-12-20 06:03:51Никита Сиргиенкоsetmessages: + msg332178
2018-12-20 05:41:46benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg332175
2018-12-19 14:54:20Никита Сиргиенкоcreate