@@ -2507,27 +2507,16 @@ lookup_inittab_entry(const struct _Py_ext_module_loader_info* info)
25072507
25082508static PyObject *
25092509create_builtin (
2510- PyThreadState * tstate , PyObject * name ,
2510+ PyThreadState * tstate ,
2511+ PyObject * name , /* if NULL, get from spec */
25112512 PyObject * spec ,
25122513 PyModInitFunction initfunc )
25132514{
25142515 struct _Py_ext_module_loader_info info ;
2515- if (_Py_ext_module_loader_info_init_for_builtin (& info , name ) < 0 ) {
2516+ _Py_ext_module_origin origin = _Py_ext_module_origin_BUILTIN ;
2517+ if (_Py_ext_module_loader_info_init (& info , name , spec , origin ) < 0 ) {
25162518 return NULL ;
25172519 }
2518- if (initfunc != NULL ) {
2519- /* An explicitly provided init function (see
2520- * PyImport_CreateModuleFromInitfunc()) may belong to a submodule
2521- * whose single-phase init creates the module using only the last
2522- * component of the name (as e.g. pybind11 does). Set the package
2523- * context so that PyModule_Create() resolves the full name, the
2524- * same as for dynamically loaded extensions. */
2525- info .newcontext = PyUnicode_AsUTF8 (info .name );
2526- if (info .newcontext == NULL ) {
2527- _Py_ext_module_loader_info_clear (& info );
2528- return NULL ;
2529- }
2530- }
25312520
25322521 struct extensions_cache_value * cached = NULL ;
25332522 PyObject * mod = import_find_extension (tstate , & info , & cached );
@@ -2558,7 +2547,7 @@ create_builtin(
25582547 struct _inittab * entry = lookup_inittab_entry (& info );
25592548 if (entry == NULL ) {
25602549 mod = NULL ;
2561- _PyErr_SetModuleNotFoundError (name );
2550+ _PyErr_SetModuleNotFoundError (info . name );
25622551 goto finally ;
25632552 }
25642553
@@ -2610,20 +2599,7 @@ PyImport_CreateModuleFromInitfunc(
26102599
26112600 PyThreadState * tstate = _PyThreadState_GET ();
26122601
2613- PyObject * name = PyObject_GetAttr (spec , & _Py_ID (name ));
2614- if (name == NULL ) {
2615- return NULL ;
2616- }
2617-
2618- if (!PyUnicode_Check (name )) {
2619- PyErr_Format (PyExc_TypeError ,
2620- "spec name must be string, not %T" , name );
2621- Py_DECREF (name );
2622- return NULL ;
2623- }
2624-
2625- PyObject * mod = create_builtin (tstate , name , spec , initfunc );
2626- Py_DECREF (name );
2602+ PyObject * mod = create_builtin (tstate , NULL , spec , initfunc );
26272603 return mod ;
26282604}
26292605
@@ -2835,8 +2811,8 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co,
28352811 Py_FatalError ("no current interpreter" );
28362812 }
28372813
2838- external = PyObject_GetAttrString (IMPORTLIB (interp ),
2839- " _bootstrap_external" );
2814+ external = PyObject_GetAttr (IMPORTLIB (interp ),
2815+ & _Py_ID ( _bootstrap_external ) );
28402816 if (external != NULL ) {
28412817 pathobj = PyObject_CallMethodOneArg (
28422818 external , & _Py_ID (_get_sourcefile ), cpathobj );
@@ -2920,8 +2896,8 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname,
29202896 if (pathname == NULL ) {
29212897 pathname = ((PyCodeObject * )co )-> co_filename ;
29222898 }
2923- external = PyObject_GetAttrString (IMPORTLIB (tstate -> interp ),
2924- " _bootstrap_external" );
2899+ external = PyObject_GetAttr (IMPORTLIB (tstate -> interp ),
2900+ & _Py_ID ( _bootstrap_external ) );
29252901 if (external == NULL ) {
29262902 Py_DECREF (d );
29272903 return NULL ;
@@ -3499,8 +3475,8 @@ PyObject *
34993475_PyImport_GetImportlibExternalLoader (PyInterpreterState * interp ,
35003476 const char * loader_name )
35013477{
3502- PyObject * bootstrap = PyObject_GetAttrString (IMPORTLIB (interp ),
3503- " _bootstrap_external" );
3478+ PyObject * bootstrap = PyObject_GetAttr (IMPORTLIB (interp ),
3479+ & _Py_ID ( _bootstrap_external ) );
35043480 if (bootstrap == NULL ) {
35053481 return NULL ;
35063482 }
@@ -3513,8 +3489,8 @@ _PyImport_GetImportlibExternalLoader(PyInterpreterState *interp,
35133489PyObject *
35143490_PyImport_BlessMyLoader (PyInterpreterState * interp , PyObject * module_globals )
35153491{
3516- PyObject * external = PyObject_GetAttrString (IMPORTLIB (interp ),
3517- " _bootstrap_external" );
3492+ PyObject * external = PyObject_GetAttr (IMPORTLIB (interp ),
3493+ & _Py_ID ( _bootstrap_external ) );
35183494 if (external == NULL ) {
35193495 return NULL ;
35203496 }
@@ -5085,27 +5061,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
50855061{
50865062 PyThreadState * tstate = _PyThreadState_GET ();
50875063
5088- PyObject * name = PyObject_GetAttrString (spec , "name" );
5089- if (name == NULL ) {
5090- return NULL ;
5091- }
5092-
5093- if (!PyUnicode_Check (name )) {
5094- PyErr_Format (PyExc_TypeError ,
5095- "name must be string, not %.200s" ,
5096- Py_TYPE (name )-> tp_name );
5097- Py_DECREF (name );
5098- return NULL ;
5099- }
5100-
5101- if (PyUnicode_GetLength (name ) == 0 ) {
5102- PyErr_Format (PyExc_ValueError , "name must not be empty" );
5103- Py_DECREF (name );
5104- return NULL ;
5105- }
5106-
5107- PyObject * mod = create_builtin (tstate , name , spec , NULL );
5108- Py_DECREF (name );
5064+ PyObject * mod = create_builtin (tstate , NULL , spec , NULL );
51095065 return mod ;
51105066}
51115067
@@ -5437,7 +5393,8 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
54375393 PyThreadState * tstate = _PyThreadState_GET ();
54385394
54395395 struct _Py_ext_module_loader_info info ;
5440- if (_Py_ext_module_loader_info_init_from_spec (& info , spec ) < 0 ) {
5396+ _Py_ext_module_origin origin = _Py_ext_module_origin_DYNAMIC ;
5397+ if (_Py_ext_module_loader_info_init (& info , NULL , spec , origin ) < 0 ) {
54415398 return NULL ;
54425399 }
54435400
0 commit comments