code.html 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
  6. <meta property="og:title" content="Code Objects" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/c-api/code.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Code objects are a low-level detail of the CPython implementation. Each one represents a chunk of executable code that hasn’t yet been bound into a function. Extra information: To support low-level..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Code objects are a low-level detail of the CPython implementation. Each one represents a chunk of executable code that hasn’t yet been bound into a function. Extra information: To support low-level..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>Code Objects &#8212; Python 3.12.0 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?digest=b37c26da2f7529d09fe70b41c4b2133fe4931a90" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css" />
  21. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  22. <script src="../_static/jquery.js"></script>
  23. <script src="../_static/underscore.js"></script>
  24. <script src="../_static/doctools.js"></script>
  25. <script src="../_static/sidebar.js"></script>
  26. <link rel="search" type="application/opensearchdescription+xml"
  27. title="Search within Python 3.12.0 documentation"
  28. href="../_static/opensearch.xml"/>
  29. <link rel="author" title="About these documents" href="../about.html" />
  30. <link rel="index" title="Index" href="../genindex.html" />
  31. <link rel="search" title="Search" href="../search.html" />
  32. <link rel="copyright" title="Copyright" href="../copyright.html" />
  33. <link rel="next" title="File Objects" href="file.html" />
  34. <link rel="prev" title="Cell Objects" href="cell.html" />
  35. <link rel="canonical" href="https://docs.python.org/3/c-api/code.html" />
  36. <style>
  37. @media only screen {
  38. table.full-width-table {
  39. width: 100%;
  40. }
  41. }
  42. </style>
  43. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  44. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  45. <script type="text/javascript" src="../_static/copybutton.js"></script>
  46. <script type="text/javascript" src="../_static/menu.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">Code Objects</a></li>
  86. <li><a class="reference internal" href="#extra-information">Extra information</a></li>
  87. </ul>
  88. </div>
  89. <div>
  90. <h4>Previous topic</h4>
  91. <p class="topless"><a href="cell.html"
  92. title="previous chapter">Cell Objects</a></p>
  93. </div>
  94. <div>
  95. <h4>Next topic</h4>
  96. <p class="topless"><a href="file.html"
  97. title="next chapter">File Objects</a></p>
  98. </div>
  99. <div role="note" aria-label="source link">
  100. <h3>This Page</h3>
  101. <ul class="this-page-menu">
  102. <li><a href="../bugs.html">Report a Bug</a></li>
  103. <li>
  104. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/code.rst"
  105. rel="nofollow">Show Source
  106. </a>
  107. </li>
  108. </ul>
  109. </div>
  110. </nav>
  111. </div>
  112. </div>
  113. <div class="related" role="navigation" aria-label="related navigation">
  114. <h3>Navigation</h3>
  115. <ul>
  116. <li class="right" style="margin-right: 10px">
  117. <a href="../genindex.html" title="General Index"
  118. accesskey="I">index</a></li>
  119. <li class="right" >
  120. <a href="../py-modindex.html" title="Python Module Index"
  121. >modules</a> |</li>
  122. <li class="right" >
  123. <a href="file.html" title="File Objects"
  124. accesskey="N">next</a> |</li>
  125. <li class="right" >
  126. <a href="cell.html" title="Cell Objects"
  127. accesskey="P">previous</a> |</li>
  128. <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  129. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  130. <li class="switchers">
  131. <div class="language_switcher_placeholder"></div>
  132. <div class="version_switcher_placeholder"></div>
  133. </li>
  134. <li>
  135. </li>
  136. <li id="cpython-language-and-version">
  137. <a href="../index.html">3.12.0 Documentation</a> &#187;
  138. </li>
  139. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  140. <li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &#187;</li>
  141. <li class="nav-item nav-item-this"><a href="">Code Objects</a></li>
  142. <li class="right">
  143. <div class="inline-search" role="search">
  144. <form class="inline-search" action="../search.html" method="get">
  145. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  146. <input type="submit" value="Go" />
  147. </form>
  148. </div>
  149. |
  150. </li>
  151. <li class="right">
  152. <label class="theme-selector-label">
  153. Theme
  154. <select class="theme-selector" oninput="activateTheme(this.value)">
  155. <option value="auto" selected>Auto</option>
  156. <option value="light">Light</option>
  157. <option value="dark">Dark</option>
  158. </select>
  159. </label> |</li>
  160. </ul>
  161. </div>
  162. <div class="document">
  163. <div class="documentwrapper">
  164. <div class="bodywrapper">
  165. <div class="body" role="main">
  166. <section id="code-objects">
  167. <span id="codeobjects"></span><span id="index-0"></span><h1>Code Objects<a class="headerlink" href="#code-objects" title="Permalink to this headline">¶</a></h1>
  168. <p>Code objects are a low-level detail of the CPython implementation.
  169. Each one represents a chunk of executable code that hasn’t yet been
  170. bound into a function.</p>
  171. <dl class="c type">
  172. <dt class="sig sig-object c" id="c.PyCodeObject">
  173. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCodeObject</span></span></span><a class="headerlink" href="#c.PyCodeObject" title="Permalink to this definition">¶</a><br /></dt>
  174. <dd><p>The C structure of the objects used to describe code objects. The
  175. fields of this type are subject to change at any time.</p>
  176. </dd></dl>
  177. <dl class="c var">
  178. <dt class="sig sig-object c" id="c.PyCode_Type">
  179. <a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><span class="n"><span class="pre">PyTypeObject</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_Type</span></span></span><a class="headerlink" href="#c.PyCode_Type" title="Permalink to this definition">¶</a><br /></dt>
  180. <dd><p>This is an instance of <a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTypeObject</span></code></a> representing the Python
  181. <a class="reference internal" href="../library/code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-class docutils literal notranslate"><span class="pre">code</span></code></a> type.</p>
  182. </dd></dl>
  183. <dl class="c function">
  184. <dt class="sig sig-object c" id="c.PyCode_Check">
  185. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_Check</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_Check" title="Permalink to this definition">¶</a><br /></dt>
  186. <dd><p>Return true if <em>co</em> is a <a class="reference internal" href="../library/code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-class docutils literal notranslate"><span class="pre">code</span></code></a> object. This function always succeeds.</p>
  187. </dd></dl>
  188. <dl class="c function">
  189. <dt class="sig sig-object c" id="c.PyCode_GetNumFree">
  190. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_GetNumFree</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_GetNumFree" title="Permalink to this definition">¶</a><br /></dt>
  191. <dd><p>Return the number of free variables in <em>co</em>.</p>
  192. </dd></dl>
  193. <dl class="c function">
  194. <dt class="sig sig-object c" id="c.PyUnstable_Code_New">
  195. <a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Code_New</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argcount</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">kwonlyargcount</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nlocals</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">stacksize</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">code</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">consts</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">names</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">varnames</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">freevars</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">cellvars</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">qualname</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">firstlineno</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">linetable</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exceptiontable</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Code_New" title="Permalink to this definition">¶</a><br /></dt>
  196. <dd><div class="unstable-c-api warning admonition">
  197. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  198. <p>Return a new code object. If you need a dummy code object to create a frame,
  199. use <a class="reference internal" href="#c.PyCode_NewEmpty" title="PyCode_NewEmpty"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_NewEmpty()</span></code></a> instead.</p>
  200. <p>Since the definition of the bytecode changes often, calling
  201. <a class="reference internal" href="#c.PyUnstable_Code_New" title="PyUnstable_Code_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Code_New()</span></code></a> directly can bind you to a precise Python version.</p>
  202. <p>The many arguments of this function are inter-dependent in complex
  203. ways, meaning that subtle changes to values are likely to result in incorrect
  204. execution or VM crashes. Use this function only with extreme care.</p>
  205. <div class="versionchanged">
  206. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added <code class="docutils literal notranslate"><span class="pre">qualname</span></code> and <code class="docutils literal notranslate"><span class="pre">exceptiontable</span></code> parameters.</p>
  207. </div>
  208. <div class="versionchanged" id="index-1">
  209. <p><span class="versionmodified changed">Changed in version 3.12: </span>Renamed from <code class="docutils literal notranslate"><span class="pre">PyCode_New</span></code> as part of <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable C API</span></a>.
  210. The old name is deprecated, but will remain available until the
  211. signature changes again.</p>
  212. </div>
  213. </dd></dl>
  214. <dl class="c function">
  215. <dt class="sig sig-object c" id="c.PyUnstable_Code_NewWithPosOnlyArgs">
  216. <a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Code_NewWithPosOnlyArgs</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argcount</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">posonlyargcount</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">kwonlyargcount</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">nlocals</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">stacksize</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">flags</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">code</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">consts</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">names</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">varnames</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">freevars</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">cellvars</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">qualname</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">firstlineno</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">linetable</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exceptiontable</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Code_NewWithPosOnlyArgs" title="Permalink to this definition">¶</a><br /></dt>
  217. <dd><div class="unstable-c-api warning admonition">
  218. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  219. <p>Similar to <a class="reference internal" href="#c.PyUnstable_Code_New" title="PyUnstable_Code_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Code_New()</span></code></a>, but with an extra “posonlyargcount” for positional-only arguments.
  220. The same caveats that apply to <code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_New</span></code> also apply to this function.</p>
  221. <div class="versionadded" id="index-2">
  222. <p><span class="versionmodified added">New in version 3.8: </span>as <code class="docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs</span></code></p>
  223. </div>
  224. <div class="versionchanged">
  225. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added <code class="docutils literal notranslate"><span class="pre">qualname</span></code> and <code class="docutils literal notranslate"><span class="pre">exceptiontable</span></code> parameters.</p>
  226. </div>
  227. <div class="versionchanged">
  228. <p><span class="versionmodified changed">Changed in version 3.12: </span>Renamed to <code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_NewWithPosOnlyArgs</span></code>.
  229. The old name is deprecated, but will remain available until the
  230. signature changes again.</p>
  231. </div>
  232. </dd></dl>
  233. <dl class="c function">
  234. <dt class="sig sig-object c" id="c.PyCode_NewEmpty">
  235. <a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_NewEmpty</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">funcname</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">firstlineno</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_NewEmpty" title="Permalink to this definition">¶</a><br /></dt>
  236. <dd><em class="refcount">Return value: New reference.</em><p>Return a new empty code object with the specified filename,
  237. function name, and first line number. The resulting code
  238. object will raise an <code class="docutils literal notranslate"><span class="pre">Exception</span></code> if executed.</p>
  239. </dd></dl>
  240. <dl class="c function">
  241. <dt class="sig sig-object c" id="c.PyCode_Addr2Line">
  242. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_Addr2Line</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">byte_offset</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_Addr2Line" title="Permalink to this definition">¶</a><br /></dt>
  243. <dd><p>Return the line number of the instruction that occurs on or before <code class="docutils literal notranslate"><span class="pre">byte_offset</span></code> and ends after it.
  244. If you just need the line number of a frame, use <a class="reference internal" href="frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a> instead.</p>
  245. <p>For efficiently iterating over the line numbers in a code object, use <a class="reference external" href="https://peps.python.org/pep-0626/#out-of-process-debuggers-and-profilers">the API described in PEP 626</a>.</p>
  246. </dd></dl>
  247. <dl class="c function">
  248. <dt class="sig sig-object c" id="c.PyCode_Addr2Location">
  249. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_Addr2Location</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">byte_offset</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start_line</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start_column</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">end_line</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">end_column</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_Addr2Location" title="Permalink to this definition">¶</a><br /></dt>
  250. <dd><p>Sets the passed <code class="docutils literal notranslate"><span class="pre">int</span></code> pointers to the source code line and column numbers
  251. for the instruction at <code class="docutils literal notranslate"><span class="pre">byte_offset</span></code>. Sets the value to <code class="docutils literal notranslate"><span class="pre">0</span></code> when
  252. information is not available for any particular element.</p>
  253. <p>Returns <code class="docutils literal notranslate"><span class="pre">1</span></code> if the function succeeds and 0 otherwise.</p>
  254. <div class="versionadded">
  255. <p><span class="versionmodified added">New in version 3.11.</span></p>
  256. </div>
  257. </dd></dl>
  258. <dl class="c function">
  259. <dt class="sig sig-object c" id="c.PyCode_GetCode">
  260. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_GetCode</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_GetCode" title="Permalink to this definition">¶</a><br /></dt>
  261. <dd><p>Equivalent to the Python code <code class="docutils literal notranslate"><span class="pre">getattr(co,</span> <span class="pre">'co_code')</span></code>.
  262. Returns a strong reference to a <a class="reference internal" href="bytes.html#c.PyBytesObject" title="PyBytesObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyBytesObject</span></code></a> representing the
  263. bytecode in a code object. On error, <code class="docutils literal notranslate"><span class="pre">NULL</span></code> is returned and an exception
  264. is raised.</p>
  265. <p>This <code class="docutils literal notranslate"><span class="pre">PyBytesObject</span></code> may be created on-demand by the interpreter and does
  266. not necessarily represent the bytecode actually executed by CPython. The
  267. primary use case for this function is debuggers and profilers.</p>
  268. <div class="versionadded">
  269. <p><span class="versionmodified added">New in version 3.11.</span></p>
  270. </div>
  271. </dd></dl>
  272. <dl class="c function">
  273. <dt class="sig sig-object c" id="c.PyCode_GetVarnames">
  274. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_GetVarnames</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_GetVarnames" title="Permalink to this definition">¶</a><br /></dt>
  275. <dd><p>Equivalent to the Python code <code class="docutils literal notranslate"><span class="pre">getattr(co,</span> <span class="pre">'co_varnames')</span></code>.
  276. Returns a new reference to a <a class="reference internal" href="tuple.html#c.PyTupleObject" title="PyTupleObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTupleObject</span></code></a> containing the names of
  277. the local variables. On error, <code class="docutils literal notranslate"><span class="pre">NULL</span></code> is returned and an exception
  278. is raised.</p>
  279. <div class="versionadded">
  280. <p><span class="versionmodified added">New in version 3.11.</span></p>
  281. </div>
  282. </dd></dl>
  283. <dl class="c function">
  284. <dt class="sig sig-object c" id="c.PyCode_GetCellvars">
  285. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_GetCellvars</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_GetCellvars" title="Permalink to this definition">¶</a><br /></dt>
  286. <dd><p>Equivalent to the Python code <code class="docutils literal notranslate"><span class="pre">getattr(co,</span> <span class="pre">'co_cellvars')</span></code>.
  287. Returns a new reference to a <a class="reference internal" href="tuple.html#c.PyTupleObject" title="PyTupleObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTupleObject</span></code></a> containing the names of
  288. the local variables that are referenced by nested functions. On error, <code class="docutils literal notranslate"><span class="pre">NULL</span></code>
  289. is returned and an exception is raised.</p>
  290. <div class="versionadded">
  291. <p><span class="versionmodified added">New in version 3.11.</span></p>
  292. </div>
  293. </dd></dl>
  294. <dl class="c function">
  295. <dt class="sig sig-object c" id="c.PyCode_GetFreevars">
  296. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_GetFreevars</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_GetFreevars" title="Permalink to this definition">¶</a><br /></dt>
  297. <dd><p>Equivalent to the Python code <code class="docutils literal notranslate"><span class="pre">getattr(co,</span> <span class="pre">'co_freevars')</span></code>.
  298. Returns a new reference to a <a class="reference internal" href="tuple.html#c.PyTupleObject" title="PyTupleObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTupleObject</span></code></a> containing the names of
  299. the free variables. On error, <code class="docutils literal notranslate"><span class="pre">NULL</span></code> is returned and an exception is raised.</p>
  300. <div class="versionadded">
  301. <p><span class="versionmodified added">New in version 3.11.</span></p>
  302. </div>
  303. </dd></dl>
  304. <dl class="c function">
  305. <dt class="sig sig-object c" id="c.PyCode_AddWatcher">
  306. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_AddWatcher</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyCode_WatchCallback" title="PyCode_WatchCallback"><span class="n"><span class="pre">PyCode_WatchCallback</span></span></a><span class="w"> </span><span class="n"><span class="pre">callback</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_AddWatcher" title="Permalink to this definition">¶</a><br /></dt>
  307. <dd><p>Register <em>callback</em> as a code object watcher for the current interpreter.
  308. Return an ID which may be passed to <a class="reference internal" href="#c.PyCode_ClearWatcher" title="PyCode_ClearWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_ClearWatcher()</span></code></a>.
  309. In case of error (e.g. no more watcher IDs available),
  310. return <code class="docutils literal notranslate"><span class="pre">-1</span></code> and set an exception.</p>
  311. <div class="versionadded">
  312. <p><span class="versionmodified added">New in version 3.12.</span></p>
  313. </div>
  314. </dd></dl>
  315. <dl class="c function">
  316. <dt class="sig sig-object c" id="c.PyCode_ClearWatcher">
  317. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_ClearWatcher</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">watcher_id</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyCode_ClearWatcher" title="Permalink to this definition">¶</a><br /></dt>
  318. <dd><p>Clear watcher identified by <em>watcher_id</em> previously returned from
  319. <a class="reference internal" href="#c.PyCode_AddWatcher" title="PyCode_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_AddWatcher()</span></code></a> for the current interpreter.
  320. Return <code class="docutils literal notranslate"><span class="pre">0</span></code> on success, or <code class="docutils literal notranslate"><span class="pre">-1</span></code> and set an exception on error
  321. (e.g. if the given <em>watcher_id</em> was never registered.)</p>
  322. <div class="versionadded">
  323. <p><span class="versionmodified added">New in version 3.12.</span></p>
  324. </div>
  325. </dd></dl>
  326. <dl class="c type">
  327. <dt class="sig sig-object c" id="c.PyCodeEvent">
  328. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyCodeEvent</span></span></span><a class="headerlink" href="#c.PyCodeEvent" title="Permalink to this definition">¶</a><br /></dt>
  329. <dd><p>Enumeration of possible code object watcher events:
  330. - <code class="docutils literal notranslate"><span class="pre">PY_CODE_EVENT_CREATE</span></code>
  331. - <code class="docutils literal notranslate"><span class="pre">PY_CODE_EVENT_DESTROY</span></code></p>
  332. <div class="versionadded">
  333. <p><span class="versionmodified added">New in version 3.12.</span></p>
  334. </div>
  335. </dd></dl>
  336. <dl class="c type">
  337. <dt class="sig sig-object c" id="c.PyCode_WatchCallback">
  338. <span class="k"><span class="pre">typedef</span></span><span class="w"> </span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">(</span></span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyCode_WatchCallback</span></span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">(</span></span><a class="reference internal" href="#c.PyCodeEvent" title="PyCodeEvent"><span class="n"><span class="pre">PyCodeEvent</span></span></a><span class="w"> </span><span class="n"><span class="pre">event</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference internal" href="#c.PyCodeObject" title="PyCodeObject"><span class="n"><span class="pre">PyCodeObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="p"><span class="pre">)</span></span><a class="headerlink" href="#c.PyCode_WatchCallback" title="Permalink to this definition">¶</a><br /></dt>
  339. <dd><p>Type of a code object watcher callback function.</p>
  340. <p>If <em>event</em> is <code class="docutils literal notranslate"><span class="pre">PY_CODE_EVENT_CREATE</span></code>, then the callback is invoked
  341. after <cite>co</cite> has been fully initialized. Otherwise, the callback is invoked
  342. before the destruction of <em>co</em> takes place, so the prior state of <em>co</em>
  343. can be inspected.</p>
  344. <p>If <em>event</em> is <code class="docutils literal notranslate"><span class="pre">PY_CODE_EVENT_DESTROY</span></code>, taking a reference in the callback
  345. to the about-to-be-destroyed code object will resurrect it and prevent it
  346. from being freed at this time. When the resurrected object is destroyed
  347. later, any watcher callbacks active at that time will be called again.</p>
  348. <p>Users of this API should not rely on internal runtime implementation
  349. details. Such details may include, but are not limited to, the exact
  350. order and timing of creation and destruction of code objects. While
  351. changes in these details may result in differences observable by watchers
  352. (including whether a callback is invoked or not), it does not change
  353. the semantics of the Python code being executed.</p>
  354. <p>If the callback sets an exception, it must return <code class="docutils literal notranslate"><span class="pre">-1</span></code>; this exception will
  355. be printed as an unraisable exception using <a class="reference internal" href="exceptions.html#c.PyErr_WriteUnraisable" title="PyErr_WriteUnraisable"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WriteUnraisable()</span></code></a>.
  356. Otherwise it should return <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  357. <p>There may already be a pending exception set on entry to the callback. In
  358. this case, the callback should return <code class="docutils literal notranslate"><span class="pre">0</span></code> with the same exception still
  359. set. This means the callback may not call any other API that can set an
  360. exception unless it saves and clears the exception state first, and restores
  361. it before returning.</p>
  362. <div class="versionadded">
  363. <p><span class="versionmodified added">New in version 3.12.</span></p>
  364. </div>
  365. </dd></dl>
  366. </section>
  367. <section id="extra-information">
  368. <h1>Extra information<a class="headerlink" href="#extra-information" title="Permalink to this headline">¶</a></h1>
  369. <p>To support low-level extensions to frame evaluation, such as external
  370. just-in-time compilers, it is possible to attach arbitrary extra data to
  371. code objects.</p>
  372. <p>These functions are part of the unstable C API tier:
  373. this functionality is a CPython implementation detail, and the API
  374. may change without deprecation warnings.</p>
  375. <dl class="c function">
  376. <dt class="sig sig-object c" id="c.PyUnstable_Eval_RequestCodeExtraIndex">
  377. <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Eval_RequestCodeExtraIndex</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="typeobj.html#c.freefunc" title="freefunc"><span class="n"><span class="pre">freefunc</span></span></a><span class="w"> </span><span class="n"><span class="pre">free</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Eval_RequestCodeExtraIndex" title="Permalink to this definition">¶</a><br /></dt>
  378. <dd><div class="unstable-c-api warning admonition">
  379. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  380. <p>Return a new an opaque index value used to adding data to code objects.</p>
  381. <p>You generally call this function once (per interpreter) and use the result
  382. with <code class="docutils literal notranslate"><span class="pre">PyCode_GetExtra</span></code> and <code class="docutils literal notranslate"><span class="pre">PyCode_SetExtra</span></code> to manipulate
  383. data on individual code objects.</p>
  384. <p>If <em>free</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>: when a code object is deallocated,
  385. <em>free</em> will be called on non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code> data stored under the new index.
  386. Use <a class="reference internal" href="refcounting.html#c.Py_DecRef" title="Py_DecRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecRef()</span></code></a> when storing <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span></code></a>.</p>
  387. <div class="versionadded" id="index-3">
  388. <p><span class="versionmodified added">New in version 3.6: </span>as <code class="docutils literal notranslate"><span class="pre">_PyEval_RequestCodeExtraIndex</span></code></p>
  389. </div>
  390. <div class="versionchanged">
  391. <p><span class="versionmodified changed">Changed in version 3.12: </span>Renamed to <code class="docutils literal notranslate"><span class="pre">PyUnstable_Eval_RequestCodeExtraIndex</span></code>.
  392. The old private name is deprecated, but will be available until the API
  393. changes.</p>
  394. </div>
  395. </dd></dl>
  396. <dl class="c function">
  397. <dt class="sig sig-object c" id="c.PyUnstable_Code_GetExtra">
  398. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Code_GetExtra</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">code</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">index</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">extra</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Code_GetExtra" title="Permalink to this definition">¶</a><br /></dt>
  399. <dd><div class="unstable-c-api warning admonition">
  400. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  401. <p>Set <em>extra</em> to the extra data stored under the given index.
  402. Return 0 on success. Set an exception and return -1 on failure.</p>
  403. <p>If no data was set under the index, set <em>extra</em> to <code class="docutils literal notranslate"><span class="pre">NULL</span></code> and return
  404. 0 without setting an exception.</p>
  405. <div class="versionadded" id="index-4">
  406. <p><span class="versionmodified added">New in version 3.6: </span>as <code class="docutils literal notranslate"><span class="pre">_PyCode_GetExtra</span></code></p>
  407. </div>
  408. <div class="versionchanged">
  409. <p><span class="versionmodified changed">Changed in version 3.12: </span>Renamed to <code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_GetExtra</span></code>.
  410. The old private name is deprecated, but will be available until the API
  411. changes.</p>
  412. </div>
  413. </dd></dl>
  414. <dl class="c function">
  415. <dt class="sig sig-object c" id="c.PyUnstable_Code_SetExtra">
  416. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Code_SetExtra</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">code</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">index</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">extra</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Code_SetExtra" title="Permalink to this definition">¶</a><br /></dt>
  417. <dd><div class="unstable-c-api warning admonition">
  418. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  419. <p>Set the extra data stored under the given index to <em>extra</em>.
  420. Return 0 on success. Set an exception and return -1 on failure.</p>
  421. <div class="versionadded" id="index-5">
  422. <p><span class="versionmodified added">New in version 3.6: </span>as <code class="docutils literal notranslate"><span class="pre">_PyCode_SetExtra</span></code></p>
  423. </div>
  424. <div class="versionchanged">
  425. <p><span class="versionmodified changed">Changed in version 3.12: </span>Renamed to <code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_SetExtra</span></code>.
  426. The old private name is deprecated, but will be available until the API
  427. changes.</p>
  428. </div>
  429. </dd></dl>
  430. </section>
  431. <div class="clearer"></div>
  432. </div>
  433. </div>
  434. </div>
  435. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  436. <div class="sphinxsidebarwrapper">
  437. <div>
  438. <h3><a href="../contents.html">Table of Contents</a></h3>
  439. <ul>
  440. <li><a class="reference internal" href="#">Code Objects</a></li>
  441. <li><a class="reference internal" href="#extra-information">Extra information</a></li>
  442. </ul>
  443. </div>
  444. <div>
  445. <h4>Previous topic</h4>
  446. <p class="topless"><a href="cell.html"
  447. title="previous chapter">Cell Objects</a></p>
  448. </div>
  449. <div>
  450. <h4>Next topic</h4>
  451. <p class="topless"><a href="file.html"
  452. title="next chapter">File Objects</a></p>
  453. </div>
  454. <div role="note" aria-label="source link">
  455. <h3>This Page</h3>
  456. <ul class="this-page-menu">
  457. <li><a href="../bugs.html">Report a Bug</a></li>
  458. <li>
  459. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/code.rst"
  460. rel="nofollow">Show Source
  461. </a>
  462. </li>
  463. </ul>
  464. </div>
  465. </div>
  466. </div>
  467. <div class="clearer"></div>
  468. </div>
  469. <div class="related" role="navigation" aria-label="related navigation">
  470. <h3>Navigation</h3>
  471. <ul>
  472. <li class="right" style="margin-right: 10px">
  473. <a href="../genindex.html" title="General Index"
  474. >index</a></li>
  475. <li class="right" >
  476. <a href="../py-modindex.html" title="Python Module Index"
  477. >modules</a> |</li>
  478. <li class="right" >
  479. <a href="file.html" title="File Objects"
  480. >next</a> |</li>
  481. <li class="right" >
  482. <a href="cell.html" title="Cell Objects"
  483. >previous</a> |</li>
  484. <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  485. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  486. <li class="switchers">
  487. <div class="language_switcher_placeholder"></div>
  488. <div class="version_switcher_placeholder"></div>
  489. </li>
  490. <li>
  491. </li>
  492. <li id="cpython-language-and-version">
  493. <a href="../index.html">3.12.0 Documentation</a> &#187;
  494. </li>
  495. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  496. <li class="nav-item nav-item-2"><a href="concrete.html" >Concrete Objects Layer</a> &#187;</li>
  497. <li class="nav-item nav-item-this"><a href="">Code Objects</a></li>
  498. <li class="right">
  499. <div class="inline-search" role="search">
  500. <form class="inline-search" action="../search.html" method="get">
  501. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  502. <input type="submit" value="Go" />
  503. </form>
  504. </div>
  505. |
  506. </li>
  507. <li class="right">
  508. <label class="theme-selector-label">
  509. Theme
  510. <select class="theme-selector" oninput="activateTheme(this.value)">
  511. <option value="auto" selected>Auto</option>
  512. <option value="light">Light</option>
  513. <option value="dark">Dark</option>
  514. </select>
  515. </label> |</li>
  516. </ul>
  517. </div>
  518. <div class="footer">
  519. &copy; <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation.
  520. <br />
  521. This page is licensed under the Python Software Foundation License Version 2.
  522. <br />
  523. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  524. <br />
  525. See <a href="/license.html">History and License</a> for more information.<br />
  526. <br />
  527. The Python Software Foundation is a non-profit corporation.
  528. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  529. <br />
  530. <br />
  531. Last updated on Oct 02, 2023.
  532. <a href="/bugs.html">Found a bug</a>?
  533. <br />
  534. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0.
  535. </div>
  536. </body>
  537. </html>