<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="IS">Hi there.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">The discussion on <a href="http://bugs.python.org/issue20440">
http://bugs.python.org/issue20440</a> started me thinking that much of this<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">bikeshedding could be avoided if we weren‘t constrained to writing macros for all of this stuff.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">For example, a<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">Py_INLINE(PyObject *) Py_Incref(PyObject *obj)<br>
</span><span lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Py_INCREF(obj);<br>
return obj;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">could be used in a Py_Assign() function, if a new reference were wanted:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="IS">Py_INLINE(void) Py_Assign(PyObject ** target, PyObject *obj)<br>
</span><span lang="EN-US">{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> PyObject *tmp = *target;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> *target = tmp;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Py_DECREF(tmp);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">So that you could then safely write code like<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Py_Assign(&MyVar, Py_Incref(obj));<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This would also allow you to stop writing various super macros to try to cater to all possible permutations.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Now, Larry Hastings pointed out that we support C89 which doesn’t support Inlines. Rather than suggesting here that we update that compatibility requirement,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">how about adding a Py_INLINE() macro.? This would be like Py_LOCAL_INLINE() except that it would drop the “static” keyword, unless inline isn’t supported:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#if</span><span style="font-size:9.5pt;font-family:Consolas">
<span style="color:blue">defined</span>(<span style="color:#010001">_MSC_VER</span>)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#define</span><span style="font-size:9.5pt;font-family:Consolas">
<span style="color:#010001">Py_INLINE</span>(<span style="color:#010001">type</span>)
<span style="color:blue">__inline</span> <span style="color:#010001">type</span><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#elif</span><span style="font-size:9.5pt;font-family:Consolas">
<span style="color:blue">defined</span>(<span style="color:#010001">USE_INLINE</span>)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#define</span><span style="font-size:9.5pt;font-family:Consolas">
<span style="color:#010001">Py_INLINE</span>(<span style="color:#010001">type</span>)
<span style="color:blue">inline</span> <span style="color:#010001">type</span><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#else</span><span style="font-size:9.5pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#define</span><span style="font-size:9.5pt;font-family:Consolas">
<span style="color:#010001">Py_INLINE</span>(<span style="color:#010001">type</span>)
<span style="color:blue">static</span> <span style="color:#010001">type</span><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:blue">#endif<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The only question is with the last line. How many platforms actually _<i>do_not</i>_ have inlines? Would writing stuff like this be considered problematic for those platforms? Note, that I’m not suggesting replacing
macros all over the place, only for new code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Another question is: Is “static inline” in any practical way different from “inline”?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">It would be great to get rid of macros in code. It would be great for debugging too!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">K<o:p></o:p></span></p>
</div>
</body>
</html>