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
a6b7c714
Commit
a6b7c714
authored
Dec 10, 1996
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed.
parent
5de1f8da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
81 deletions
+84
-81
Modules/newmodule.c
Modules/newmodule.c
+84
-81
No files found.
Modules/newmodule.c
View file @
a6b7c714
...
...
@@ -31,155 +31,158 @@ PERFORMANCE OF THIS SOFTWARE.
/* Module new -- create new objects of various types */
#include "
allobjects
.h"
#include "
Python
.h"
#include "compile.h"
static
char
new_instance_doc
[]
=
"Create an instance object from (CLASS, DICT) without calling its __init__()."
;
static
o
bject
*
static
PyO
bject
*
new_instance
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
o
bject
*
klass
;
o
bject
*
dict
;
instanceo
bject
*
inst
;
if
(
!
newgetargs
(
args
,
"O!O!"
,
&
Classt
ype
,
&
klass
,
&
Dictt
ype
,
&
dict
))
PyO
bject
*
klass
;
PyO
bject
*
dict
;
PyInstanceO
bject
*
inst
;
if
(
!
PyArg_ParseTuple
(
args
,
"O!O!"
,
&
PyClass_T
ype
,
&
klass
,
&
PyDict_T
ype
,
&
dict
))
return
NULL
;
inst
=
NEWOBJ
(
instanceobject
,
&
Instancet
ype
);
inst
=
PyObject_NEW
(
PyInstanceObject
,
&
PyInstance_T
ype
);
if
(
inst
==
NULL
)
return
NULL
;
INCREF
(
klass
);
INCREF
(
dict
);
inst
->
in_class
=
(
classo
bject
*
)
klass
;
Py_
INCREF
(
klass
);
Py_
INCREF
(
dict
);
inst
->
in_class
=
(
PyClassO
bject
*
)
klass
;
inst
->
in_dict
=
dict
;
return
(
o
bject
*
)
inst
;
return
(
PyO
bject
*
)
inst
;
}
static
char
new_im_doc
[]
=
"Create a instance method object from (FUNCTION, INSTANCE, CLASS)."
;
static
o
bject
*
static
PyO
bject
*
new_instancemethod
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
o
bject
*
func
;
o
bject
*
self
;
o
bject
*
classObj
;
if
(
!
newgetargs
(
args
,
"O!O!O!"
,
&
Funct
ype
,
&
func
,
&
Instancet
ype
,
&
self
,
&
Classt
ype
,
&
classObj
))
PyO
bject
*
func
;
PyO
bject
*
self
;
PyO
bject
*
classObj
;
if
(
!
PyArg_ParseTuple
(
args
,
"O!O!O!"
,
&
PyFunction_T
ype
,
&
func
,
&
PyInstance_T
ype
,
&
self
,
&
PyClass_T
ype
,
&
classObj
))
return
NULL
;
return
newinstancemethodobject
(
func
,
self
,
classObj
);
return
PyMethod_New
(
func
,
self
,
classObj
);
}
static
char
new_function_doc
[]
=
"Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS])."
;
static
o
bject
*
static
PyO
bject
*
new_function
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
o
bject
*
code
;
o
bject
*
globals
;
object
*
name
=
None
;
object
*
defaults
=
None
;
funco
bject
*
newfunc
;
if
(
!
newgetargs
(
args
,
"O!O!|SO!"
,
&
Codet
ype
,
&
code
,
&
Mappingt
ype
,
&
globals
,
&
name
,
&
Tuplet
ype
,
&
defaults
))
PyO
bject
*
code
;
PyO
bject
*
globals
;
PyObject
*
name
=
Py_
None
;
PyObject
*
defaults
=
Py_
None
;
PyFunctionO
bject
*
newfunc
;
if
(
!
PyArg_ParseTuple
(
args
,
"O!O!|SO!"
,
&
PyCode_T
ype
,
&
code
,
&
PyDict_T
ype
,
&
globals
,
&
name
,
&
PyTuple_T
ype
,
&
defaults
))
return
NULL
;
newfunc
=
(
funcobject
*
)
newfuncobject
(
code
,
globals
);
newfunc
=
(
PyFunctionObject
*
)
PyFunction_New
(
code
,
globals
);
if
(
newfunc
==
NULL
)
return
NULL
;
if
(
name
!=
None
)
{
XINCREF
(
name
);
XDECREF
(
newfunc
->
func_name
);
if
(
name
!=
Py_
None
)
{
Py_
XINCREF
(
name
);
Py_
XDECREF
(
newfunc
->
func_name
);
newfunc
->
func_name
=
name
;
}
if
(
defaults
!=
NULL
)
{
XINCREF
(
defaults
);
XDECREF
(
newfunc
->
func_defaults
);
Py_
XINCREF
(
defaults
);
Py_
XDECREF
(
newfunc
->
func_defaults
);
newfunc
->
func_defaults
=
defaults
;
}
return
(
o
bject
*
)
newfunc
;
return
(
PyO
bject
*
)
newfunc
;
}
static
char
new_code_doc
[]
=
"Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME)."
;
static
o
bject
*
static
PyO
bject
*
new_code
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
int
argcount
;
int
nlocals
;
int
flags
;
o
bject
*
code
;
o
bject
*
consts
;
o
bject
*
names
;
o
bject
*
varnames
;
o
bject
*
filename
;
o
bject
*
name
;
PyO
bject
*
code
;
PyO
bject
*
consts
;
PyO
bject
*
names
;
PyO
bject
*
varnames
;
PyO
bject
*
filename
;
PyO
bject
*
name
;
if
(
!
newgetargs
(
args
,
"iiiSO!O!O!SS"
,
&
argcount
,
&
nlocals
,
&
flags
,
/* These are new */
&
code
,
&
Tupletype
,
&
consts
,
&
Tupletype
,
&
names
,
&
Tupletype
,
&
varnames
,
/* These are new */
&
filename
,
&
name
))
if
(
!
PyArg_ParseTuple
(
args
,
"iiiSO!O!O!SS"
,
&
argcount
,
&
nlocals
,
&
flags
,
/* These are new */
&
code
,
&
PyTuple_Type
,
&
consts
,
&
PyTuple_Type
,
&
names
,
&
PyTuple_Type
,
&
varnames
,
/* These are new */
&
filename
,
&
name
))
return
NULL
;
return
(
object
*
)
newcodeobject
(
argcount
,
nlocals
,
flags
,
code
,
consts
,
names
,
varnames
,
filename
,
name
);
return
(
PyObject
*
)
PyCode_New
(
argcount
,
nlocals
,
flags
,
code
,
consts
,
names
,
varnames
,
filename
,
name
);
}
static
char
new_module_doc
[]
=
"Create a module object from (NAME)."
;
static
o
bject
*
static
PyO
bject
*
new_module
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
char
*
name
;
if
(
!
newgetargs
(
args
,
"s"
,
&
name
))
if
(
!
PyArg_ParseTuple
(
args
,
"s"
,
&
name
))
return
NULL
;
return
newmoduleobject
(
name
);
return
PyModule_New
(
name
);
}
static
char
new_class_doc
[]
=
"Create a class object from (NAME, BASE_CLASSES, DICT)."
;
static
o
bject
*
static
PyO
bject
*
new_class
(
unused
,
args
)
o
bject
*
unused
;
o
bject
*
args
;
PyO
bject
*
unused
;
PyO
bject
*
args
;
{
o
bject
*
name
;
o
bject
*
classes
;
o
bject
*
dict
;
PyO
bject
*
name
;
PyO
bject
*
classes
;
PyO
bject
*
dict
;
if
(
!
newgetargs
(
args
,
"SO!O!"
,
&
name
,
&
Tuplet
ype
,
&
classes
,
&
Mappingt
ype
,
&
dict
))
if
(
!
PyArg_ParseTuple
(
args
,
"SO!O!"
,
&
name
,
&
PyTuple_T
ype
,
&
classes
,
&
PyDict_T
ype
,
&
dict
))
return
NULL
;
return
newclassobject
(
classes
,
dict
,
name
);
return
PyClass_New
(
classes
,
dict
,
name
);
}
static
struct
methodlist
new_methods
[]
=
{
static
PyMethodDef
new_methods
[]
=
{
{
"instance"
,
new_instance
,
1
,
new_instance_doc
},
{
"instancemethod"
,
new_instancemethod
,
1
,
new_im_doc
},
{
"function"
,
new_function
,
1
,
new_function_doc
},
...
...
@@ -197,6 +200,6 @@ You need to know a great deal about the interpreter to use this!";
void
initnew
()
{
initmodule4
(
"new"
,
new_methods
,
new_doc
,
(
o
bject
*
)
NULL
,
PYTHON_API_VERSION
);
Py_InitModule4
(
"new"
,
new_methods
,
new_doc
,
(
PyO
bject
*
)
NULL
,
PYTHON_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