Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / ext / nullPointers.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="ext.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="ext.html" title='Extending and Embedding the Python Interpreter' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='last' href='about.html' title='About this document...' />
10<link rel='help' href='about.html' title='About this document...' />
11<link rel="prev" href="thinIce.html" />
12<link rel="parent" href="refcounts.html" />
13<link rel="next" href="cplusplus.html" />
14<meta name='aesop' content='information' />
15<title>1.10.4 NULL Pointers
16</title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="1.10.3 Thin Ice"
24 href="thinIce.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="1.10 Reference Counts"
27 href="refcounts.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="1.11 Writing Extensions in"
30 href="cplusplus.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><img src='../icons/blank.png'
37 border='0' height='32' alt='' width='32' /></td>
38<td class='online-navigation'><img src='../icons/blank.png'
39 border='0' height='32' alt='' width='32' /></td>
40</tr></table>
41<div class='online-navigation'>
42<b class="navlabel">Previous:</b>
43<a class="sectref" rel="prev" href="thinIce.html">1.10.3 Thin Ice</A>
44<b class="navlabel">Up:</b>
45<a class="sectref" rel="parent" href="refcounts.html">1.10 Reference Counts</A>
46<b class="navlabel">Next:</b>
47<a class="sectref" rel="next" href="cplusplus.html">1.11 Writing Extensions in</A>
48</div>
49<hr /></div>
50</DIV>
51<!--End of Navigation Panel-->
52
53<H2><A NAME="SECTION0031040000000000000000"></A><A NAME="nullPointers"></A>
54<BR>
551.10.4 NULL Pointers
56
57</H2>
58
59<P>
60In general, functions that take object references as arguments do not
61expect you to pass them <tt class="constant">NULL</tt> pointers, and will dump core (or
62cause later core dumps) if you do so. Functions that return object
63references generally return <tt class="constant">NULL</tt> only to indicate that an
64exception occurred. The reason for not testing for <tt class="constant">NULL</tt>
65arguments is that functions often pass the objects they receive on to
66other function -- if each function were to test for <tt class="constant">NULL</tt>,
67there would be a lot of redundant tests and the code would run more
68slowly.
69
70<P>
71It is better to test for <tt class="constant">NULL</tt> only at the ``source:'' when a
72pointer that may be <tt class="constant">NULL</tt> is received, for example, from
73<tt class="cfunction">malloc()</tt> or from a function that may raise an exception.
74
75<P>
76The macros <tt class="cfunction">Py_INCREF()</tt> and <tt class="cfunction">Py_DECREF()</tt>
77do not check for <tt class="constant">NULL</tt> pointers -- however, their variants
78<tt class="cfunction">Py_XINCREF()</tt> and <tt class="cfunction">Py_XDECREF()</tt> do.
79
80<P>
81The macros for checking for a particular object type
82(<code>Py<var>type</var>_Check()</code>) don't check for <tt class="constant">NULL</tt> pointers --
83again, there is much code that calls several of these in a row to test
84an object against various different expected types, and this would
85generate redundant tests. There are no variants with <tt class="constant">NULL</tt>
86checking.
87
88<P>
89The C function calling mechanism guarantees that the argument list
90passed to C functions (<code>args</code> in the examples) is never
91<tt class="constant">NULL</tt> -- in fact it guarantees that it is always a tuple.<A NAME="tex2html4"
92 HREF="#foot464"><SUP>1.4</SUP></A>
93<P>
94It is a severe error to ever let a <tt class="constant">NULL</tt> pointer ``escape'' to
95the Python user.
96
97<P>
98<BR><HR><H4>Footnotes</H4>
99<DL>
100<DT><A NAME="foot464">... tuple.</A><A
101 href="nullPointers.html#tex2html4"><SUP>1.4</SUP></A></DT>
102<DD>
103These guarantees don't hold when you use the ``old'' style
104calling convention -- this is still found in much existing code.
105
106</DD>
107</DL>
108<DIV CLASS="navigation">
109<div class='online-navigation'>
110<p></p><hr />
111<table align="center" width="100%" cellpadding="0" cellspacing="2">
112<tr>
113<td class='online-navigation'><a rel="prev" title="1.10.3 Thin Ice"
114 href="thinIce.html"><img src='../icons/previous.png'
115 border='0' height='32' alt='Previous Page' width='32' /></A></td>
116<td class='online-navigation'><a rel="parent" title="1.10 Reference Counts"
117 href="refcounts.html"><img src='../icons/up.png'
118 border='0' height='32' alt='Up One Level' width='32' /></A></td>
119<td class='online-navigation'><a rel="next" title="1.11 Writing Extensions in"
120 href="cplusplus.html"><img src='../icons/next.png'
121 border='0' height='32' alt='Next Page' width='32' /></A></td>
122<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
123<td class='online-navigation'><a rel="contents" title="Table of Contents"
124 href="contents.html"><img src='../icons/contents.png'
125 border='0' height='32' alt='Contents' width='32' /></A></td>
126<td class='online-navigation'><img src='../icons/blank.png'
127 border='0' height='32' alt='' width='32' /></td>
128<td class='online-navigation'><img src='../icons/blank.png'
129 border='0' height='32' alt='' width='32' /></td>
130</tr></table>
131<div class='online-navigation'>
132<b class="navlabel">Previous:</b>
133<a class="sectref" rel="prev" href="thinIce.html">1.10.3 Thin Ice</A>
134<b class="navlabel">Up:</b>
135<a class="sectref" rel="parent" href="refcounts.html">1.10 Reference Counts</A>
136<b class="navlabel">Next:</b>
137<a class="sectref" rel="next" href="cplusplus.html">1.11 Writing Extensions in</A>
138</div>
139</div>
140<hr />
141<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
142</DIV>
143<!--End of Navigation Panel-->
144<ADDRESS>
145See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
146</ADDRESS>
147</BODY>
148</HTML>