Alocar objetos na pilha¶
-
PyObject*
_PyObject_New
(PyTypeObject *type)¶ - Return value: New reference.
-
PyVarObject*
_PyObject_NewVar
(PyTypeObject *type, Py_ssize_t size)¶ - Return value: New reference.
Alterado na versão 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
PyObject*
PyObject_Init
(PyObject *op, PyTypeObject *type)¶ - Return value: Borrowed reference.
Inicializa um objeto op recém-alocado com seu tipo e sua referência inicial. Retorna o objeto inicializado. Se type indicar no detector de lixo cíclico que o objeto participa, ele é adicionado ao grupo do detector de objetos observados. Outros campos do objeto não são afetados.
-
PyVarObject*
PyObject_InitVar
(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)¶ - Return value: Borrowed reference.
Isso faz tudo que
PyObject_Init()
faz, e também inicializa a informação de comprimento para um objeto tamanho de variável.Alterado na versão 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
TYPE*
PyObject_New
(TYPE, PyTypeObject *type)¶ - Return value: New reference.
Aloca um novo objeto Python usando o tipo de estrutura C TYPE e o tipo de objeto Python type. Campos não definidos no cabeçalho do objeto Python não são inicializados; a contagem de referências do objeto será um deles. O tamanho da alocação de memória é determinado do campo
tp_basicsize
do objeto tipo.
-
TYPE*
PyObject_NewVar
(TYPE, PyTypeObject *type, Py_ssize_t size)¶ - Return value: New reference.
Aloca um novo objeto Python usando o tipo de estrutura C TYPE e o tipo de objeto Python type. Campos não definidos pelo cabeçalho do objeto Python não são inicializados. A memória alocada permite a estrutura TYPE e os campos size do tamanho dado pelo campo
tp_itemsize
do tipo type. Isto é útil para implementar objetos como tuplas, que são capazes de determinar seu tamanho em tempo de construção. Incorporando o vetor de campos dentro da mesma alocação diminuindo o numero de alocações, melhorando a eficiência de gerenciamento de memória.Alterado na versão 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
void
PyObject_Del
(PyObject *op)¶ Libera memória alocada a um objeto usando
PyObject_New()
ouPyObject_NewVar()
. Isso é normalmente chamado portp_dealloc
manipulador especificado no tipo do objeto. Os campos do objeto não devem ser acessados após esta chamada, já que a memória não é mais um objeto Python válido.
-
PyObject*
Py_InitModule
(char *name, PyMethodDef *methods)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object.
Alterado na versão 2.3: Older versions of Python did not support NULL as the value for the methods argument.
-
PyObject*
Py_InitModule3
(char *name, PyMethodDef *methods, char *doc)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object. If doc is non-NULL, it will be used to define the docstring for the module.
Alterado na versão 2.3: Older versions of Python did not support NULL as the value for the methods argument.
-
PyObject*
Py_InitModule4
(char *name, PyMethodDef *methods, char *doc, PyObject *self, int apiver)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object. If doc is non-NULL, it will be used to define the docstring for the module. If self is non-NULL, it will be passed to the functions of the module as their (otherwise NULL) first parameter. (This was added as an experimental feature, and there are no known uses in the current version of Python.) For apiver, the only value which should be passed is defined by the constant
PYTHON_API_VERSION
.Nota
Most uses of this function should probably be using the
Py_InitModule3()
instead; only use this if you are sure you need it.Alterado na versão 2.3: Older versions of Python did not support NULL as the value for the methods argument.