@@ -1744,26 +1744,29 @@ PyImport_ReloadModule(PyObject *m)
1744
1744
PyObject *
1745
1745
PyImport_Import (PyObject * module_name )
1746
1746
{
1747
+ _Py_IDENTIFIER (__import__ );
1748
+ _Py_IDENTIFIER (__builtins__ );
1749
+
1747
1750
PyThreadState * tstate = _PyThreadState_GET ();
1748
- static PyObject * silly_list = NULL ;
1749
- static PyObject * builtins_str = NULL ;
1750
- static PyObject * import_str = NULL ;
1751
1751
PyObject * globals = NULL ;
1752
1752
PyObject * import = NULL ;
1753
1753
PyObject * builtins = NULL ;
1754
1754
PyObject * r = NULL ;
1755
1755
1756
1756
/* Initialize constant string objects */
1757
- if (silly_list == NULL ) {
1758
- import_str = PyUnicode_InternFromString ("__import__" );
1759
- if (import_str == NULL )
1760
- return NULL ;
1761
- builtins_str = PyUnicode_InternFromString ("__builtins__" );
1762
- if (builtins_str == NULL )
1763
- return NULL ;
1764
- silly_list = PyList_New (0 );
1765
- if (silly_list == NULL )
1766
- return NULL ;
1757
+ PyObject * import_str = _PyUnicode_FromId (& PyId___import__ ); // borrowed ref
1758
+ if (import_str == NULL ) {
1759
+ return NULL ;
1760
+ }
1761
+
1762
+ PyObject * builtins_str = _PyUnicode_FromId (& PyId___builtins__ ); // borrowed ref
1763
+ if (builtins_str == NULL ) {
1764
+ return NULL ;
1765
+ }
1766
+
1767
+ PyObject * from_list = PyList_New (0 );
1768
+ if (from_list == NULL ) {
1769
+ goto err ;
1767
1770
}
1768
1771
1769
1772
/* Get the builtins from current globals */
@@ -1778,8 +1781,9 @@ PyImport_Import(PyObject *module_name)
1778
1781
/* No globals -- use standard builtins, and fake globals */
1779
1782
builtins = PyImport_ImportModuleLevel ("builtins" ,
1780
1783
NULL , NULL , NULL , 0 );
1781
- if (builtins == NULL )
1782
- return NULL ;
1784
+ if (builtins == NULL ) {
1785
+ goto err ;
1786
+ }
1783
1787
globals = Py_BuildValue ("{OO}" , builtins_str , builtins );
1784
1788
if (globals == NULL )
1785
1789
goto err ;
@@ -1801,7 +1805,7 @@ PyImport_Import(PyObject *module_name)
1801
1805
Always use absolute import here.
1802
1806
Calling for side-effect of import. */
1803
1807
r = PyObject_CallFunction (import , "OOOOi" , module_name , globals ,
1804
- globals , silly_list , 0 , NULL );
1808
+ globals , from_list , 0 , NULL );
1805
1809
if (r == NULL )
1806
1810
goto err ;
1807
1811
Py_DECREF (r );
@@ -1815,6 +1819,7 @@ PyImport_Import(PyObject *module_name)
1815
1819
Py_XDECREF (globals );
1816
1820
Py_XDECREF (builtins );
1817
1821
Py_XDECREF (import );
1822
+ Py_XDECREF (from_list );
1818
1823
1819
1824
return r ;
1820
1825
}
0 commit comments