Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b3fd0652
Commit
b3fd0652
authored
Mar 04, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3080: Add PyModule_NewObject() function
parent
ad3d4111
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
8 deletions
+28
-8
Doc/c-api/module.rst
Doc/c-api/module.rst
+9
-1
Include/moduleobject.h
Include/moduleobject.h
+3
-0
Objects/moduleobject.c
Objects/moduleobject.c
+16
-7
No files found.
Doc/c-api/module.rst
View file @
b3fd0652
...
@@ -29,7 +29,7 @@ There are only a few functions special to module objects.
...
@@ -29,7 +29,7 @@ There are only a few functions special to module objects.
:c:data:`PyModule_Type`.
:c:data:`PyModule_Type`.
.. c:function:: PyObject* PyModule_New
(const char
*name)
.. c:function:: PyObject* PyModule_New
Object(PyObject
*name)
.. index::
.. index::
single: __name__ (module attribute)
single: __name__ (module attribute)
...
@@ -40,6 +40,14 @@ There are only a few functions special to module objects.
...
@@ -40,6 +40,14 @@ There are only a few functions special to module objects.
Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
the caller is responsible for providing a :attr:`__file__` attribute.
the caller is responsible for providing a :attr:`__file__` attribute.
.. versionadded:: 3.3
.. c:function:: PyObject* PyModule_New(const char *name)
Similar to :c:func:`PyImport_NewObject`, but the name is an UTF-8 encoded
string instead of a Unicode object.
.. c:function:: PyObject* PyModule_GetDict(PyObject *module)
.. c:function:: PyObject* PyModule_GetDict(PyObject *module)
...
...
Include/moduleobject.h
View file @
b3fd0652
...
@@ -12,6 +12,9 @@ PyAPI_DATA(PyTypeObject) PyModule_Type;
...
@@ -12,6 +12,9 @@ PyAPI_DATA(PyTypeObject) PyModule_Type;
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
PyAPI_FUNC
(
PyObject
*
)
PyModule_NewObject
(
PyObject
*
name
);
PyAPI_FUNC
(
PyObject
*
)
PyModule_New
(
PyAPI_FUNC
(
PyObject
*
)
PyModule_New
(
const
char
*
name
/* UTF-8 encoded string */
const
char
*
name
/* UTF-8 encoded string */
);
);
...
...
Objects/moduleobject.c
View file @
b3fd0652
...
@@ -27,35 +27,44 @@ static PyTypeObject moduledef_type = {
...
@@ -27,35 +27,44 @@ static PyTypeObject moduledef_type = {
PyObject
*
PyObject
*
PyModule_New
(
const
char
*
name
)
PyModule_New
Object
(
PyObject
*
name
)
{
{
PyModuleObject
*
m
;
PyModuleObject
*
m
;
PyObject
*
nameobj
;
m
=
PyObject_GC_New
(
PyModuleObject
,
&
PyModule_Type
);
m
=
PyObject_GC_New
(
PyModuleObject
,
&
PyModule_Type
);
if
(
m
==
NULL
)
if
(
m
==
NULL
)
return
NULL
;
return
NULL
;
m
->
md_def
=
NULL
;
m
->
md_def
=
NULL
;
m
->
md_state
=
NULL
;
m
->
md_state
=
NULL
;
nameobj
=
PyUnicode_FromString
(
name
);
m
->
md_dict
=
PyDict_New
();
m
->
md_dict
=
PyDict_New
();
if
(
m
->
md_dict
==
NULL
||
nameobj
==
NULL
)
if
(
m
->
md_dict
==
NULL
)
goto
fail
;
goto
fail
;
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__name__"
,
name
obj
)
!=
0
)
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__name__"
,
name
)
!=
0
)
goto
fail
;
goto
fail
;
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__doc__"
,
Py_None
)
!=
0
)
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__doc__"
,
Py_None
)
!=
0
)
goto
fail
;
goto
fail
;
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__package__"
,
Py_None
)
!=
0
)
if
(
PyDict_SetItemString
(
m
->
md_dict
,
"__package__"
,
Py_None
)
!=
0
)
goto
fail
;
goto
fail
;
Py_DECREF
(
nameobj
);
PyObject_GC_Track
(
m
);
PyObject_GC_Track
(
m
);
return
(
PyObject
*
)
m
;
return
(
PyObject
*
)
m
;
fail:
fail:
Py_XDECREF
(
nameobj
);
Py_DECREF
(
m
);
Py_DECREF
(
m
);
return
NULL
;
return
NULL
;
}
}
PyObject
*
PyModule_New
(
const
char
*
name
)
{
PyObject
*
nameobj
,
*
module
;
nameobj
=
PyUnicode_FromString
(
name
);
if
(
nameobj
==
NULL
)
return
NULL
;
module
=
PyModule_NewObject
(
nameobj
);
Py_DECREF
(
nameobj
);
return
module
;
}
PyObject
*
PyObject
*
PyModule_Create2
(
struct
PyModuleDef
*
module
,
int
module_api_version
)
PyModule_Create2
(
struct
PyModuleDef
*
module
,
int
module_api_version
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment