Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c2784229
Kaydet (Commit)
c2784229
authored
Mar 31, 2009
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#5417: replace references to undocumented functions by ones to documented functions.
üst
b945bbf3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
extending.rst
Doc/extending/extending.rst
+13
-12
No files found.
Doc/extending/extending.rst
Dosyayı görüntüle @
c2784229
...
...
@@ -465,10 +465,10 @@ reference count of an object and are safe in the presence of *NULL* pointers
(but note that *temp* will not be *NULL* in this context). More info on them
in section :ref:`refcounts`.
.. index:: single: Py
Eval
_CallObject()
.. index:: single: Py
Object
_CallObject()
Later, when it is time to call the function, you call the C function
:cfunc:`Py
Eval
_CallObject`. This function has two arguments, both pointers to
:cfunc:`Py
Object
_CallObject`. This function has two arguments, both pointers to
arbitrary Python objects: the Python function, and the argument list. The
argument list must always be a tuple object, whose length is the number of
arguments. To call the Python function with no arguments, pass in NULL, or
...
...
@@ -484,16 +484,16 @@ or more format codes between parentheses. For example::
...
/* Time to call the callback */
arglist = Py_BuildValue("(i)", arg);
result = Py
Eval
_CallObject(my_callback, arglist);
result = Py
Object
_CallObject(my_callback, arglist);
Py_DECREF(arglist);
:cfunc:`Py
Eval
_CallObject` returns a Python object pointer: this is the return
value of the Python function. :cfunc:`Py
Eval
_CallObject` is
:cfunc:`Py
Object
_CallObject` returns a Python object pointer: this is the return
value of the Python function. :cfunc:`Py
Object
_CallObject` is
"reference-count-neutral" with respect to its arguments. In the example a new
tuple was created to serve as the argument list, which is :cfunc:`Py_DECREF`\
-ed immediately after the call.
The return value of :cfunc:`Py
Eval
_CallObject` is "new": either it is a brand
The return value of :cfunc:`Py
Object
_CallObject` is "new": either it is a brand
new object, or it is an existing object whose reference count has been
incremented. So, unless you want to save it in a global variable, you should
somehow :cfunc:`Py_DECREF` the result, even (especially!) if you are not
...
...
@@ -501,7 +501,7 @@ interested in its value.
Before you do this, however, it is important to check that the return value
isn't *NULL*. If it is, the Python function terminated by raising an exception.
If the C code that called :cfunc:`Py
Eval
_CallObject` is called from Python, it
If the C code that called :cfunc:`Py
Object
_CallObject` is called from Python, it
should now return an error indication to its Python caller, so the interpreter
can print a stack trace, or the calling Python code can handle the exception.
If this is not possible or desirable, the exception should be cleared by calling
...
...
@@ -513,7 +513,7 @@ If this is not possible or desirable, the exception should be cleared by calling
Py_DECREF(result);
Depending on the desired interface to the Python callback function, you may also
have to provide an argument list to :cfunc:`Py
Eval
_CallObject`. In some cases
have to provide an argument list to :cfunc:`Py
Object
_CallObject`. In some cases
the argument list is also provided by the Python program, through the same
interface that specified the callback function. It can then be saved and used
in the same manner as the function object. In other cases, you may have to
...
...
@@ -524,7 +524,7 @@ event code, you might use the following code::
PyObject *arglist;
...
arglist = Py_BuildValue("(l)", eventcode);
result = Py
Eval
_CallObject(my_callback, arglist);
result = Py
Object
_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
return NULL; /* Pass error back */
...
...
@@ -536,19 +536,20 @@ the error check! Also note that strictly speaking this code is not complete:
:cfunc:`Py_BuildValue` may run out of memory, and this should be checked.
You may also call a function with keyword arguments by using
:cfunc:`Py
Eval_CallObjectWithKeywords`. As in the above example, we use
:cfunc:`Py_BuildValue` to construct the dictionary. ::
:cfunc:`Py
Object_Call`, which supports arguments and keyword arguments. As in
the above example, we use
:cfunc:`Py_BuildValue` to construct the dictionary. ::
PyObject *dict;
...
dict = Py_BuildValue("{s:i}", "name", val);
result = Py
Eval_CallObjectWithKeywords
(my_callback, NULL, dict);
result = Py
Object_Call
(my_callback, NULL, dict);
Py_DECREF(dict);
if (result == NULL)
return NULL; /* Pass error back */
/* Here maybe use the result */
Py_DECREF(result);
.. _parsetuple:
Extracting Parameters in Extension Functions
...
...
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