<dd><emclass="refcount return_borrowed_ref">回傳值:借用參照。</em><p>These functions are similar to their <codeclass="docutils literal notranslate"><spanclass="pre">PyFunction_Get*</span></code> counterparts, but
do not do type checking. Passing anything other than an instance of
<aclass="reference internal" href="#c.PyFunction_Type" title="PyFunction_Type"><codeclass="xref c c-data docutils literal notranslate"><spanclass="pre">PyFunction_Type</span></code></a> is undefined behavior.</p>
<dd><p>Register <em>callback</em> as a function watcher for the current interpreter.
Return an ID which may be passed to <aclass="reference internal" href="#c.PyFunction_ClearWatcher" title="PyFunction_ClearWatcher"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyFunction_ClearWatcher()</span></code></a>.
In case of error (e.g. no more watcher IDs available),
return <codeclass="docutils literal notranslate"><spanclass="pre">-1</span></code> and set an exception.</p>
<dd><p>Clear watcher identified by <em>watcher_id</em> previously returned from
<aclass="reference internal" href="#c.PyFunction_AddWatcher" title="PyFunction_AddWatcher"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyFunction_AddWatcher()</span></code></a> for the current interpreter.
Return <codeclass="docutils literal notranslate"><spanclass="pre">0</span></code> on success, or <codeclass="docutils literal notranslate"><spanclass="pre">-1</span></code> and set an exception on error
(e.g. if the given <em>watcher_id</em> was never registered.)</p>
<dd><p>Apply the macro <em>V</em> to each suffix of <aclass="reference internal" href="#c.PyFunction_WatchEvent" title="PyFunction_WatchEvent"><codeclass="xref c c-type docutils literal notranslate"><spanclass="pre">PyFunction_WatchEvent</span></code></a>
constants.
Currently expands to <codeclass="docutils literal notranslate"><spanclass="pre">V(CREATE)</span><spanclass="pre">V(DESTROY)</span><spanclass="pre">V(MODIFY_CODE)</span>
<dd><p>Type of a function watcher callback function.</p>
<p>If <em>event</em> is <codeclass="docutils literal notranslate"><spanclass="pre">PyFunction_EVENT_CREATE</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">PyFunction_EVENT_DESTROY</span></code>
then <em>new_value</em> will be <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code>. Otherwise, <em>new_value</em> will hold a
<aclass="reference internal" href="../glossary.html#term-borrowed-reference"><spanclass="xref std std-term">borrowed reference</span></a> to the new value that is about to be stored in
<em>func</em> for the attribute that is being modified.</p>
<p>The callback may inspect but must not modify <em>func</em>; doing so could have
unpredictable effects, including infinite recursion.</p>
<p>If <em>event</em> is <codeclass="docutils literal notranslate"><spanclass="pre">PyFunction_EVENT_CREATE</span></code>, then the callback is invoked
after <em>func</em> has been fully initialized. Otherwise, the callback is invoked
before the modification to <em>func</em> takes place, so the prior state of <em>func</em>
can be inspected. The runtime is permitted to optimize away the creation of
function objects when possible. In such cases no event will be emitted.
Although this creates the possibility of an observable difference of
runtime behavior depending on optimization decisions, it does not change
the semantics of the Python code being executed.</p>
<p>If <em>event</em> is <codeclass="docutils literal notranslate"><spanclass="pre">PyFunction_EVENT_DESTROY</span></code>, taking a reference in the
callback to the about-to-be-destroyed function will resurrect it, preventing
it from being freed at this time. When the resurrected object is destroyed
later, any watcher callbacks active at that time will be called again.</p>
<p>If the callback sets an exception, it must return <codeclass="docutils literal notranslate"><spanclass="pre">-1</span></code>; this exception will
be printed as an unraisable exception using <aclass="reference internal" href="exceptions.html#c.PyErr_WriteUnraisable" title="PyErr_WriteUnraisable"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyErr_WriteUnraisable()</span></code></a>.
Otherwise it should return <codeclass="docutils literal notranslate"><spanclass="pre">0</span></code>.</p>
<p>There may already be a pending exception set on entry to the callback. In
this case, the callback should return <codeclass="docutils literal notranslate"><spanclass="pre">0</span></code> with the same exception still
set. This means the callback may not call any other API that can set an
exception unless it saves and clears the exception state first, and restores