%!PS-Adobe-2.0
%%Creator: dvips(k) 5.96.1 Copyright 2007 Radical Eye Software
%%Title: paper-letter/api.dvi
%%CreationDate: Fri Dec 19 16:18:56 2008
%%Pages: 151
%%PageOrder: Ascend
%%BoundingBox: 0 0 612 792
%%DocumentFonts: Helvetica Helvetica-Oblique Times-Roman Times-Bold
%%+ CMSY10 Times-Italic Helvetica-Bold Courier Courier-Bold
%%+ Times-BoldItalic Courier-BoldOblique Courier-Oblique CMMI10
%%DocumentPaperSizes: Letter
%%EndComments
%DVIPSWebPage: (www.radicaleye.com)
%DVIPSCommandLine: dvips -N0 -t letter -o paper-letter/api.ps
%+ paper-letter/api.dvi
%DVIPSParameters: dpi=600
%DVIPSSource:  TeX output 2008.12.19:1618
%%BeginProcSet: tex.pro 0 0
%!
/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S
N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72
mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0
0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{
landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize
mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[
matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round
exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{
statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0]
N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin
/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array
/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2
array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N
df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A
definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get
}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub}
B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr
1 add N}if}B/CharBuilder{save 3 1 roll S A/base get 2 index get S
/BitMaps get S get/Cd X pop/ctr 0 N Cdx 0 Cx Cy Ch sub Cx Cw add Cy
setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx sub Cy .1 sub]{Ci}imagemask
restore}B/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn
/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put
}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{
bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A
mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{
SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{
userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X
1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4
index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N
/p{show}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 N/Ry 0 N/V{}B/RV/v{
/Ry X/Rx X V}B statusdict begin/product where{pop false[(Display)(NeXT)
(LaserWriter 16/600)]{A length product length le{A length product exch 0
exch getinterval eq{pop true exit}if}{pop}ifelse}forall}{false}ifelse
end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{BDot}imagemask
grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat{BDot}
imagemask grestore}}ifelse B/QV{gsave newpath transform round exch round
exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 rlineto
fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B/M{S p
delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M}B/g{0 M}
B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p -3 w}B/n{
p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{0 S
rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end

%%EndProcSet
%%BeginProcSet: 8r.enc 0 0
% File 8r.enc  TeX Base 1 Encoding  Revision 2.0  2002-10-30
%
% @@psencodingfile@{
%   author    = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry,
%                W. Schmidt, P. Lehman",
%   version   = "2.0",
%   date      = "27nov06",
%   filename  = "8r.enc",
%   email     = "tex-fonts@@tug.org",
%   docstring = "This is the encoding vector for Type1 and TrueType
%                fonts to be used with TeX.  This file is part of the
%                PSNFSS bundle, version 9"
% @}
%
% The idea is to have all the characters normally included in Type 1 fonts
% available for typesetting. This is effectively the characters in Adobe
% Standard encoding, ISO Latin 1, Windows ANSI including the euro symbol,
% MacRoman, and some extra characters from Lucida.
%
% Character code assignments were made as follows:
%
% (1) the Windows ANSI characters are almost all in their Windows ANSI
% positions, because some Windows users cannot easily reencode the
% fonts, and it makes no difference on other systems. The only Windows
% ANSI characters not available are those that make no sense for
% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen
% (173). quotesingle and grave are moved just because it's such an
% irritation not having them in TeX positions.
%
% (2) Remaining characters are assigned arbitrarily to the lower part
% of the range, avoiding 0, 10 and 13 in case we meet dumb software.
%
% (3) Y&Y Lucida Bright includes some extra text characters; in the
% hopes that other PostScript fonts, perhaps created for public
% consumption, will include them, they are included starting at 0x12.
% These are /dotlessj /ff /ffi /ffl.
%
% (4) hyphen appears twice for compatibility with both ASCII and Windows.
%
% (5) /Euro was assigned to 128, as in Windows ANSI
%
% (6) Missing characters from MacRoman encoding incorporated as follows:
%
%     PostScript      MacRoman        TeXBase1
%     --------------  --------------  --------------
%     /notequal       173             0x16
%     /infinity       176             0x17
%     /lessequal      178             0x18
%     /greaterequal   179             0x19
%     /partialdiff    182             0x1A
%     /summation      183             0x1B
%     /product        184             0x1C
%     /pi             185             0x1D
%     /integral       186             0x81
%     /Omega          189             0x8D
%     /radical        195             0x8E
%     /approxequal    197             0x8F
%     /Delta          198             0x9D
%     /lozenge        215             0x9E
%
/TeXBase1Encoding [
% 0x00
/.notdef /dotaccent /fi /fl
/fraction /hungarumlaut /Lslash /lslash
/ogonek /ring /.notdef /breve
/minus /.notdef /Zcaron /zcaron
% 0x10
/caron /dotlessi /dotlessj /ff
/ffi /ffl /notequal /infinity
/lessequal /greaterequal /partialdiff /summation
/product /pi /grave /quotesingle
% 0x20
/space /exclam /quotedbl /numbersign
/dollar /percent /ampersand /quoteright
/parenleft /parenright /asterisk /plus
/comma /hyphen /period /slash
% 0x30
/zero /one /two /three
/four /five /six /seven
/eight /nine /colon /semicolon
/less /equal /greater /question
% 0x40
/at /A /B /C
/D /E /F /G
/H /I /J /K
/L /M /N /O
% 0x50
/P /Q /R /S
/T /U /V /W
/X /Y /Z /bracketleft
/backslash /bracketright /asciicircum /underscore
% 0x60
/quoteleft /a /b /c
/d /e /f /g
/h /i /j /k
/l /m /n /o
% 0x70
/p /q /r /s
/t /u /v /w
/x /y /z /braceleft
/bar /braceright /asciitilde /.notdef
% 0x80
/Euro /integral /quotesinglbase /florin
/quotedblbase /ellipsis /dagger /daggerdbl
/circumflex /perthousand /Scaron /guilsinglleft
/OE /Omega /radical /approxequal
% 0x90
/.notdef /.notdef /.notdef /quotedblleft
/quotedblright /bullet /endash /emdash
/tilde /trademark /scaron /guilsinglright
/oe /Delta /lozenge /Ydieresis
% 0xA0
/.notdef /exclamdown /cent /sterling
/currency /yen /brokenbar /section
/dieresis /copyright /ordfeminine /guillemotleft
/logicalnot /hyphen /registered /macron
% 0xB0
/degree /plusminus /twosuperior /threesuperior
/acute /mu /paragraph /periodcentered
/cedilla /onesuperior /ordmasculine /guillemotright
/onequarter /onehalf /threequarters /questiondown
% 0xC0
/Agrave /Aacute /Acircumflex /Atilde
/Adieresis /Aring /AE /Ccedilla
/Egrave /Eacute /Ecircumflex /Edieresis
/Igrave /Iacute /Icircumflex /Idieresis
% 0xD0
/Eth /Ntilde /Ograve /Oacute
/Ocircumflex /Otilde /Odieresis /multiply
/Oslash /Ugrave /Uacute /Ucircumflex
/Udieresis /Yacute /Thorn /germandbls
% 0xE0
/agrave /aacute /acircumflex /atilde
/adieresis /aring /ae /ccedilla
/egrave /eacute /ecircumflex /edieresis
/igrave /iacute /icircumflex /idieresis
% 0xF0
/eth /ntilde /ograve /oacute
/ocircumflex /otilde /odieresis /divide
/oslash /ugrave /uacute /ucircumflex
/udieresis /yacute /thorn /ydieresis
] def


%%EndProcSet
%%BeginProcSet: texps.pro 0 0
%!
TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2
index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll
exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]FontType 0
ne{/Metrics exch def dict begin Encoding{exch dup type/integertype ne{
pop pop 1 sub dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get
div def}ifelse}forall Metrics/Metrics currentdict end def}{{1 index type
/nametype eq{exit}if exch pop}loop}ifelse[2 index currentdict end
definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{dup
sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 roll
mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def dup[
exch{dup CharStrings exch known not{pop/.notdef/Encoding true def}if}
forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def}def
end

%%EndProcSet
%%BeginFont: CMMI10
%!PS-AdobeFont-1.1: CMMI10 1.100
%%CreationDate: 1996 Jul 23 07:53:57
% Copyright (C) 1997 American Mathematical Society. All Rights Reserved.
11 dict begin
/FontInfo 7 dict dup begin
/version (1.100) readonly def
/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def
/FullName (CMMI10) readonly def
/FamilyName (Computer Modern) readonly def
/Weight (Medium) readonly def
/ItalicAngle -14.04 def
/isFixedPitch false def
end readonly def
/FontName /CMMI10 def
/PaintType 0 def
/FontType 1 def
/FontMatrix [0.001 0 0 0.001 0 0] readonly def
/Encoding 256 array
0 1 255 {1 index exch /.notdef put} for
dup 60 /less put
dup 62 /greater put
readonly def
/FontBBox{-32 -250 1048 750}readonly def
currentdict end
currentfile eexec
D9D66F633B846A97B686A97E45A3D0AA0529731C99A784CCBE85B4993B2EEBDE
3B12D472B7CF54651EF21185116A69AB1096ED4BAD2F646635E019B6417CC77B
532F85D811C70D1429A19A5307EF63EB5C5E02C89FC6C20F6D9D89E7D91FE470
B72BEFDA23F5DF76BE05AF4CE93137A219ED8A04A9D7D6FDF37E6B7FCDE0D90B
986423E5960A5D9FBB4C956556E8DF90CBFAEC476FA36FD9A5C8175C9AF513FE
D919C2DDD26BDC0D99398B9F4D03D5993DFC0930297866E1CD0A319B6B1FD958
9E394A533A081C36D456A09920001A3D2199583EB9B84B4DEE08E3D12939E321
990CD249827D9648574955F61BAAA11263A91B6C3D47A5190165B0C25ABF6D3E
6EC187E4B05182126BB0D0323D943170B795255260F9FD25F2248D04F45DFBFB
DEF7FF8B19BFEF637B210018AE02572B389B3F76282BEB29CC301905D388C721
59616893E774413F48DE0B408BC66DCE3FE17CB9F84D205839D58014D6A88823
D9320AE93AF96D97A02C4D5A2BB2B8C7925C4578003959C46E3CE1A2F0EAC4BF
8B9B325E46435BDE60BC54D72BC8ACB5C0A34413AC87045DC7B84646A324B808
6FD8E34217213E131C3B1510415CE45420688ED9C1D27890EC68BD7C1235FAF9
1DAB3A369DD2FC3BE5CF9655C7B7EDA7361D7E05E5831B6B8E2EEC542A7B38EE
03BE4BAC6079D038ACB3C7C916279764547C2D51976BABA94BA9866D79F13909
95AA39B0F03103A07CBDF441B8C5669F729020AF284B7FF52A29C6255FCAACF1
74109050FBA2602E72593FBCBFC26E726EE4AEF97B7632BC4F5F353B5C67FED2
3EA752A4A57B8F7FEFF1D7341D895F0A3A0BE1D8E3391970457A967EFF84F6D8
47750B1145B8CC5BD96EE7AA99DDC9E06939E383BDA41175233D58AD263EBF19
AFC0E2F840512D321166547B306C592B8A01E1FA2564B9A26DAC14256414E4C8
42616728D918C74D13C349F4186EC7B9708B86467425A6FDB3A396562F7EE4D8
40B43621744CF8A23A6E532649B66C2A0002DD04F8F39618E4F572819DD34837
B5A08E643FDCA1505AF6A1FA3DDFD1FA758013CAED8ACDDBBB334D664DFF5B53
95601766777978D01677B8D19E1B10A078432D2884BB4F7B8C3293B68BB78100
16724E495064BA0168CC86D413CB48560D6D318357397832F7A858CD82030C7D
8A4A1919716E8B26AFF8789AAF489EE4E0A88DC477551A87C7DF2856189E4596
FE015956AFE5CC019F5CA6323A12B763B7B08B92C1A2940D3C566C43729E5482
63C6DC5E834AEB4DAFB5AE8F0B8931A4687C94D11587B9071C8D81DA14F12776
53A1985A3EBE37827656BD4635E03F09C3231F906874645E7DB3E59045A59D67
E745D8487CF73FC50F64060544F624F357BC998A87FBE468DEBB38A09449EBCA
D041D7C29225ACD16CB8A59E87924D15A9125F064710A6CCCA3AD3103D8FCC94
CC3571C6F9192774FCFE5BB42A14B27960903144D28BF047BF4C77646EA7BF6F
440D4EDEB712C63F2E8080419E42D1D58EED685EB5CDD49F80DB6E5553B519FA
C6A39A093155802F3EC607721F390307E91ECB597ABA60A537E3F8C045BF5DD3
D88CF6518D37FCD95D2F295D902D617440D23516D962F47750A682A319ACE1
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
cleartomark
%%EndFont
%%BeginFont: CMSY10
%!PS-AdobeFont-1.1: CMSY10 1.0
%%CreationDate: 1991 Aug 15 07:20:57
% Copyright (C) 1997 American Mathematical Society. All Rights Reserved.
11 dict begin
/FontInfo 7 dict dup begin
/version (1.0) readonly def
/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def
/FullName (CMSY10) readonly def
/FamilyName (Computer Modern) readonly def
/Weight (Medium) readonly def
/ItalicAngle -14.035 def
/isFixedPitch false def
end readonly def
/FontName /CMSY10 def
/PaintType 0 def
/FontType 1 def
/FontMatrix [0.001 0 0 0.001 0 0] readonly def
/Encoding 256 array
0 1 255 {1 index exch /.notdef put} for
dup 13 /circlecopyrt put
dup 15 /bullet put
dup 110 /backslash put
readonly def
/FontBBox{-29 -960 1116 775}readonly def
currentdict end
currentfile eexec
D9D66F633B846A97B686A97E45A3D0AA052F09F9C8ADE9D907C058B87E9B6964
7D53359E51216774A4EAA1E2B58EC3176BD1184A633B951372B4198D4E8C5EF4
A213ACB58AA0A658908035BF2ED8531779838A960DFE2B27EA49C37156989C85
E21B3ABF72E39A89232CD9F4237FC80C9E64E8425AA3BEF7DED60B122A52922A
221A37D9A807DD01161779DDE7D31FF2B87F97C73D63EECDDA4C49501773468A
27D1663E0B62F461F6E40A5D6676D1D12B51E641C1D4E8E2771864FC104F8CBF
5B78EC1D88228725F1C453A678F58A7E1B7BD7CA700717D288EB8DA1F57C4F09
0ABF1D42C5DDD0C384C7E22F8F8047BE1D4C1CC8E33368FB1AC82B4E96146730
DE3302B2E6B819CB6AE455B1AF3187FFE8071AA57EF8A6616B9CB7941D44EC7A
71A7BB3DF755178D7D2E4BB69859EFA4BBC30BD6BB1531133FD4D9438FF99F09
4ECC068A324D75B5F696B8688EEB2F17E5ED34CCD6D047A4E3806D000C199D7C
515DB70A8D4F6146FE068DC1E5DE8BC570317AAEA74A842CFD26F9591866F5A0
9B4EAD7D6453FF5CA8A92D9A114BDCA5317C72494CC6B411D28AB25DFF7CC399
0E0B48746E2F32645AB037970789429CE73FE9E900637A7582373D77C76B5CF5
8D207B801140B5125CD200857F65241A97E5DCEEA4B0D20E33742DEBC4F8F31C
7F1FF35BAAA8071BB8E3819A5EAA183191DC544CFD0B424FCD6901760033DBA1
A76B9C2D3C7C80011A9B15144AE22D74C3EE28EA85D1B15112B3A0645801AA86
C328AEF15F3353E91100EEE496E5DCA70BBC16ADC918D54117977579A0CD3699
E94604C893E277D2D843614FEAC558720AF8267E657C309AE973D33BB93ACB22
1724E1A2C8E6F972B632F26671316D4B3C5FB64539EE84F188FEFD6D7D1FBC9F
1FF1E07AD1DC71FB33AB6E61677C0E87D67889DF88D26385D362B217EC5334B5
93C0316D8FE4ACC492F46843175FC9349C361AE247A53388CF4F8646B1656FB1
2DA1E76F8331005270C22DED39122BD76842130EB314784629B1AA0022FE69F5
89080FA1F2E2FF6574EF5D5A3EEF6B5B5C3CD34C9D9313E1D1442BC6C2B47D3C
A6DB6C09291ECDDF57862020A511749A8218081F8CC25398323BB5E57E4F90D3

0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
cleartomark
%%EndFont
TeXDict begin 40258431 52099146 1000 600 600 (paper-letter/api.dvi)
@start /Fa 214[25 25 40[{TeXBase1Encoding ReEncodeFont}2
74.7198 /Times-Roman rf /Fb 193[65 1[65 60[{}2 83.022
/CMMI10 rf /Fc 162[40 1[40 91[{TeXBase1Encoding ReEncodeFont}2
119.552 /Times-Roman rf /Fd 170[50 6[50 1[50 76[{
TeXBase1Encoding ReEncodeFont}3 83.022 /Courier-Oblique
rf /Fe 170[50 6[50 1[50 76[{TeXBase1Encoding ReEncodeFont}3
83.022 /Courier-BoldOblique rf /Ff 134[37 1[55 37 1[23
32 32 1[42 42 46 65 23 1[23 23 46 42 28 37 42 37 42 42
18[60 11[55 55 19[28 45[{TeXBase1Encoding ReEncodeFont}25
83.022 /Times-BoldItalic rf /Fg 130[50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 1[50 1[50 1[50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
5[50 50 1[50 1[50 1[50 50 50 50 4[50 1[50 50 50 1[50
2[50 1[50 33[{TeXBase1Encoding ReEncodeFont}73 83.022
/Courier-Bold rf /Fh 134[50 50 72 50 55 28 50 33 1[55
55 55 83 22 50 22 22 55 55 28 55 55 50 55 55 8[66 94
1[72 61 66 72 1[66 78 72 83 55 2[28 1[78 61 66 72 72
66 66 7[55 55 55 55 55 55 55 55 55 55 1[28 43[50 2[{
TeXBase1Encoding ReEncodeFont}55 99.6264 /Helvetica rf
/Fi 167[48 4[37 3[48 48 4[22 2[37 41 1[44 1[48 65[{
TeXBase1Encoding ReEncodeFont}9 66.4176 /Times-Roman
rf /Fj 103[50 15[50 10[50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 1[50 1[50 1[50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 1[50 50 50
50 50 50 50 50 1[50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 1[50 50 50 33[{TeXBase1Encoding ReEncodeFont}89
83.022 /Courier rf /Fk 130[45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45
45 45 45 45 1[45 45 45 45 45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 1[45
45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45
45 45 45 45 45 45 2[45 45 45 33[{TeXBase1Encoding ReEncodeFont}89
74.7198 /Courier rf /Fl 134[60 60 86 60 66 33 60 40 66
66 66 66 100 27 60 27 27 66 66 33 66 66 60 66 66 10[80
86 73 80 86 1[80 93 86 100 66 80 1[33 86 93 73 80 86
86 80 80 7[66 66 66 66 66 66 66 66 66 66 1[33 1[33 41[60
2[{TeXBase1Encoding ReEncodeFont}58 119.552 /Helvetica
rf /Fm 167[80 113 80 86 73 80 86 2[93 86 4[33 86 93 73
80 2[86 86 65[{TeXBase1Encoding ReEncodeFont}16 119.552
/Helvetica-Bold rf /Fn 133[42 42 42 60 42 46 23 42 28
46 46 46 46 69 18 42 18 18 46 46 23 46 46 42 46 46 8[55
1[55 60 51 55 60 1[55 65 60 69 46 2[23 60 65 51 55 60
60 55 55 7[46 46 46 46 46 46 46 46 46 46 23 23 28 23
41[42 2[{TeXBase1Encoding ReEncodeFont}61 83.022 /Helvetica
rf /Fo 133[32 37 37 55 37 42 23 32 32 42 42 42 42 60
23 37 23 23 42 42 23 37 42 37 42 42 3[32 1[32 46 46 51
69 51 60 46 42 51 1[51 60 55 69 46 2[28 60 60 51 51 60
55 51 51 6[28 1[42 4[42 42 42 1[23 21 28 21 1[42 28 28
28 5[28 29[42 42 2[{TeXBase1Encoding ReEncodeFont}67
83.022 /Times-Italic rf /Fp 133[37 42 42 60 42 46 28
32 37 1[46 42 46 69 23 1[28 23 46 42 28 37 46 37 46 42
28 2[28 1[28 1[60 1[83 60 60 55 46 60 1[51 65 60 78 55
2[32 65 65 51 55 60 60 55 60 1[42 4[28 42 42 42 42 42
42 42 42 42 42 23 21 28 21 1[42 28 28 28 35[46 46 2[{
TeXBase1Encoding ReEncodeFont}70 83.022 /Times-Bold rf
/Fq 145[42 94[42 1[83 13[{}3 83.022 /CMSY10 rf /Fr 104[83
42 1[37 37 24[37 42 42 60 42 42 23 32 28 42 42 42 42
65 23 42 23 23 42 42 28 37 42 37 42 37 28 2[28 1[28 51
60 60 78 60 60 51 46 55 60 46 60 60 74 51 60 32 28 60
60 46 51 60 55 55 60 1[37 1[47 1[23 23 42 42 42 42 42
42 42 42 42 42 23 21 28 21 47 42 28 28 28 1[69 3[28 29[46
46 2[{TeXBase1Encoding ReEncodeFont}86 83.022 /Times-Roman
rf /Fs 133[37 37 37 54 37 42 21 37 25 42 42 42 42 62
17 37 17 17 42 42 21 42 42 37 42 42 12[46 50 54 1[50
2[62 3[21 6[50 1[76 5[21 42 42 42 1[42 1[42 42 42 42
21 21 25 42[37 2[{TeXBase1Encoding ReEncodeFont}47 74.7198
/Helvetica rf /Ft 134[50 1[72 1[55 33 1[44 2[50 55 4[28
55 1[33 44 55 2[50 13[55 2[61 9[61 70[{TeXBase1Encoding ReEncodeFont}16
99.6264 /Times-Bold rf /Fu 139[28 1[33 4[78 28 2[28 50
2[44 1[44 50 44 27[61 72 9[28 50 50 5[50 50 50 3[25 44[{
TeXBase1Encoding ReEncodeFont}19 99.6264 /Times-Roman
rf /Fv 137[72 80 40 72 48 2[80 80 120 1[72 1[32 3[80
80 2[80 14[104 5[80 1[72 2[112 88 1[104 21[40 1[40 44[{
TeXBase1Encoding ReEncodeFont}21 143.462 /Helvetica rf
/Fw 140[72 6[32 6[80 3[80 14[104 28[80 1[80 80 3[40 46[{
TeXBase1Encoding ReEncodeFont}9 143.462 /Helvetica-Oblique
rf /Fx 133[103 103 103 1[103 115 57 103 69 1[115 115
115 172 46 1[46 46 115 115 57 115 115 103 115 115 8[138
1[138 149 126 138 149 1[138 161 149 172 115 2[57 149
1[126 138 149 149 138 138 17[57 2[57 44[{TeXBase1Encoding ReEncodeFont}
44 206.559 /Helvetica rf end
%%EndProlog
%%BeginSetup
%%Feature: *Resolution 600dpi
TeXDict begin
%%BeginPaperSize: Letter
/setpagedevice where
{ pop << /PageSize [612 792] >> setpagedevice }
{ /letter where { pop letter } if }
ifelse
%%EndPaperSize
end
%%EndSetup
%%Page: 1 1
TeXDict begin 1 0 bop 0 83 3901 9 v 923 446 a Fx(Python/C)58
b(API)g(Ref)-6 b(erence)57 b(Man)n(ual)3015 676 y Fw(Release)38
b(2.5.3)2684 1852 y Fv(Guido)g(v)l(an)i(Rossum)2365 2035
y(F)-6 b(red)39 b(L.)g(Dr)o(ak)m(e)n(,)f(Jr)-7 b(.,)39
b(editor)3044 4091 y Fu(19th)24 b(December)l(,)h(2008)2676
5201 y Ft(Python)g(Softwar)n(e)h(F)n(oundation)3019 5317
y Fu(Email:)k Fs(docs@p)n(ython.org)p eop end
%%Page: 2 2
TeXDict begin 2 1 bop 0 83 a Fr(Cop)o(yright)380 80 y(c)357
83 y Fq(\015)20 b Fr(2001-2008)d(Python)i(Softw)o(are)h(F)o(oundation.)
i(All)f(rights)f(reserv)o(ed.)0 230 y(Cop)o(yright)380
227 y(c)357 230 y Fq(\015)g Fr(2000)f(BeOpen.com.)24
b(All)c(rights)g(reserv)o(ed.)0 377 y(Cop)o(yright)380
374 y(c)357 377 y Fq(\015)g Fr(1995-2000)d(Corporation)h(for)h
(National)h(Research)g(Initiati)n(v)o(es.)k(All)d(rights)f(reserv)o
(ed.)0 524 y(Cop)o(yright)380 521 y(c)357 524 y Fq(\015)g
Fr(1991-1995)d(Stichting)j(Mathematisch)f(Centrum.)24
b(All)d(rights)f(reserv)o(ed.)0 671 y(See)h(the)f(end)f(of)h(this)h
(document)d(for)i(complete)f(license)h(and)g(permissions)f
(information.)p eop end
%%Page: 1 3
TeXDict begin 1 2 bop 1796 2510 a Fp(Abstract)0 2739
y Fr(This)26 b(manual)g(documents)e(the)j(API)f(used)g(by)g(C)h(and)f
(C)1694 2732 y(++)1815 2739 y(programmers)d(who)j(w)o(ant)h(to)f(write)
h(e)o(xtension)d(modules)i(or)g(embed)0 2839 y(Python.)d(It)d(is)g(a)g
(companion)d(to)j Fo(Extending)d(and)i(Embedding)e(the)i(Python)f
(Interpr)m(eter)p Fr(,)h(which)g(describes)g(the)g(general)g
(principles)0 2939 y(of)h(e)o(xtension)f(writing)g(b)n(ut)h(does)g(not)
g(document)e(the)j(API)f(functions)f(in)h(detail.)0 3086
y Fp(W)-5 b(ar)o(ning:)26 b Fr(The)c(current)e(v)o(ersion)g(of)h(this)h
(document)d(is)k(incomplete.)k(I)21 b(hope)g(that)g(it)h(is)h(ne)n(v)o
(ertheless)d(useful.)28 b(I)21 b(will)i(continue)c(to)0
3185 y(w)o(ork)h(on)f(it,)i(and)f(release)g(ne)n(w)g(v)o(ersions)f
(from)g(time)i(to)f(time,)g(independent)e(from)h(Python)g(source)g
(code)h(releases.)p eop end
%%Page: 2 4
TeXDict begin 2 3 bop eop end
%%Page: 1 5
TeXDict begin 1 4 bop 2764 747 a Fx(CONTENTS)0 1594 y
Fp(1)83 b(Intr)o(oduction)3281 b(1)125 1694 y Fr(1.1)110
b(Include)19 b(Files)59 b(.)41 b(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)143 b(1)125 1793 y(1.2)110 b(Objects,)21 b(T)-7 b(ypes)20
b(and)f(Reference)g(Counts)54 b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)143 b(2)125 1893 y(1.3)110
b(Exceptions)57 b(.)41 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
143 b(5)125 1993 y(1.4)110 b(Embedding)18 b(Python)98
b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)143 b(7)125 2092 y(1.5)110
b(Deb)n(ugging)18 b(Builds)72 b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)143
b(8)0 2275 y Fp(2)83 b(The)21 b(V)-8 b(ery)19 b(High)h(Le)o(v)o(el)h
(Lay)o(er)2725 b(11)0 2457 y(3)83 b(Refer)o(ence)19 b(Counting)2985
b(15)0 2640 y(4)83 b(Exception)19 b(Handling)2984 b(17)125
2740 y Fr(4.1)110 b(Standard)19 b(Exceptions)52 b(.)42
b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(21)125 2839 y(4.2)110
b(Deprecation)19 b(of)h(String)g(Exceptions)63 b(.)41
b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
102 b(21)0 3022 y Fp(5)83 b(Utilities)3415 b(23)125 3122
y Fr(5.1)110 b(Operating)19 b(System)h(Utilities)103
b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)102 b(23)125 3221 y(5.2)110 b(Process)21
b(Control)85 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(23)125 3321 y(5.3)110 b(Importing)18 b(Modules)94 b(.)42
b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(24)125 3421 y(5.4)110
b(Data)21 b(marshalling)e(support)84 b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(26)125 3520 y(5.5)110 b(P)o(arsing)20 b(ar)o(guments)e(and)i(b)n
(uilding)f(v)n(alues)80 b(.)41 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)102 b(27)125 3620 y(5.6)110 b(String)20
b(con)m(v)o(ersion)e(and)h(formatting)77 b(.)41 b(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(33)0
3802 y Fp(6)83 b(Abstract)19 b(Objects)h(Lay)o(er)2858
b(35)125 3902 y Fr(6.1)110 b(Object)20 b(Protocol)90
b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(35)125
4002 y(6.2)110 b(Number)19 b(Protocol)101 b(.)41 b(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)102 b(39)125 4101 y(6.3)110 b(Sequence)19
b(Protocol)55 b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(42)125 4201 y(6.4)110 b(Mapping)19 b(Protocol)73 b(.)41
b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(44)125 4301 y(6.5)110
b(Iterator)19 b(Protocol)67 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
102 b(45)125 4400 y(6.6)110 b(Buf)n(fer)20 b(Protocol)96
b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(45)0
4583 y Fp(7)83 b(Concr)o(ete)18 b(Objects)i(Lay)o(er)2846
b(47)125 4682 y Fr(7.1)110 b(Fundamental)19 b(Objects)93
b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(47)125 4782 y(7.2)110
b(Numeric)20 b(Objects)49 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(48)125 4882 y(7.3)110 b(Sequence)19 b(Objects)84 b(.)41
b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(53)125 4981 y(7.4)110
b(Mapping)19 b(Objects)102 b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(67)125 5081 y(7.5)110 b(Other)20 b(Objects)88 b(.)42
b(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(70)0 5264
y Fp(8)83 b(Initialization,)19 b(Finalization,)g(and)h(Thr)o(eads)2280
b(83)125 5363 y Fr(8.1)110 b(Thread)19 b(State)i(and)f(the)g(Global)g
(Interpreter)e(Lock)53 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)102 b(86)p 0 5549 3901 4 v 3882 5649 a Fn(i)p eop
end
%%Page: 2 6
TeXDict begin 2 5 bop 125 83 a Fr(8.2)110 b(Pro\002ling)20
b(and)f(T)m(racing)93 b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(91)125 183 y(8.3)110 b(Adv)n(anced)19 b(Deb)n(ugger)f(Support)84
b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)102 b(92)0 365 y Fp(9)83 b(Memory)20 b(Management)2900
b(93)125 465 y Fr(9.1)110 b(Ov)o(ervie)n(w)102 b(.)41
b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(93)125
565 y(9.2)110 b(Memory)19 b(Interf)o(ace)74 b(.)41 b(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)102 b(94)125 664 y(9.3)110 b(Examples)99
b(.)41 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102
b(94)0 847 y Fp(10)41 b(Object)19 b(Implementation)h(Support)2553
b(97)125 946 y Fr(10.1)68 b(Allocating)20 b(Objects)g(on)g(the)g(Heap)
65 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)102 b(97)125 1046 y(10.2)68 b(Common)19 b(Object)h
(Structures)78 b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)102 b(98)125 1146 y(10.3)68
b(T)-7 b(ype)20 b(Objects)51 b(.)41 b(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)60 b(100)125 1245 y(10.4)68 b(Mapping)19 b(Object)h
(Structures)87 b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)60 b(114)125 1345 y(10.5)68
b(Number)19 b(Object)h(Structures)53 b(.)41 b(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)
h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)60
b(114)125 1445 y(10.6)68 b(Sequence)19 b(Object)h(Structures)69
b(.)42 b(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)g(.)60 b(114)125 1544 y(10.7)68 b(Buf)n(fer)20
b(Object)g(Structures)48 b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g
(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)60
b(114)125 1644 y(10.8)68 b(Supporting)18 b(the)i(Iterator)f(Protocol)53
b(.)41 b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)
g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)60 b(115)125 1743 y(10.9)68 b(Supporting)18
b(Cyclic)j(Garbage)e(Collection)85 b(.)41 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g
(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)
f(.)g(.)g(.)h(.)f(.)g(.)g(.)60 b(115)0 1926 y Fp(A)65
b(Reporting)19 b(Bugs)3095 b(119)0 2109 y(B)70 b(History)19
b(and)h(License)2941 b(121)125 2208 y Fr(B.1)97 b(History)20
b(of)g(the)g(softw)o(are)34 b(.)41 b(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)
g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)60
b(121)125 2308 y(B.2)97 b(T)-6 b(erms)20 b(and)g(conditions)f(for)g
(accessing)h(or)g(otherwise)g(using)f(Python)47 b(.)41
b(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h(.)f
(.)g(.)g(.)60 b(122)125 2408 y(B.3)97 b(Licenses)21 b(and)e(Ackno)n
(wledgements)e(for)j(Incorporated)d(Softw)o(are)54 b(.)41
b(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)g(.)h
(.)f(.)g(.)g(.)60 b(125)0 2590 y Fp(Index)3572 b(135)p
0 5549 3901 4 v 0 5649 a Fn(ii)p eop end
%%Page: 1 7
TeXDict begin 1 6 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3641
427 y Fm(ONE)p 0 515 V 2763 978 a Fx(Introduction)0 1457
y Fr(The)21 b(Application)g(Programmer')-5 b(s)19 b(Interf)o(ace)i(to)h
(Python)e(gi)n(v)o(es)h(C)i(and)e(C)2188 1450 y(++)2305
1457 y(programmers)e(access)j(to)g(the)f(Python)g(interpreter)f(at)0
1556 y(a)27 b(v)n(ariety)f(of)g(le)n(v)o(els.)45 b(The)26
b(API)h(is)h(equally)d(usable)i(from)e(C)1827 1549 y(++)1921
1556 y(,)k(b)n(ut)e(for)f(bre)n(vity)f(it)j(is)f(generally)e(referred)g
(to)i(as)h(the)e(Python/C)0 1656 y(API.)21 b(There)g(are)g(tw)o(o)g
(fundamentally)d(dif)n(ferent)i(reasons)g(for)h(using)g(the)g(Python/C)
f(API.)h(The)g(\002rst)h(reason)e(is)i(to)g(write)f Fo(e)n(xtension)0
1756 y(modules)29 b Fr(for)g(speci\002c)h(purposes;)j(these)d(are)f(C)i
(modules)d(that)i(e)o(xtend)e(the)i(Python)e(interpreter)-5
b(.)52 b(This)30 b(is)h(probably)c(the)j(most)0 1855
y(common)22 b(use.)34 b(The)23 b(second)g(reason)f(is)j(to)e(use)h
(Python)e(as)i(a)g(component)d(in)j(a)f(lar)o(ger)g(application;)g
(this)h(technique)e(is)i(generally)0 1955 y(referred)18
b(to)j(as)g Fo(embedding)d Fr(Python)h(in)h(an)g(application.)0
2102 y(Writing)e(an)f(e)o(xtension)f(module)h(is)h(a)g(relati)n(v)o
(ely)f(well-understood)e(process,)i(where)g(a)h(\223cookbook\224)d
(approach)g(w)o(orks)j(well.)24 b(There)0 2201 y(are)d(se)n(v)o(eral)f
(tools)h(that)g(automate)f(the)h(process)g(to)g(some)g(e)o(xtent.)26
b(While)c(people)e(ha)n(v)o(e)g(embedded)f(Python)g(in)j(other)e
(applications)0 2301 y(since)g(its)i(early)d(e)o(xistence,)g(the)i
(process)e(of)h(embedding)e(Python)h(is)i(less)g(straightforw)o(ard)d
(than)i(writing)g(an)g(e)o(xtension.)0 2448 y(Man)o(y)k(API)h
(functions)e(are)i(useful)f(independent)e(of)i(whether)g(you')l(re)f
(embedding)f(or)i(e)o(xtending)f(Python;)j(moreo)o(v)o(er)m(,)c(most)j
(ap-)0 2547 y(plications)20 b(that)i(embed)e(Python)f(will)j(need)e(to)
i(pro)o(vide)d(a)i(custom)g(e)o(xtension)e(as)j(well,)f(so)h(it')-5
b(s)22 b(probably)d(a)i(good)f(idea)h(to)g(become)0 2647
y(f)o(amiliar)f(with)g(writing)g(an)g(e)o(xtension)f(before)f
(attempting)h(to)i(embed)e(Python)g(in)h(a)h(real)f(application.)0
2974 y Fl(1.1)121 b(Include)34 b(Files)0 3207 y Fr(All)24
b(function,)e(type)g(and)h(macro)f(de\002nitions)g(needed)g(to)h(use)g
(the)h(Python/C)e(API)h(are)g(included)f(in)h(your)f(code)g(by)h(the)g
(follo)n(wing)0 3307 y(line:)236 3545 y Fk(#include)44
b("Python.h")0 3832 y Fr(This)63 b(implies)f(inclusion)f(of)h(the)h
(follo)n(wing)d(standard)h(headers:)109 b Fj(<stdio.h>)p
Fr(,)72 b Fj(<string.h>)p Fr(,)f Fj(<errno.h>)p Fr(,)0
3931 y Fj(<limits.h>)p Fr(,)19 b(and)g Fj(<stdlib.h>)g
Fr(\(if)h(a)n(v)n(ailable\).)p 0 4018 3901 17 v 0 4309
17 292 v 75 4133 a Fp(W)-5 b(ar)o(ning:)64 b Fr(Since)24
b(Python)f(may)g(de\002ne)g(some)h(pre-processor)d(de\002nitions)i
(which)h(af)n(fect)f(the)h(standard)f(headers)g(on)g(some)75
4233 y(systems,)d(you)f Fo(must)i Fr(include)e(`)p Fs(Python.h)p
Fr(')f(before)h(an)o(y)g(standard)g(headers)h(are)g(included.)p
3883 4309 V 0 4326 3901 17 v 0 4481 a(All)25 b(user)g(visible)g(names)g
(de\002ned)e(by)i(Python.h)e(\(e)o(xcept)g(those)i(de\002ned)f(by)g
(the)h(included)e(standard)h(headers\))f(ha)n(v)o(e)i(one)f(of)h(the)0
4581 y(pre\002x)o(es)e(`)p Fj(Py)p Fr(')h(or)f(`)p Fj(_Py)p
Fr('.)36 b(Names)24 b(be)o(ginning)e(with)i(`)p Fj(_Py)p
Fr(')f(are)h(for)f(internal)h(use)g(by)f(the)h(Python)f(implementation)
f(and)i(should)0 4680 y(not)c(be)g(used)g(by)g(e)o(xtension)e(writers.)
25 b(Structure)20 b(member)e(names)i(do)g(not)g(ha)n(v)o(e)f(a)i
(reserv)o(ed)e(pre\002x.)0 4827 y Fp(Important:)48 b
Fr(user)32 b(code)f(should)g(ne)n(v)o(er)g(de\002ne)g(names)h(that)g
(be)o(gin)f(with)h(`)p Fj(Py)p Fr(')f(or)h(`)p Fj(_Py)p
Fr('.)60 b(This)32 b(confuses)f(the)h(reader)m(,)h(and)0
4927 y(jeopardizes)22 b(the)i(portability)f(of)g(the)h(user)g(code)f
(to)h(future)e(Python)h(v)o(ersions,)g(which)h(may)f(de\002ne)g
(additional)g(names)g(be)o(ginning)0 5026 y(with)d(one)g(of)g(these)g
(pre\002x)o(es.)0 5173 y(The)59 b(header)f(\002les)i(are)f(typically)g
(installed)g(with)g(Python.)141 b(On)61 b(U)t Fi(N)t(I)t(X)r
Fr(,)70 b(these)59 b(are)g(located)g(in)g(the)h(directories)0
5273 y(`)p Fs(pre\002x/include/p)n(ython)p Fo(ver)o(sion)p
Fn(/)p Fr(')22 b(and)k(`)p Fs(e)n(x)n(ec)p 1366 5273
23 4 v 26 w(pre\002x/include/p)n(ython)p Fo(ver)o(sion)p
Fn(/)p Fr(',)e(where)i(pre\002x)g(and)h(e)o(x)o(ec)p
3171 5273 25 4 v 28 w(pre\002x)g(are)g(de\002ned)f(by)0
5372 y(the)g(corresponding)d(parameters)i(to)h(Python')-5
b(s)25 b Fp(con\002gur)o(e)h Fr(script)g(and)g Fo(ver)o(sion)g
Fr(is)h Fj(sys.version[:3])p Fr(.)41 b(On)26 b(W)m(indo)n(ws,)h(the)p
0 5549 3901 4 v 3854 5649 a Fn(1)p eop end
%%Page: 2 8
TeXDict begin 2 7 bop 0 83 a Fr(headers)19 b(are)h(installed)h(in)f(`)p
Fs(pre\002x/include)p Fr(',)d(where)i(pre\002x)h(is)h(the)f
(installation)g(directory)e(speci\002ed)i(to)h(the)f(installer)-5
b(.)0 230 y(T)e(o)22 b(include)f(the)h(headers,)f(place)h(both)f
(directories)g(\(if)h(dif)n(ferent\))e(on)h(your)g(compiler')-5
b(s)21 b(search)g(path)h(for)f(includes.)29 b(Do)22 b
Fo(not)g Fr(place)0 330 y(the)e(parent)f(directories)g(on)h(the)g
(search)f(path)h(and)f(then)h(use)g(`)p Fj(#include)48
b(<python2.5/Python.h>)p Fr(';)17 b(this)j(will)h(break)e(on)0
429 y(multi-platform)g(b)n(uilds)i(since)h(the)g(platform)e
(independent)f(headers)h(under)g(pre\002x)h(include)g(the)g(platform)f
(speci\002c)i(headers)f(from)0 529 y(e)o(x)o(ec)p 156
529 25 4 v 28 w(pre\002x.)0 676 y(C)55 669 y(++)173 676
y(users)j(should)e(note)h(that)g(though)f(the)h(API)h(is)g(de\002ned)f
(entirely)f(using)h(C,)h(the)g(header)e(\002les)i(do)f(properly)e
(declare)i(the)g(entry)0 775 y(points)d(to)g(be)g Fj(extern)49
b("C")p Fr(,)20 b(so)g(there)g(is)h(no)f(need)g(to)g(do)g(an)o(ything)e
(special)i(to)g(use)h(the)f(API)h(from)e(C)3068 768 y(++)3162
775 y(.)0 1103 y Fl(1.2)121 b(Objects)n(,)34 b(T)-14
b(ypes)33 b(and)i(Ref)l(erence)h(Counts)0 1336 y Fr(Most)19
b(Python/C)f(API)h(functions)f(ha)n(v)o(e)g(one)g(or)h(more)f(ar)o
(guments)f(as)i(well)g(as)h(a)f(return)f(v)n(alue)g(of)h(type)f
Fj(PyObject)3421 1351 y(*)3471 1336 y Fr(.)23 b(This)c(type)g(is)0
1435 y(a)j(pointer)e(to)h(an)g(opaque)f(data)h(type)f(representing)g
(an)h(arbitrary)e(Python)h(object.)28 b(Since)21 b(all)h(Python)e
(object)h(types)g(are)g(treated)g(the)0 1535 y(same)g(w)o(ay)g(by)f
(the)h(Python)e(language)g(in)i(most)g(situations)f(\(e.g.,)g
(assignments,)g(scope)g(rules,)h(and)f(ar)o(gument)e(passing\),)i(it)i
(is)f(only)0 1634 y(\002tting)c(that)h(the)o(y)e(should)g(be)h
(represented)f(by)h(a)g(single)g(C)h(type.)24 b(Almost)17
b(all)h(Python)e(objects)h(li)n(v)o(e)g(on)g(the)g(heap:)23
b(you)16 b(ne)n(v)o(er)g(declare)0 1734 y(an)22 b(automatic)e(or)i
(static)g(v)n(ariable)f(of)h(type)f Fj(PyObject)p Fr(,)g(only)g
(pointer)f(v)n(ariables)h(of)h(type)f Fj(PyObject)3130
1749 y(*)3200 1734 y Fr(can)h(be)g(declared.)28 b(The)0
1834 y(sole)23 b(e)o(xception)e(are)h(the)h(type)f(objects;)i(since)f
(these)f(must)h(ne)n(v)o(er)e(be)i(deallocated,)f(the)o(y)f(are)i
(typically)f(static)h Fj(PyTypeObject)0 1933 y Fr(objects.)0
2080 y(All)c(Python)f(objects)h(\(e)n(v)o(en)e(Python)h(inte)o(gers\))g
(ha)n(v)o(e)g(a)h Fo(type)g Fr(and)f(a)h Fo(r)m(efer)m(ence)g(count)p
Fr(.)k(An)c(object')-5 b(s)19 b(type)f(determines)g(what)h(kind)f(of)0
2180 y(object)f(it)i(is)f(\(e.g.,)f(an)h(inte)o(ger)m(,)f(a)h(list,)h
(or)e(a)h(user)n(-de\002ned)e(function;)h(there)h(are)f(man)o(y)g(more)
g(as)h(e)o(xplained)e(in)i(the)g Fo(Python)e(Refer)m(ence)0
2279 y(Manual)p Fr(\).)32 b(F)o(or)23 b(each)g(of)g(the)g(well-kno)n
(wn)e(types)i(there)f(is)i(a)g(macro)e(to)h(check)g(whether)f(an)h
(object)f(is)i(of)f(that)h(type;)g(for)e(instance,)0
2379 y(`)p Fj(PyList_Check\()p Fo(a)p Fj(\))p Fr(')17
b(is)k(true)f(if)g(\(and)g(only)f(if\))h(the)g(object)g(pointed)f(to)h
(by)g Fo(a)g Fr(is)h(a)g(Python)e(list.)0 2664 y Fh(1.2.1)100
b(Ref)m(erence)29 b(Counts)0 2867 y Fr(The)20 b(reference)f(count)h(is)
h(important)e(because)h(today')-5 b(s)20 b(computers)f(ha)n(v)o(e)h(a)h
(\002nite)g(\(and)f(often)g(se)n(v)o(erely)f(limited\))h(memory)f
(size;)j(it)0 2966 y(counts)d(ho)n(w)g(man)o(y)f(dif)n(ferent)g(places)
i(there)f(are)g(that)h(ha)n(v)o(e)f(a)g(reference)f(to)i(an)f(object.)
25 b(Such)19 b(a)h(place)f(could)f(be)i(another)e(object,)h(or)0
3066 y(a)h(global)f(\(or)f(static\))i(C)h(v)n(ariable,)d(or)h(a)h
(local)g(v)n(ariable)e(in)i(some)f(C)h(function.)j(When)d(an)f(object')
-5 b(s)19 b(reference)f(count)h(becomes)f(zero,)0 3166
y(the)23 b(object)e(is)j(deallocated.)30 b(If)23 b(it)g(contains)f
(references)f(to)i(other)e(objects,)i(their)f(reference)f(count)g(is)j
(decremented.)29 b(Those)22 b(other)0 3265 y(objects)e(may)g(be)g
(deallocated)f(in)h(turn,)f(if)i(this)f(decrement)f(mak)o(es)h(their)g
(reference)e(count)h(become)g(zero,)h(and)f(so)i(on.)j(\(There')-5
b(s)20 b(an)0 3365 y(ob)o(vious)e(problem)h(with)h(objects)g(that)h
(reference)d(each)i(other)f(here;)h(for)g(no)n(w)-5 b(,)19
b(the)h(solution)f(is)i(\223don')o(t)e(do)g(that.)-6
b(\224\))0 3512 y(Reference)16 b(counts)h(are)g(al)o(w)o(ays)h
(manipulated)d(e)o(xplicitly)-5 b(.)23 b(The)17 b(normal)f(w)o(ay)h(is)
h(to)g(use)f(the)g(macro)g Fj(Py_INCREF\(\))f Fr(to)h(increment)0
3611 y(an)32 b(object')-5 b(s)32 b(reference)f(count)g(by)h(one,)j(and)
d Fj(Py_DECREF\(\))f Fr(to)h(decrement)f(it)i(by)f(one.)60
b(The)32 b Fj(Py_DECREF\(\))f Fr(macro)h(is)0 3711 y(considerably)15
b(more)g(comple)o(x)g(than)i(the)f(incref)g(one,)h(since)g(it)g(must)g
(check)f(whether)f(the)i(reference)e(count)h(becomes)g(zero)g(and)g
(then)0 3811 y(cause)h(the)g(object')-5 b(s)17 b(deallocator)e(to)i(be)
g(called.)23 b(The)17 b(deallocator)e(is)j(a)f(function)f(pointer)f
(contained)h(in)h(the)g(object')-5 b(s)16 b(type)h(structure.)0
3910 y(The)j(type-speci\002c)e(deallocator)h(tak)o(es)h(care)g(of)f
(decrementing)f(the)h(reference)g(counts)g(for)g(other)g(objects)h
(contained)e(in)i(the)g(object)0 4010 y(if)e(this)g(is)h(a)g(compound)
14 b(object)k(type,)f(such)h(as)h(a)f(list,)h(as)g(well)f(as)g
(performing)d(an)o(y)i(additional)g(\002nalization)g(that')-5
b(s)18 b(needed.)23 b(There')-5 b(s)0 4110 y(no)25 b(chance)g(that)h
(the)g(reference)f(count)f(can)i(o)o(v)o(er\003o)n(w;)h(at)f(least)h
(as)g(man)o(y)d(bits)j(are)f(used)f(to)h(hold)f(the)h(reference)f
(count)f(as)j(there)0 4209 y(are)g(distinct)g(memory)f(locations)g(in)h
(virtual)g(memory)e(\(assuming)h Fj(sizeof\(long\))48
b(>=)h(sizeof\(char)3390 4224 y(*)3440 4209 y(\))p Fr(\).)43
b(Thus,)29 b(the)0 4309 y(reference)19 b(count)g(increment)f(is)k(a)e
(simple)g(operation.)0 4456 y(It)f(is)i(not)d(necessary)h(to)g
(increment)f(an)h(object')-5 b(s)19 b(reference)e(count)h(for)h(e)n(v)o
(ery)f(local)h(v)n(ariable)f(that)h(contains)f(a)i(pointer)e(to)h(an)g
(object.)0 4555 y(In)25 b(theory)-5 b(,)25 b(the)h(object')-5
b(s)25 b(reference)f(count)g(goes)i(up)f(by)g(one)g(when)g(the)g(v)n
(ariable)f(is)j(made)e(to)g(point)g(to)h(it)g(and)f(it)h(goes)g(do)n
(wn)e(by)0 4655 y(one)d(when)g(the)h(v)n(ariable)e(goes)i(out)f(of)g
(scope.)29 b(Ho)n(we)n(v)o(er)m(,)20 b(these)i(tw)o(o)f(cancel)h(each)f
(other)g(out,)g(so)h(at)g(the)g(end)f(the)h(reference)e(count)0
4755 y(hasn')o(t)e(changed.)23 b(The)c(only)g(real)g(reason)f(to)i(use)
f(the)h(reference)d(count)i(is)h(to)f(pre)n(v)o(ent)f(the)h(object)g
(from)f(being)g(deallocated)g(as)i(long)0 4854 y(as)j(our)e(v)n
(ariable)g(is)i(pointing)d(to)i(it.)31 b(If)22 b(we)g(kno)n(w)f(that)h
(there)f(is)i(at)g(least)f(one)g(other)f(reference)f(to)i(the)g(object)
g(that)g(li)n(v)o(es)g(at)g(least)h(as)0 4954 y(long)d(as)i(our)f(v)n
(ariable,)f(there)g(is)i(no)f(need)g(to)g(increment)f(the)h(reference)e
(count)i(temporarily)-5 b(.)25 b(An)c(important)f(situation)g(where)h
(this)0 5053 y(arises)f(is)g(in)f(objects)g(that)g(are)g(passed)g(as)g
(ar)o(guments)e(to)i(C)h(functions)e(in)h(an)g(e)o(xtension)f(module)f
(that)i(are)g(called)g(from)f(Python;)h(the)0 5153 y(call)i(mechanism)e
(guarantees)f(to)j(hold)e(a)i(reference)d(to)i(e)n(v)o(ery)f(ar)o
(gument)f(for)i(the)g(duration)e(of)i(the)h(call.)0 5300
y(Ho)n(we)n(v)o(er)m(,)k(a)i(common)d(pitf)o(all)h(is)i(to)f(e)o
(xtract)f(an)h(object)g(from)e(a)j(list)g(and)e(hold)g(on)h(to)g(it)g
(for)g(a)g(while)g(without)f(incrementing)f(its)0 5400
y(reference)c(count.)30 b(Some)21 b(other)g(operation)f(might)i(concei)
n(v)n(ably)d(remo)o(v)o(e)h(the)i(object)g(from)f(the)h(list,)h
(decrementing)c(its)k(reference)p 0 5549 3901 4 v 0 5649
a Fn(2)2958 b(Chapter)23 b(1.)52 b(Introduction)p eop
end
%%Page: 3 9
TeXDict begin 3 8 bop 0 83 a Fr(count)24 b(and)g(possible)g
(deallocating)g(it.)39 b(The)24 b(real)h(danger)e(is)j(that)f
(innocent-looking)c(operations)i(may)h(in)m(v)n(ok)o(e)g(arbitrary)f
(Python)0 183 y(code)f(which)f(could)h(do)g(this;)h(there)f(is)i(a)e
(code)g(path)g(which)f(allo)n(ws)i(control)e(to)h(\003o)n(w)h(back)e
(to)i(the)f(user)g(from)g(a)g Fj(Py_DECREF\(\))p Fr(,)0
282 y(so)f(almost)f(an)o(y)f(operation)f(is)k(potentially)d(dangerous.)
0 429 y(A)42 b(safe)g(approach)e(is)i(to)g(al)o(w)o(ays)g(use)g(the)g
(generic)e(operations)g(\(functions)g(whose)i(name)f(be)o(gins)f(with)i
(`)p Fj(PyObject_-)0 529 y Fr(',)31 b(`)p Fj(PyNumber_)p
Fr(',)f(`)p Fj(PySequence_)p Fr(')c(or)j(`)p Fj(PyMapping_)p
Fr('\).)49 b(These)29 b(operations)f(al)o(w)o(ays)h(increment)f(the)h
(reference)f(count)0 628 y(of)18 b(the)g(object)g(the)o(y)f(return.)23
b(This)c(lea)n(v)o(es)f(the)g(caller)g(with)h(the)f(responsibility)f
(to)h(call)g Fj(Py_DECREF\(\))f Fr(when)h(the)o(y)f(are)h(done)f(with)0
728 y(the)j(result;)h(this)f(soon)g(becomes)f(second)g(nature.)0
996 y Fn(Ref)n(erence)k(Count)g(Details)0 1199 y Fr(The)e(reference)f
(count)h(beha)n(vior)f(of)h(functions)f(in)i(the)f(Python/C)g(API)h(is)
h(best)e(e)o(xplained)f(in)i(terms)f(of)h Fo(owner)o(ship)f(of)h(r)m
(efer)m(ences)p Fr(.)0 1299 y(Ownership)31 b(pertains)h(to)g
(references,)i(ne)n(v)o(er)d(to)h(objects)g(\(objects)g(are)g(not)g(o)n
(wned:)48 b(the)o(y)32 b(are)g(al)o(w)o(ays)h(shared\).)60
b(\224Owning)31 b(a)0 1398 y(reference\224)18 b(means)h(being)g
(responsible)g(for)g(calling)g(Py)p 1658 1398 25 4 v
30 w(DECREF)i(on)e(it)h(when)g(the)f(reference)g(is)h(no)g(longer)e
(needed.)24 b(Ownership)0 1498 y(can)f(also)g(be)g(transferred,)e
(meaning)g(that)i(the)g(code)f(that)h(recei)n(v)o(es)f(o)n(wnership)g
(of)g(the)h(reference)e(then)i(becomes)f(responsible)f(for)0
1598 y(e)n(v)o(entually)h(decref)5 b('ing)22 b(it)j(by)e(calling)h
Fj(Py_DECREF\(\))f Fr(or)g Fj(Py_XDECREF\(\))g Fr(when)g(it')-5
b(s)26 b(no)d(longer)g(needed\227or)f(passing)i(on)0
1697 y(this)d(responsibility)f(\(usually)g(to)g(its)i(caller\).)27
b(When)20 b(a)h(function)e(passes)j(o)n(wnership)d(of)h(a)i(reference)d
(on)h(to)h(its)h(caller)m(,)e(the)h(caller)g(is)0 1797
y(said)g(to)g(recei)n(v)o(e)f(a)i Fo(ne)o(w)f Fr(reference.)k(When)c
(no)g(o)n(wnership)e(is)j(transferred,)d(the)i(caller)g(is)h(said)f(to)
g Fo(borr)l(ow)g Fr(the)g(reference.)26 b(Nothing)0 1897
y(needs)20 b(to)g(be)g(done)f(for)h(a)h(borro)n(wed)c(reference.)0
2043 y(Con)m(v)o(ersely)-5 b(,)22 b(when)h(a)h(calling)f(function)e
(passes)k(it)f(a)g(reference)e(to)h(an)h(object,)f(there)g(are)h(tw)o
(o)f(possibilities:)33 b(the)23 b(function)f Fo(steals)0
2143 y Fr(a)g(reference)e(to)i(the)f(object,)h(or)f(it)h(does)g(not.)28
b Fo(Stealing)21 b(a)g(r)m(efer)m(ence)h Fr(means)f(that)h(when)f(you)g
(pass)h(a)g(reference)e(to)h(a)h(function,)e(that)0 2243
y(function)e(assumes)j(that)f(it)h(no)n(w)f(o)n(wns)g(that)g
(reference,)e(and)i(you)f(are)h(not)g(responsible)f(for)h(it)h(an)o(y)e
(longer)-5 b(.)0 2390 y(Fe)n(w)20 b(functions)f(steal)h(references;)f
(the)h(tw)o(o)g(notable)f(e)o(xceptions)f(are)i Fj(PyList_SetItem\(\))d
Fr(and)i Fj(PyTuple_SetItem\(\))p Fr(,)0 2489 y(which)28
b(steal)h(a)g(reference)d(to)j(the)f(item)h(\(b)n(ut)f(not)g(to)g(the)h
(tuple)f(or)g(list)h(into)f(which)g(the)g(item)h(is)g(put!\).)49
b(These)28 b(functions)f(were)0 2589 y(designed)19 b(to)i(steal)g(a)g
(reference)e(because)g(of)i(a)f(common)f(idiom)h(for)g(populating)e(a)j
(tuple)f(or)g(list)i(with)e(ne)n(wly)g(created)g(objects;)g(for)0
2688 y(e)o(xample,)k(the)g(code)g(to)h(create)f(the)g(tuple)g
Fj(\(1,)50 b(2,)f("three"\))23 b Fr(could)h(look)g(lik)o(e)g(this)h
(\(for)o(getting)d(about)h(error)h(handling)e(for)0 2788
y(the)e(moment;)f(a)i(better)f(w)o(ay)g(to)g(code)g(this)g(is)i(sho)n
(wn)d(belo)n(w\):)236 3026 y Fk(PyObject)640 3039 y(*)685
3026 y(t;)236 3209 y(t)45 b(=)g(PyTuple_New\(3\);)236
3300 y(PyTuple_SetItem\(t,)d(0,)j(PyInt_FromLong\(1L\)\);)236
3392 y(PyTuple_SetItem\(t,)d(1,)j(PyInt_FromLong\(2L\)\);)236
3483 y(PyTuple_SetItem\(t,)d(2,)j(PyString_FromString\("three"\)\);)0
3769 y Fr(Here,)37 b Fj(PyInt_FromLong\(\))32 b Fr(returns)i(a)g(ne)n
(w)g(reference)f(which)g(is)j(immediately)c(stolen)j(by)e
Fj(PyTuple_SetItem\(\))p Fr(.)0 3869 y(When)f(you)f(w)o(ant)i(to)f(k)o
(eep)g(using)g(an)g(object)f(although)g(the)h(reference)f(to)h(it)h
(will)g(be)f(stolen,)j(use)d Fj(Py_INCREF\(\))f Fr(to)h(grab)0
3969 y(another)19 b(reference)f(before)h(calling)h(the)g
(reference-stealing)d(function.)0 4116 y(Incidentally)-5
b(,)53 b Fj(PyTuple_SetItem\(\))46 b Fr(is)k(the)e Fo(only)g
Fr(w)o(ay)h(to)g(set)g(tuple)f(items;)64 b Fj(PySequence_SetItem\(\))45
b Fr(and)0 4215 y Fj(PyObject_SetItem\(\))13 b Fr(refuse)i(to)g(do)g
(this)h(since)g(tuples)f(are)h(an)f(immutable)g(data)g(type.)23
b(Y)-9 b(ou)15 b(should)f(only)h(use)h Fj(PyTuple_-)0
4315 y(SetItem\(\))j Fr(for)h(tuples)g(that)g(you)f(are)h(creating)g
(yourself.)0 4462 y(Equi)n(v)n(alent)e(code)i(for)f(populating)f(a)j
(list)g(can)f(be)g(written)g(using)g Fj(PyList_New\(\))e
Fr(and)i Fj(PyList_SetItem\(\))p Fr(.)0 4609 y(Ho)n(we)n(v)o(er)m(,)30
b(in)g(practice,)h(you)d(will)j(rarely)d(use)i(these)g(w)o(ays)g(of)f
(creating)g(and)g(populating)e(a)j(tuple)f(or)g(list.)55
b(There')-5 b(s)29 b(a)h(generic)0 4708 y(function,)e
Fj(Py_BuildValue\(\))p Fr(,)g(that)g(can)h(create)f(most)g(common)e
(objects)i(from)g(C)h(v)n(alues,)g(directed)f(by)g(a)g
Fo(format)g(string)p Fr(.)0 4808 y(F)o(or)f(e)o(xample,)h(the)g(abo)o
(v)o(e)e(tw)o(o)i(blocks)f(of)h(code)f(could)g(be)g(replaced)g(by)g
(the)h(follo)n(wing)e(\(which)h(also)h(tak)o(es)g(care)f(of)h(the)g
(error)0 4907 y(checking\):)p 0 5549 3901 4 v 0 5649
a Fn(1.2.)52 b(Objects)o(,)22 b(T)-10 b(ypes)23 b(and)g(Ref)n(erence)g
(Counts)2270 b(3)p eop end
%%Page: 4 10
TeXDict begin 4 9 bop 236 83 a Fk(PyObject)640 96 y(*)685
83 y(tuple,)998 96 y(*)1043 83 y(list;)236 266 y(tuple)44
b(=)h(Py_BuildValue\("\(iis\)",)c(1,)k(2,)f("three"\);)236
357 y(list)g(=)h(Py_BuildValue\("[iis]",)c(1,)k(2,)f("three"\);)0
644 y Fr(It)29 b(is)h(much)e(more)g(common)f(to)i(use)g
Fj(PyObject_SetItem\(\))e Fr(and)h(friends)g(with)h(items)g(whose)g
(references)f(you)g(are)g(only)0 743 y(borro)n(wing,)19
b(lik)o(e)j(ar)o(guments)e(that)i(were)f(passed)h(in)g(to)g(the)f
(function)f(you)h(are)h(writing.)29 b(In)21 b(that)h(case,)g(their)g
(beha)n(viour)e(re)o(garding)0 843 y(reference)f(counts)h(is)h(much)e
(saner)m(,)h(since)h(you)e(don')o(t)g(ha)n(v)o(e)h(to)h(increment)e(a)i
(reference)d(count)i(so)h(you)e(can)i(gi)n(v)o(e)e(a)i(reference)e(a)o
(w)o(ay)0 942 y(\(\223ha)n(v)o(e)e(it)h(be)f(stolen\224\).)24
b(F)o(or)17 b(e)o(xample,)g(this)h(function)e(sets)i(all)h(items)f(of)f
(a)h(list)h(\(actually)-5 b(,)16 b(an)o(y)h(mutable)g(sequence\))f(to)i
(a)g(gi)n(v)o(en)e(item:)236 1181 y Fk(int)236 1272 y
(set_all\(PyObject)998 1285 y(*)1043 1272 y(target,)44
b(PyObject)1805 1285 y(*)1850 1272 y(item\))236 1363
y({)416 1455 y(int)g(i,)g(n;)416 1637 y(n)g(=)h
(PyObject_Length\(target\);)416 1729 y(if)f(\(n)h(<)f(0\))595
1820 y(return)g(-1;)416 1911 y(for)g(\(i)g(=)h(0;)g(i)f(<)h(n;)f(i++\))
h({)595 2002 y(PyObject)998 2015 y(*)1043 2002 y(index)f(=)h
(PyInt_FromLong\(i\);)595 2094 y(if)f(\(!index\))774
2185 y(return)g(-1;)595 2276 y(if)g(\(PyObject_SetItem\(target,)d
(index,)j(item\))g(<)g(0\))774 2368 y(return)g(-1;)595
2459 y(Py_DECREF\(index\);)416 2550 y(})416 2642 y(return)f(0;)236
2733 y(})0 3063 y Fr(The)28 b(situation)f(is)i(slightly)e(dif)n(ferent)
f(for)i(function)e(return)g(v)n(alues.)48 b(While)28
b(passing)g(a)g(reference)e(to)i(most)g(functions)e(does)i(not)0
3162 y(change)18 b(your)h(o)n(wnership)f(responsibilities)h(for)g(that)
h(reference,)e(man)o(y)g(functions)g(that)i(return)f(a)h(reference)e
(to)i(an)f(object)h(gi)n(v)o(e)e(you)0 3262 y(o)n(wnership)25
b(of)i(the)g(reference.)43 b(The)26 b(reason)h(is)g(simple:)39
b(in)27 b(man)o(y)f(cases,)j(the)e(returned)e(object)h(is)i(created)e
(on)g(the)h(\003y)-5 b(,)28 b(and)f(the)0 3361 y(reference)17
b(you)g(get)i(is)g(the)f(only)g(reference)f(to)h(the)h(object.)24
b(Therefore,)16 b(the)i(generic)g(functions)f(that)h(return)f(object)h
(references,)f(lik)o(e)0 3461 y Fj(PyObject_GetItem\(\))j
Fr(and)h Fj(PySequence_GetItem\(\))p Fr(,)f(al)o(w)o(ays)i(return)g(a)g
(ne)n(w)g(reference)f(\(the)h(caller)g(becomes)g(the)0
3561 y(o)n(wner)d(of)h(the)g(reference\).)0 3708 y(It)h(is)h(important)
d(to)j(realize)e(that)h(whether)f(you)g(o)n(wn)h(a)g(reference)e
(returned)g(by)i(a)g(function)e(depends)h(on)g(which)h(function)e(you)h
(call)0 3807 y(only)h(\227)i Fo(the)f(pluma)o(g)o(e)f
Fr(\(the)h(type)g(of)g(the)g(object)f(passed)h(as)h(an)f(ar)o(gument)e
(to)i(the)h(function\))d Fo(doesn')n(t)g(enter)j(into)f(it!)31
b Fr(Thus,)22 b(if)g(you)0 3907 y(e)o(xtract)h(an)g(item)h(from)f(a)h
(list)g(using)g Fj(PyList_GetItem\(\))p Fr(,)d(you)i(don')o(t)f(o)n(wn)
h(the)h(reference)e(\227)i(b)n(ut)f(if)h(you)f(obtain)g(the)g(same)0
4006 y(item)d(from)f(the)h(same)g(list)h(using)f Fj
(PySequence_GetItem\(\))d Fr(\(which)i(happens)g(to)h(tak)o(e)g(e)o
(xactly)f(the)h(same)g(ar)o(guments\),)d(you)0 4106 y(do)j(o)n(wn)f(a)i
(reference)e(to)h(the)g(returned)e(object.)0 4253 y(Here)24
b(is)i(an)e(e)o(xample)f(of)h(ho)n(w)g(you)f(could)g(write)i(a)g
(function)d(that)j(computes)e(the)h(sum)h(of)f(the)g(items)h(in)f(a)h
(list)h(of)e(inte)o(gers;)h(once)0 4353 y(using)20 b
Fj(PyList_GetItem\(\))p Fr(,)d(and)j(once)f(using)h Fj
(PySequence_GetItem\(\))p Fr(.)p 0 5549 3901 4 v 0 5649
a Fn(4)2958 b(Chapter)23 b(1.)52 b(Introduction)p eop
end
%%Page: 5 11
TeXDict begin 5 10 bop 236 174 a Fk(long)236 266 y(sum_list\(PyObject)
1043 279 y(*)1088 266 y(list\))236 357 y({)416 448 y(int)44
b(i,)g(n;)416 540 y(long)g(total)g(=)g(0;)416 631 y(PyObject)819
644 y(*)864 631 y(item;)416 814 y(n)g(=)h(PyList_Size\(list\);)416
905 y(if)f(\(n)h(<)f(0\))595 996 y(return)g(-1;)g(/)1133
1009 y(*)1223 996 y(Not)g(a)h(list)1716 1009 y(*)1761
996 y(/)416 1088 y(for)f(\(i)g(=)h(0;)g(i)f(<)h(n;)f(i++\))h({)595
1179 y(item)f(=)h(PyList_GetItem\(list,)c(i\);)j(/)2074
1192 y(*)2164 1179 y(Can't)g(fail)2657 1192 y(*)2702
1179 y(/)595 1270 y(if)g(\(!PyInt_Check\(item\)\))e(continue;)h(/)2164
1283 y(*)2254 1270 y(Skip)h(non-integers)3061 1283 y(*)3106
1270 y(/)595 1362 y(total)g(+=)g(PyInt_AsLong\(item\);)416
1453 y(})416 1544 y(return)f(total;)236 1636 y(})236
2056 y(long)236 2148 y(sum_sequence\(PyObject)1223 2161
y(*)1268 2148 y(sequence\))236 2239 y({)416 2330 y(int)h(i,)g(n;)416
2422 y(long)g(total)g(=)g(0;)416 2513 y(PyObject)819
2526 y(*)864 2513 y(item;)416 2604 y(n)g(=)h
(PySequence_Length\(sequence\);)416 2696 y(if)f(\(n)h(<)f(0\))595
2787 y(return)g(-1;)g(/)1133 2800 y(*)1223 2787 y(Has)g(no)g(length)
1850 2800 y(*)1895 2787 y(/)416 2878 y(for)g(\(i)g(=)h(0;)g(i)f(<)h(n;)
f(i++\))h({)595 2970 y(item)f(=)h(PySequence_GetItem\(sequence,)40
b(i\);)595 3061 y(if)k(\(item)g(==)h(NULL\))774 3152
y(return)f(-1;)g(/)1312 3165 y(*)1402 3152 y(Not)g(a)h(sequence,)e(or)i
(other)f(failure)2881 3165 y(*)2926 3152 y(/)595 3244
y(if)g(\(PyInt_Check\(item\)\))774 3335 y(total)g(+=)h
(PyInt_AsLong\(item\);)595 3426 y(Py_DECREF\(item\);)d(/)1402
3439 y(*)1492 3426 y(Discard)h(reference)g(ownership)2747
3439 y(*)2792 3426 y(/)416 3518 y(})416 3609 y(return)g(total;)236
3700 y(})0 4168 y Fh(1.2.2)100 b(T)-12 b(ypes)0 4371
y Fr(There)20 b(are)h(fe)n(w)g(other)g(data)f(types)h(that)h(play)e(a)i
(signi\002cant)e(role)h(in)g(the)g(Python/C)g(API;)g(most)g(are)g
(simple)g(C)h(types)f(such)g(as)h Fj(int)p Fr(,)0 4470
y Fj(long)p Fr(,)c Fj(double)g Fr(and)f Fj(char)895 4485
y(*)945 4470 y Fr(.)24 b(A)19 b(fe)n(w)f(structure)f(types)h(are)g
(used)g(to)g(describe)f(static)i(tables)g(used)e(to)i(list)g(the)f
(functions)f(e)o(xported)0 4570 y(by)i(a)g(module)e(or)i(the)g(data)g
(attrib)n(utes)g(of)f(a)i(ne)n(w)e(object)h(type,)f(and)h(another)e(is)
j(used)f(to)g(describe)f(the)h(v)n(alue)f(of)h(a)g(comple)o(x)e(number)
-5 b(.)0 4670 y(These)20 b(will)h(be)f(discussed)g(together)f(with)h
(the)g(functions)f(that)h(use)h(them.)0 4997 y Fl(1.3)121
b(Exceptions)0 5230 y Fr(The)16 b(Python)f(programmer)f(only)h(needs)h
(to)h(deal)f(with)h(e)o(xceptions)e(if)h(speci\002c)h(error)e(handling)
g(is)i(required;)f(unhandled)e(e)o(xceptions)0 5329 y(are)j
(automatically)e(propagated)f(to)j(the)g(caller)m(,)g(then)f(to)h(the)g
(caller')-5 b(s)17 b(caller)m(,)g(and)f(so)h(on,)g(until)g(the)o(y)f
(reach)g(the)h(top-le)n(v)o(el)e(interpreter)m(,)p 0
5549 3901 4 v 0 5649 a Fn(1.3.)52 b(Exceptions)3258 b(5)p
eop end
%%Page: 6 12
TeXDict begin 6 11 bop 0 83 a Fr(where)20 b(the)o(y)f(are)h(reported)f
(to)h(the)g(user)g(accompanied)e(by)i(a)g(stack)h(traceback.)0
230 y(F)o(or)j(C)h(programmers,)c(ho)n(we)n(v)o(er)m(,)i(error)g
(checking)f(al)o(w)o(ays)i(has)h(to)f(be)g(e)o(xplicit.)35
b(All)25 b(functions)e(in)h(the)g(Python/C)f(API)h(can)g(raise)0
330 y(e)o(xceptions,)k(unless)f(an)h(e)o(xplicit)f(claim)g(is)i(made)e
(otherwise)g(in)h(a)g(function')-5 b(s)26 b(documentation.)44
b(In)27 b(general,)h(when)f(a)h(function)0 429 y(encounters)e(an)h
(error)m(,)g(it)h(sets)h(an)e(e)o(xception,)g(discards)g(an)o(y)f
(object)h(references)f(that)i(it)g(o)n(wns,)g(and)f(returns)f(an)i
(error)e(indicator)0 529 y(\227)f(usually)f Fj(NULL)g
Fr(or)g Fj(-1)p Fr(.)38 b(A)24 b(fe)n(w)h(functions)e(return)g(a)i
(Boolean)e(true/f)o(alse)h(result,)i(with)e(f)o(alse)h(indicating)e(an)
h(error)-5 b(.)37 b(V)-9 b(ery)24 b(fe)n(w)0 628 y(functions)f(return)h
(no)g(e)o(xplicit)g(error)f(indicator)g(or)i(ha)n(v)o(e)f(an)g
(ambiguous)f(return)g(v)n(alue,)i(and)f(require)f(e)o(xplicit)h
(testing)g(for)g(errors)0 728 y(with)c Fj(PyErr_Occurred\(\))p
Fr(.)0 875 y(Exception)h(state)j(is)g(maintained)d(in)j(per)n(-thread)d
(storage)h(\(this)h(is)h(equi)n(v)n(alent)e(to)h(using)f(global)g
(storage)h(in)g(an)g(unthreaded)d(appli-)0 975 y(cation\).)k(A)c
(thread)f(can)h(be)f(in)h(one)g(of)f(tw)o(o)h(states:)26
b(an)20 b(e)o(xception)e(has)i(occurred,)d(or)j(not.)k(The)c(function)e
Fj(PyErr_Occurred\(\))0 1074 y Fr(can)28 b(be)h(used)f(to)h(check)e
(for)h(this:)42 b(it)30 b(returns)d(a)i(borro)n(wed)d(reference)h(to)i
(the)f(e)o(xception)f(type)h(object)f(when)h(an)h(e)o(xception)d(has)0
1174 y(occurred,)21 b(and)g Fj(NULL)i Fr(otherwise.)30
b(There)22 b(are)g(a)h(number)d(of)i(functions)f(to)i(set)g(the)f(e)o
(xception)f(state:)30 b Fj(PyErr_SetString\(\))0 1273
y Fr(is)24 b(the)f(most)g(common)e(\(though)g(not)i(the)g(most)g
(general\))e(function)h(to)h(set)g(the)h(e)o(xception)d(state,)j(and)e
Fj(PyErr_Clear\(\))f Fr(clears)0 1373 y(the)f(e)o(xception)f(state.)0
1520 y(The)29 b(full)g(e)o(xception)e(state)j(consists)g(of)f(three)f
(objects)h(\(all)h(of)f(which)f(can)h(be)g Fj(NULL)p
Fr(\):)g(the)g(e)o(xception)f(type,)i(the)f(correspond-)0
1620 y(ing)f(e)o(xception)e(v)n(alue,)j(and)f(the)g(traceback.)48
b(These)28 b(ha)n(v)o(e)f(the)i(same)f(meanings)f(as)i(the)f(Python)85
b(objects)27 b Fj(sys.exc_type)p Fr(,)0 1719 y Fj(sys.exc_value)p
Fr(,)22 b(and)h Fj(sys.exc_traceback)p Fr(;)f(ho)n(we)n(v)o(er)m(,)g
(the)o(y)g(are)i(not)f(the)g(same:)32 b(the)23 b(Python)f(objects)h
(represent)g(the)0 1819 y(last)j(e)o(xception)d(being)i(handled)e(by)i
(a)h(Python)e Fj(try)h Fr(.)12 b(.)g(.)38 b Fj(except)25
b Fr(statement,)h(while)f(the)g(C)i(le)n(v)o(el)d(e)o(xception)g(state)
i(only)e(e)o(xists)0 1918 y(while)k(an)f(e)o(xception)f(is)j(being)d
(passed)i(on)f(between)g(C)h(functions)f(until)g(it)h(reaches)g(the)f
(Python)g(bytecode)f(interpreter')-5 b(s)26 b(main)0
2018 y(loop,)19 b(which)h(tak)o(es)g(care)g(of)g(transferring)e(it)j
(to)g Fj(sys.exc_type)d Fr(and)i(friends.)0 2165 y(Note)25
b(that)g(starting)g(with)g(Python)f(1.5,)i(the)f(preferred,)f
(thread-safe)f(w)o(ay)i(to)g(access)h(the)f(e)o(xception)e(state)j
(from)e(Python)g(code)h(is)0 2265 y(to)j(call)h(the)f(function)55
b Fj(sys.exc_info\(\))p Fr(,)27 b(which)h(returns)f(the)h(per)n
(-thread)e(e)o(xception)g(state)j(for)f(Python)f(code.)47
b(Also,)31 b(the)0 2364 y(semantics)21 b(of)g(both)g(w)o(ays)g(to)h
(access)g(the)f(e)o(xception)f(state)i(ha)n(v)o(e)e(changed)g(so)h
(that)h(a)g(function)d(which)i(catches)g(an)g(e)o(xception)f(will)0
2464 y(sa)n(v)o(e)k(and)f(restore)f(its)j(thread')-5
b(s)23 b(e)o(xception)e(state)j(so)g(as)g(to)g(preserv)o(e)e(the)h(e)o
(xception)f(state)i(of)f(its)i(caller)-5 b(.)35 b(This)23
b(pre)n(v)o(ents)f(common)0 2563 y(b)n(ugs)h(in)g(e)o(xception)e
(handling)g(code)i(caused)f(by)h(an)g(innocent-looking)c(function)i(o)o
(v)o(erwriting)g(the)i(e)o(xception)e(being)h(handled;)h(it)0
2663 y(also)c(reduces)f(the)h(often)f(unw)o(anted)f(lifetime)i(e)o
(xtension)e(for)i(objects)f(that)h(are)g(referenced)e(by)h(the)h(stack)
g(frames)f(in)h(the)g(traceback.)0 2810 y(As)26 b(a)g(general)f
(principle,)g(a)h(function)e(that)i(calls)g(another)e(function)g(to)i
(perform)d(some)i(task)h(should)f(check)g(whether)f(the)i(called)0
2910 y(function)18 b(raised)i(an)h(e)o(xception,)d(and)h(if)i(so,)f
(pass)h(the)f(e)o(xception)e(state)j(on)f(to)g(its)h(caller)-5
b(.)26 b(It)20 b(should)f(discard)h(an)o(y)f(object)h(references)0
3009 y(that)e(it)h(o)n(wns,)f(and)f(return)g(an)h(error)e(indicator)m
(,)h(b)n(ut)h(it)h(should)e Fo(not)g Fr(set)i(another)d(e)o(xception)h
(\227)h(that)g(w)o(ould)f(o)o(v)o(erwrite)f(the)i(e)o(xception)0
3109 y(that)i(w)o(as)h(just)g(raised,)f(and)f(lose)i(important)e
(information)e(about)j(the)g(e)o(xact)f(cause)i(of)f(the)g(error)-5
b(.)0 3256 y(A)23 b(simple)f(e)o(xample)e(of)i(detecting)f(e)o
(xceptions)g(and)h(passing)f(them)h(on)g(is)h(sho)n(wn)e(in)i(the)f
Fj(sum_sequence\(\))e Fr(e)o(xample)g(abo)o(v)o(e.)0
3355 y(It)g(so)g(happens)e(that)i(that)g(e)o(xample)e(doesn')o(t)g
(need)h(to)h(clean)g(up)f(an)o(y)g(o)n(wned)f(references)h(when)g(it)h
(detects)g(an)g(error)-5 b(.)24 b(The)19 b(follo)n(wing)0
3455 y(e)o(xample)d(function)f(sho)n(ws)j(some)f(error)f(cleanup.)23
b(First,)18 b(to)g(remind)e(you)g(why)h(you)f(lik)o(e)i(Python,)e(we)i
(sho)n(w)f(the)g(equi)n(v)n(alent)f(Python)0 3555 y(code:)236
3793 y Fk(def)45 b(incr_item\(dict,)d(key\):)416 3884
y(try:)595 3975 y(item)i(=)h(dict[key])416 4067 y(except)e(KeyError:)
595 4158 y(item)h(=)h(0)416 4249 y(dict[key])e(=)i(item)f(+)g(1)0
4579 y Fr(Here)20 b(is)h(the)f(corresponding)d(C)k(code,)f(in)g(all)h
(its)g(glory:)p 0 5549 3901 4 v 0 5649 a Fn(6)2958 b(Chapter)23
b(1.)52 b(Introduction)p eop end
%%Page: 7 13
TeXDict begin 7 12 bop 236 174 a Fk(int)236 266 y(incr_item\(PyObject)
1088 279 y(*)1133 266 y(dict,)44 b(PyObject)1805 279
y(*)1850 266 y(key\))236 357 y({)416 448 y(/)461 461
y(*)550 448 y(Objects)g(all)g(initialized)f(to)i(NULL)f(for)g
(Py_XDECREF)2657 461 y(*)2702 448 y(/)416 540 y(PyObject)819
553 y(*)864 540 y(item)g(=)h(NULL,)1447 553 y(*)1492
540 y(const_one)e(=)h(NULL,)2298 553 y(*)2343 540 y(incremented_item)e
(=)j(NULL;)416 631 y(int)f(rv)g(=)h(-1;)f(/)1043 644
y(*)1133 631 y(Return)g(value)g(initialized)f(to)h(-1)h(\(failure\))
2971 644 y(*)3016 631 y(/)416 814 y(item)f(=)g(PyObject_GetItem\(dict,)
e(key\);)416 905 y(if)i(\(item)g(==)h(NULL\))f({)595
996 y(/)640 1009 y(*)729 996 y(Handle)g(KeyError)g(only:)1716
1009 y(*)1761 996 y(/)595 1088 y(if)g
(\(!PyErr_ExceptionMatches\(PyExc_KeyError\)\))774 1179
y(goto)g(error;)595 1362 y(/)640 1375 y(*)729 1362 y(Clear)g(the)h
(error)f(and)g(use)g(zero:)2074 1375 y(*)2119 1362 y(/)595
1453 y(PyErr_Clear\(\);)595 1544 y(item)g(=)h(PyInt_FromLong\(0L\);)595
1636 y(if)f(\(item)g(==)h(NULL\))774 1727 y(goto)f(error;)416
1818 y(})416 1910 y(const_one)f(=)i(PyInt_FromLong\(1L\);)416
2001 y(if)f(\(const_one)f(==)i(NULL\))595 2092 y(goto)f(error;)416
2275 y(incremented_item)e(=)i(PyNumber_Add\(item,)e(const_one\);)416
2366 y(if)i(\(incremented_item)e(==)j(NULL\))595 2457
y(goto)f(error;)416 2640 y(if)g(\(PyObject_SetItem\(dict,)d(key,)j
(incremented_item\))e(<)j(0\))595 2731 y(goto)f(error;)416
2823 y(rv)g(=)h(0;)f(/)819 2836 y(*)909 2823 y(Success)1267
2836 y(*)1312 2823 y(/)416 2914 y(/)461 2927 y(*)550
2914 y(Continue)g(with)g(cleanup)f(code)1761 2927 y(*)1806
2914 y(/)281 3097 y(error:)416 3188 y(/)461 3201 y(*)550
3188 y(Cleanup)h(code,)g(shared)g(by)g(success)g(and)g(failure)g(path)
2747 3201 y(*)2792 3188 y(/)416 3371 y(/)461 3384 y(*)550
3371 y(Use)g(Py_XDECREF\(\))f(to)i(ignore)f(NULL)g(references)2478
3384 y(*)2523 3371 y(/)416 3462 y(Py_XDECREF\(item\);)416
3553 y(Py_XDECREF\(const_one\);)416 3645 y
(Py_XDECREF\(incremented_item\);)416 3827 y(return)f(rv;)i(/)954
3840 y(*)1043 3827 y(-1)g(for)f(error,)g(0)h(for)f(success)2298
3840 y(*)2343 3827 y(/)236 3919 y(})0 4248 y Fr(This)j(e)o(xample)f
(represents)g(an)h(endorsed)e(use)i(of)g(the)g Fj(goto)f
Fr(statement)h(in)g(C!)h(It)f(illustrates)g(the)g(use)h(of)e
Fj(PyErr_-)0 4348 y(ExceptionMatches\(\))26 b Fr(and)i
Fj(PyErr_Clear\(\))f Fr(to)h(handle)g(speci\002c)h(e)o(xceptions,)f
(and)g(the)h(use)g(of)f Fj(Py_XDECREF\(\))0 4447 y Fr(to)21
b(dispose)g(of)f(o)n(wned)g(references)g(that)h(may)f(be)h
Fj(NULL)g Fr(\(note)f(the)h(`)p Fj(X)p Fr(')f(in)h(the)g(name;)g
Fj(Py_DECREF\(\))e Fr(w)o(ould)i(crash)f(when)g(con-)0
4547 y(fronted)c(with)h(a)h Fj(NULL)f Fr(reference\).)22
b(It)17 b(is)h(important)e(that)h(the)g(v)n(ariables)g(used)g(to)g
(hold)f(o)n(wned)h(references)e(are)j(initialized)e(to)i
Fj(NULL)0 4647 y Fr(for)i(this)i(to)f(w)o(ork;)g(lik)o(e)n(wise,)g(the)
g(proposed)e(return)g(v)n(alue)i(is)h(initialized)e(to)h
Fj(-1)g Fr(\(f)o(ailure\))f(and)g(only)h(set)g(to)g(success)h(after)e
(the)h(\002nal)0 4746 y(call)g(made)e(is)i(successful.)0
5068 y Fl(1.4)121 b(Embedding)35 b(Python)0 5300 y Fr(The)20
b(one)g(important)f(task)i(that)g(only)f(embedders)f(\(as)i(opposed)e
(to)i(e)o(xtension)e(writers\))h(of)h(the)f(Python)g(interpreter)f(ha)n
(v)o(e)h(to)h(w)o(orry)0 5400 y(about)f(is)h(the)g(initialization,)f
(and)g(possibly)g(the)h(\002nalization,)f(of)g(the)h(Python)e
(interpreter)-5 b(.)26 b(Most)21 b(functionality)d(of)j(the)f
(interpreter)p 0 5549 3901 4 v 0 5649 a Fn(1.4.)52 b(Embedding)25
b(Python)2963 b(7)p eop end
%%Page: 8 14
TeXDict begin 8 13 bop 0 83 a Fr(can)20 b(only)f(be)h(used)g(after)g
(the)g(interpreter)f(has)h(been)g(initialized.)0 230
y(The)f(basic)g(initialization)g(function)e(is)k Fj(Py_Initialize\(\))p
Fr(.)h(This)d(initializes)h(the)f(table)g(of)g(loaded)g(modules,)f(and)
g(creates)i(the)0 330 y(fundamental)j(modules)i Fj(__builtin__)p
Fr(,)h Fj(__main__)p Fr(,)g Fj(sys)p Fr(,)h(and)e Fj(exceptions)p
Fr(.)40 b(It)26 b(also)g(initializes)h(the)f(module)e(search)0
429 y(path)c(\()p Fj(sys.path)p Fr(\).)0 576 y Fj(Py_Initialize\(\))f
Fr(does)h(not)h(set)g(the)g(\223script)g(ar)o(gument)d(list\224)k(\()p
Fj(sys.argv)p Fr(\).)j(If)c(this)g(v)n(ariable)f(is)i(needed)d(by)i
(Python)e(code)0 676 y(that)i(will)h(be)f(e)o(x)o(ecuted)f(later)m(,)h
(it)h(must)f(be)g(set)h(e)o(xplicitly)e(with)i(a)g(call)f(to)h
Fj(PySys_SetArgv\()p Fo(ar)m(gc)p Fj(,)46 b Fo(ar)m(gv)p
Fj(\))20 b Fr(subsequent)g(to)i(the)0 775 y(call)f(to)f
Fj(Py_Initialize\(\))p Fr(.)0 922 y(On)46 b(most)h(systems)g(\(in)f
(particular)m(,)51 b(on)d(U)t Fi(N)t(I)t(X)i Fr(and)c(W)m(indo)n(ws,)52
b(although)44 b(the)j(details)g(are)f(slightly)g(dif)n(ferent\),)51
b Fj(Py_-)0 1022 y(Initialize\(\))19 b Fr(calculates)i(the)g(module)e
(search)i(path)f(based)h(upon)e(its)j(best)f(guess)g(for)g(the)g
(location)e(of)i(the)g(standard)f(Python)0 1121 y(interpreter)i(e)o(x)o
(ecutable,)g(assuming)h(that)g(the)h(Python)e(library)g(is)j(found)c
(in)j(a)g(\002x)o(ed)f(location)f(relati)n(v)o(e)h(to)g(the)h(Python)e
(interpreter)0 1221 y(e)o(x)o(ecutable.)57 b(In)31 b(particular)m(,)h
(it)g(looks)f(for)g(a)h(directory)d(named)h(`)p Fs(lib/p)n(ython2.5)p
Fr(')d(relati)n(v)o(e)k(to)g(the)h(parent)e(directory)g(where)h(the)0
1321 y(e)o(x)o(ecutable)18 b(named)h(`)p Fs(p)n(ython)p
Fr(')f(is)k(found)c(on)i(the)g(shell)h(command)d(search)i(path)f(\(the)
h(en)m(vironment)d(v)n(ariable)i(P)-8 b(A)f(TH\).)0 1468
y(F)o(or)35 b(instance,)j(if)e(the)f(Python)g(e)o(x)o(ecutable)e(is)j
(found)e(in)h(`)p Fs(/usr/local/bin/p)n(ython)p Fr(',)e(it)j(will)g
(assume)f(that)h(the)f(libraries)g(are)g(in)0 1567 y(`)p
Fs(/usr/local/lib/p)n(ython2)o(.5)p Fr(')o(.)46 b(\(In)28
b(f)o(act,)j(this)e(particular)f(path)g(is)i(also)f(the)g(\223f)o
(allback\224)f(location,)i(used)e(when)h(no)f(e)o(x)o(ecutable)f
(\002le)0 1667 y(named)34 b(`)p Fs(p)n(ython)p Fr(')e(is)k(found)d
(along)h(P)-8 b(A)f(TH.\))35 b(The)f(user)h(can)g(o)o(v)o(erride)d
(this)k(beha)n(vior)d(by)h(setting)h(the)g(en)m(vironment)d(v)n
(ariable)0 1766 y(PYTHONHOME,)20 b(or)f(insert)i(additional)e
(directories)g(in)h(front)f(of)h(the)g(standard)f(path)h(by)g(setting)g
(PYTHONP)-8 b(A)f(TH.)0 1913 y(The)37 b(embedding)e(application)h(can)h
(steer)h(the)g(search)f(by)g(calling)g Fj(Py_SetProgramName\()p
Fo(\002le)p Fj(\))d Fo(befor)m(e)j Fr(calling)g Fj(Py_-)0
2013 y(Initialize\(\))p Fr(.)76 b(Note)38 b(that)g(PYTHONHOME)f(still)i
(o)o(v)o(errides)d(this)i(and)f(PYTHONP)-8 b(A)f(TH)38
b(is)h(still)g(inserted)e(in)h(front)0 2113 y(of)33 b(the)g(standard)f
(path.)63 b(An)33 b(application)f(that)h(requires)f(total)h(control)f
(has)h(to)g(pro)o(vide)e(its)k(o)n(wn)d(implementation)f(of)i
Fj(Py_-)0 2212 y(GetPath\(\))p Fr(,)28 b Fj(Py_GetPrefix\(\))p
Fr(,)f Fj(Py_GetExecPrefix\(\))p Fr(,)g(and)g Fj
(Py_GetProgramFullPath\(\))d Fr(\(all)k(de\002ned)0 2312
y(in)20 b(`)p Fs(Modules/getpath.c)p Fr('\).)0 2459 y(Sometimes,)f(it)i
(is)g(desirable)e(to)h(\223uninitialize\224)e(Python.)24
b(F)o(or)19 b(instance,)h(the)g(application)e(may)h(w)o(ant)h(to)g
(start)h(o)o(v)o(er)d(\(mak)o(e)h(another)0 2558 y(call)h(to)g
Fj(Py_Initialize\(\))p Fr(\))d(or)i(the)g(application)f(is)j(simply)e
(done)g(with)g(its)i(use)f(of)f(Python)f(and)h(w)o(ants)h(to)g(free)f
(memory)f(allo-)0 2658 y(cated)23 b(by)g(Python.)33 b(This)23
b(can)g(be)h(accomplished)d(by)i(calling)g Fj(Py_Finalize\(\))p
Fr(.)32 b(The)23 b(function)e Fj(Py_IsInitialized\(\))0
2758 y Fr(returns)j(true)h(if)h(Python)e(is)i(currently)e(in)h(the)h
(initialized)f(state.)41 b(More)24 b(information)f(about)i(these)g
(functions)f(is)i(gi)n(v)o(en)e(in)i(a)f(later)0 2857
y(chapter)-5 b(.)55 b(Notice)31 b(that)f Fj(Py_Finalize)f
Fr(does)h Fo(not)g Fr(free)h(all)g(memory)d(allocated)i(by)g(the)h
(Python)e(interpreter)m(,)i(e.g.)55 b(memory)0 2957 y(allocated)19
b(by)h(e)o(xtension)f(modules)g(currently)g(cannot)g(be)h(released.)0
3278 y Fl(1.5)121 b(Deb)n(ugging)36 b(Builds)0 3511 y
Fr(Python)17 b(can)i(be)f(b)n(uilt)h(with)g(se)n(v)o(eral)f(macros)f
(to)i(enable)f(e)o(xtra)g(checks)g(of)g(the)g(interpreter)f(and)h(e)o
(xtension)f(modules.)24 b(These)18 b(checks)0 3610 y(tend)i(to)g(add)g
(a)g(lar)o(ge)g(amount)e(of)i(o)o(v)o(erhead)e(to)i(the)g(runtime)f(so)
i(the)o(y)e(are)i(not)e(enabled)g(by)h(def)o(ault.)0
3757 y(A)26 b(full)f(list)i(of)e(the)h(v)n(arious)e(types)h(of)h(deb)n
(ugging)d(b)n(uilds)i(is)h(in)g(the)g(\002le)g(`)p Fs
(Misc/SpecialBuilds)o(.txt)p Fr(')21 b(in)26 b(the)g(Python)e(source)h
(distri-)0 3857 y(b)n(ution.)42 b(Builds)27 b(are)f(a)n(v)n(ailable)g
(that)g(support)f(tracing)h(of)g(reference)e(counts,)j(deb)n(ugging)d
(the)i(memory)f(allocator)m(,)h(or)g(lo)n(w-le)n(v)o(el)0
3957 y(pro\002ling)20 b(of)g(the)h(main)g(interpreter)e(loop.)27
b(Only)20 b(the)h(most)g(frequently-used)d(b)n(uilds)j(will)g(be)g
(described)f(in)h(the)g(remainder)e(of)i(this)0 4056
y(section.)0 4203 y(Compiling)d(the)h(interpreter)f(with)h(the)h
Fj(Py_DEBUG)e Fr(macro)g(de\002ned)g(produces)g(what)h(is)h(generally)e
(meant)h(by)g(\224a)g(deb)n(ug)f(b)n(uild\224)h(of)0
4303 y(Python.)34 b Fj(Py_DEBUG)23 b Fr(is)h(enabled)e(in)i(the)i(U)t
Fi(N)t(I)t(X)g Fr(b)n(uild)e(by)f(adding)f Fp(--with-pydeb)n(ug)h
Fr(to)g(the)h(`)p Fs(con\002gure)p Fr(')e(command.)33
b(It)24 b(is)g(also)0 4402 y(implied)d(by)g(the)h(presence)e(of)i(the)f
(not-Python-speci\002c)e Fj(_DEBUG)i Fr(macro.)28 b(When)22
b Fj(Py_DEBUG)e Fr(is)j(enabled)d(in)i(the)i(U)t Fi(N)t(I)t(X)g
Fr(b)n(uild,)0 4502 y(compiler)19 b(optimization)f(is)k(disabled.)0
4649 y(In)e(addition)f(to)h(the)g(reference)f(count)g(deb)n(ugging)f
(described)h(belo)n(w)-5 b(,)19 b(the)h(follo)n(wing)e(e)o(xtra)i
(checks)f(are)i(performed:)125 4844 y Fq(\017)41 b Fr(Extra)19
b(checks)h(are)g(added)f(to)h(the)g(object)g(allocator)-5
b(.)125 4996 y Fq(\017)41 b Fr(Extra)19 b(checks)h(are)g(added)f(to)h
(the)g(parser)g(and)g(compiler)-5 b(.)125 5148 y Fq(\017)41
b Fr(Do)n(wncasts)20 b(from)f(wide)h(types)g(to)g(narro)n(w)f(types)h
(are)g(check)o(ed)f(for)h(loss)h(of)e(information.)125
5300 y Fq(\017)41 b Fr(A)20 b(number)f(of)h(assertions)g(are)g(added)f
(to)h(the)h(dictionary)d(and)i(set)h(implementations.)i(In)d(addition,)
e(the)j(set)g(object)e(acquires)208 5400 y(a)h Fj(test_c_api)f
Fr(method.)p 0 5549 3901 4 v 0 5649 a Fn(8)2958 b(Chapter)23
b(1.)52 b(Introduction)p eop end
%%Page: 9 15
TeXDict begin 9 14 bop 125 83 a Fq(\017)41 b Fr(Sanity)20
b(checks)f(of)h(the)g(input)g(ar)o(guments)e(are)i(added)f(to)h(frame)g
(creation.)125 249 y Fq(\017)41 b Fr(The)19 b(storage)h(for)f(long)h
(ints)h(is)g(initialized)f(with)g(a)h(kno)n(wn)d(in)m(v)n(alid)h
(pattern)g(to)i(catch)f(reference)e(to)j(uninitialized)d(digits.)125
415 y Fq(\017)41 b Fr(Lo)n(w-le)n(v)o(el)18 b(tracing)h(and)h(e)o(xtra)
g(e)o(xception)e(checking)g(are)i(added)f(to)i(the)f(runtime)f(virtual)
h(machine.)125 581 y Fq(\017)41 b Fr(Extra)19 b(checks)h(are)g(added)f
(to)h(the)g(memory)f(arena)g(implementation.)125 747
y Fq(\017)41 b Fr(Extra)19 b(deb)n(ugging)f(is)j(added)e(to)h(the)g
(thread)g(module.)0 977 y(There)f(may)h(be)g(additional)f(checks)h(not)
g(mentioned)e(here.)0 1124 y(De\002ning)23 b Fj(Py_TRACE_REFS)g
Fr(enables)g(reference)g(tracing.)36 b(When)24 b(de\002ned,)g(a)h
(circular)e(doubly)f(link)o(ed)i(list)h(of)f(acti)n(v)o(e)g(objects)0
1224 y(is)j(maintained)e(by)g(adding)g(tw)o(o)i(e)o(xtra)e(\002elds)i
(to)f(e)n(v)o(ery)f Fj(PyObject)p Fr(.)41 b(T)-7 b(otal)27
b(allocations)e(are)h(track)o(ed)f(as)i(well.)44 b(Upon)25
b(e)o(xit,)i(all)0 1323 y(e)o(xisting)18 b(references)g(are)h(printed.)
k(\(In)c(interacti)n(v)o(e)e(mode)h(this)i(happens)e(after)g(e)n(v)o
(ery)g(statement)h(run)f(by)h(the)g(interpreter)-5 b(.\))23
b(Implied)0 1423 y(by)d Fj(Py_DEBUG)p Fr(.)0 1570 y(Please)h(refer)e
(to)i(`)p Fs(Misc/SpecialBuilds)o(.txt)p Fr(')16 b(in)k(the)h(Python)e
(source)g(distrib)n(ution)g(for)h(more)f(detailed)h(information.)p
0 5549 3901 4 v 0 5649 a Fn(1.5.)52 b(Deb)n(ugging)25
b(Builds)3016 b(9)p eop end
%%Page: 10 16
TeXDict begin 10 15 bop 0 5549 3901 4 v 0 5649 a Fn(10)p
eop end
%%Page: 11 17
TeXDict begin 11 16 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3623
427 y Fm(TW)n(O)p 0 515 V 1429 978 a Fx(The)58 b(V)-17
b(er)6 b(y)57 b(High)h(Le)-6 b(v)h(el)56 b(La)-6 b(y)l(er)0
1468 y Fr(The)23 b(functions)g(in)h(this)g(chapter)f(will)h(let)h(you)d
(e)o(x)o(ecute)h(Python)f(source)i(code)f(gi)n(v)o(en)f(in)i(a)g
(\002le)h(or)e(a)h(b)n(uf)n(fer)m(,)f(b)n(ut)h(the)o(y)f(will)i(not)e
(let)0 1568 y(you)c(interact)h(in)g(a)h(more)e(detailed)h(w)o(ay)g
(with)h(the)f(interpreter)-5 b(.)0 1714 y(Se)n(v)o(eral)26
b(of)g(these)h(functions)e(accept)h(a)h(start)g(symbol)f(from)f(the)i
(grammar)e(as)i(a)g(parameter)-5 b(.)43 b(The)26 b(a)n(v)n(ailable)h
(start)g(symbols)f(are)0 1814 y Fj(Py_eval_input)p Fr(,)33
b Fj(Py_file_input)p Fr(,)f(and)g Fj(Py_single_input)p
Fr(.)58 b(These)31 b(are)h(described)f(follo)n(wing)f(the)i(functions)0
1914 y(which)20 b(accept)f(them)h(as)h(parameters.)0
2061 y(Note)30 b(also)g(that)g(se)n(v)o(eral)g(of)g(these)g(functions)e
(tak)o(e)j Fj(FILE)1783 2076 y(*)1862 2061 y Fr(parameters.)53
b(On)30 b(particular)f(issue)i(which)e(needs)h(to)g(be)g(handled)0
2160 y(carefully)25 b(is)h(that)g(the)g Fj(FILE)g Fr(structure)f(for)g
(dif)n(ferent)f(C)j(libraries)f(can)g(be)f(dif)n(ferent)g(and)g
(incompatible.)40 b(Under)25 b(W)m(indo)n(ws)g(\(at)0
2260 y(least\),)f(it)g(is)h(possible)e(for)g(dynamically)e(link)o(ed)i
(e)o(xtensions)f(to)h(actually)g(use)h(dif)n(ferent)d(libraries,)j(so)g
(care)f(should)f(be)i(tak)o(en)e(that)0 2359 y Fj(FILE)200
2374 y(*)269 2359 y Fr(parameters)d(are)g(only)g(passed)h(to)f(these)h
(functions)e(if)i(it)h(is)f(certain)f(that)h(the)o(y)f(were)h(created)f
(by)g(the)g(same)h(library)f(that)h(the)0 2459 y(Python)f(runtime)g(is)
i(using.)0 2606 y Fj(int)49 b Fg(Py_Main)p Fj(\()p Fo(int)19
b(ar)m(gc,)h(c)o(har)f(**ar)m(gv)p Fj(\))208 2706 y Fr(The)i(main)h
(program)d(for)j(the)f(standard)g(interpreter)-5 b(.)29
b(This)22 b(is)h(made)e(a)n(v)n(ailable)h(for)f(programs)f(which)h
(embed)g(Python.)29 b(The)208 2805 y Fo(ar)m(gc)g Fr(and)h
Fo(ar)m(gv)f Fr(parameters)g(should)g(be)h(prepared)e(e)o(xactly)h(as)i
(those)e(which)h(are)g(passed)g(to)g(a)g(C)h(program')-5
b(s)28 b Fj(main\(\))208 2905 y Fr(function.)22 b(It)d(is)g(important)e
(to)i(note)f(that)g(the)h(ar)o(gument)d(list)j(may)f(be)h(modi\002ed)e
(\(b)n(ut)h(the)h(contents)e(of)h(the)h(strings)f(pointed)f(to)208
3004 y(by)i(the)g(ar)o(gument)f(list)j(are)e(not\).)24
b(The)c(return)e(v)n(alue)h(will)h(be)g(the)g(inte)o(ger)e(passed)i(to)
g(the)f Fj(sys.exit\(\))g Fr(function,)f Fj(1)i Fr(if)g(the)208
3104 y(interpreter)e(e)o(xits)i(due)g(to)g(an)h(e)o(xception,)d(or)i
Fj(2)g Fr(if)h(the)f(parameter)e(list)k(does)e(not)g(represent)f(a)h(v)
n(alid)g(Python)f(command)f(line.)0 3251 y Fj(int)49
b Fg(PyRun_AnyFile)p Fj(\()p Fo(FILE)18 b(*fp,)h(const)h(c)o(har)g
(*\002lename)p Fj(\))208 3351 y Fr(This)h(is)i(a)f(simpli\002ed)f
(interf)o(ace)g(to)g Fj(PyRun_AnyFileExFlags\(\))d Fr(belo)n(w)-5
b(,)21 b(lea)n(ving)g Fo(closeit)i Fr(set)f(to)g Fj(0)g
Fr(and)f Fo(\003a)o(gs)g Fr(set)h(to)208 3450 y Fj(NULL)p
Fr(.)0 3597 y Fj(int)49 b Fg(PyRun_AnyFileFlags)p Fj(\()p
Fo(FILE)17 b(*fp,)i(const)h(c)o(har)g(*\002lename)o(,)e(PyCompilerFla)o
(gs)i(*\003a)o(gs)p Fj(\))208 3697 y Fr(This)g(is)h(a)g(simpli\002ed)f
(interf)o(ace)f(to)h Fj(PyRun_AnyFileExFlags\(\))d Fr(belo)n(w)-5
b(,)19 b(lea)n(ving)g(the)i Fo(closeit)h Fr(ar)o(gument)17
b(set)k(to)g Fj(0)p Fr(.)0 3844 y Fj(int)49 b Fg(PyRun_AnyFileEx)p
Fj(\()p Fo(FILE)17 b(*fp,)j(const)g(c)o(har)g(*\002lename)o(,)e(int)i
(closeit)q Fj(\))208 3943 y Fr(This)e(is)h(a)g(simpli\002ed)f(interf)o
(ace)g(to)g Fj(PyRun_AnyFileExFlags\(\))d Fr(belo)n(w)-5
b(,)17 b(lea)n(ving)h(the)g Fo(\003a)o(gs)g Fr(ar)o(gument)e(set)j(to)g
Fj(NULL)p Fr(.)0 4090 y Fj(int)49 b Fg(PyRun_AnyFileExFlags)p
Fj(\()p Fo(FILE)16 b(*fp,)k(const)g(c)o(har)g(*\002lename)o(,)e(int)j
(closeit,)f(PyCompilerFla)o(gs)f(*\003a)o(gs)p Fj(\))208
4190 y Fr(If)j Fo(fp)h Fr(refers)g(to)g(a)g(\002le)g(associated)g(with)
g(an)g(interacti)n(v)o(e)e(de)n(vice)h(\(console)g(or)g(terminal)h
(input)f(or)i(U)t Fi(N)t(I)t(X)i Fr(pseudo-terminal\),)208
4289 y(return)16 b(the)i(v)n(alue)g(of)f Fj(PyRun_InteractiveLoop\(\))p
Fr(,)e(otherwise)i(return)g(the)h(result)g(of)g Fj
(PyRun_SimpleFile\(\))p Fr(.)208 4389 y(If)i Fo(\002lename)f
Fr(is)i Fj(NULL)p Fr(,)f(this)g(function)f(uses)h Fj("???")g
Fr(as)h(the)f(\002lename.)0 4536 y Fj(int)49 b Fg(PyRun_SimpleString)p
Fj(\()p Fo(const)17 b(c)o(har)i(*command)r Fj(\))208
4635 y Fr(This)32 b(is)h(a)f(simpli\002ed)g(interf)o(ace)f(to)i
Fj(PyRun_SimpleStringFlags\(\))28 b Fr(belo)n(w)-5 b(,)33
b(lea)n(ving)f(the)g Fo(PyCompilerFla)o(gs*)208 4735
y Fr(ar)o(gument)17 b(set)k(to)g(NULL.)0 4882 y Fj(int)49
b Fg(PyRun_SimpleStringFlags)p Fj(\()p Fo(const)16 b(c)o(har)j
(*command,)f(PyCompilerFla)o(gs)i(*\003a)o(gs)p Fj(\))208
4982 y Fr(Ex)o(ecutes)f(the)i(Python)f(source)g(code)g(from)f
Fo(command)i Fr(in)g(the)g Fj(__main__)f Fr(module)f(according)g(to)i
(the)f Fo(\003a)o(gs)h Fr(ar)o(gument.)j(If)208 5081
y Fj(__main__)19 b Fr(does)h(not)g(already)f(e)o(xist,)h(it)h(is)g
(created.)j(Returns)c Fj(0)h Fr(on)e(success)i(or)f Fj(-1)g
Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised.)k(If)20
b(there)208 5181 y(w)o(as)h(an)f(error)m(,)e(there)i(is)h(no)f(w)o(ay)g
(to)g(get)h(the)f(e)o(xception)e(information.)23 b(F)o(or)c(the)i
(meaning)d(of)i Fo(\003a)o(gs)p Fr(,)g(see)h(belo)n(w)-5
b(.)0 5328 y Fj(int)49 b Fg(PyRun_SimpleFile)p Fj(\()p
Fo(FILE)17 b(*fp,)j(const)g(c)o(har)f(*\002lename)p Fj(\))p
0 5549 3901 4 v 3808 5649 a Fn(11)p eop end
%%Page: 12 18
TeXDict begin 12 17 bop 208 83 a Fr(This)25 b(is)h(a)g(simpli\002ed)e
(interf)o(ace)h(to)g Fj(PyRun_SimpleFileExFlags\(\))c
Fr(belo)n(w)-5 b(,)25 b(lea)n(ving)g Fo(closeit)i Fr(set)f(to)f
Fj(0)g Fr(and)g Fo(\003a)o(gs)208 183 y Fr(set)c(to)f
Fj(NULL)p Fr(.)0 330 y Fj(int)49 b Fg(PyRun_SimpleFileFlags)p
Fj(\()p Fo(FILE)16 b(*fp,)k(const)g(c)o(har)f(*\002lename)o(,)g
(PyCompilerFla)o(gs)g(*\003a)o(gs)p Fj(\))208 429 y Fr(This)h(is)h(a)g
(simpli\002ed)f(interf)o(ace)f(to)h Fj(PyRun_SimpleFileExFlags\(\))c
Fr(belo)n(w)-5 b(,)19 b(lea)n(ving)h Fo(closeit)i Fr(set)f(to)f
Fj(0)p Fr(.)0 576 y Fj(int)49 b Fg(PyRun_SimpleFileEx)p
Fj(\()p Fo(FILE)17 b(*fp,)i(const)h(c)o(har)g(*\002lename)o(,)e(int)j
(closeit)q Fj(\))208 676 y Fr(This)f(is)h(a)g(simpli\002ed)f(interf)o
(ace)f(to)h Fj(PyRun_SimpleFileExFlags\(\))c Fr(belo)n(w)-5
b(,)19 b(lea)n(ving)h Fo(\003a)o(gs)g Fr(set)h(to)f Fj(NULL)p
Fr(.)0 823 y Fj(int)49 b Fg(PyRun_SimpleFileExFlags)p
Fj(\()p Fo(FILE)16 b(*fp,)j(const)h(c)o(har)g(*\002lename)o(,)f(int)h
(closeit,)g(PyCompilerFla)o(gs)g(*\003a)o(gs)p Fj(\))208
922 y Fr(Similar)26 b(to)g Fj(PyRun_SimpleStringFlags\(\))p
Fr(,)e(b)n(ut)i(the)g(Python)f(source)h(code)f(is)i(read)f(from)f
Fo(fp)i Fr(instead)f(of)g(an)g(in-)208 1022 y(memory)g(string.)50
b Fo(\002lename)27 b Fr(should)g(be)i(the)f(name)g(of)g(the)h(\002le.)
50 b(If)29 b Fo(closeit)h Fr(is)f(true,)h(the)f(\002le)g(is)g(closed)f
(before)f(PyRun)p 3848 1022 25 4 v 29 w(-)208 1121 y(SimpleFileExFlags)
19 b(returns.)0 1268 y Fj(int)49 b Fg(PyRun_InteractiveOne)p
Fj(\()p Fo(FILE)16 b(*fp,)k(const)g(c)o(har)g(*\002lename)p
Fj(\))208 1368 y Fr(This)g(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(PyRun_InteractiveOneFlags\(\))c Fr(belo)n(w)-5 b(,)19
b(lea)n(ving)g Fo(\003a)o(gs)h Fr(set)h(to)g Fj(NULL)p
Fr(.)0 1515 y Fj(int)49 b Fg(PyRun_InteractiveOneFlags)p
Fj(\()p Fo(FILE)15 b(*fp,)20 b(const)g(c)o(har)g(*\002lename)o(,)e
(PyCompilerFla)o(gs)h(*\003a)o(gs)p Fj(\))208 1614 y
Fr(Read)f(and)g(e)o(x)o(ecute)f(a)i(single)f(statement)g(from)g(a)g
(\002le)h(associated)g(with)f(an)g(interacti)n(v)o(e)g(de)n(vice)f
(according)f(to)j(the)f Fo(\003a)o(gs)g Fr(ar)o(gu-)208
1714 y(ment.)25 b(If)c Fo(\002lename)e Fr(is)i Fj(NULL)p
Fr(,)f Fj("???")h Fr(is)g(used)f(instead.)26 b(The)20
b(user)h(will)g(be)f(prompted)f(using)h Fj(sys.ps1)g
Fr(and)g Fj(sys.ps2)p Fr(.)208 1814 y(Returns)25 b Fj(0)h
Fr(when)e(the)i(input)f(w)o(as)h(e)o(x)o(ecuted)d(successfully)-5
b(,)26 b Fj(-1)g Fr(if)f(there)g(w)o(as)i(an)e(e)o(xception,)g(or)g(an)
g(error)f(code)h(from)g(the)208 1913 y(`)p Fs(errcode)o(.h)p
Fr(')g(include)i(\002le)i(distrib)n(uted)e(as)i(part)f(of)f(Python)g
(if)i(there)e(w)o(as)i(a)g(parse)f(error)-5 b(.)48 b(\(Note)27
b(that)h(`)p Fs(errcode)o(.h)p Fr(')e(is)j(not)208 2013
y(included)18 b(by)i(`)p Fs(Python.h)p Fr(',)e(so)i(must)h(be)f
(included)e(speci\002cally)i(if)h(needed.\))0 2160 y
Fj(int)49 b Fg(PyRun_InteractiveLoop)p Fj(\()p Fo(FILE)16
b(*fp,)k(const)g(c)o(har)f(*\002lename)p Fj(\))208 2259
y Fr(This)h(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(PyRun_InteractiveLoopFlags\(\))c Fr(belo)n(w)-5 b(,)19
b(lea)n(ving)g Fo(\003a)o(gs)h Fr(set)h(to)f Fj(NULL)p
Fr(.)0 2406 y Fj(int)49 b Fg(PyRun_InteractiveLoopFlags)p
Fj(\()p Fo(FILE)15 b(*fp,)20 b(const)g(c)o(har)g(*\002lename)o(,)e
(PyCompilerFla)o(gs)h(*\003a)o(gs)p Fj(\))208 2506 y
Fr(Read)j(and)h(e)o(x)o(ecute)e(statements)i(from)f(a)h(\002le)g
(associated)g(with)g(an)f(interacti)n(v)o(e)g(de)n(vice)g(until)i
Fi(E)t(O)t(F)h Fr(is)f(reached.)31 b(If)23 b Fo(\002lename)208
2606 y Fr(is)d Fj(NULL)p Fr(,)e Fj("???")h Fr(is)h(used)f(instead.)25
b(The)19 b(user)g(will)h(be)f(prompted)e(using)h Fj(sys.ps1)h
Fr(and)f Fj(sys.ps2)p Fr(.)24 b(Returns)19 b Fj(0)h Fr(at)i
Fi(E)t(O)t(F)r Fr(.)0 2752 y Fj(struct)49 b(_node)599
2767 y(*)697 2752 y Fg(PyParser_SimpleParseString)p Fj(\()p
Fo(const)15 b(c)o(har)20 b(*str)-9 b(,)21 b(int)f(start)q
Fj(\))208 2852 y Fr(This)32 b(is)h(a)g(simpli\002ed)f(interf)o(ace)f
(to)h Fj(PyParser_SimpleParseStringFlagsFilen)o(ame\(\))26
b Fr(belo)n(w)-5 b(,)34 b(lea)n(ving)208 2952 y Fo(\002lename)19
b Fr(set)i(to)f Fj(NULL)g Fr(and)g Fo(\003a)o(gs)f Fr(set)i(to)g
Fj(0)p Fr(.)0 3099 y Fj(struct)49 b(_node)599 3114 y(*)697
3099 y Fg(PyParser_SimpleParseStringFlags)p Fj(\()15
b Fo(const)20 b(c)o(har)g(*str)-9 b(,)20 b(int)h(start,)g(int)f(\003a)o
(gs)p Fj(\))208 3198 y Fr(This)32 b(is)h(a)g(simpli\002ed)f(interf)o
(ace)f(to)h Fj(PyParser_SimpleParseStringFlagsFilen)o(ame\(\))26
b Fr(belo)n(w)-5 b(,)34 b(lea)n(ving)208 3298 y Fo(\002lename)19
b Fr(set)i(to)f Fj(NULL)p Fr(.)0 3445 y Fj(struct)49
b(_node)599 3460 y(*)697 3445 y Fg
(PyParser_SimpleParseStringFlagsFilena)o(me)p Fj(\()34
b Fo(const)40 b(c)o(har)f(*str)-9 b(,)45 b(const)39 b(c)o(har)g
(*\002le-)2696 3544 y(n)o(ame)o(,)14 b(int)21 b(start,)g(int)f(\003a)o
(gs)p Fj(\))208 3627 y Fr(P)o(arse)25 b(Python)f(source)h(code)f(from)h
Fo(str)j Fr(using)d(the)g(start)h(tok)o(en)f Fo(start)i
Fr(according)d(to)h(the)h Fo(\003a)o(gs)e Fr(ar)o(gument.)38
b(The)25 b(result)h(can)208 3726 y(be)g(used)g(to)g(create)g(a)h(code)e
(object)h(which)f(can)h(be)h(e)n(v)n(aluated)d(ef)n(\002ciently)-5
b(.)42 b(This)26 b(is)i(useful)d(if)i(a)f(code)g(fragment)e(must)j(be)
208 3826 y(e)n(v)n(aluated)18 b(man)o(y)h(times.)0 3973
y Fj(struct)49 b(_node)599 3988 y(*)697 3973 y Fg
(PyParser_SimpleParseFile)p Fj(\()p Fo(FILE)16 b(*fp,)j(const)h(c)o
(har)g(*\002lename)o(,)f(int)h(start)q Fj(\))208 4072
y Fr(This)g(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(PyParser_SimpleParseFileFlags\(\))15 b Fr(belo)n(w)-5
b(,)19 b(lea)n(ving)h Fo(\003a)o(gs)f Fr(set)i(to)g Fj(0)0
4219 y(struct)49 b(_node)599 4234 y(*)697 4219 y Fg
(PyParser_SimpleParseFileFlags)p Fj(\()p Fo(FILE)15 b(*fp,)k(const)h(c)
o(har)g(*\002lename)o(,)f(int)h(start,)h(int)f(\003a)o(gs)p
Fj(\))208 4319 y Fr(Similar)33 b(to)g Fj
(PyParser_SimpleParseStringFlagsFilena)o(me\(\))p Fr(,)d(b)n(ut)k(the)f
(Python)f(source)g(code)h(is)h(read)208 4418 y(from)19
b Fo(fp)h Fr(instead)g(of)g(an)g(in-memory)e(string.)0
4565 y Fj(PyObject)400 4580 y(*)498 4565 y Fg(PyRun_String)p
Fj(\()p Fo(const)g(c)o(har)h(*str)-9 b(,)21 b(int)f(start,)h(PyObject)f
(*globals,)e(PyObject)i(*locals)p Fj(\))208 4665 y Fo(Return)f(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 4765 y Fr(This)g(is)h(a)g
(simpli\002ed)f(interf)o(ace)f(to)h Fj(PyRun_StringFlags\(\))d
Fr(belo)n(w)-5 b(,)19 b(lea)n(ving)h Fo(\003a)o(gs)g
Fr(set)h(to)f Fj(NULL)p Fr(.)0 4911 y Fj(PyObject)400
4926 y(*)498 4911 y Fg(PyRun_StringFlags)p Fj(\()p Fo(const)h(c)o(har)k
(*str)-9 b(,)26 b(int)f(start,)h(PyObject)f(*globals,)f(PyObject)g
(*locals,)h(PyCompil-)1398 5011 y(erFla)o(gs)17 b(*\003a)o(gs)p
Fj(\))208 5094 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 5194 y Fr(Ex)o(ecute)26 b(Python)g(source)h(code)g(from)g
Fo(str)j Fr(in)e(the)g(conte)o(xt)e(speci\002ed)h(by)g(the)h
(dictionaries)f Fo(globals)f Fr(and)h Fo(locals)h Fr(with)g(the)208
5294 y(compiler)21 b(\003ags)j(speci\002ed)f(by)g Fo(\003a)o(gs)p
Fr(.)33 b(The)23 b(parameter)f Fo(start)j Fr(speci\002es)f(the)f(start)
h(tok)o(en)f(that)g(should)f(be)h(used)g(to)h(parse)f(the)208
5393 y(source)c(code.)p 0 5549 3901 4 v 0 5649 a Fn(12)2376
b(Chapter)23 b(2.)52 b(The)23 b(V)-7 b(er)r(y)24 b(High)g(Le)n(v)n(el)e
(La)n(y)n(er)p eop end
%%Page: 13 19
TeXDict begin 13 18 bop 208 83 a Fr(Returns)20 b(the)g(result)g(of)g(e)
o(x)o(ecuting)e(the)i(code)g(as)h(a)f(Python)f(object,)h(or)g
Fj(NULL)g Fr(if)g(an)g(e)o(xception)f(w)o(as)i(raised.)0
230 y Fj(PyObject)400 245 y(*)498 230 y Fg(PyRun_File)p
Fj(\()p Fo(FILE)d(*fp,)i(const)g(c)o(har)f(*\002lename)o(,)g(int)h
(start,)h(PyObject)f(*globals,)e(PyObject)i(*locals)p
Fj(\))208 330 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 429 y Fr(This)c(is)h(a)f(simpli\002ed)g(interf)o(ace)f(to)h
Fj(PyRun_FileExFlags\(\))d Fr(belo)n(w)-5 b(,)16 b(lea)n(ving)f
Fo(closeit)j Fr(set)f(to)f Fj(0)h Fr(and)e Fo(\003a)o(gs)h
Fr(set)h(to)f Fj(NULL)p Fr(.)0 576 y Fj(PyObject)400
591 y(*)498 576 y Fg(PyRun_FileEx)p Fj(\()p Fo(FILE)j(*fp,)j(const)g(c)
o(har)f(*\002lename)o(,)g(int)h(start,)h(PyObject)f(*globals,)e
(PyObject)i(*locals,)f(int)1148 676 y(closeit)q Fj(\))208
751 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 851 y Fr(This)g(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(PyRun_FileExFlags\(\))d Fr(belo)n(w)-5 b(,)19 b(lea)n(ving)h
Fo(\003a)o(gs)g Fr(set)h(to)f Fj(NULL)p Fr(.)0 997 y
Fj(PyObject)400 1012 y(*)498 997 y Fg(PyRun_FileFlags)p
Fj(\()p Fo(FILE)15 b(*fp,)j(const)g(c)o(har)f(*\002lename)o(,)g(int)h
(start,)h(PyObject)f(*globals,)f(PyObject)g(*locals,)1298
1097 y(PyCompilerFla)o(gs)f(*\003a)o(gs)p Fj(\))208 1180
y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1280 y Fr(This)g(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(PyRun_FileExFlags\(\))d Fr(belo)n(w)-5 b(,)19 b(lea)n(ving)h
Fo(closeit)i Fr(set)f(to)f Fj(0)p Fr(.)0 1427 y Fj(PyObject)400
1442 y(*)498 1427 y Fg(PyRun_FileExFlags)p Fj(\()p Fo(FILE)d(*fp,)k
(const)g(c)o(har)f(*\002lename)o(,)f(int)i(start,)h(PyObject)e
(*globals,)g(PyObject)g(*lo-)1398 1526 y(cals,)d(int)j(closeit,)h
(PyCompilerFla)o(gs)e(*\003a)o(gs)p Fj(\))208 1610 y
Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208
1709 y Fr(Similar)27 b(to)h Fj(PyRun_StringFlags\(\))p
Fr(,)e(b)n(ut)i(the)g(Python)e(source)h(code)g(is)i(read)e(from)g
Fo(fp)h Fr(instead)f(of)g(an)h(in-memory)208 1809 y(string.)81
b Fo(\002lename)39 b Fr(should)f(be)h(the)g(name)g(of)g(the)g(\002le.)
83 b(If)39 b Fo(closeit)i Fr(is)g(true,)i(the)c(\002le)h(is)g(closed)f
(before)f Fj(PyRun_-)208 1909 y(FileExFlags\(\))18 b
Fr(returns.)0 2056 y Fj(PyObject)400 2071 y(*)498 2056
y Fg(Py_CompileString)p Fj(\()p Fo(const)f(c)o(har)j(*str)-9
b(,)20 b(const)g(c)o(har)g(*\002lename)o(,)e(int)j(start)q
Fj(\))208 2155 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2255 y Fr(This)g(is)h(a)g(simpli\002ed)f(interf)o(ace)f(to)h
Fj(Py_CompileStringFlags\(\))d Fr(belo)n(w)-5 b(,)19
b(lea)n(ving)g Fo(\003a)o(gs)h Fr(set)h(to)f Fj(NULL)p
Fr(.)0 2402 y Fj(PyObject)400 2417 y(*)498 2402 y Fg
(Py_CompileStringFlags)p Fj(\()p Fo(const)34 b(c)o(har)j(*str)-9
b(,)42 b(const)c(c)o(har)f(*\002lename)o(,)k(int)d(start,)k
(PyCompilerFla)o(gs)1598 2501 y(*\003a)o(gs)p Fj(\))208
2585 y Fo(Return)19 b(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2684 y Fr(P)o(arse)f(and)g(compile)g(the)h(Python)e(source)h
(code)g(in)h Fo(str)r Fr(,)h(returning)c(the)j(resulting)f(code)g
(object.)24 b(The)19 b(start)h(tok)o(en)f(is)i(gi)n(v)o(en)d(by)208
2784 y Fo(start)q Fr(;)28 b(this)d(can)f(be)h(used)f(to)g(constrain)g
(the)h(code)e(which)h(can)h(be)f(compiled)f(and)h(should)g(be)g
Fj(Py_eval_input)p Fr(,)g Fj(Py_-)208 2884 y(file_input)p
Fr(,)31 b(or)f Fj(Py_single_input)p Fr(.)52 b(The)30
b(\002lename)g(speci\002ed)g(by)g Fo(\002lename)f Fr(is)i(used)f(to)g
(construct)f(the)h(code)208 2983 y(object)c(and)g(may)h(appear)f(in)h
(tracebacks)f(or)g Fj(SyntaxError)g Fr(e)o(xception)f(messages.)45
b(This)27 b(returns)f Fj(NULL)h Fr(if)g(the)g(code)208
3083 y(cannot)19 b(be)h(parsed)f(or)h(compiled.)0 3230
y Fj(int)49 b Fg(Py_eval_input)208 3329 y Fr(The)19 b(start)i(symbol)e
(from)h(the)g(Python)f(grammar)f(for)i(isolated)g(e)o(xpressions;)f
(for)g(use)i(with)f Fj(Py_CompileString\(\))p Fr(.)0
3476 y Fj(int)49 b Fg(Py_file_input)208 3576 y Fr(The)21
b(start)i(symbol)e(from)g(the)h(Python)f(grammar)g(for)g(sequences)h
(of)f(statements)i(as)g(read)e(from)g(a)i(\002le)g(or)e(other)h
(source;)g(for)208 3675 y(use)h(with)g Fj(Py_CompileString\(\))p
Fr(.)32 b(This)23 b(is)h(the)g(symbol)e(to)h(use)h(when)e(compiling)g
(arbitrarily)g(long)g(Python)g(source)208 3775 y(code.)0
3922 y Fj(int)49 b Fg(Py_single_input)208 4021 y Fr(The)17
b(start)i(symbol)e(from)f(the)i(Python)f(grammar)f(for)i(a)g(single)g
(statement;)g(for)g(use)g(with)g Fj(Py_CompileString\(\))p
Fr(.)j(This)208 4121 y(is)g(the)f(symbol)f(used)h(for)g(the)g
(interacti)n(v)o(e)f(interpreter)f(loop.)0 4268 y Fg(struct)49
b(PyCompilerFlags)208 4368 y Fr(This)26 b(is)g(the)g(structure)f(used)h
(to)g(hold)f(compiler)g(\003ags.)42 b(In)26 b(cases)h(where)e(code)g
(is)i(only)e(being)g(compiled,)h(it)g(is)h(passed)f(as)208
4467 y Fj(int)49 b(flags)p Fr(,)25 b(and)g(in)g(cases)g(where)g(code)f
(is)i(being)e(e)o(x)o(ecuted,)f(it)j(is)g(passed)f(as)g
Fj(PyCompilerFlags)3471 4482 y(*)3521 4467 y(flags)p
Fr(.)39 b(In)208 4567 y(this)20 b(case,)h Fj(from)49
b(__future__)f(import)19 b Fr(can)h(modify)f Fo(\003a)o(gs)p
Fr(.)208 4696 y(Whene)n(v)o(er)e Fj(PyCompilerFlags)1362
4711 y(*)1412 4696 y(flags)i Fr(is)i Fj(NULL)p Fr(,)e
Fj(cf_flags)g Fr(is)h(treated)f(as)h(equal)f(to)h Fj(0)p
Fr(,)g(and)f(an)o(y)f(modi\002cation)208 4795 y(due)h(to)i
Fj(from)49 b(__future__)f(import)19 b Fr(is)i(discarded.)444
5015 y Fk(struct)44 b(PyCompilerFlags)e({)623 5107 y(int)i(cf_flags;)
444 5198 y(})0 5400 y Fj(int)49 b Fg(CO_FUTURE_DIVISION)p
0 5549 3901 4 v 3808 5649 a Fn(13)p eop end
%%Page: 14 20
TeXDict begin 14 19 bop 208 83 a Fr(This)18 b(bit)g(can)g(be)g(set)g
(in)h Fo(\003a)o(gs)e Fr(to)h(cause)g(di)n(vision)f(operator)f
Fj(/)j Fr(to)f(be)g(interpreted)e(as)j(\223true)e(di)n(vision\224)g
(according)f(to)i(PEP)h(238.)p 0 5549 3901 4 v 0 5649
a Fn(14)2376 b(Chapter)23 b(2.)52 b(The)23 b(V)-7 b(er)r(y)24
b(High)g(Le)n(v)n(el)e(La)n(y)n(er)p eop end
%%Page: 15 21
TeXDict begin 15 20 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3495
427 y Fm(THREE)p 0 515 V 2012 978 a Fx(Ref)-6 b(erence)57
b(Counting)0 1468 y Fr(The)20 b(macros)f(in)i(this)f(section)g(are)h
(used)e(for)h(managing)e(reference)h(counts)g(of)h(Python)f(objects.)0
1615 y Fj(void)49 b Fg(Py_INCREF)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 1714 y Fr(Increment)i(the)h(reference)g(count)f(for)i
(object)f Fo(o)p Fr(.)30 b(The)21 b(object)h(must)g(not)f(be)h
Fj(NULL)p Fr(;)g(if)g(you)f(aren')o(t)f(sure)i(that)g(it)g(isn')o(t)g
Fj(NULL)p Fr(,)208 1814 y(use)e Fj(Py_XINCREF\(\))p Fr(.)0
1961 y Fj(void)49 b Fg(Py_XINCREF)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 2061 y Fr(Increment)g(the)i(reference)f(count)g(for)g
(object)h Fo(o)p Fr(.)25 b(The)20 b(object)g(may)f(be)h
Fj(NULL)p Fr(,)g(in)h(which)e(case)i(the)f(macro)f(has)i(no)e(ef)n
(fect.)0 2207 y Fj(void)49 b Fg(Py_DECREF)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 2307 y Fr(Decrement)h(the)i(reference)d(count)i(for)g
(object)g Fo(o)p Fr(.)26 b(The)21 b(object)f(must)g(not)g(be)h
Fj(NULL)p Fr(;)f(if)h(you)f(aren')o(t)f(sure)i(that)f(it)i(isn')o(t)e
Fj(NULL)p Fr(,)208 2407 y(use)e Fj(Py_XDECREF\(\))p Fr(.)k(If)c(the)h
(reference)d(count)h(reaches)h(zero,)f(the)h(object')-5
b(s)18 b(type')-5 b(s)18 b(deallocation)f(function)f(\(which)i(must)208
2506 y(not)h(be)i Fj(NULL)p Fr(\))e(is)i(in)m(v)n(ok)o(ed.)208
2639 y Fp(W)-5 b(ar)o(ning:)26 b Fr(The)21 b(deallocation)e(function)h
(can)h(cause)g(arbitrary)e(Python)i(code)f(to)h(be)h(in)m(v)n(ok)o(ed)d
(\(e.g.)27 b(when)21 b(a)h(class)g(instance)208 2739
y(with)j(a)h Fj(__del__\(\))f Fr(method)f(is)i(deallocated\).)39
b(While)26 b(e)o(xceptions)e(in)i(such)f(code)g(are)g(not)g
(propagated,)f(the)h(e)o(x)o(ecuted)208 2838 y(code)d(has)i(free)f
(access)h(to)f(all)h(Python)e(global)h(v)n(ariables.)33
b(This)24 b(means)f(that)g(an)o(y)g(object)g(that)g(is)h(reachable)e
(from)h(a)g(global)208 2938 y(v)n(ariable)17 b(should)g(be)h(in)h(a)g
(consistent)f(state)h(before)e Fj(Py_DECREF\(\))g Fr(is)i(in)m(v)n(ok)o
(ed.)j(F)o(or)c(e)o(xample,)f(code)h(to)h(delete)f(an)g(object)208
3038 y(from)k(a)h(list)i(should)d(cop)o(y)h(a)g(reference)f(to)h(the)h
(deleted)e(object)h(in)g(a)h(temporary)d(v)n(ariable,)i(update)f(the)h
(list)i(data)e(structure,)208 3137 y(and)c(then)h(call)h
Fj(Py_DECREF\(\))d Fr(for)i(the)g(temporary)e(v)n(ariable.)0
3284 y Fj(void)49 b Fg(Py_XDECREF)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 3384 y Fr(Decrement)k(the)i(reference)e(count)h(for)g
(object)g Fo(o)p Fr(.)36 b(The)24 b(object)f(may)g(be)h
Fj(NULL)p Fr(,)f(in)h(which)g(case)g(the)g(macro)f(has)h(no)f(ef)n
(fect;)208 3483 y(otherwise)c(the)h(ef)n(fect)g(is)h(the)f(same)h(as)g
(for)e Fj(Py_DECREF\(\))p Fr(,)g(and)g(the)h(same)h(w)o(arning)e
(applies.)0 3630 y Fj(void)49 b Fg(Py_CLEAR)p Fj(\()p
Fo(PyObject)18 b(*o)p Fj(\))208 3730 y Fr(Decrement)k(the)i(reference)e
(count)h(for)g(object)g Fo(o)p Fr(.)36 b(The)24 b(object)f(may)g(be)h
Fj(NULL)p Fr(,)f(in)h(which)g(case)g(the)g(macro)f(has)h(no)f(ef)n
(fect;)208 3829 y(otherwise)30 b(the)h(ef)n(fect)f(is)i(the)f(same)g
(as)h(for)f Fj(Py_DECREF\(\))p Fr(,)g(e)o(xcept)f(that)i(the)f(ar)o
(gument)d(is)k(also)f(set)h(to)f Fj(NULL)p Fr(.)g(The)208
3929 y(w)o(arning)20 b(for)g Fj(Py_DECREF\(\))g Fr(does)h(not)h(apply)e
(with)h(respect)h(to)f(the)g(object)g(passed)h(because)e(the)i(macro)e
(carefully)g(uses)208 4029 y(a)g(temporary)e(v)n(ariable)h(and)h(sets)h
(the)f(ar)o(gument)e(to)j Fj(NULL)p Fr(before)d(decrementing)f(its)k
(reference)e(count.)208 4162 y(It)h(is)g(a)g(good)f(idea)g(to)h(use)g
(this)g(macro)f(whene)n(v)o(er)f(decrementing)f(the)j(v)n(alue)f(of)g
(a)h(v)n(ariable)f(that)h(might)f(be)h(tra)n(v)o(ersed)e(during)208
4261 y(garbage)g(collection.)208 4394 y(Ne)n(w)i(in)g(v)o(ersion)f
(2.4.)0 4541 y(The)32 b(follo)n(wing)f(functions)h(are)g(for)g(runtime)
g(dynamic)f(embedding)f(of)j(Python:)49 b Fj(Py_IncRef\(PyObject)3494
4556 y(*)3544 4541 y(o\))p Fr(,)36 b Fj(Py_-)0 4641 y(DecRef\(PyObject)
797 4656 y(*)847 4641 y(o\))p Fr(.)24 b(The)o(y)17 b(are)g(simply)h(e)o
(xported)d(function)h(v)o(ersions)h(of)g Fj(Py_XINCREF\(\))f
Fr(and)h Fj(Py_XDECREF\(\))p Fr(,)0 4740 y(respecti)n(v)o(ely)-5
b(.)0 4887 y(The)42 b(follo)n(wing)f(functions)g(or)h(macros)f(are)h
(only)g(for)g(use)g(within)g(the)h(interpreter)d(core:)69
b Fj(_Py_Dealloc\(\))p Fr(,)46 b Fj(_Py_-)0 4987 y(ForgetReference\(\))
p Fr(,)17 b Fj(_Py_NewReference\(\))p Fr(,)g(as)k(well)g(as)g(the)f
(global)g(v)n(ariable)f Fj(_Py_RefTotal)p Fr(.)p 0 5549
3901 4 v 3808 5649 a Fn(15)p eop end
%%Page: 16 22
TeXDict begin 16 21 bop 0 5549 3901 4 v 0 5649 a Fn(16)p
eop end
%%Page: 17 23
TeXDict begin 17 22 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3561
427 y Fm(FOUR)p 0 515 V 2063 978 a Fx(Exception)58 b(Handling)0
1468 y Fr(The)22 b(functions)e(described)h(in)h(this)g(chapter)f(will)h
(let)h(you)e(handle)g(and)g(raise)h(Python)f(e)o(xceptions.)28
b(It)23 b(is)f(important)f(to)h(understand)0 1568 y(some)e(of)g(the)g
(basics)h(of)f(Python)f(e)o(xception)f(handling.)23 b(It)d(w)o(orks)g
(some)n(what)f(lik)o(e)i(the)h(U)t Fi(N)t(I)t(X)h Fj(errno)d
Fr(v)n(ariable:)k(there)c(is)h(a)f(global)0 1667 y(indicator)15
b(\(per)h(thread\))f(of)h(the)h(last)g(error)e(that)i(occurred.)22
b(Most)16 b(functions)g(don')o(t)e(clear)j(this)g(on)f(success,)h(b)n
(ut)g(will)g(set)g(it)h(to)e(indicate)0 1767 y(the)23
b(cause)h(of)f(the)g(error)g(on)g(f)o(ailure.)34 b(Most)23
b(functions)f(also)i(return)e(an)i(error)e(indicator)m(,)h(usually)f
Fj(NULL)i Fr(if)f(the)o(y)g(are)g(supposed)f(to)0 1866
y(return)f(a)h(pointer)m(,)e(or)i Fj(-1)g Fr(if)g(the)o(y)f(return)f
(an)i(inte)o(ger)f(\(e)o(xception:)26 b(the)c Fj(PyArg_)2404
1881 y(*)2454 1866 y(\(\))e Fr(functions)h(return)f Fj(1)i
Fr(for)g(success)g(and)f Fj(0)h Fr(for)0 1966 y(f)o(ailure\).)0
2113 y(When)31 b(a)g(function)e(must)j(f)o(ail)f(because)f(some)h
(function)e(it)j(called)f(f)o(ailed,)i(it)f(generally)d(doesn')o(t)h
(set)i(the)f(error)e(indicator;)36 b(the)0 2213 y(function)22
b(it)i(called)f(already)g(set)h(it.)35 b(It)24 b(is)h(responsible)d
(for)h(either)g(handling)e(the)j(error)e(and)h(clearing)f(the)i(e)o
(xception)d(or)j(returning)0 2312 y(after)29 b(cleaning)g(up)g(an)o(y)f
(resources)h(it)h(holds)f(\(such)g(as)i(object)e(references)f(or)h
(memory)f(allocations\);)33 b(it)d(should)f Fo(not)g
Fr(continue)0 2412 y(normally)23 b(if)h(it)h(is)g(not)f(prepared)e(to)i
(handle)f(the)i(error)-5 b(.)36 b(If)24 b(returning)e(due)i(to)g(an)g
(error)m(,)g(it)g(is)i(important)c(to)i(indicate)g(to)g(the)h(caller)0
2511 y(that)f(an)f(error)g(has)h(been)f(set.)36 b(If)23
b(the)h(error)f(is)h(not)f(handled)g(or)g(carefully)f(propagated,)g
(additional)g(calls)i(into)g(the)f(Python/C)g(API)0 2611
y(may)d(not)g(beha)n(v)o(e)f(as)h(intended)f(and)h(may)f(f)o(ail)i(in)f
(mysterious)g(w)o(ays.)0 2758 y(The)36 b(error)f(indicator)g(consists)i
(of)f(three)g(Python)f(objects)h(corresponding)d(to)110
b(the)37 b(Python)e(v)n(ariables)g Fj(sys.exc_type)p
Fr(,)0 2858 y Fj(sys.exc_value)23 b Fr(and)h Fj(sys.exc_traceback)p
Fr(.)35 b(API)25 b(functions)e(e)o(xist)i(to)g(interact)f(with)h(the)f
(error)g(indicator)f(in)i(v)n(arious)0 2957 y(w)o(ays.)g(There)20
b(is)h(a)f(separate)g(error)f(indicator)g(for)h(each)f(thread.)0
3104 y Fj(void)49 b Fg(PyErr_Print)p Fj(\(\))208 3204
y Fr(Print)19 b(a)i(standard)d(traceback)h(to)h Fj(sys.stderr)e
Fr(and)h(clear)h(the)g(error)f(indicator)-5 b(.)24 b(Call)c(this)h
(function)d(only)h(when)g(the)h(error)208 3303 y(indicator)e(is)k(set.)
j(\(Otherwise)20 b(it)h(will)g(cause)f(a)h(f)o(atal)f(error!\))0
3450 y Fj(PyObject)400 3465 y(*)498 3450 y Fg(PyErr_Occurred)p
Fj(\(\))208 3550 y Fo(Return)f(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 3649 y Fr(T)-6 b(est)28 b(whether)g(the)g
(error)f(indicator)g(is)i(set.)49 b(If)28 b(set,)j(return)c(the)h(e)o
(xception)f Fo(type)h Fr(\(the)g(\002rst)g(ar)o(gument)e(to)j(the)f
(last)h(call)f(to)208 3749 y(one)20 b(of)h(the)g Fj(PyErr_Set)1013
3764 y(*)1063 3749 y(\(\))e Fr(functions)g(or)i(to)g
Fj(PyErr_Restore\(\))p Fr(\).)k(If)c(not)f(set,)i(return)e
Fj(NULL)p Fr(.)g(Y)-9 b(ou)21 b(do)f(not)h(o)n(wn)f(a)208
3849 y(reference)f(to)j(the)f(return)g(v)n(alue,)g(so)g(you)g(do)g(not)
g(need)g(to)h Fj(Py_DECREF\(\))e Fr(it.)29 b Fp(Note:)e
Fr(Do)21 b(not)h(compare)d(the)j(return)e(v)n(alue)208
3948 y(to)j(a)g(speci\002c)g(e)o(xception;)g(use)g Fj
(PyErr_ExceptionMatches\(\))c Fr(instead,)k(sho)n(wn)f(belo)n(w)-5
b(.)32 b(\(The)23 b(comparison)e(could)208 4048 y(easily)i(f)o(ail)h
(since)f(the)g(e)o(xception)e(may)i(be)g(an)g(instance)g(instead)g(of)g
(a)g(class,)i(in)e(the)g(case)h(of)f(a)g(class)i(e)o(xception,)c(or)i
(it)h(may)208 4148 y(the)c(a)g(subclass)h(of)f(the)g(e)o(xpected)f(e)o
(xception.\))0 4294 y Fj(int)49 b Fg(PyErr_ExceptionMatches)p
Fj(\()p Fo(PyObject)16 b(*e)n(xc)p Fj(\))208 4394 y Fr(Equi)n(v)n
(alent)21 b(to)i(`)p Fj(PyErr_GivenExceptionMatches\(PyE)o(rr_Occ)o
(urred)o(\(\),)44 b Fo(e)n(xc)p Fj(\))p Fr('.)33 b(This)23
b(should)f(only)g(be)208 4494 y(called)e(when)f(an)h(e)o(xception)f(is)
i(actually)e(set;)i(a)g(memory)d(access)j(violation)e(will)i(occur)e
(if)i(no)f(e)o(xception)e(has)i(been)g(raised.)0 4641
y Fj(int)49 b Fg(PyErr_GivenExceptionMatches)p Fj(\()p
Fo(PyObject)15 b(*given,)k(PyObject)g(*e)n(xc)p Fj(\))208
4740 y Fr(Return)25 b(true)g(if)h(the)f Fo(given)g Fr(e)o(xception)f
(matches)h(the)h(e)o(xception)d(in)j Fo(e)n(xc)p Fr(.)42
b(If)25 b Fo(e)n(xc)h Fr(is)h(a)f(class)g(object,)g(this)g(also)g
(returns)f(true)208 4840 y(when)17 b Fo(given)g Fr(is)i(an)e(instance)h
(of)f(a)h(subclass.)25 b(If)17 b Fo(e)n(xc)i Fr(is)f(a)h(tuple,)e(all)i
(e)o(xceptions)d(in)i(the)g(tuple)f(\(and)g(recursi)n(v)o(ely)f(in)i
(subtuples\))208 4939 y(are)i(searched)f(for)g(a)i(match.)j(If)c
Fo(given)g Fr(is)h Fj(NULL)p Fr(,)f(a)h(memory)d(access)j(violation)e
(will)i(occur)-5 b(.)0 5086 y Fj(void)49 b Fg(PyErr_NormalizeException)
p Fj(\()p Fo(PyObject**)o(e)n(xc,)15 b(PyObject**val,)j(PyObject**tb)p
Fj(\))208 5186 y Fr(Under)e(certain)h(circumstances,)g(the)g(v)n(alues)
g(returned)f(by)h Fj(PyErr_Fetch\(\))f Fr(belo)n(w)h(can)g(be)g
(\223unnormalized\224,)e(meaning)208 5286 y(that)354
5301 y Fj(*)404 5286 y Fo(e)n(xc)21 b Fr(is)h(a)g(class)g(object)f(b)n
(ut)1204 5301 y Fj(*)1254 5286 y Fo(val)g Fr(is)h(not)f(an)g(instance)g
(of)g(the)g(same)h(class.)28 b(This)22 b(function)d(can)i(be)g(used)g
(to)h(instantiate)208 5385 y(the)29 b(class)g(in)h(that)f(case.)51
b(If)29 b(the)g(v)n(alues)g(are)g(already)e(normalized,)i(nothing)f
(happens.)50 b(The)28 b(delayed)g(normalization)f(is)p
0 5549 3901 4 v 3808 5649 a Fn(17)p eop end
%%Page: 18 24
TeXDict begin 18 23 bop 208 83 a Fr(implemented)18 b(to)i(impro)o(v)o
(e)e(performance.)0 230 y Fj(void)49 b Fg(PyErr_Clear)p
Fj(\(\))208 330 y Fr(Clear)20 b(the)g(error)f(indicator)-5
b(.)24 b(If)d(the)f(error)f(indicator)g(is)i(not)f(set,)g(there)g(is)h
(no)f(ef)n(fect.)0 476 y Fj(void)49 b Fg(PyErr_Fetch)p
Fj(\()p Fo(PyObject)18 b(**ptype)o(,)g(PyObject)i(**pvalue)o(,)e
(PyObject)h(**ptr)o(acebac)n(k)q Fj(\))208 576 y Fr(Retrie)n(v)o(e)i
(the)h(error)e(indicator)h(into)g(three)g(v)n(ariables)g(whose)h
(addresses)f(are)h(passed.)29 b(If)22 b(the)g(error)e(indicator)h(is)i
(not)e(set,)i(set)208 676 y(all)f(three)g(v)n(ariables)f(to)h
Fj(NULL)p Fr(.)g(If)g(it)g(is)h(set,)g(it)g(will)g(be)f(cleared)f(and)g
(you)h(o)n(wn)f(a)i(reference)d(to)i(each)g(object)f(retrie)n(v)o(ed.)
29 b(The)208 775 y(v)n(alue)c(and)h(traceback)g(object)g(may)g(be)g
Fj(NULL)h Fr(e)n(v)o(en)e(when)h(the)h(type)f(object)g(is)h(not.)44
b Fp(Note:)37 b Fr(This)27 b(function)e(is)i(normally)208
875 y(only)21 b(used)i(by)f(code)g(that)h(needs)f(to)h(handle)e(e)o
(xceptions)g(or)i(by)f(code)g(that)h(needs)f(to)h(sa)n(v)o(e)f(and)h
(restore)f(the)g(error)g(indicator)208 975 y(temporarily)-5
b(.)0 1121 y Fj(void)49 b Fg(PyErr_Restore)p Fj(\()p
Fo(PyObject)17 b(*type)o(,)j(PyObject)f(*value)o(,)g(PyObject)h(*tr)o
(acebac)n(k)q Fj(\))208 1221 y Fr(Set)g(the)f(error)g(indicator)f(from)
h(the)h(three)f(objects.)24 b(If)c(the)f(error)g(indicator)f(is)j
(already)d(set,)i(it)h(is)f(cleared)f(\002rst.)26 b(If)19
b(the)h(objects)208 1321 y(are)29 b Fj(NULL)p Fr(,)f(the)i(error)e
(indicator)g(is)i(cleared.)51 b(Do)29 b(not)g(pass)h(a)f
Fj(NULL)g Fr(type)g(and)g(non-)p Fj(NULL)e Fr(v)n(alue)h(or)h
(traceback.)51 b(The)208 1420 y(e)o(xception)24 b(type)i(should)g(be)h
(a)g(class.)45 b(Do)27 b(not)f(pass)h(an)g(in)m(v)n(alid)e(e)o
(xception)g(type)h(or)g(v)n(alue.)44 b(\(V)-5 b(iolating)25
b(these)i(rules)g(will)208 1520 y(cause)20 b(subtle)h(problems)f(later)
-5 b(.\))27 b(This)21 b(call)h(tak)o(es)f(a)o(w)o(ay)g(a)g(reference)f
(to)h(each)f(object:)27 b(you)20 b(must)h(o)n(wn)f(a)h(reference)f(to)h
(each)208 1620 y(object)f(before)f(the)i(call)g(and)f(after)g(the)h
(call)g(you)f(no)g(longer)g(o)n(wn)g(these)h(references.)k(\(If)20
b(you)g(don')o(t)f(understand)f(this,)j(don')o(t)208
1719 y(use)26 b(this)i(function.)42 b(I)27 b(w)o(arned)f(you.\))43
b Fp(Note:)37 b Fr(This)27 b(function)e(is)j(normally)d(only)h(used)g
(by)g(code)g(that)h(needs)f(to)h(sa)n(v)o(e)g(and)208
1819 y(restore)19 b(the)h(error)f(indicator)g(temporarily;)g(use)h
Fj(PyErr_Fetch\(\))e Fr(to)j(sa)n(v)o(e)f(the)g(current)f(e)o(xception)
f(state.)0 1966 y Fj(void)49 b Fg(PyErr_SetString)p Fj(\()p
Fo(PyObject)17 b(*type)o(,)i(const)h(c)o(har)g(*messa)o(g)o(e)p
Fj(\))208 2065 y Fr(This)26 b(is)g(the)g(most)g(common)e(w)o(ay)i(to)g
(set)h(the)e(error)g(indicator)-5 b(.)41 b(The)26 b(\002rst)g(ar)o
(gument)e(speci\002es)i(the)g(e)o(xception)e(type;)k(it)f(is)208
2165 y(normally)19 b(one)h(of)h(the)g(standard)f(e)o(xceptions,)f(e.g.)
27 b Fj(PyExc_RuntimeError)p Fr(.)d(Y)-9 b(ou)21 b(need)f(not)h
(increment)e(its)j(reference)208 2265 y(count.)i(The)19
b(second)h(ar)o(gument)e(is)j(an)f(error)f(message;)h(it)h(is)g(con)m
(v)o(erted)d(to)i(a)g(string)g(object.)0 2411 y Fj(void)49
b Fg(PyErr_SetObject)p Fj(\()p Fo(PyObject)17 b(*type)o(,)i(PyObject)h
(*value)p Fj(\))208 2511 y Fr(This)32 b(function)e(is)i(similar)g(to)g
Fj(PyErr_SetString\(\))e Fr(b)n(ut)i(lets)g(you)f(specify)g(an)h
(arbitrary)e(Python)h(object)g(for)h(the)208 2611 y(\223v)n(alue\224)19
b(of)h(the)g(e)o(xception.)0 2758 y Fj(PyObject)400 2773
y(*)498 2758 y Fg(PyErr_Format)p Fj(\()p Fo(PyObject)d(*e)n(xception,)i
(const)h(c)o(har)g(*format,)f(...)p Fj(\))208 2857 y
Fo(Return)g(value:)25 b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208
2957 y Fr(This)i(function)f(sets)j(the)e(error)g(indicator)f(and)h
(returns)g Fj(NULL)p Fr(.)g Fo(e)n(xception)g Fr(should)f(be)i(a)g
(Python)e(e)o(xception)g(\(class,)i(not)g(an)208 3056
y(instance\).)e Fo(format)c Fr(should)c(be)i(a)g(string,)g(containing)e
(format)h(codes,)h(similar)g(to)g Fj(printf\(\))p Fr(.)22
b(The)16 b Fj(width.precision)208 3156 y Fr(before)i(a)j(format)e(code)
h(is)h(parsed,)e(b)n(ut)h(the)g(width)g(part)g(is)h(ignored.)257
3365 y Fp(F)n(ormat)e(Characters)p 988 3395 4 100 v 99
w(T)-6 b(ype)p 1556 3395 V 393 w(Comment)p 208 3398 7488
4 v 257 3468 a Fj(\045\045)p 988 3498 4 100 v 683 w Fo(n/a)p
1556 3498 V 460 w Fr(The)20 b(literal)h(\045)g(character)-5
b(.)257 3567 y Fj(\045c)p 988 3597 V 683 w Fr(int)p 1556
3597 V 479 w(A)21 b(single)f(character)m(,)f(represented)f(as)j(an)f(C)
h(int.)257 3667 y Fj(\045d)p 988 3697 V 683 w Fr(int)p
1556 3697 V 479 w(Exactly)f(equi)n(v)n(alent)e(to)j Fj
(printf\("\045d"\))p Fr(.)257 3767 y Fj(\045u)p 988 3797
V 683 w Fr(unsigned)d(int)p 1556 3797 V 159 w(Exactly)i(equi)n(v)n
(alent)e(to)j Fj(printf\("\045u"\))p Fr(.)257 3866 y
Fj(\045ld)p 988 3896 V 633 w Fr(long)p 1556 3896 V 418
w(Exactly)f(equi)n(v)n(alent)e(to)j Fj(printf\("\045ld"\))p
Fr(.)257 3966 y Fj(\045lu)p 988 3996 V 633 w Fr(unsigned)d(long)p
1556 3996 V 98 w(Exactly)i(equi)n(v)n(alent)e(to)j Fj
(printf\("\045lu"\))p Fr(.)257 4066 y Fj(\045zd)p 988
4096 V 633 w Fr(Py)p 1133 4066 25 4 v 29 w(ssize)p 1323
4066 V 30 w(t)p 1556 4096 4 100 v 236 w(Exactly)f(equi)n(v)n(alent)e
(to)j Fj(printf\("\045zd"\))p Fr(.)257 4165 y Fj(\045zu)p
988 4195 V 633 w Fr(size)p 1174 4165 25 4 v 30 w(t)p
1556 4195 4 100 v 385 w(Exactly)f(equi)n(v)n(alent)e(to)j
Fj(printf\("\045zu"\))p Fr(.)257 4265 y Fj(\045i)p 988
4295 V 683 w Fr(int)p 1556 4295 V 479 w(Exactly)f(equi)n(v)n(alent)e
(to)j Fj(printf\("\045i"\))p Fr(.)257 4364 y Fj(\045x)p
988 4394 V 683 w Fr(int)p 1556 4394 V 479 w(Exactly)f(equi)n(v)n(alent)
e(to)j Fj(printf\("\045x"\))p Fr(.)257 4464 y Fj(\045s)p
988 4494 V 683 w Fr(char*)p 1556 4494 V 381 w(A)g(null-terminated)d(C)j
(character)e(array)-5 b(.)257 4564 y Fj(\045p)p 988 4594
V 683 w Fr(v)n(oid*)p 1556 4594 V 378 w(The)20 b(he)o(x)g
(representation)e(of)i(a)g(C)h(pointer)-5 b(.)24 b(Mostly)d(equi)n(v)n
(alent)d(to)i Fj(printf\("\045p"\))f Fr(e)o(xcept)g(that)h(it)h(is)g
(guaranteed)d(to)j(start)f(with)h(the)f(literal)g Fj(0x)h
Fr(re)o(gardless)d(of)i(what)h(the)f(platform')-5 b(s)19
b Fj(printf)g Fr(yields.)208 4690 y(An)j(unrecognized)d(format)j
(character)f(causes)i(all)g(the)g(rest)g(of)f(the)h(format)e(string)h
(to)h(be)g(copied)e(as-is)i(to)g(the)g(result)f(string,)208
4789 y(and)d(an)o(y)h(e)o(xtra)f(ar)o(guments)f(discarded.)0
4936 y Fj(void)49 b Fg(PyErr_SetNone)p Fj(\()p Fo(PyObject)17
b(*type)p Fj(\))208 5036 y Fr(This)j(is)h(a)g(shorthand)d(for)h(`)p
Fj(PyErr_SetObject\()p Fo(type)p Fj(,)46 b(Py_None\))p
Fr('.)0 5183 y Fj(int)j Fg(PyErr_BadArgument)p Fj(\(\))208
5282 y Fr(This)24 b(is)i(a)f(shorthand)d(for)i(`)p Fj
(PyErr_SetString\(PyExc_TypeError,)43 b Fo(messa)o(g)o(e)p
Fj(\))p Fr(',)25 b(where)f Fo(messa)o(g)o(e)h Fr(indicates)208
5382 y(that)20 b(a)g(b)n(uilt-in)g(operation)e(w)o(as)j(in)m(v)n(ok)o
(ed)e(with)h(an)g(ille)o(gal)g(ar)o(gument.)j(It)d(is)h(mostly)f(for)g
(internal)f(use.)p 0 5549 3901 4 v 0 5649 a Fn(18)2630
b(Chapter)24 b(4.)52 b(Exception)23 b(Handling)p eop
end
%%Page: 19 25
TeXDict begin 19 24 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyErr_NoMemory)p Fj(\(\))208 183 y Fo(Return)19
b(value:)25 b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208 282 y
Fr(This)16 b(is)g(a)g(shorthand)e(for)h(`)p Fj
(PyErr_SetNone\(PyExc_MemoryError\))p Fr(';)d(it)k(returns)f
Fj(NULL)g Fr(so)i(an)e(object)h(allocation)208 382 y(function)i(can)i
(write)g(`)p Fj(return)49 b(PyErr_NoMemory\(\);)p Fr(')17
b(when)j(it)g(runs)g(out)g(of)g(memory)-5 b(.)0 529 y
Fj(PyObject)400 544 y(*)498 529 y Fg(PyErr_SetFromErrno)p
Fj(\()p Fo(PyObject)16 b(*type)p Fj(\))208 628 y Fo(Return)j(value:)25
b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208 728 y Fr(This)c(is)i(a)e(con)m(v)o
(enience)e(function)h(to)h(raise)h(an)f(e)o(xception)f(when)h(a)h(C)g
(library)e(function)g(has)i(returned)d(an)j(error)e(and)h(set)h(the)g
(C)208 828 y(v)n(ariable)f Fj(errno)p Fr(.)24 b(It)19
b(constructs)f(a)h(tuple)f(object)g(whose)h(\002rst)g(item)g(is)h(the)e
(inte)o(ger)g Fj(errno)g Fr(v)n(alue)g(and)g(whose)h(second)e(item)208
927 y(is)22 b(the)g(corresponding)d(error)h(message)i(\(gotten)f(from)g
Fj(strerror\(\))p Fr(\),)f(and)h(then)h(calls)g(`)p Fj
(PyErr_SetObject\()p Fo(type)p Fj(,)208 1027 y Fo(object)q
Fj(\))p Fr('.)g(On)c(U)t Fi(N)t(I)t(X)r Fr(,)g(when)d(the)h
Fj(errno)g Fr(v)n(alue)f(is)i Fj(EINTR)p Fr(,)e(indicating)g(an)g
(interrupted)f(system)i(call,)h(this)g(calls)f Fj(PyErr_-)208
1127 y(CheckSignals\(\))p Fr(,)i(and)j(if)g(that)g(set)h(the)f(error)f
(indicator)m(,)f(lea)n(v)o(es)i(it)h(set)g(to)f(that.)28
b(The)20 b(function)f(al)o(w)o(ays)j(returns)e Fj(NULL)p
Fr(,)208 1226 y(so)h(a)g(wrapper)f(function)f(around)g(a)j(system)f
(call)h(can)f(write)g(`)p Fj(return)48 b(PyErr_SetFromErrno\()p
Fo(type)p Fj(\);)p Fr(')17 b(when)k(the)208 1326 y(system)f(call)h
(returns)e(an)h(error)-5 b(.)0 1473 y Fj(PyObject)400
1488 y(*)498 1473 y Fg(PyErr_SetFromErrnoWithFilename)p
Fj(\()p Fo(PyOb)o(ject)15 b(*type)o(,)20 b(const)g(c)o(har)f
(*\002lename)p Fj(\))208 1572 y Fo(Return)g(value:)25
b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208 1672 y Fr(Similar)g(to)h
Fj(PyErr_SetFromErrno\(\))p Fr(,)d(with)j(the)g(additional)e(beha)n
(vior)g(that)i(if)g Fo(\002lename)f Fr(is)i(not)e Fj(NULL)p
Fr(,)g(it)i(is)g(passed)208 1772 y(to)e(the)g(constructor)e(of)i
Fo(type)g Fr(as)h(a)f(third)g(parameter)-5 b(.)26 b(In)21
b(the)g(case)h(of)f(e)o(xceptions)e(such)i(as)h Fj(IOError)e
Fr(and)h Fj(OSError)p Fr(,)f(this)208 1871 y(is)h(used)f(to)g(de\002ne)
g(the)g Fj(filename)f Fr(attrib)n(ute)h(of)g(the)g(e)o(xception)e
(instance.)0 2018 y Fj(PyObject)400 2033 y(*)498 2018
y Fg(PyErr_SetFromWindowsErr)p Fj(\()p Fo(int)e(ierr)r
Fj(\))208 2118 y Fo(Return)j(value:)25 b Ff(Alw)o(ays)c
Fe(NULL)p Fo(.)208 2217 y Fr(This)k(is)h(a)g(con)m(v)o(enience)c
(function)h(to)i(raise)h Fj(WindowsError)p Fr(.)38 b(If)25
b(called)g(with)g Fo(ierr)k Fr(of)24 b Fj(0)p Fr(,)j(the)e(error)f
(code)h(returned)e(by)208 2317 y(a)29 b(call)h(to)g Fj
(GetLastError\(\))e Fr(is)i(used)f(instead.)53 b(It)30
b(calls)g(the)f(W)m(in32)g(function)f Fj(FormatMessage\(\))f
Fr(to)j(retrie)n(v)o(e)208 2417 y(the)g(W)m(indo)n(ws)h(description)e
(of)h(error)g(code)g(gi)n(v)o(en)g(by)g Fo(ierr)k Fr(or)d
Fj(GetLastError\(\))p Fr(,)g(then)f(it)i(constructs)e(a)h(tuple)f(ob-)
208 2516 y(ject)24 b(whose)g(\002rst)g(item)g(is)h(the)f
Fo(ierr)j Fr(v)n(alue)d(and)f(whose)h(second)f(item)h(is)h(the)f
(corresponding)c(error)j(message)h(\(gotten)f(from)208
2616 y Fj(FormatMessage\(\))p Fr(\),)28 b(and)h(then)f(calls)i(`)p
Fj(PyErr_SetObject\()p Fo(PyExc)p 2585 2616 25 4 v 26
w(W)-5 b(indowsErr)l(or)r Fj(,)49 b Fo(object)q Fj(\))p
Fr('.)j(This)29 b(func-)208 2715 y(tion)19 b(al)o(w)o(ays)i(returns)e
Fj(NULL)p Fr(.)h(A)-6 b(v)n(ailability:)24 b(W)m(indo)n(ws.)0
2862 y Fj(PyObject)400 2877 y(*)498 2862 y Fg
(PyErr_SetExcFromWindowsErr)p Fj(\()p Fo(PyObject)15
b(*type)o(,)k(int)i(ierr)r Fj(\))208 2962 y Fo(Return)e(value:)25
b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208 3062 y Fr(Similar)h(to)g
Fj(PyErr_SetFromWindowsErr\(\))p Fr(,)d(with)j(an)g(additional)f
(parameter)g(specifying)f(the)i(e)o(xception)f(type)g(to)208
3161 y(be)f(raised.)k(A)-6 b(v)n(ailability:)25 b(W)m(indo)n(ws.)50
b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.3.)0 3308 y Fj(PyObject)400
3323 y(*)498 3308 y Fg(PyErr_SetFromWindowsErrWithFilename)p
Fj(\()o Fo(int)d(ierr)-9 b(,)21 b(const)f(c)o(har)f(*\002lename)p
Fj(\))208 3408 y Fo(Return)g(value:)25 b Ff(Alw)o(ays)c
Fe(NULL)p Fo(.)208 3507 y Fr(Similar)g(to)h Fj
(PyErr_SetFromWindowsErr\(\))p Fr(,)17 b(with)k(the)h(additional)e
(beha)n(vior)g(that)h(if)h Fo(\002lename)e Fr(is)i(not)g
Fj(NULL)p Fr(,)f(it)h(is)208 3607 y(passed)e(to)g(the)g(constructor)e
(of)i Fj(WindowsError)f Fr(as)i(a)f(third)g(parameter)-5
b(.)24 b(A)-6 b(v)n(ailability:)24 b(W)m(indo)n(ws.)0
3754 y Fj(PyObject)400 3769 y(*)498 3754 y Fg
(PyErr_SetExcFromWindowsErrWithFilena)o(me)p Fj(\()p
Fo(Py)o(Object)15 b(*type)o(,)k(int)h(ierr)-9 b(,)21
b(c)o(har)f(*\002lename)p Fj(\))208 3853 y Fo(Return)f(value:)25
b Ff(Alw)o(ays)c Fe(NULL)p Fo(.)208 3953 y Fr(Similar)h(to)g
Fj(PyErr_SetFromWindowsErrWithFilename\()o(\))p Fr(,)17
b(with)22 b(an)h(additional)d(parameter)h(specifying)g(the)208
4053 y(e)o(xception)d(type)i(to)g(be)g(raised.)25 b(A)-6
b(v)n(ailability:)24 b(W)m(indo)n(ws.)50 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.3.)0 4200 y Fj(void)49 b Fg
(PyErr_BadInternalCall)p Fj(\(\))208 4299 y Fr(This)24
b(is)i(a)f(shorthand)d(for)i(`)p Fj(PyErr_SetString\(PyExc_TypeError,)
43 b Fo(messa)o(g)o(e)p Fj(\))p Fr(',)25 b(where)f Fo(messa)o(g)o(e)h
Fr(indicates)208 4399 y(that)c(an)g(internal)f(operation)f(\(e.g.)27
b(a)21 b(Python/C)g(API)g(function\))e(w)o(as)j(in)m(v)n(ok)o(ed)d
(with)j(an)f(ille)o(gal)f(ar)o(gument.)25 b(It)d(is)g(mostly)e(for)208
4498 y(internal)f(use.)0 4645 y Fj(int)49 b Fg(PyErr_WarnEx)p
Fj(\()p Fo(PyObject)18 b(*cate)m(gory)-5 b(,)18 b(c)o(har)i(*messa)o(g)
o(e)o(,)g(int)g(stac)n(kle)o(vel)p Fj(\))208 4745 y Fr(Issue)29
b(a)h(w)o(arning)e(message.)52 b(The)29 b Fo(cate)m(gory)f
Fr(ar)o(gument)f(is)j(a)g(w)o(arning)e(cate)o(gory)f(\(see)j(belo)n
(w\))e(or)h Fj(NULL)p Fr(;)g(the)g Fo(messa)o(g)o(e)208
4845 y Fr(ar)o(gument)17 b(is)k(a)g(message)f(string.)k
Fo(stac)n(kle)o(vel)c Fr(is)h(a)g(positi)n(v)o(e)e(number)f(gi)n(ving)h
(a)h(number)e(of)i(stack)g(frames;)g(the)g(w)o(arning)f(will)208
4944 y(be)i(issued)g(from)f(the)i(currently)d(e)o(x)o(ecuting)h(line)h
(of)g(code)g(in)g(that)g(stack)h(frame.)27 b(A)22 b Fo(stac)n(kle)o
(vel)f Fr(of)h(1)f(is)h(the)f(function)f(calling)208
5044 y Fj(PyErr_WarnEx\(\))p Fr(,)d(2)k(is)g(the)f(function)f(abo)o(v)o
(e)f(that,)i(and)g(so)g(forth.)208 5177 y(This)28 b(function)f
(normally)g(prints)h(a)h(w)o(arning)e(message)h(to)h
Fo(sys.stderr)r Fr(;)34 b(ho)n(we)n(v)o(er)m(,)28 b(it)h(is)g(also)g
(possible)f(that)h(the)f(user)g(has)208 5276 y(speci\002ed)16
b(that)i(w)o(arnings)e(are)h(to)g(be)g(turned)f(into)h(errors,)f(and)h
(in)g(that)g(case)h(this)g(will)g(raise)f(an)g(e)o(xception.)22
b(It)17 b(is)h(also)g(possible)208 5376 y(that)28 b(the)g(function)f
(raises)i(an)f(e)o(xception)f(because)h(of)g(a)h(problem)d(with)j(the)f
(w)o(arning)f(machinery)g(\(the)h(implementation)p 0
5549 3901 4 v 3808 5649 a Fn(19)p eop end
%%Page: 20 26
TeXDict begin 20 25 bop 208 83 a Fr(imports)22 b(the)h
Fj(warnings)f Fr(module)g(to)h(do)g(the)g(hea)n(vy)f(lifting\).)33
b(The)22 b(return)g(v)n(alue)h(is)h Fj(0)f Fr(if)g(no)g(e)o(xception)e
(is)j(raised,)g(or)e Fj(-1)208 183 y Fr(if)27 b(an)g(e)o(xception)e(is)
j(raised.)45 b(\(It)27 b(is)h(not)f(possible)g(to)g(determine)e
(whether)h(a)i(w)o(arning)e(message)h(is)h(actually)e(printed,)h(nor)
208 282 y(what)19 b(the)g(reason)g(is)h(for)e(the)i(e)o(xception;)d
(this)j(is)g(intentional.\))j(If)c(an)h(e)o(xception)d(is)j(raised,)f
(the)g(caller)g(should)g(do)g(its)h(normal)208 382 y(e)o(xception)e
(handling)g(\(for)h(e)o(xample,)g Fj(Py_DECREF\(\))g
Fr(o)n(wned)g(references)f(and)i(return)f(an)h(error)f(v)n(alue\).)208
515 y(W)-7 b(arning)18 b(cate)o(gories)f(must)i(be)g(subclasses)g(of)f
Fj(Warning)p Fr(;)h(the)g(def)o(ault)e(w)o(arning)h(cate)o(gory)f(is)j
Fj(RuntimeWarning)p Fr(.)i(The)208 614 y(standard)14
b(Python)g(w)o(arning)g(cate)o(gories)h(are)g(a)n(v)n(ailable)g(as)h
(global)f(v)n(ariables)g(whose)g(names)g(are)g(`)p Fj(PyExc_)p
Fr(')f(follo)n(wed)h(by)g(the)208 714 y(Python)f(e)o(xception)g(name.)
23 b(These)16 b(ha)n(v)o(e)g(the)g(type)f Fj(PyObject)2085
729 y(*)2135 714 y Fr(;)h(the)o(y)g(are)g(all)g(class)h(objects.)23
b(Their)16 b(names)f(are)h Fj(PyExc_-)208 814 y(Warning)p
Fr(,)72 b Fj(PyExc_UserWarning)p Fr(,)f Fj(PyExc_UnicodeWarning)p
Fr(,)f Fj(PyExc_DeprecationWarning)p Fr(,)208 913 y Fj
(PyExc_SyntaxWarning)p Fr(,)52 b Fj(PyExc_RuntimeWarning)p
Fr(,)g(and)c Fj(PyExc_FutureWarning)p Fr(.)107 b Fj(PyExc_-)208
1013 y(Warning)28 b Fr(is)i(a)g(subclass)f(of)g Fj(PyExc_Exception)p
Fr(;)j(the)d(other)f(w)o(arning)g(cate)o(gories)h(are)g(subclasses)g
(of)g Fj(PyExc_-)208 1112 y(Warning)p Fr(.)208 1245 y(F)o(or)19
b(information)e(about)h(w)o(arning)g(control,)g(see)i(the)f
(documentation)e(for)i(the)g Fj(warnings)f Fr(module)g(and)h(the)h
Fp(-W)f Fr(option)f(in)208 1345 y(the)i(command)e(line)i
(documentation.)i(There)e(is)h(no)e(C)j(API)e(for)g(w)o(arning)f
(control.)0 1492 y Fj(int)49 b Fg(PyErr_Warn)p Fj(\()p
Fo(PyObject)18 b(*cate)m(gory)-5 b(,)19 b(c)o(har)g(*messa)o(g)o(e)p
Fj(\))208 1591 y Fr(Issue)29 b(a)h(w)o(arning)e(message.)52
b(The)29 b Fo(cate)m(gory)f Fr(ar)o(gument)f(is)j(a)g(w)o(arning)e
(cate)o(gory)f(\(see)j(belo)n(w\))e(or)h Fj(NULL)p Fr(;)g(the)g
Fo(messa)o(g)o(e)208 1691 y Fr(ar)o(gument)16 b(is)j(a)g(message)g
(string.)24 b(The)18 b(w)o(arning)f(will)i(appear)f(to)g(be)h(issued)g
(from)e(the)i(function)d(calling)i Fj(PyErr_Warn\(\))p
Fr(,)208 1791 y(equi)n(v)n(alent)g(to)i(calling)g Fj(PyErr_WarnEx\(\))e
Fr(with)j(a)f Fo(stac)n(kle)o(vel)h Fr(of)e(1.)208 1924
y(Deprecated;)f(use)j Fj(PyErr_WarnEx\(\))d Fr(instead.)0
2070 y Fj(int)49 b Fg(PyErr_WarnExplicit)p Fj(\()p Fo(PyObject)22
b(*cate)m(gory)-5 b(,)26 b(const)g(c)o(har)g(*messa)o(g)o(e)o(,)h
(const)f(c)o(har)g(*\002lename)o(,)g(int)g(lineno,)h(const)1149
2170 y(c)o(har)16 b(*module)o(,)j(PyObject)h(*r)m(e)m(gistry)p
Fj(\))208 2252 y Fr(Issue)28 b(a)g(w)o(arning)f(message)h(with)h(e)o
(xplicit)e(control)g(o)o(v)o(er)g(all)i(w)o(arning)e(attrib)n(utes.)48
b(This)29 b(is)g(a)f(straightforw)o(ard)e(wrapper)208
2352 y(around)d(the)j(Python)f(function)f Fj
(warnings.warn_explicit\(\))p Fr(,)f(see)j(there)f(for)g(more)g
(information.)39 b(The)26 b Fo(module)208 2451 y Fr(and)19
b Fo(r)m(e)m(gistry)i Fr(ar)o(guments)d(may)i(be)g(set)h(to)f
Fj(NULL)g Fr(to)g(get)h(the)f(def)o(ault)f(ef)n(fect)h(described)f
(there.)0 2598 y Fj(int)49 b Fg(PyErr_CheckSignals)p
Fj(\(\))208 2698 y Fr(This)21 b(function)e(interacts)i(with)g(Python')
-5 b(s)21 b(signal)g(handling.)k(It)d(checks)e(whether)g(a)i(signal)f
(has)g(been)f(sent)i(to)f(the)g(processes)208 2797 y(and)c(if)h(so,)g
(in)m(v)n(ok)o(es)f(the)g(corresponding)e(signal)i(handler)-5
b(.)23 b(If)18 b(the)f Fj(signal)h Fr(module)e(is)j(supported,)c(this)k
(can)e(in)m(v)n(ok)o(e)g(a)h(signal)208 2897 y(handler)j(written)h(in)g
(Python.)31 b(In)22 b(all)h(cases,)g(the)g(def)o(ault)f(ef)n(fect)f
(for)h Fj(SIGINT)g Fr(is)h(to)g(raise)g(the)45 b Fj(KeyboardInterrupt)
208 2997 y Fr(e)o(xception.)23 b(If)e(an)f(e)o(xception)f(is)i(raised)f
(the)h(error)e(indicator)g(is)i(set)h(and)e(the)g(function)f(returns)g
Fj(-1)p Fr(;)i(otherwise)f(the)g(function)208 3096 y(returns)f
Fj(0)p Fr(.)25 b(The)20 b(error)f(indicator)g(may)h(or)g(may)f(not)h
(be)g(cleared)g(if)g(it)h(w)o(as)g(pre)n(viously)d(set.)0
3243 y Fj(void)49 b Fg(PyErr_SetInterrupt)p Fj(\(\))208
3343 y Fr(This)23 b(function)e(simulates)j(the)f(ef)n(fect)f(of)h(a)h
Fj(SIGINT)f Fr(signal)g(arri)n(ving)e(\227)j(the)f(ne)o(xt)f(time)i
Fj(PyErr_CheckSignals\(\))208 3442 y Fr(is)d(called,)40
b Fj(KeyboardInterrupt)18 b Fr(will)j(be)f(raised.)25
b(It)20 b(may)g(be)g(called)g(without)f(holding)g(the)h(interpreter)f
(lock.)0 3589 y Fj(PyObject)400 3604 y(*)498 3589 y Fg
(PyErr_NewException)p Fj(\()p Fo(c)o(har)d(*name)o(,)j(PyObject)h
(*base)o(,)f(PyObject)h(*dict)q Fj(\))208 3689 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3789 y Fr(This)k(utility)g
(function)e(creates)j(and)e(returns)g(a)i(ne)n(w)f(e)o(xception)e
(object.)37 b(The)23 b Fo(name)h Fr(ar)o(gument)e(must)i(be)g(the)g
(name)g(of)g(the)208 3888 y(ne)n(w)19 b(e)o(xception,)e(a)i(C)i(string)
d(of)h(the)h(form)e Fj(module.class)p Fr(.)23 b(The)18
b Fo(base)h Fr(and)g Fo(dict)i Fr(ar)o(guments)c(are)i(normally)f
Fj(NULL)p Fr(.)g(This)208 3988 y(creates)i(a)g(class)i(object)d(deri)n
(v)o(ed)g(from)g Fj(Exception)g Fr(\(accessible)h(in)g(C)h(as)g
Fj(PyExc_Exception)p Fr(\).)208 4121 y(The)j Fj(__module__)g
Fr(attrib)n(ute)h(of)g(the)g(ne)n(w)g(class)h(is)h(set)f(to)f(the)g
(\002rst)h(part)f(\(up)f(to)i(the)f(last)h(dot\))e(of)h(the)h
Fo(name)e Fr(ar)o(gument,)208 4220 y(and)c(the)i(class)g(name)f(is)h
(set)h(to)e(the)h(last)g(part)f(\(after)g(the)g(last)i(dot\).)28
b(The)21 b Fo(base)g Fr(ar)o(gument)e(can)i(be)h(used)f(to)g(specify)g
(alternate)208 4320 y(base)k(classes;)k(it)d(can)f(either)g(be)g(only)g
(one)g(class)h(or)f(a)h(tuple)e(of)h(classes.)42 b(The)25
b Fo(dict)i Fr(ar)o(gument)c(can)i(be)g(used)g(to)h(specify)e(a)208
4420 y(dictionary)18 b(of)i(class)h(v)n(ariables)e(and)h(methods.)0
4566 y Fj(void)49 b Fg(PyErr_WriteUnraisable)p Fj(\()p
Fo(PyObject)16 b(*obj)p Fj(\))208 4666 y Fr(This)j(utility)g(function)e
(prints)i(a)g(w)o(arning)f(message)h(to)g Fj(sys.stderr)f
Fr(when)g(an)h(e)o(xception)e(has)i(been)g(set)h(b)n(ut)f(it)g(is)h
(impos-)208 4766 y(sible)i(for)g(the)h(interpreter)d(to)j(actually)f
(raise)h(the)f(e)o(xception.)30 b(It)23 b(is)g(used,)f(for)g(e)o
(xample,)g(when)f(an)i(e)o(xception)d(occurs)i(in)h(an)208
4865 y Fj(__del__\(\))c Fr(method.)208 4998 y(The)24
b(function)f(is)i(called)f(with)h(a)g(single)g(ar)o(gument)d
Fo(obj)i Fr(that)h(identi\002es)f(the)h(conte)o(xt)e(in)i(which)f(the)g
(unraisable)f(e)o(xception)208 5098 y(occurred.)f(The)e(repr)g(of)g
Fo(obj)f Fr(will)i(be)g(printed)e(in)h(the)g(w)o(arning)f(message.)p
0 5549 3901 4 v 0 5649 a Fn(20)2630 b(Chapter)24 b(4.)52
b(Exception)23 b(Handling)p eop end
%%Page: 21 27
TeXDict begin 21 26 bop 0 88 a Fl(4.1)121 b(Standard)35
b(Exceptions)0 321 y Fr(All)23 b(standard)d(Python)h(e)o(xceptions)f
(are)i(a)n(v)n(ailable)g(as)g(global)f(v)n(ariables)g(whose)h(names)f
(are)h(`)p Fj(PyExc_)p Fr(')f(follo)n(wed)f(by)i(the)g(Python)0
421 y(e)o(xception)27 b(name.)51 b(These)29 b(ha)n(v)o(e)f(the)h(type)g
Fj(PyObject)1719 436 y(*)1769 421 y Fr(;)k(the)o(y)28
b(are)h(all)h(class)g(objects.)51 b(F)o(or)29 b(completeness,)g(here)g
(are)g(all)h(the)0 520 y(v)n(ariables:)637 710 y Fp(C)21
b(Name)p 1930 740 4 100 v 1056 w(Python)e(Name)p 2976
740 V 582 w(Notes)p 587 743 2726 4 v 637 813 a Fj(PyExc_BaseException)p
1930 843 4 100 v 395 w(BaseException)p 2976 843 V 396
w Fr(\(1\),)g(\(4\))637 913 y Fj(PyExc_Exception)p 1930
943 V 595 w(Exception)p 2976 943 V 665 w Fr(\(1\))637
1012 y Fj(PyExc_StandardError)p 1930 1042 V 395 w(StandardError)p
2976 1042 V 465 w Fr(\(1\))637 1112 y Fj(PyExc_ArithmeticError)p
1930 1142 V 295 w(ArithmeticError)p 2976 1142 V 365 w
Fr(\(1\))637 1212 y Fj(PyExc_LookupError)p 1930 1241
V 495 w(LookupError)p 2976 1241 V 565 w Fr(\(1\))637
1311 y Fj(PyExc_AssertionError)p 1930 1341 V 345 w(AssertionError)p
2976 1341 V 637 1411 a(PyExc_AttributeError)p 1930 1441
V 345 w(AttributeError)p 2976 1441 V 637 1510 a(PyExc_EOFError)p
1930 1540 V 645 w(EOFError)p 2976 1540 V 637 1610 a
(PyExc_EnvironmentError)p 1930 1640 V 245 w(EnvironmentError)p
2976 1640 V 315 w Fr(\(1\))637 1710 y Fj(PyExc_FloatingPointError)p
1930 1740 V 145 w(FloatingPointError)p 2976 1740 V 637
1809 a(PyExc_IOError)p 1930 1839 V 695 w(IOError)p 2976
1839 V 637 1909 a(PyExc_ImportError)p 1930 1939 V 495
w(ImportError)p 2976 1939 V 637 2009 a(PyExc_IndexError)p
1930 2038 V 545 w(IndexError)p 2976 2038 V 637 2108 a(PyExc_KeyError)p
1930 2138 V 645 w(KeyError)p 2976 2138 V 637 2208 a
(PyExc_KeyboardInterrupt)p 1930 2238 V 195 w(KeyboardInterrupt)p
2976 2238 V 637 2307 a(PyExc_MemoryError)p 1930 2337
V 495 w(MemoryError)p 2976 2337 V 637 2407 a(PyExc_NameError)p
1930 2437 V 595 w(NameError)p 2976 2437 V 637 2507 a
(PyExc_NotImplementedError)p 1930 2537 V 95 w(NotImplementedError)p
2976 2537 V 637 2606 a(PyExc_OSError)p 1930 2636 V 695
w(OSError)p 2976 2636 V 637 2706 a(PyExc_OverflowError)p
1930 2736 V 395 w(OverflowError)p 2976 2736 V 637 2806
a(PyExc_ReferenceError)p 1930 2835 V 345 w(ReferenceError)p
2976 2835 V 415 w Fr(\(2\))637 2905 y Fj(PyExc_RuntimeError)p
1930 2935 V 445 w(RuntimeError)p 2976 2935 V 637 3005
a(PyExc_SyntaxError)p 1930 3035 V 495 w(SyntaxError)p
2976 3035 V 637 3104 a(PyExc_SystemError)p 1930 3134
V 495 w(SystemError)p 2976 3134 V 637 3204 a(PyExc_SystemExit)p
1930 3234 V 545 w(SystemExit)p 2976 3234 V 637 3304 a(PyExc_TypeError)p
1930 3334 V 595 w(TypeError)p 2976 3334 V 637 3403 a(PyExc_ValueError)p
1930 3433 V 545 w(ValueError)p 2976 3433 V 637 3503 a
(PyExc_WindowsError)p 1930 3533 V 445 w(WindowsError)p
2976 3533 V 515 w Fr(\(3\))637 3603 y Fj(PyExc_ZeroDivisionError)p
1930 3632 V 195 w(ZeroDivisionError)p 2976 3632 V 0 3807
a Fr(Notes:)0 4005 y Fp(\(1\))40 b Fr(This)21 b(is)g(a)f(base)h(class)g
(for)e(other)h(standard)f(e)o(xceptions.)0 4163 y Fp(\(2\))40
b Fr(This)21 b(is)g(the)f(same)g(as)h Fj(weakref.ReferenceError)p
Fr(.)0 4321 y Fp(\(3\))40 b Fr(Only)27 b(de\002ned)f(on)g(W)m(indo)n
(ws;)k(protect)c(code)g(that)h(uses)g(this)h(by)e(testing)h(that)g(the)
g(preprocessor)d(macro)i Fj(MS_WINDOWS)g Fr(is)208 4421
y(de\002ned.)0 4579 y Fp(\(4\))40 b Fr(Ne)n(w)21 b(in)f(v)o(ersion)f
(2.5.)0 4903 y Fl(4.2)121 b(Deprecation)35 b(of)f(Str)r(ing)g
(Exceptions)0 5136 y Fr(All)21 b(e)o(xceptions)d(b)n(uilt)j(into)f
(Python)f(or)h(pro)o(vided)d(in)k(the)f(standard)f(library)g(are)h
(deri)n(v)o(ed)f(from)g Fj(BaseException)p Fr(.)0 5282
y(String)29 b(e)o(xceptions)g(are)h(still)h(supported)d(in)i(the)g
(interpreter)e(to)i(allo)n(w)g(e)o(xisting)f(code)g(to)h(run)f
(unmodi\002ed,)h(b)n(ut)g(this)h(will)f(also)0 5382 y(change)19
b(in)h(a)h(future)e(release.)p 0 5549 3901 4 v 0 5649
a Fn(4.1.)52 b(Standard)24 b(Exceptions)2852 b(21)p eop
end
%%Page: 22 28
TeXDict begin 22 27 bop 0 5549 3901 4 v 0 5649 a Fn(22)p
eop end
%%Page: 23 29
TeXDict begin 23 28 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3634
427 y Fm(FIVE)p 0 515 V 3177 978 a Fx(Utilities)0 1457
y Fr(The)30 b(functions)g(in)g(this)i(chapter)d(perform)g(v)n(arious)g
(utility)i(tasks,)j(ranging)28 b(from)i(helping)f(C)j(code)e(be)g(more)
g(portable)g(across)0 1556 y(platforms,)g(using)f(Python)f(modules)g
(from)g(C,)i(and)f(parsing)f(function)f(ar)o(guments)h(and)g
(constructing)g(Python)g(v)n(alues)g(from)h(C)0 1656
y(v)n(alues.)0 1983 y Fl(5.1)121 b(Oper)o(ating)35 b(System)e
(Utilities)0 2202 y Fj(int)49 b Fg(Py_FdIsInteractive)p
Fj(\()p Fo(FILE)17 b(*fp,)i(const)h(c)o(har)g(*\002lename)p
Fj(\))208 2302 y Fr(Return)14 b(true)i(\(nonzero\))c(if)k(the)f
(standard)f(I/O)i(\002le)g Fo(fp)g Fr(with)f(name)g Fo(\002lename)f
Fr(is)j(deemed)d(interacti)n(v)o(e.)22 b(This)15 b(is)i(the)e(case)h
(for)f(\002les)208 2401 y(for)20 b(which)g(`)p Fj(isatty\(fileno\()p
Fo(fp)p Fj(\)\))p Fr(')d(is)22 b(true.)k(If)21 b(the)f(global)g(\003ag)
h Fj(Py_InteractiveFlag)d Fr(is)k(true,)e(this)h(function)208
2501 y(also)k(returns)g(true)g(if)h(the)f Fo(\002lename)f
Fr(pointer)g(is)j Fj(NULL)e Fr(or)g(if)h(the)f(name)g(is)h(equal)f(to)h
(one)f(of)g(the)g(strings)h Fj('<stdin>')e Fr(or)208
2601 y Fj('???')p Fr(.)0 2747 y Fj(long)49 b Fg
(PyOS_GetLastModificationTime)p Fj(\()p Fo(c)o(ha)o(r)15
b(*\002lename)p Fj(\))208 2847 y Fr(Return)j(the)h(time)g(of)g(last)h
(modi\002cation)e(of)g(the)h(\002le)h Fo(\002lename)p
Fr(.)k(The)18 b(result)h(is)h(encoded)e(in)h(the)g(same)g(w)o(ay)g(as)h
(the)f(timestamp)208 2947 y(returned)f(by)i(the)g(standard)f(C)i
(library)e(function)g Fj(time\(\))p Fr(.)0 3094 y Fj(void)49
b Fg(PyOS_AfterFork)p Fj(\(\))208 3193 y Fr(Function)16
b(to)j(update)e(some)h(internal)f(state)i(after)f(a)g(process)g(fork;)g
(this)g(should)f(be)h(called)g(in)g(the)h(ne)n(w)f(process)f(if)i(the)f
(Python)208 3293 y(interpreter)j(will)j(continue)e(to)i(be)f(used.)34
b(If)23 b(a)h(ne)n(w)f(e)o(x)o(ecutable)f(is)i(loaded)e(into)h(the)h
(ne)n(w)f(process,)g(this)h(function)e(does)h(not)208
3392 y(need)c(to)h(be)h(called.)0 3539 y Fj(int)49 b
Fg(PyOS_CheckStack)p Fj(\(\))208 3639 y Fr(Return)25
b(true)h(when)g(the)h(interpreter)d(runs)i(out)g(of)g(stack)h(space.)43
b(This)26 b(is)i(a)e(reliable)g(check,)h(b)n(ut)g(is)g(only)e(a)n(v)n
(ailable)h(when)208 3739 y Fj(USE_STACKCHECK)j Fr(is)j(de\002ned)e
(\(currently)g(on)h(W)m(indo)n(ws)f(using)h(the)g(Microsoft)g(V)-5
b(isual)31 b(C)3122 3732 y(++)3248 3739 y(compiler\).)57
b Fj(USE_-)208 3838 y(STACKCHECK)18 b Fr(will)j(be)g(de\002ned)e
(automatically;)f(you)i(should)f(ne)n(v)o(er)g(change)g(the)h
(de\002nition)f(in)h(your)f(o)n(wn)h(code.)0 3985 y Fj
(PyOS_sighandler_t)47 b Fg(PyOS_getsig)p Fj(\()p Fo(int)18
b(i)p Fj(\))208 4085 y Fr(Return)38 b(the)g(current)f(signal)i(handler)
e(for)g(signal)i Fo(i)p Fr(.)80 b(This)39 b(is)g(a)g(thin)f(wrapper)f
(around)g(either)h Fj(sigaction\(\))f Fr(or)208 4184
y Fj(signal\(\))p Fr(.)70 b(Do)36 b(not)f(call)h(those)g(functions)e
(directly!)71 b Fj(PyOS_sighandler_t)33 b Fr(is)k(a)f(typedef)e(alias)j
(for)e Fj(void)208 4284 y(\()258 4299 y(*)308 4284 y(\)\(int\))p
Fr(.)0 4431 y Fj(PyOS_sighandler_t)47 b Fg(PyOS_setsig)p
Fj(\()p Fo(int)18 b(i,)i(PyOS)p 1862 4431 25 4 v 29 w(sighandler)p
2248 4431 V 28 w(t)h(h)p Fj(\))208 4530 y Fr(Set)26 b(the)h(signal)f
(handler)e(for)i(signal)g Fo(i)h Fr(to)f(be)g Fo(h)p
Fr(;)k(return)25 b(the)h(old)g(signal)g(handler)-5 b(.)42
b(This)26 b(is)h(a)g(thin)f(wrapper)f(around)f(either)208
4630 y Fj(sigaction\(\))i Fr(or)h Fj(signal\(\))p Fr(.)45
b(Do)28 b(not)f(call)h(those)f(functions)f(directly!)46
b Fj(PyOS_sighandler_t)25 b Fr(is)j(a)g(typedef)208 4730
y(alias)20 b(for)g Fj(void)49 b(\()797 4745 y(*)847 4730
y(\)\(int\))p Fr(.)0 5057 y Fl(5.2)121 b(Process)33 b(Control)0
5276 y Fj(void)49 b Fg(Py_FatalError)p Fj(\()p Fo(const)17
b(c)o(har)j(*messa)o(g)o(e)p Fj(\))208 5376 y Fr(Print)g(a)h(f)o(atal)f
(error)g(message)g(and)g(kill)h(the)f(process.)25 b(No)20
b(cleanup)g(is)h(performed.)i(This)d(function)f(should)g(only)h(be)g
(in)m(v)n(ok)o(ed)p 0 5549 3901 4 v 3808 5649 a Fn(23)p
eop end
%%Page: 24 30
TeXDict begin 24 29 bop 208 83 a Fr(when)20 b(a)i(condition)e(is)j
(detected)d(that)i(w)o(ould)f(mak)o(e)g(it)h(dangerous)d(to)j(continue)
e(using)h(the)g(Python)g(interpreter;)f(e.g.,)h(when)208
183 y(the)d(object)h(administration)e(appears)h(to)h(be)g(corrupted.)j
(On)f(U)t Fi(N)t(I)t(X)r Fr(,)f(the)f(standard)f(C)i(library)e
(function)f Fj(abort\(\))h Fr(is)i(called)208 282 y(which)f(will)i
(attempt)f(to)g(produce)e(a)j(`)p Fs(core)p Fr(')e(\002le.)0
429 y Fj(void)49 b Fg(Py_Exit)p Fj(\()p Fo(int)19 b(status)p
Fj(\))208 529 y Fr(Exit)42 b(the)g(current)f(process.)91
b(This)42 b(calls)h Fj(Py_Finalize\(\))e Fr(and)h(then)f(calls)i(the)g
(standard)e(C)i(library)e(function)208 628 y Fj(exit\()p
Fo(status)p Fj(\))p Fr(.)0 775 y Fj(int)49 b Fg(Py_AtExit)p
Fj(\()p Fo(void)18 b(\(*func\))h(\(\))p Fj(\))208 875
y Fr(Re)o(gister)26 b(a)h(cleanup)f(function)e(to)j(be)g(called)f(by)g
Fj(Py_Finalize\(\))p Fr(.)42 b(The)27 b(cleanup)e(function)g(will)i(be)
g(called)f(with)h(no)208 975 y(ar)o(guments)21 b(and)j(should)e(return)
h(no)h(v)n(alue.)35 b(At)24 b(most)g(32)g(cleanup)e(functions)h(can)g
(be)h(re)o(gistered.)35 b(When)23 b(the)h(re)o(gistration)208
1074 y(is)d(successful,)g Fj(Py_AtExit\(\))e Fr(returns)h
Fj(0)p Fr(;)h(on)g(f)o(ailure,)f(it)h(returns)f Fj(-1)p
Fr(.)27 b(The)20 b(cleanup)g(function)f(re)o(gistered)g(last)j(is)g
(called)208 1174 y(\002rst.)i(Each)18 b(cleanup)e(function)g(will)j(be)
e(called)h(at)g(most)g(once.)23 b(Since)18 b(Python')-5
b(s)17 b(internal)g(\002nalization)g(will)h(ha)n(v)o(e)f(completed)208
1273 y(before)h(the)j(cleanup)e(function,)f(no)i(Python)f(APIs)h
(should)g(be)g(called)g(by)f Fo(func)p Fr(.)0 1597 y
Fl(5.3)121 b(Impor)5 b(ting)34 b(Modules)0 1811 y Fj(PyObject)400
1826 y(*)498 1811 y Fg(PyImport_ImportModule)p Fj(\()p
Fo(const)16 b(c)o(har)k(*name)p Fj(\))208 1911 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2010 y Fr(This)32
b(is)h(a)g(simpli\002ed)f(interf)o(ace)g(to)g Fj
(PyImport_ImportModuleEx\(\))c Fr(belo)n(w)-5 b(,)34
b(lea)n(ving)e(the)g Fo(globals)g Fr(and)g Fo(locals)208
2110 y Fr(ar)o(guments)19 b(set)j(to)f Fj(NULL)p Fr(.)g(When)g(the)g
Fo(name)g Fr(ar)o(gument)e(contains)h(a)i(dot)f(\(when)f(it)i
(speci\002es)g(a)g(submodule)d(of)i(a)h(package\),)208
2210 y(the)g Fo(fr)l(omlist)j Fr(ar)o(gument)20 b(is)k(set)f(to)g(the)f
(list)i Fj([')1577 2225 y(*)1627 2210 y('])e Fr(so)h(that)f(the)h
(return)e(v)n(alue)h(is)h(the)g(named)e(module)g(rather)h(than)g(the)g
(top-)208 2309 y(le)n(v)o(el)k(package)f(containing)f(it)k(as)f(w)o
(ould)f(otherwise)g(be)g(the)h(case.)44 b(\(Unfortunately)-5
b(,)25 b(this)i(has)g(an)f(additional)f(side)i(ef)n(fect)208
2409 y(when)d Fo(name)g Fr(in)i(f)o(act)f(speci\002es)g(a)h(subpackage)
d(instead)h(of)h(a)h(submodule:)32 b(the)25 b(submodules)f(speci\002ed)
g(in)i(the)f(package')-5 b(s)208 2509 y Fj(__all__)19
b Fr(v)n(ariable)g(are)h(loaded.\))j(Return)d(a)g(ne)n(w)g(reference)f
(to)h(the)g(imported)e(module,)h(or)h Fj(NULL)f Fr(with)i(an)f(e)o
(xception)e(set)208 2608 y(on)g(f)o(ailure.)24 b(Before)18
b(Python)f(2.4,)h(the)g(module)g(may)g(still)h(be)g(created)f(in)g(the)
h(f)o(ailure)f(case)h(\227)g(e)o(xamine)e Fj(sys.modules)g
Fr(to)208 2708 y(\002nd)h(out.)24 b(Starting)18 b(with)h(Python)f(2.4,)
g(a)h(f)o(ailing)f(import)g(of)g(a)h(module)f(no)g(longer)g(lea)n(v)o
(es)g(the)h(module)e(in)i Fj(sys.modules)p Fr(.)208 2808
y(Changed)f(in)j(v)o(ersion)e(2.4:)g(f)o(ailing)h(imports)f(remo)o(v)o
(e)g(incomplete)f(module)h(objects.)0 2954 y Fj(PyObject)400
2969 y(*)498 2954 y Fg(PyImport_ImportModuleEx)p Fj(\()p
Fo(c)o(har)44 b(*name)o(,)56 b(PyObject)48 b(*globals,)55
b(PyObject)49 b(*locals,)55 b(PyObject)1698 3054 y(*fr)l(omlist)q
Fj(\))208 3137 y Fo(Return)19 b(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 3237 y Fr(Import)j(a)i(module.)38
b(This)25 b(is)g(best)g(described)f(by)g(referring)f(to)i(the)g(b)n
(uilt-in)f(Python)g(function)f Fj(__import__\(\))p Fr(,)h(as)i(the)208
3337 y(standard)19 b Fj(__import__\(\))f Fr(function)h(calls)h(this)h
(function)e(directly)-5 b(.)208 3465 y(The)24 b(return)g(v)n(alue)h(is)
h(a)g(ne)n(w)f(reference)e(to)j(the)f(imported)f(module)g(or)g(top-le)n
(v)o(el)g(package,)h(or)g Fj(NULL)g Fr(with)g(an)g(e)o(xception)208
3565 y(set)k(on)g(f)o(ailure)f(\(before)f(Python)g(2.4,)j(the)f(module)
f(may)g(still)i(be)f(created)f(in)h(this)g(case\).)51
b(Lik)o(e)28 b(for)g Fj(__import__\(\))p Fr(,)208 3664
y(the)i(return)f(v)n(alue)g(when)h(a)g(submodule)e(of)i(a)g(package)f
(w)o(as)i(requested)e(is)i(normally)d(the)j(top-le)n(v)o(el)d(package,)
j(unless)f(a)208 3764 y(non-empty)17 b Fo(fr)l(omlist)23
b Fr(w)o(as)e(gi)n(v)o(en.)49 b(Changed)19 b(in)i(v)o(ersion)d(2.4:)i
(f)o(ailing)g(imports)f(remo)o(v)o(e)g(incomplete)f(module)h(objects.)0
3911 y Fj(PyObject)400 3926 y(*)498 3911 y Fg(PyImport_Import)p
Fj(\()p Fo(PyObject)e(*name)p Fj(\))208 4010 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4110 y Fr(This)k(is)i(a)f(higher)
n(-le)n(v)o(el)e(interf)o(ace)g(that)i(calls)h(the)e(current)g
(\223import)f(hook)g(function\224.)37 b(It)25 b(in)m(v)n(ok)o(es)f(the)
g Fj(__import__\(\))208 4210 y Fr(function)d(from)g(the)i
Fj(__builtins__)e Fr(of)i(the)g(current)e(globals.)32
b(This)23 b(means)g(that)g(the)f(import)g(is)i(done)e(using)g(whate)n
(v)o(er)208 4309 y(import)d(hooks)g(are)h(installed)g(in)g(the)h
(current)d(en)m(vironment,)f(e.g.)25 b(by)20 b Fj(rexec)g
Fr(or)f Fj(ihooks)p Fr(.)0 4456 y Fj(PyObject)400 4471
y(*)498 4456 y Fg(PyImport_ReloadModule)p Fj(\()p Fo(PyObject)d(*m)p
Fj(\))208 4556 y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4655 y Fr(Reload)e(a)h(module.)k(This)18 b(is)i(best)f
(described)e(by)h(referring)e(to)j(the)f(b)n(uilt-in)g(Python)g
(function)e Fj(reload\(\))p Fr(,)i(as)h(the)g(standard)208
4755 y Fj(reload\(\))h Fr(function)f(calls)j(this)g(function)d
(directly)-5 b(.)26 b(Return)21 b(a)h(ne)n(w)f(reference)e(to)i(the)g
(reloaded)f(module,)g(or)g Fj(NULL)h Fr(with)208 4855
y(an)f(e)o(xception)e(set)j(on)f(f)o(ailure)f(\(the)h(module)f(still)i
(e)o(xists)g(in)f(this)h(case\).)0 5001 y Fj(PyObject)400
5016 y(*)498 5001 y Fg(PyImport_AddModule)p Fj(\()p Fo(const)c(c)o(har)
i(*name)p Fj(\))208 5101 y Fo(Return)g(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 5201 y Fr(Return)40 b(the)h(module)f(object)g
(corresponding)e(to)j(a)h(module)d(name.)87 b(The)41
b Fo(name)f Fr(ar)o(gument)f(may)i(be)g(of)g(the)g(form)208
5300 y Fj(package.module)p Fr(.)56 b(First)32 b(check)e(the)h(modules)g
(dictionary)e(if)j(there')-5 b(s)31 b(one)f(there,)k(and)c(if)i(not,)h
(create)e(a)h(ne)n(w)f(one)208 5400 y(and)19 b(insert)h(it)h(in)f(the)h
(modules)e(dictionary)-5 b(.)22 b(Return)e Fj(NULL)g
Fr(with)g(an)h(e)o(xception)d(set)j(on)e(f)o(ailure.)25
b Fp(Note:)f Fr(This)c(function)f(does)p 0 5549 3901
4 v 0 5649 a Fn(24)3078 b(Chapter)24 b(5.)51 b(Utilities)p
eop end
%%Page: 25 31
TeXDict begin 25 30 bop 208 83 a Fr(not)21 b(load)g(or)g(import)g(the)g
(module;)g(if)h(the)g(module)e(w)o(asn')o(t)h(already)g(loaded,)f(you)h
(will)h(get)g(an)f(empty)g(module)f(object.)29 b(Use)208
183 y Fj(PyImport_ImportModule\(\))22 b Fr(or)j(one)g(of)h(its)h(v)n
(ariants)e(to)h(import)e(a)j(module.)40 b(P)o(ackage)25
b(structures)g(implied)g(by)g(a)208 282 y(dotted)19 b(name)g(for)h
Fo(name)g Fr(are)g(not)g(created)f(if)h(not)g(already)f(present.)0
429 y Fj(PyObject)400 444 y(*)498 429 y Fg(PyImport_ExecCodeModule)p
Fj(\()p Fo(c)o(har)c(*name)o(,)k(PyObject)h(*co)p Fj(\))208
529 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 628 y Fr(Gi)n(v)o(en)14 b(a)i(module)e(name)h(\(possibly)g(of)
g(the)g(form)g Fj(package.module)p Fr(\))e(and)i(a)h(code)f(object)g
(read)g(from)f(a)i(Python)e(bytecode)208 728 y(\002le)19
b(or)g(obtained)f(from)g(the)i(b)n(uilt-in)e(function)g
Fj(compile\(\))p Fr(,)g(load)h(the)g(module.)k(Return)c(a)h(ne)n(w)f
(reference)e(to)j(the)f(module)208 828 y(object,)g(or)h
Fj(NULL)f Fr(with)h(an)g(e)o(xception)e(set)j(if)g(an)e(error)g
(occurred.)k(Before)d(Python)e(2.4,)i(the)g(module)e(could)h(still)i
(be)f(created)208 927 y(in)28 b(error)g(cases.)51 b(Starting)28
b(with)h(Python)e(2.4,)j Fo(name)e Fr(is)h(remo)o(v)o(ed)e(from)g
Fj(sys.modules)g Fr(in)i(error)e(cases,)32 b(and)c(e)n(v)o(en)f(if)208
1027 y Fo(name)21 b Fr(w)o(as)j(already)d(in)h Fj(sys.modules)f
Fr(on)h(entry)g(to)h Fj(PyImport_ExecCodeModule\(\))p
Fr(.)k(Lea)n(ving)21 b(incompletely)208 1127 y(initialized)g(modules)f
(in)i Fj(sys.modules)e Fr(is)i(dangerous,)e(as)i(imports)f(of)g(such)h
(modules)e(ha)n(v)o(e)h(no)g(w)o(ay)h(to)f(kno)n(w)g(that)h(the)208
1226 y(module)c(object)i(is)h(an)f(unkno)n(wn)e(\(and)h(probably)f
(damaged)h(with)h(respect)g(to)g(the)g(module)f(author')-5
b(s)19 b(intents\))h(state.)208 1359 y(This)i(function)e(will)j(reload)
e(the)i(module)d(if)j(it)g(w)o(as)g(already)e(imported.)29
b(See)23 b Fj(PyImport_ReloadModule\(\))18 b Fr(for)k(the)208
1459 y(intended)c(w)o(ay)i(to)h(reload)e(a)i(module.)208
1591 y(If)k Fo(name)f Fr(points)h(to)g(a)g(dotted)g(name)f(of)h(the)g
(form)f Fj(package.module)p Fr(,)g(an)o(y)g(package)g(structures)h(not)
f(already)g(created)208 1691 y(will)c(still)i(not)e(be)g(created.)208
1824 y(Changed)e(in)j(v)o(ersion)e(2.4:)g Fo(name)h Fr(is)h(remo)o(v)o
(ed)d(from)h Fj(sys.modules)g Fr(in)h(error)f(cases.)0
1971 y Fj(long)49 b Fg(PyImport_GetMagicNumber)p Fj(\(\))208
2070 y Fr(Return)19 b(the)h(magic)f(number)f(for)i(Python)e(bytecode)h
(\002les)h(\(a.k.a.)k(`)p Fs(.p)n(yc)p Fr(')c(and)f(`)p
Fs(.p)n(y)o(o)p Fr(')f(\002les\).)26 b(The)19 b(magic)h(number)e
(should)h(be)208 2170 y(present)g(in)h(the)h(\002rst)g(four)e(bytes)h
(of)g(the)g(bytecode)e(\002le,)j(in)f(little-endian)f(byte)h(order)-5
b(.)0 2317 y Fj(PyObject)400 2332 y(*)498 2317 y Fg
(PyImport_GetModuleDict)p Fj(\(\))208 2417 y Fo(Return)19
b(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208
2516 y Fr(Return)31 b(the)h(dictionary)e(used)i(for)g(the)g(module)e
(administration)h(\(a.k.a.)f Fj(sys.modules)p Fr(\).)59
b(Note)32 b(that)g(this)h(is)g(a)f(per)n(-)208 2616 y(interpreter)18
b(v)n(ariable.)0 2763 y Fj(void)49 b Fg(_PyImport_Init)p
Fj(\(\))208 2862 y Fr(Initialize)19 b(the)i(import)e(mechanism.)k(F)o
(or)d(internal)g(use)g(only)-5 b(.)0 3009 y Fj(void)49
b Fg(PyImport_Cleanup)p Fj(\(\))208 3109 y Fr(Empty)19
b(the)h(module)f(table.)25 b(F)o(or)19 b(internal)h(use)g(only)-5
b(.)0 3256 y Fj(void)49 b Fg(_PyImport_Fini)p Fj(\(\))208
3355 y Fr(Finalize)20 b(the)g(import)f(mechanism.)24
b(F)o(or)c(internal)f(use)h(only)-5 b(.)0 3502 y Fj(PyObject)400
3517 y(*)498 3502 y Fg(_PyImport_FindExtension)p Fj(\()p
Fo(c)o(har)15 b(*,)20 b(c)o(har)g(*)p Fj(\))208 3602
y Fr(F)o(or)f(internal)h(use)g(only)-5 b(.)0 3749 y Fj(PyObject)400
3764 y(*)498 3749 y Fg(_PyImport_FixupExtension)p Fj(\()p
Fo(c)o(har)15 b(*,)20 b(c)o(har)g(*)p Fj(\))208 3848
y Fr(F)o(or)f(internal)h(use)g(only)-5 b(.)0 3995 y Fj(int)49
b Fg(PyImport_ImportFrozenModule)p Fj(\()p Fo(c)o(har)15
b(*name)p Fj(\))208 4095 y Fr(Load)31 b(a)h(frozen)f(module)g(named)g
Fo(name)p Fr(.)60 b(Return)31 b Fj(1)i Fr(for)e(success,)k
Fj(0)e Fr(if)f(the)g(module)f(is)i(not)f(found,)h(and)e
Fj(-1)h Fr(with)h(an)208 4194 y(e)o(xception)16 b(set)k(if)f(the)g
(initialization)f(f)o(ailed.)24 b(T)-7 b(o)19 b(access)h(the)f
(imported)e(module)g(on)i(a)g(successful)f(load,)h(use)g
Fj(PyImport_-)208 4294 y(ImportModule\(\))p Fr(.)j(\(Note)c(the)g
(misnomer)f(\227)i(this)g(function)d(w)o(ould)i(reload)f(the)i(module)e
(if)h(it)h(w)o(as)h(already)d(imported.\))0 4441 y Fg(struct)49
b(_frozen)208 4541 y Fr(This)35 b(is)h(the)f(structure)f(type)h
(de\002nition)f(for)g(frozen)g(module)g(descriptors,)j(as)f(generated)d
(by)i(the)g Fp(fr)o(eeze)f Fr(utility)h(\(see)208 4640
y(`)p Fs(T)-9 b(ools/freez)o(e/)p Fr(')16 b(in)21 b(the)f(Python)f
(source)g(distrib)n(ution\).)24 b(Its)d(de\002nition,)d(found)h(in)h(`)
p Fs(Include/impor)s(t.h)p Fr(',)c(is:)444 4773 y Fk(struct)44
b(_frozen)f({)623 4864 y(char)847 4877 y(*)892 4864 y(name;)623
4956 y(unsigned)h(char)1251 4969 y(*)1296 4956 y(code;)623
5047 y(int)g(size;)444 5138 y(};)0 5338 y Fj(struct)49
b(_frozen)699 5353 y(*)797 5338 y Fg(PyImport_FrozenModules)p
0 5549 3901 4 v 0 5649 a Fn(5.3.)j(Impor)s(ting)25 b(Modules)2932
b(25)p eop end
%%Page: 26 32
TeXDict begin 26 31 bop 208 83 a Fr(This)16 b(pointer)f(is)i
(initialized)e(to)i(point)e(to)h(an)g(array)f(of)h Fj(struct)49
b(_frozen)15 b Fr(records,)h(terminated)f(by)g(one)h(whose)g(members)
208 183 y(are)25 b(all)h Fj(NULL)f Fr(or)f(zero.)40 b(When)25
b(a)h(frozen)d(module)h(is)i(imported,)f(it)h(is)g(searched)e(in)i
(this)g(table.)39 b(Third-party)23 b(code)i(could)208
282 y(play)19 b(tricks)i(with)f(this)h(to)f(pro)o(vide)e(a)j
(dynamically)d(created)h(collection)h(of)f(frozen)g(modules.)0
429 y Fj(int)49 b Fg(PyImport_AppendInittab)p Fj(\()p
Fo(c)o(har)16 b(*name)o(,)j(void)g(\(*initfunc\)\(void\))p
Fj(\))208 529 y Fr(Add)40 b(a)h(single)g(module)f(to)h(the)f(e)o
(xisting)h(table)f(of)h(b)n(uilt-in)f(modules.)86 b(This)41
b(is)h(a)f(con)m(v)o(enience)d(wrapper)h(around)208 628
y Fj(PyImport_ExtendInittab\(\))p Fr(,)29 b(returning)g
Fj(-1)i Fr(if)h(the)f(table)g(could)f(not)h(be)g(e)o(xtended.)55
b(The)31 b(ne)n(w)g(module)f(can)208 728 y(be)25 b(imported)f(by)i(the)
g(name)f Fo(name)p Fr(,)h(and)f(uses)i(the)e(function)g
Fo(initfunc)g Fr(as)h(the)g(initialization)f(function)f(called)i(on)f
(the)h(\002rst)208 828 y(attempted)19 b(import.)24 b(This)c(should)f
(be)h(called)g(before)f Fj(Py_Initialize\(\))p Fr(.)0
975 y Fg(struct)49 b(_inittab)208 1074 y Fr(Structure)22
b(describing)h(a)h(single)g(entry)f(in)h(the)g(list)h(of)f(b)n(uilt-in)
f(modules.)35 b(Each)23 b(of)h(these)g(structures)f(gi)n(v)o(es)h(the)g
(name)f(and)208 1174 y(initialization)17 b(function)f(for)h(a)i(module)
d(b)n(uilt)i(into)g(the)g(interpreter)-5 b(.)23 b(Programs)16
b(which)i(embed)f(Python)f(may)i(use)g(an)g(array)f(of)208
1273 y(these)j(structures)f(in)h(conjunction)e(with)i
Fj(PyImport_ExtendInittab\(\))c Fr(to)k(pro)o(vide)e(additional)h(b)n
(uilt-in)g(modules.)208 1373 y(The)g(structure)h(is)h(de\002ned)e(in)h
(`)p Fs(Include/impor)s(t.h)p Fr(')c(as:)444 1597 y Fk(struct)44
b(_inittab)f({)623 1689 y(char)847 1702 y(*)892 1689
y(name;)623 1780 y(void)h(\()892 1793 y(*)937 1780 y
(initfunc\)\(void\);)444 1871 y(};)0 2075 y Fj(int)49
b Fg(PyImport_ExtendInittab)p Fj(\()p Fo(struct)p 1560
2075 25 4 v 47 w(inittab)19 b(*ne)o(wtab)p Fj(\))208
2174 y Fr(Add)j(a)i(collection)e(of)h(modules)f(to)h(the)g(table)g(of)g
(b)n(uilt-in)f(modules.)33 b(The)23 b Fo(ne)o(wtab)f
Fr(array)g(must)h(end)g(with)g(a)g(sentinel)g(entry)208
2274 y(which)k(contains)h Fj(NULL)g Fr(for)g(the)g Fj(name)h
Fr(\002eld;)j(f)o(ailure)c(to)h(pro)o(vide)d(the)i(sentinel)h(v)n(alue)
e(can)h(result)h(in)f(a)h(memory)e(f)o(ault.)208 2374
y(Returns)22 b Fj(0)h Fr(on)g(success)g(or)f Fj(-1)h
Fr(if)g(insuf)n(\002cient)f(memory)f(could)h(be)h(allocated)f(to)h(e)o
(xtend)e(the)i(internal)f(table.)32 b(In)23 b(the)f(e)n(v)o(ent)208
2473 y(of)d(f)o(ailure,)h(no)g(modules)f(are)h(added)f(to)h(the)g
(internal)g(table.)25 b(This)20 b(should)f(be)h(called)g(before)f
Fj(Py_Initialize\(\))p Fr(.)0 2801 y Fl(5.4)121 b(Data)34
b(marshalling)g(suppor)5 b(t)0 3034 y Fr(These)27 b(routines)g(allo)n
(w)g(C)h(code)f(to)h(w)o(ork)f(with)g(serialized)g(objects)g(using)g
(the)h(same)f(data)h(format)e(as)i(the)g Fj(marshal)e
Fr(module.)0 3133 y(There)f(are)h(functions)e(to)i(write)g(data)g(into)
g(the)g(serialization)f(format,)h(and)f(additional)g(functions)f(that)i
(can)g(be)g(used)f(to)h(read)g(the)0 3233 y(data)20 b(back.)k(Files)e
(used)d(to)i(store)f(marshalled)f(data)h(must)g(be)g(opened)f(in)h
(binary)f(mode.)0 3380 y(Numeric)g(v)n(alues)h(are)g(stored)g(with)g
(the)g(least)h(signi\002cant)f(byte)g(\002rst.)0 3527
y(The)e(module)g(supports)g(tw)o(o)h(v)o(ersions)f(of)g(the)h(data)g
(format:)k(v)o(ersion)18 b(0)h(is)g(the)g(historical)g(v)o(ersion,)e(v)
o(ersion)h(1)h(\(ne)n(w)f(in)h(Python)f(2.4\))0 3626
y(shares)j(interned)e(strings)i(in)g(the)g(\002le,)h(and)e(upon)g
(unmarshalling.)25 b Fo(Py)p 2069 3626 V 29 w(MARSHAL)p
2468 3626 V 29 w(VERSION)g Fr(indicates)c(the)f(current)g(\002le)i
(format)0 3726 y(\(currently)c(1\).)0 3873 y Fj(void)49
b Fg(PyMarshal_WriteLongToFile)p Fj(\()p Fo(long)15 b(value)o(,)k(FILE)
h(*\002le)o(,)g(int)g(ver)o(sion)p Fj(\))208 3972 y Fr(Marshal)j(a)h
Fj(long)f Fr(inte)o(ger)m(,)g Fo(value)p Fr(,)g(to)h
Fo(\002le)p Fr(.)35 b(This)24 b(will)g(only)f(write)g(the)h
(least-signi\002cant)f(32)g(bits)h(of)f Fo(value)p Fr(;)i(re)o
(gardless)d(of)208 4072 y(the)e(size)h(of)f(the)g(nati)n(v)o(e)f
Fj(long)h Fr(type.)208 4205 y(Changed)e(in)j(v)o(ersion)e(2.4:)g
Fo(ver)o(sion)i Fr(indicates)f(the)g(\002le)h(format.)0
4352 y Fj(void)49 b Fg(PyMarshal_WriteObjectToFile)p
Fj(\()p Fo(PyObject)15 b(*value)o(,)k(FILE)h(*\002le)o(,)f(int)i(ver)o
(sion)p Fj(\))208 4451 y Fr(Marshal)e(a)i(Python)e(object,)g
Fo(value)p Fr(,)h(to)g Fo(\002le)p Fr(.)208 4584 y(Changed)e(in)j(v)o
(ersion)e(2.4:)g Fo(ver)o(sion)i Fr(indicates)f(the)g(\002le)h(format.)
0 4731 y Fj(PyObject)400 4746 y(*)498 4731 y Fg
(PyMarshal_WriteObjectToString)p Fj(\()p Fo(PyObjec)o(t)15
b(*value)o(,)k(int)i(ver)o(sion)p Fj(\))208 4831 y Fo(Return)e(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 4930 y Fr(Return)f(a)i(string)
f(object)f(containing)g(the)h(marshalled)f(representation)f(of)i
Fo(value)p Fr(.)208 5063 y(Changed)e(in)j(v)o(ersion)e(2.4:)g
Fo(ver)o(sion)i Fr(indicates)f(the)g(\002le)h(format.)0
5210 y(The)f(follo)n(wing)e(functions)h(allo)n(w)h(marshalled)f(v)n
(alues)h(to)h(be)f(read)f(back)h(in.)0 5357 y(XXX)30
b(What)g(about)e(error)g(detection?)52 b(It)30 b(appears)e(that)i
(reading)e(past)i(the)f(end)g(of)g(the)h(\002le)g(will)g(al)o(w)o(ays)g
(result)f(in)h(a)g(ne)o(gati)n(v)o(e)p 0 5549 3901 4
v 0 5649 a Fn(26)3078 b(Chapter)24 b(5.)51 b(Utilities)p
eop end
%%Page: 27 33
TeXDict begin 27 32 bop 0 83 a Fr(numeric)17 b(v)n(alue)h(\(where)g
(that')-5 b(s)19 b(rele)n(v)n(ant\),)e(b)n(ut)i(it')-5
b(s)20 b(not)e(clear)g(that)h(ne)o(gati)n(v)o(e)e(v)n(alues)h(w)o(on')o
(t)f(be)i(handled)e(properly)f(when)i(there')-5 b(s)19
b(no)0 183 y(error)-5 b(.)24 b(What')-5 b(s)21 b(the)f(right)g(w)o(ay)g
(to)h(tell?)k(Should)19 b(only)h(non-ne)o(gati)n(v)o(e)c(v)n(alues)k
(be)g(written)g(using)f(these)i(routines?)0 330 y Fj(long)49
b Fg(PyMarshal_ReadLongFromFile)p Fj(\()p Fo(FILE)15
b(*\002le)p Fj(\))208 429 y Fr(Return)j(a)h(C)h Fj(long)f
Fr(from)f(the)h(data)g(stream)g(in)g(a)g Fj(FILE)1844
444 y(*)1913 429 y Fr(opened)e(for)i(reading.)k(Only)18
b(a)i(32-bit)e(v)n(alue)g(can)h(be)g(read)f(in)h(using)208
529 y(this)h(function,)e(re)o(gardless)h(of)h(the)g(nati)n(v)o(e)g
(size)g(of)g Fj(long)p Fr(.)0 676 y Fj(int)49 b Fg
(PyMarshal_ReadShortFromFile)p Fj(\()p Fo(FILE)15 b(*\002le)p
Fj(\))208 775 y Fr(Return)25 b(a)h(C)g Fj(short)g Fr(from)e(the)i(data)
f(stream)h(in)g(a)g Fj(FILE)1961 790 y(*)2036 775 y Fr(opened)e(for)h
(reading.)40 b(Only)25 b(a)h(16-bit)e(v)n(alue)h(can)h(be)f(read)g(in)
208 875 y(using)19 b(this)i(function,)d(re)o(gardless)h(of)h(the)g
(nati)n(v)o(e)f(size)i(of)f Fj(short)p Fr(.)0 1022 y
Fj(PyObject)400 1037 y(*)498 1022 y Fg(PyMarshal_ReadObjectFromFile)p
Fj(\()p Fo(FILE)15 b(*\002le)p Fj(\))208 1121 y Fo(Return)k(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1221 y Fr(Return)27
b(a)h(Python)e(object)h(from)g(the)g(data)h(stream)f(in)h(a)g
Fj(FILE)2114 1236 y(*)2191 1221 y Fr(opened)e(for)h(reading.)45
b(On)28 b(error)m(,)g(sets)g(the)g(appropriate)208 1321
y(e)o(xception)18 b(\()p Fj(EOFError)h Fr(or)h Fj(TypeError)p
Fr(\))e(and)i(returns)f Fj(NULL)p Fr(.)0 1468 y Fj(PyObject)400
1483 y(*)498 1468 y Fg(PyMarshal_ReadLastObjectFromFile)p
Fj(\()p Fo(FI)o(LE)c(*\002le)p Fj(\))208 1567 y Fo(Return)k(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1667 y Fr(Return)38
b(a)i(Python)e(object)h(from)f(the)h(data)g(stream)g(in)g(a)h
Fj(FILE)2230 1682 y(*)2319 1667 y Fr(opened)d(for)i(reading.)80
b(Unlik)o(e)39 b Fj(PyMarshal_-)208 1766 y(ReadObjectFromFile\(\))p
Fr(,)18 b(this)j(function)f(assumes)h(that)g(no)g(further)f(objects)h
(will)h(be)f(read)f(from)g(the)i(\002le,)g(allo)n(wing)208
1866 y(it)e(to)h(aggressi)n(v)o(ely)d(load)h(\002le)i(data)f(into)g
(memory)e(so)j(that)f(the)g(de-serialization)e(can)i(operate)f(from)g
(data)h(in)g(memory)e(rather)208 1966 y(than)23 b(reading)f(a)h(byte)g
(at)h(a)g(time)g(from)e(the)i(\002le.)35 b(Only)23 b(use)h(these)g(v)n
(ariant)e(if)i(you)f(are)g(certain)g(that)h(you)e(w)o(on')o(t)h(be)g
(reading)208 2065 y(an)o(ything)d(else)j(from)f(the)g(\002le.)33
b(On)22 b(error)m(,)g(sets)i(the)e(appropriate)e(e)o(xception)h(\()p
Fj(EOFError)g Fr(or)h Fj(TypeError)p Fr(\))f(and)h(returns)208
2165 y Fj(NULL)p Fr(.)0 2312 y Fj(PyObject)400 2327 y(*)498
2312 y Fg(PyMarshal_ReadObjectFromString)p Fj(\()p Fo(c)o(h)o(ar)15
b(*string)o(,)20 b(Py)p 2583 2312 25 4 v 29 w(ssize)p
2768 2312 V 31 w(t)h(len)p Fj(\))208 2411 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2511 y Fr(Return)g(a)i(Python)f
(object)f(from)h(the)g(data)g(stream)h(in)f(a)h(character)e(b)n(uf)n
(fer)g(containing)g Fo(len)h Fr(bytes)g(pointed)f(to)i(by)f
Fo(string)p Fr(.)29 b(On)208 2611 y(error)m(,)18 b(sets)j(the)g
(appropriate)c(e)o(xception)i(\()p Fj(EOFError)g Fr(or)g
Fj(TypeError)p Fr(\))g(and)h(returns)f Fj(NULL)p Fr(.)0
2938 y Fl(5.5)121 b(P)-5 b(arsing)33 b(arguments)i(and)g(b)n(uilding)f
(v)m(alues)0 3171 y Fr(These)27 b(functions)e(are)i(useful)f(when)g
(creating)g(your)f(o)n(wn)i(e)o(xtensions)e(functions)g(and)i(methods.)
43 b(Additional)26 b(information)e(and)0 3271 y(e)o(xamples)19
b(are)h(a)n(v)n(ailable)g(in)g Fo(Extending)f(and)g(Embedding)f(the)i
(Python)f(Interpr)m(eter)p Fr(.)0 3417 y(The)24 b(\002rst)i(three)e(of)
h(these)g(functions)e(described,)i Fj(PyArg_ParseTuple\(\))p
Fr(,)e Fj(PyArg_ParseTupleAndKeywords\(\))p Fr(,)0 3517
y(and)e Fj(PyArg_Parse\(\))p Fr(,)g(all)h(use)g Fo(format)g(strings)h
Fr(which)e(are)h(used)g(to)g(tell)g(the)g(function)f(about)g(the)h(e)o
(xpected)e(ar)o(guments.)28 b(The)0 3617 y(format)19
b(strings)h(use)h(the)f(same)g(syntax)g(for)f(each)h(of)g(these)g
(functions.)0 3764 y(A)d(format)e(string)h(consists)h(of)g(zero)f(or)g
(more)f(\223format)h(units.)-6 b(\224)23 b(A)17 b(format)f(unit)g
(describes)g(one)g(Python)f(object;)i(it)g(is)h(usually)e(a)h(single)0
3863 y(character)i(or)g(a)h(parenthesized)e(sequence)h(of)h(format)e
(units.)25 b(W)m(ith)20 b(a)h(fe)n(w)e(e)o(xceptions,)f(a)j(format)d
(unit)i(that)g(is)h(not)e(a)i(parenthesized)0 3963 y(sequence)29
b(normally)f(corresponds)g(to)i(a)h(single)f(address)f(ar)o(gument)f
(to)i(these)g(functions.)54 b(In)29 b(the)h(follo)n(wing)f
(description,)i(the)0 4062 y(quoted)18 b(form)g(is)j(the)e(format)f
(unit;)i(the)f(entry)g(in)g(\(round\))e(parentheses)i(is)h(the)f
(Python)g(object)g(type)f(that)i(matches)f(the)g(format)g(unit;)0
4162 y(and)h(the)g(entry)f(in)i([square])d(brack)o(ets)i(is)h(the)f
(type)g(of)g(the)g(C)h(v)n(ariable\(s\))e(whose)h(address)f(should)h
(be)g(passed.)0 4392 y Fp(`)p Fg(s)p Fp(')g(\(string)g(or)g(Unicode)g
(object\))f([const)h(char)g(*])41 b Fr(Con)m(v)o(ert)17
b(a)h(Python)f(string)h(or)f(Unicode)g(object)h(to)g(a)g(C)h(pointer)e
(to)h(a)h(character)208 4492 y(string.)k(Y)-9 b(ou)16
b(must)h(not)f(pro)o(vide)f(storage)h(for)g(the)h(string)f(itself;)j(a)
e(pointer)e(to)i(an)g(e)o(xisting)f(string)g(is)i(stored)e(into)g(the)h
(character)208 4591 y(pointer)j(v)n(ariable)h(whose)g(address)h(you)e
(pass.)31 b(The)21 b(C)i(string)e(is)i(NUL-terminated.)28
b(The)21 b(Python)g(string)g(must)h(not)g(contain)208
4691 y(embedded)17 b(NUL)j(bytes;)g(if)f(it)i(does,)e(a)h
Fj(TypeError)f Fr(e)o(xception)f(is)i(raised.)25 b(Unicode)18
b(objects)i(are)f(con)m(v)o(erted)e(to)j(C)h(strings)208
4790 y(using)e(the)h(def)o(ault)g(encoding.)j(If)d(this)h(con)m(v)o
(ersion)c(f)o(ails,)k(a)f Fj(UnicodeError)f Fr(is)i(raised.)0
4956 y Fp(`)p Fg(s#)p Fp(')f(\(string,)f(Unicode)i(or)f(any)g(r)o(ead)f
(b)n(uffer)i(compatible)f(object\))f([const)h(char)g(*,)g(int])41
b Fr(This)18 b(v)n(ariant)g(on)g(`)p Fj(s)p Fr(')g(stores)g(into)g(tw)o
(o)208 5056 y(C)k(v)n(ariables,)e(the)h(\002rst)h(one)f(a)g(pointer)f
(to)i(a)f(character)f(string,)h(the)g(second)g(one)f(its)i(length.)27
b(In)21 b(this)h(case)g(the)f(Python)f(string)208 5156
y(may)g(contain)g(embedded)f(null)i(bytes.)28 b(Unicode)20
b(objects)h(pass)h(back)e(a)i(pointer)e(to)h(the)g(def)o(ault)g
(encoded)e(string)i(v)o(ersion)f(of)208 5255 y(the)g(object)f(if)i
(such)f(a)g(con)m(v)o(ersion)e(is)j(possible.)k(All)c(other)e(read-b)n
(uf)n(fer)e(compatible)i(objects)h(pass)h(back)e(a)i(reference)d(to)j
(the)208 5355 y(ra)o(w)f(internal)f(data)h(representation.)p
0 5549 3901 4 v 0 5649 a Fn(5.5.)52 b(P)m(arsing)23 b(arguments)h(and)f
(b)n(uilding)j(v)n(alues)2194 b(27)p eop end
%%Page: 28 34
TeXDict begin 28 33 bop 0 83 a Fp(`)p Fg(z)p Fp(')20
b(\(string)g(or)g Fg(None)p Fp(\))g([const)f(char)i(*])40
b Fr(Lik)o(e)23 b(`)p Fj(s)p Fr(',)f(b)n(ut)h(the)f(Python)g(object)f
(may)h(also)h(be)g Fj(None)p Fr(,)f(in)h(which)f(case)h(the)f(C)i
(pointer)208 183 y(is)d(set)g(to)f Fj(NULL)p Fr(.)0 349
y Fp(`)p Fg(z#)p Fp(')g(\(string)g(or)g Fg(None)g Fp(or)g(any)g(r)o
(ead)f(b)n(uffer)i(compatible)f(object\))f([const)h(char)g(*,)g(int])41
b Fr(This)20 b(is)h(to)g(`)p Fj(s#)p Fr(')e(as)i(`)p
Fj(z)p Fr(')f(is)h(to)g(`)p Fj(s)p Fr('.)0 515 y Fp(`)p
Fg(u)p Fp(')f(\(Unicode)g(object\))f([Py)p 856 515 25
4 v 29 w(UNICODE)h(*])41 b Fr(Con)m(v)o(ert)17 b(a)j(Python)d(Unicode)h
(object)g(to)h(a)g(C)h(pointer)d(to)i(a)g(NUL-terminated)e(b)n(uf)n
(fer)208 614 y(of)h(16-bit)h(Unicode)f(\(UTF-16\))f(data.)25
b(As)20 b(with)f(`)p Fj(s)p Fr(',)g(there)g(is)h(no)e(need)h(to)g(pro)o
(vide)e(storage)i(for)g(the)g(Unicode)f(data)h(b)n(uf)n(fer;)f(a)208
714 y(pointer)h(to)h(the)g(e)o(xisting)f(Unicode)h(data)g(is)h(stored)e
(into)h(the)h Fj(Py_UNICODE)d Fr(pointer)h(v)n(ariable)g(whose)h
(address)g(you)f(pass.)0 880 y Fp(`)p Fg(u#)p Fp(')h(\(Unicode)g
(object\))f([Py)p 906 880 V 29 w(UNICODE)h(*,)g(int])41
b Fr(This)23 b(v)n(ariant)f(on)g(`)p Fj(u)p Fr(')g(stores)h(into)f(tw)o
(o)h(C)h(v)n(ariables,)e(the)g(\002rst)i(one)e(a)h(pointer)208
980 y(to)30 b(a)h(Unicode)e(data)h(b)n(uf)n(fer)m(,)h(the)g(second)e
(one)h(its)h(length.)55 b(Non-Unicode)27 b(objects)k(are)f(handled)f
(by)h(interpreting)e(their)208 1079 y(read-b)n(uf)n(fer)17
b(pointer)i(as)i(pointer)e(to)h(a)h Fj(Py_UNICODE)e Fr(array)-5
b(.)0 1245 y Fp(`)p Fg(es)p Fp(')20 b(\(string,)f(Unicode)i(object)e
(or)h(character)f(b)n(uffer)i(compatible)e(object\))g([const)h(char)g
(*encoding,)g(char)g(**b)n(uffer])40 b Fr(This)208 1345
y(v)n(ariant)21 b(on)i(`)p Fj(s)p Fr(')f(is)i(used)f(for)f(encoding)f
(Unicode)h(and)g(objects)h(con)m(v)o(ertible)d(to)j(Unicode)f(into)g(a)
i(character)d(b)n(uf)n(fer)-5 b(.)32 b(It)23 b(only)208
1445 y(w)o(orks)c(for)h(encoded)e(data)i(without)g(embedded)e(NUL)i
(bytes.)208 1577 y(This)e(format)f(requires)g(tw)o(o)h(ar)o(guments.)k
(The)c(\002rst)h(is)g(only)e(used)h(as)h(input,)f(and)f(must)h(be)g(a)h
Fj(const)49 b(char)3408 1592 y(*)3475 1577 y Fr(which)18
b(points)208 1677 y(to)23 b(the)h(name)f(of)h(an)f(encoding)f(as)i(a)h
(NUL-terminated)c(string,)j(or)g Fj(NULL)p Fr(,)f(in)h(which)f(case)h
(the)g(def)o(ault)f(encoding)e(is)k(used.)208 1777 y(An)18
b(e)o(xception)e(is)j(raised)f(if)g(the)h(named)e(encoding)f(is)j(not)e
(kno)n(wn)g(to)h(Python.)23 b(The)18 b(second)f(ar)o(gument)f(must)i
(be)g(a)h Fj(char)3778 1792 y(**)3878 1777 y Fr(;)208
1876 y(the)i(v)n(alue)f(of)h(the)g(pointer)f(it)i(references)e(will)i
(be)f(set)h(to)g(a)f(b)n(uf)n(fer)f(with)h(the)h(contents)e(of)h(the)g
(ar)o(gument)e(te)o(xt.)28 b(The)21 b(te)o(xt)g(will)208
1976 y(be)f(encoded)e(in)i(the)h(encoding)d(speci\002ed)i(by)f(the)i
(\002rst)g(ar)o(gument.)208 2109 y Fj(PyArg_ParseTuple\(\))e
Fr(will)24 b(allocate)e(a)h(b)n(uf)n(fer)f(of)g(the)h(needed)e(size,)j
(cop)o(y)d(the)i(encoded)e(data)h(into)h(this)g(b)n(uf)n(fer)e(and)208
2208 y(adjust)i Fo(*b)n(uf)o(fer)i Fr(to)f(reference)e(the)i(ne)n(wly)f
(allocated)g(storage.)35 b(The)23 b(caller)h(is)g(responsible)f(for)g
(calling)g Fj(PyMem_Free\(\))208 2308 y Fr(to)d(free)g(the)g(allocated)
f(b)n(uf)n(fer)g(after)h(use.)0 2474 y Fp(`)p Fg(et)p
Fp(')g(\(string,)f(Unicode)i(object)e(or)h(character)f(b)n(uffer)i
(compatible)e(object\))g([const)h(char)g(*encoding,)g(char)g(**b)n
(uffer])208 2574 y Fr(Same)41 b(as)i(`)p Fj(es)p Fr(')e(e)o(xcept)g
(that)h(8-bit)f(string)g(objects)h(are)g(passed)f(through)f(without)h
(recoding)f(them.)89 b(Instead,)47 b(the)208 2673 y(implementation)18
b(assumes)i(that)g(the)g(string)g(object)g(uses)h(the)f(encoding)e
(passed)i(in)g(as)h(parameter)-5 b(.)0 2839 y Fp(`)p
Fg(es#)p Fp(')19 b(\(string,)h(Unicode)h(object)e(or)h(character)f(b)n
(uffer)h(compatible)g(object\))f([const)h(char)g(*encoding,)g(char)g
(**b)n(uffer)-8 b(,)19 b(int)i(*b)n(uffer)p 4150 2839
V 29 w(length])208 2939 y Fr(This)k(v)n(ariant)f(on)g(`)p
Fj(s#)p Fr(')g(is)i(used)f(for)f(encoding)f(Unicode)h(and)g(objects)h
(con)m(v)o(ertible)d(to)j(Unicode)f(into)h(a)g(character)f(b)n(uf)n
(fer)-5 b(.)208 3039 y(Unlik)o(e)19 b(the)i(`)p Fj(es)p
Fr(')e(format,)g(this)i(v)n(ariant)e(allo)n(ws)i(input)e(data)h(which)g
(contains)f(NUL)i(characters.)208 3171 y(It)i(requires)e(three)h(ar)o
(guments.)31 b(The)22 b(\002rst)i(is)f(only)f(used)h(as)g(input,)f(and)
h(must)f(be)h(a)g Fj(const)49 b(char)3186 3186 y(*)3258
3171 y Fr(which)22 b(points)h(to)g(the)208 3271 y(name)j(of)i(an)f
(encoding)f(as)i(a)g(NUL-terminated)d(string,)k(or)e
Fj(NULL)p Fr(,)g(in)h(which)f(case)h(the)f(def)o(ault)g(encoding)e(is)k
(used.)47 b(An)208 3371 y(e)o(xception)22 b(is)j(raised)g(if)f(the)h
(named)e(encoding)f(is)k(not)e(kno)n(wn)f(to)h(Python.)37
b(The)24 b(second)f(ar)o(gument)f(must)j(be)f(a)h Fj(char)3778
3386 y(**)3878 3371 y Fr(;)208 3470 y(the)c(v)n(alue)f(of)h(the)g
(pointer)f(it)i(references)e(will)i(be)f(set)h(to)g(a)f(b)n(uf)n(fer)f
(with)h(the)h(contents)e(of)h(the)g(ar)o(gument)e(te)o(xt.)28
b(The)21 b(te)o(xt)g(will)208 3570 y(be)g(encoded)e(in)i(the)h
(encoding)d(speci\002ed)i(by)f(the)i(\002rst)f(ar)o(gument.)26
b(The)21 b(third)f(ar)o(gument)f(must)i(be)h(a)f(pointer)f(to)h(an)h
(inte)o(ger;)208 3670 y(the)e(referenced)e(inte)o(ger)h(will)i(be)f
(set)h(to)f(the)g(number)f(of)h(bytes)g(in)g(the)g(output)f(b)n(uf)n
(fer)-5 b(.)208 3802 y(There)19 b(are)h(tw)o(o)g(modes)g(of)g
(operation:)208 3935 y(If)k Fo(*b)n(uf)o(fer)h Fr(points)f(a)g
Fj(NULL)g Fr(pointer)m(,)g(the)g(function)f(will)i(allocate)f(a)g(b)n
(uf)n(fer)f(of)h(the)g(needed)f(size,)j(cop)o(y)d(the)h(encoded)f(data)
208 4035 y(into)j(this)i(b)n(uf)n(fer)e(and)g(set)i Fo(*b)n(uf)o(fer)g
Fr(to)f(reference)f(the)h(ne)n(wly)f(allocated)g(storage.)45
b(The)27 b(caller)g(is)h(responsible)e(for)g(calling)208
4134 y Fj(PyMem_Free\(\))18 b Fr(to)i(free)g(the)g(allocated)g(b)n(uf)n
(fer)f(after)h(usage.)208 4267 y(If)k Fo(*b)n(uf)o(fer)i
Fr(points)e(to)h(a)g(non-)p Fj(NULL)d Fr(pointer)i(\(an)g(already)f
(allocated)h(b)n(uf)n(fer\),)g Fj(PyArg_ParseTuple\(\))e
Fr(will)j(use)g(this)208 4367 y(location)g(as)i(the)g(b)n(uf)n(fer)e
(and)h(interpret)g(the)g(initial)h(v)n(alue)f(of)g Fo(*b)n(uf)o(fer)p
2302 4367 V 29 w(length)g Fr(as)h(the)g(b)n(uf)n(fer)e(size.)45
b(It)26 b(will)i(then)e(cop)o(y)g(the)208 4467 y(encoded)c(data)i(into)
g(the)g(b)n(uf)n(fer)f(and)h(NUL-terminate)e(it.)38 b(If)24
b(the)g(b)n(uf)n(fer)f(is)i(not)f(lar)o(ge)f(enough,)g(a)i
Fj(ValueError)e Fr(will)i(be)208 4566 y(set.)208 4699
y(In)19 b(both)h(cases,)h Fo(*b)n(uf)o(fer)p 926 4699
V 28 w(length)e Fr(is)j(set)f(to)f(the)g(length)f(of)h(the)h(encoded)d
(data)i(without)f(the)i(trailing)e(NUL)i(byte.)0 4865
y Fp(`)p Fg(et#)p Fp(')e(\(string,)h(Unicode)h(object)e(or)h(character)
f(b)n(uffer)h(compatible)g(object\))f([const)h(char)g(*encoding,)g
(char)g(**b)n(uffer])208 4965 y Fr(Same)d(as)h(`)p Fj(es#)p
Fr(')e(e)o(xcept)h(that)g(string)g(objects)g(are)g(passed)g(through)e
(without)i(recoding)e(them.)24 b(Instead,)17 b(the)g(implementation)208
5064 y(assumes)j(that)g(the)h(string)e(object)h(uses)h(the)f(encoding)e
(passed)i(in)h(as)f(parameter)-5 b(.)0 5230 y Fp(`)p
Fg(b)p Fp(')20 b(\(integer\))f([char])40 b Fr(Con)m(v)o(ert)19
b(a)h(Python)f(inte)o(ger)g(to)i(a)f(tin)o(y)g(int,)g(stored)g(in)g(a)h
(C)g Fj(char)p Fr(.)p 0 5549 3901 4 v 0 5649 a Fn(28)3078
b(Chapter)24 b(5.)51 b(Utilities)p eop end
%%Page: 29 35
TeXDict begin 29 34 bop 0 83 a Fp(`)p Fg(B)p Fp(')20
b(\(integer\))f([unsigned)i(char])40 b Fr(Con)m(v)o(ert)d(a)h(Python)f
(inte)o(ger)g(to)i(a)f(tin)o(y)g(int)g(without)f(o)o(v)o(er\003o)n(w)g
(checking,)j(stored)e(in)g(a)h(C)208 183 y Fj(unsigned)48
b(char)p Fr(.)i(Ne)n(w)21 b(in)f(v)o(ersion)f(2.3.)0
344 y Fp(`)p Fg(h)p Fp(')h(\(integer\))f([short)h(int])41
b Fr(Con)m(v)o(ert)18 b(a)j(Python)e(inte)o(ger)g(to)i(a)f(C)h
Fj(short)49 b(int)p Fr(.)0 505 y Fp(`)p Fg(H)p Fp(')20
b(\(integer\))f([unsigned)i(short)f(int])41 b Fr(Con)m(v)o(ert)34
b(a)i(Python)e(inte)o(ger)g(to)i(a)g(C)g Fj(unsigned)49
b(short)g(int)p Fr(,)39 b(without)34 b(o)o(v)o(er\003o)n(w)208
605 y(checking.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.3.)0
766 y Fp(`)p Fg(i)p Fp(')h(\(integer\))f([int])41 b Fr(Con)m(v)o(ert)18
b(a)j(Python)e(inte)o(ger)g(to)h(a)h(plain)f(C)h Fj(int)p
Fr(.)0 927 y Fp(`)p Fg(I)p Fp(')f(\(integer\))f([unsigned)i(int])41
b Fr(Con)m(v)o(ert)19 b(a)i(Python)f(inte)o(ger)g(to)h(a)h(C)f
Fj(unsigned)49 b(int)p Fr(,)21 b(without)f(o)o(v)o(er\003o)n(w)f
(checking.)53 b(Ne)n(w)21 b(in)208 1027 y(v)o(ersion)d(2.3.)0
1188 y Fp(`)p Fg(l)p Fp(')i(\(integer\))f([long)h(int])41
b Fr(Con)m(v)o(ert)18 b(a)j(Python)e(inte)o(ger)g(to)h(a)h(C)g
Fj(long)49 b(int)p Fr(.)0 1349 y Fp(`)p Fg(k)p Fp(')20
b(\(integer\))f([unsigned)i(long])40 b Fr(Con)m(v)o(ert)23
b(a)i(Python)f(inte)o(ger)f(or)h(long)g(inte)o(ger)g(to)g(a)h(C)h
Fj(unsigned)48 b(long)25 b Fr(without)e(o)o(v)o(er\003o)n(w)208
1449 y(checking.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.3.)0
1610 y Fp(`)p Fg(L)p Fp(')h(\(integer\))f([PY)p 595 1610
25 4 v 29 w(LONG)p 869 1610 V 29 w(LONG])41 b Fr(Con)m(v)o(ert)24
b(a)i(Python)e(inte)o(ger)g(to)h(a)h(C)g Fj(long)50 b(long)p
Fr(.)40 b(This)25 b(format)f(is)j(only)d(a)n(v)n(ailable)h(on)208
1710 y(platforms)19 b(that)h(support)f Fj(long)49 b(long)20
b Fr(\(or)f Fj(_int64)h Fr(on)g(W)m(indo)n(ws\).)0 1871
y Fp(`)p Fg(K)p Fp(')g(\(integer\))f([unsigned)i(PY)p
934 1871 V 29 w(LONG)p 1208 1871 V 30 w(LONG])40 b Fr(Con)m(v)o(ert)32
b(a)i(Python)e(inte)o(ger)g(or)h(long)g(inte)o(ger)f(to)h(a)h(C)g
Fj(unsigned)49 b(long)208 1971 y(long)24 b Fr(without)f(o)o(v)o
(er\003o)n(w)g(checking.)36 b(This)24 b(format)g(is)h(only)f(a)n(v)n
(ailable)g(on)g(platforms)f(that)h(support)f Fj(unsigned)49
b(long)208 2070 y(long)20 b Fr(\(or)f Fj(unsigned)48
b(_int64)20 b Fr(on)g(W)m(indo)n(ws\).)50 b(Ne)n(w)20
b(in)g(v)o(ersion)f(2.3.)0 2232 y Fp(`)p Fg(n)p Fp(')h(\(integer\))f
([Py)p 577 2232 V 29 w(ssize)p 767 2232 V 30 w(t])41
b Fr(Con)m(v)o(ert)18 b(a)j(Python)e(inte)o(ger)g(or)h(long)f(inte)o
(ger)g(to)i(a)f(C)i Fj(Py_ssize_t)p Fr(.)49 b(Ne)n(w)20
b(in)h(v)o(ersion)e(2.5.)0 2393 y Fp(`)p Fg(c)p Fp(')h(\(string)g(of)g
(length)g(1\))g([char])40 b Fr(Con)m(v)o(ert)19 b(a)h(Python)f
(character)m(,)g(represented)f(as)j(a)g(string)f(of)f(length)h(1,)g(to)
g(a)h(C)g Fj(char)p Fr(.)0 2554 y Fp(`)p Fg(f)p Fp(')f(\(\003oat\))f
([\003oat])39 b Fr(Con)m(v)o(ert)19 b(a)i(Python)e(\003oating)g(point)h
(number)e(to)i(a)h(C)g Fj(float)p Fr(.)0 2715 y Fp(`)p
Fg(d)p Fp(')f(\(\003oat\))f([double])40 b Fr(Con)m(v)o(ert)19
b(a)i(Python)e(\003oating)g(point)h(number)e(to)i(a)h(C)g
Fj(double)p Fr(.)0 2877 y Fp(`)p Fg(D)p Fp(')f(\(complex\))f([Py)p
623 2877 V 29 w(complex])40 b Fr(Con)m(v)o(ert)19 b(a)h(Python)f
(comple)o(x)g(number)f(to)j(a)f(C)h Fj(Py_complex)e Fr(structure.)0
3038 y Fp(`)p Fg(O)p Fp(')h(\(object\))f([PyObject)f(*])41
b Fr(Store)21 b(a)h(Python)e(object)h(\(without)f(an)o(y)h(con)m(v)o
(ersion\))d(in)k(a)g(C)g(object)f(pointer)-5 b(.)28 b(The)21
b(C)h(program)e(thus)208 3137 y(recei)n(v)o(es)i(the)h(actual)g(object)
g(that)h(w)o(as)g(passed.)34 b(The)23 b(object')-5 b(s)23
b(reference)e(count)i(is)h(not)f(increased.)33 b(The)23
b(pointer)f(stored)h(is)208 3237 y(not)c Fj(NULL)p Fr(.)0
3398 y Fp(`)p Fg(O!)p Fp(')h(\(object\))e([)p Ff(typeobject)p
Fp(,)h(PyObject)g(*])40 b Fr(Store)25 b(a)h(Python)e(object)g(in)h(a)h
(C)f(object)g(pointer)-5 b(.)38 b(This)26 b(is)f(similar)h(to)f(`)p
Fj(O)p Fr(',)f(b)n(ut)h(tak)o(es)208 3498 y(tw)o(o)c(C)g(ar)o(guments:)
k(the)c(\002rst)g(is)h(the)f(address)f(of)g(a)i(Python)d(type)i
(object,)f(the)h(second)f(is)h(the)g(address)f(of)h(the)g(C)h(v)n
(ariable)d(\(of)208 3598 y(type)g Fj(PyObject)771 3613
y(*)821 3598 y Fr(\))f(into)i(which)g(the)f(object)h(pointer)f(is)h
(stored.)25 b(If)20 b(the)f(Python)g(object)h(does)f(not)h(ha)n(v)o(e)f
(the)h(required)e(type,)208 3697 y Fj(TypeError)h Fr(is)i(raised.)0
3858 y Fp(`)p Fg(O&)p Fp(')f(\(object\))e([)p Ff(con)m(v)o(erter)p
Fp(,)i Ff(anything)p Fp(])40 b Fr(Con)m(v)o(ert)20 b(a)h(Python)f
(object)g(to)h(a)g(C)h(v)n(ariable)d(through)g(a)i Fo(con)m(verter)h
Fr(function.)j(This)c(tak)o(es)208 3958 y(tw)o(o)h(ar)o(guments:)k(the)
c(\002rst)g(is)h(a)f(function,)f(the)h(second)e(is)j(the)f(address)f
(of)h(a)g(C)h(v)n(ariable)e(\(of)g(arbitrary)f(type\),)h(con)m(v)o
(erted)e(to)208 4058 y Fj(void)457 4073 y(*)507 4058
y Fr(.)25 b(The)20 b Fo(con)m(verter)h Fr(function)e(in)h(turn)g(is)h
(called)f(as)h(follo)n(ws:)208 4188 y Fo(status)49 b
Fj(=)h Fo(con)m(verter)r Fj(\()p Fo(object)q Fr(,)18
b Fo(addr)m(ess)p Fj(\);)208 4319 y Fr(where)31 b Fo(object)j
Fr(is)f(the)f(Python)g(object)f(to)i(be)f(con)m(v)o(erted)e(and)i
Fo(addr)m(ess)g Fr(is)h(the)g Fj(void)2836 4334 y(*)2917
4319 y Fr(ar)o(gument)d(that)j(w)o(as)g(passed)f(to)208
4418 y(the)c Fj(PyArg_Parse)888 4433 y(*)938 4418 y(\(\))f
Fr(function.)49 b(The)28 b(returned)f Fo(status)i Fr(should)f(be)g
Fj(1)i Fr(for)e(a)h(successful)f(con)m(v)o(ersion)e(and)i
Fj(0)i Fr(if)f(the)208 4518 y(con)m(v)o(ersion)17 b(has)j(f)o(ailed.)25
b(When)20 b(the)g(con)m(v)o(ersion)e(f)o(ails,)j(the)f
Fo(con)m(verter)h Fr(function)e(should)g(raise)h(an)g(e)o(xception.)0
4679 y Fp(`)p Fg(S)p Fp(')g(\(string\))f([PyStringObject)f(*])41
b Fr(Lik)o(e)23 b(`)p Fj(O)p Fr(')f(b)n(ut)h(requires)f(that)h(the)g
(Python)f(object)g(is)i(a)f(string)g(object.)32 b(Raises)25
b Fj(TypeError)208 4779 y Fr(if)20 b(the)g(object)g(is)h(not)f(a)h
(string)e(object.)25 b(The)20 b(C)h(v)n(ariable)e(may)h(also)g(be)g
(declared)f(as)i Fj(PyObject)3066 4794 y(*)3116 4779
y Fr(.)0 4940 y Fp(`)p Fg(U)p Fp(')f(\(Unicode)g(string\))g
([PyUnicodeObject)e(*])40 b Fr(Lik)o(e)23 b(`)p Fj(O)p
Fr(')g(b)n(ut)g(requires)e(that)i(the)g(Python)f(object)g(is)i(a)f
(Unicode)f(object.)32 b(Raises)208 5040 y Fj(TypeError)19
b Fr(if)h(the)g(object)g(is)h(not)f(a)h(Unicode)e(object.)24
b(The)c(C)h(v)n(ariable)e(may)h(also)g(be)g(declared)f(as)i
Fj(PyObject)3627 5055 y(*)3677 5040 y Fr(.)0 5201 y Fp(`)p
Fg(t#)p Fp(')f(\(r)o(ead-only)e(character)h(b)n(uffer\))h([char)g(*,)g
(int])41 b Fr(Lik)o(e)26 b(`)p Fj(s#)p Fr(',)g(b)n(ut)g(accepts)g(an)o
(y)f(object)h(which)f(implements)g(the)h(read-only)208
5300 y(b)n(uf)n(fer)16 b(interf)o(ace.)24 b(The)18 b
Fj(char)1109 5315 y(*)1177 5300 y Fr(v)n(ariable)f(is)i(set)g(to)f
(point)g(to)g(the)h(\002rst)g(byte)e(of)h(the)h(b)n(uf)n(fer)m(,)d(and)
i(the)g Fj(int)h Fr(is)g(set)g(to)f(the)g(length)208
5400 y(of)h(the)i(b)n(uf)n(fer)-5 b(.)24 b(Only)19 b(single-se)o(gment)
g(b)n(uf)n(fer)g(objects)g(are)i(accepted;)e Fj(TypeError)g
Fr(is)i(raised)f(for)g(all)g(others.)p 0 5549 3901 4
v 0 5649 a Fn(5.5.)52 b(P)m(arsing)23 b(arguments)h(and)f(b)n(uilding)j
(v)n(alues)2194 b(29)p eop end
%%Page: 30 36
TeXDict begin 30 35 bop 0 83 a Fp(`)p Fg(w)p Fp(')20
b(\(r)o(ead-write)e(character)h(b)n(uffer\))h([char)g(*])41
b Fr(Similar)25 b(to)h(`)p Fj(s)p Fr(',)h(b)n(ut)f(accepts)g(an)o(y)f
(object)g(which)g(implements)g(the)h(read-write)208 183
y(b)n(uf)n(fer)c(interf)o(ace.)33 b(The)23 b(caller)g(must)h(determine)
e(the)h(length)g(of)g(the)g(b)n(uf)n(fer)f(by)h(other)g(means,)g(or)g
(use)h(`)p Fj(w#)p Fr(')f(instead.)34 b(Only)208 282
y(single-se)o(gment)18 b(b)n(uf)n(fer)h(objects)h(are)g(accepted;)f
Fj(TypeError)g Fr(is)i(raised)f(for)g(all)g(others.)0
445 y Fp(`)p Fg(w#)p Fp(')g(\(r)o(ead-write)e(character)h(b)n(uffer\))h
([char)g(*,)g(int])41 b Fr(Lik)o(e)20 b(`)p Fj(s#)p Fr(',)f(b)n(ut)h
(accepts)g(an)o(y)f(object)g(which)h(implements)f(the)h(read-write)208
544 y(b)n(uf)n(fer)k(interf)o(ace.)41 b(The)25 b Fj(char)1190
559 y(*)1266 544 y Fr(v)n(ariable)g(is)i(set)f(to)g(point)f(to)h(the)g
(\002rst)h(byte)e(of)g(the)h(b)n(uf)n(fer)m(,)g(and)f(the)h
Fj(int)f Fr(is)i(set)g(to)f(the)208 644 y(length)19 b(of)h(the)g(b)n
(uf)n(fer)-5 b(.)24 b(Only)c(single-se)o(gment)e(b)n(uf)n(fer)h
(objects)h(are)g(accepted;)f Fj(TypeError)g Fr(is)i(raised)f(for)g(all)
h(others.)0 806 y Fp(`)p Fg(\()p Ff(items)p Fg(\))p Fp(')f(\(tuple\))g
([)p Ff(matc)o(hing-items)p Fp(])39 b Fr(The)16 b(object)f(must)h(be)g
(a)g(Python)f(sequence)g(whose)h(length)f(is)i(the)f(number)e(of)i
(format)f(units)208 906 y(in)21 b Fo(items)p Fr(.)31
b(The)21 b(C)i(ar)o(guments)d(must)h(correspond)e(to)j(the)g(indi)n
(vidual)e(format)h(units)g(in)h Fo(items)p Fr(.)31 b(F)o(ormat)21
b(units)g(for)g(sequences)208 1006 y(may)e(be)h(nested.)208
1137 y Fp(Note:)37 b Fr(Prior)26 b(to)g(Python)g(v)o(ersion)f(1.5.2,)i
(this)g(format)e(speci\002er)i(only)e(accepted)h(a)h(tuple)f
(containing)f(the)h(indi)n(vidual)f(pa-)208 1236 y(rameters,)i(not)f
(an)g(arbitrary)e(sequence.)43 b(Code)26 b(which)f(pre)n(viously)g
(caused)h Fj(TypeError)f Fr(to)h(be)g(raised)h(here)e(may)h(no)n(w)208
1336 y(proceed)18 b(without)i(an)g(e)o(xception.)j(This)d(is)h(not)f(e)
o(xpected)f(to)h(be)g(a)h(problem)d(for)i(e)o(xisting)f(code.)0
1557 y(It)i(is)g(possible)f(to)h(pass)g(Python)e(long)h(inte)o(gers)f
(where)h(inte)o(gers)f(are)i(requested;)e(ho)n(we)n(v)o(er)g(no)h
(proper)e(range)i(checking)e(is)k(done)d(\227)0 1656
y(the)k(most)g(signi\002cant)g(bits)h(are)f(silently)g(truncated)f
(when)g(the)i(recei)n(ving)d(\002eld)i(is)i(too)d(small)i(to)f(recei)n
(v)o(e)g(the)g(v)n(alue)f(\(actually)-5 b(,)23 b(the)0
1756 y(semantics)d(are)g(inherited)f(from)g(do)n(wncasts)h(in)g(C)h
(\227)g(your)e(mileage)h(may)f(v)n(ary\).)0 1903 y(A)i(fe)n(w)f(other)f
(characters)g(ha)n(v)o(e)h(a)h(meaning)d(in)j(a)f(format)f(string.)25
b(These)20 b(may)g(not)g(occur)f(inside)h(nested)g(parentheses.)j(The)o
(y)d(are:)0 2123 y Fp(`)p Fg(|)p Fp(')41 b Fr(Indicates)23
b(that)h(the)g(remaining)e(ar)o(guments)g(in)i(the)g(Python)f(ar)o
(gument)e(list)26 b(are)d(optional.)35 b(The)24 b(C)h(v)n(ariables)e
(corresponding)208 2223 y(to)d(optional)f(ar)o(guments)f(should)h(be)h
(initialized)g(to)g(their)g(def)o(ault)g(v)n(alue)f(\227)i(when)e(an)h
(optional)f(ar)o(gument)f(is)j(not)f(speci\002ed,)208
2323 y Fj(PyArg_ParseTuple\(\))d Fr(does)j(not)g(touch)f(the)h
(contents)g(of)g(the)g(corresponding)c(C)22 b(v)n(ariable\(s\).)0
2485 y Fp(`)p Fg(:)p Fp(')41 b Fr(The)23 b(list)j(of)e(format)f(units)h
(ends)g(here;)h(the)f(string)g(after)g(the)g(colon)f(is)i(used)f(as)h
(the)f(function)f(name)g(in)i(error)e(messages)h(\(the)208
2585 y(\223associated)19 b(v)n(alue\224)h(of)g(the)g(e)o(xception)e
(that)i Fj(PyArg_ParseTuple\(\))e Fr(raises\).)0 2747
y Fp(`)p Fg(;)p Fp(')41 b Fr(The)18 b(list)i(of)e(format)g(units)h
(ends)f(here;)h(the)g(string)f(after)h(the)g(semicolon)e(is)j(used)e
(as)i(the)f(error)e(message)i Fo(instead)f Fr(of)h(the)f(def)o(ault)208
2847 y(error)h(message.)24 b(Clearly)-5 b(,)20 b(`)p
Fj(:)p Fr(')25 b(and)19 b(`)p Fj(;)p Fr(')h(mutually)f(e)o(xclude)g
(each)h(other)-5 b(.)0 3068 y(Note)26 b(that)f(an)o(y)g(Python)g
(object)g(references)f(which)h(are)h(pro)o(vided)d(to)j(the)f(caller)h
(are)f Fo(borr)l(owed)h Fr(references;)h(do)e(not)g(decrement)0
3167 y(their)20 b(reference)e(count!)0 3314 y(Additional)f(ar)o
(guments)f(passed)i(to)h(these)f(functions)f(must)h(be)h(addresses)f
(of)g(v)n(ariables)f(whose)h(type)g(is)h(determined)e(by)g(the)i
(format)0 3414 y(string;)g(these)g(are)g(used)f(to)h(store)g(v)n(alues)
f(from)g(the)g(input)g(tuple.)24 b(There)18 b(are)h(a)g(fe)n(w)g
(cases,)g(as)h(described)d(in)i(the)g(list)g(of)g(format)f(units)0
3513 y(abo)o(v)o(e,)26 b(where)g(these)h(parameters)f(are)g(used)h(as)g
(input)f(v)n(alues;)k(the)o(y)c(should)f(match)i(what)f(is)i
(speci\002ed)e(for)g(the)h(corresponding)0 3613 y(format)19
b(unit)h(in)g(that)h(case.)0 3760 y(F)o(or)i(the)g(con)m(v)o(ersion)e
(to)j(succeed,)f(the)g Fo(ar)m(g)h Fr(object)f(must)g(match)g(the)g
(format)g(and)f(the)i(format)e(must)i(be)f(e)o(xhausted.)33
b(On)23 b(success,)0 3859 y(the)d Fj(PyArg_Parse)672
3874 y(*)722 3859 y(\(\))e Fr(functions)h(return)g(true,)h(otherwise)f
(the)o(y)h(return)f(f)o(alse)h(and)g(raise)h(an)f(appropriate)e(e)o
(xception.)0 4006 y Fj(int)49 b Fg(PyArg_ParseTuple)p
Fj(\()p Fo(PyObject)17 b(*ar)m(gs,)i(const)h(c)o(har)g(*format,)f(...)p
Fj(\))208 4106 y Fr(P)o(arse)26 b(the)h(parameters)e(of)i(a)g(function)
e(that)h(tak)o(es)h(only)f(positional)g(parameters)f(into)h(local)h(v)n
(ariables.)43 b(Returns)27 b(true)f(on)208 4206 y(success;)20
b(on)g(f)o(ailure,)g(it)g(returns)g(f)o(alse)g(and)g(raises)h(the)f
(appropriate)e(e)o(xception.)0 4352 y Fj(int)49 b Fg(PyArg_VaParse)p
Fj(\()p Fo(PyObject)17 b(*ar)m(gs,)j(const)g(c)o(har)g(*format,)f(va)p
2210 4352 25 4 v 29 w(list)j(var)m(gs)p Fj(\))208 4452
y Fr(Identical)j(to)i Fj(PyArg_ParseTuple\(\))p Fr(,)e(e)o(xcept)h
(that)h(it)g(accepts)g(a)g(v)n(a)p 2449 4452 V 29 w(list)h(rather)d
(than)i(a)g(v)n(ariable)e(number)g(of)h(ar)o(gu-)208
4552 y(ments.)0 4699 y Fj(int)49 b Fg(PyArg_ParseTupleAndKeywords)p
Fj(\()p Fo(PyObject)11 b(*ar)m(gs,)16 b(PyObject)g(*kw)-6
b(,)17 b(const)g(c)o(har)f(*format,)g(c)o(har)g(*k)o(e)n(ywor)m(ds[],)
1599 4798 y(...)p Fj(\))208 4872 y Fr(P)o(arse)23 b(the)h(parameters)e
(of)h(a)h(function)e(that)h(tak)o(es)h(both)e(positional)h(and)g(k)o(e)
o(yw)o(ord)e(parameters)i(into)g(local)g(v)n(ariables.)34
b(Re-)208 4972 y(turns)19 b(true)h(on)g(success;)h(on)f(f)o(ailure,)f
(it)i(returns)e(f)o(alse)i(and)e(raises)i(the)f(appropriate)e(e)o
(xception.)0 5119 y Fj(int)49 b Fg(PyArg_VaParseTupleAndKeywords)p
Fj(\()p Fo(PyObjec)o(t)30 b(*ar)m(gs,)38 b(PyObject)d(*kw)-6
b(,)39 b(const)34 b(c)o(har)h(*format,)j(c)o(har)d(*k)o(e)n(y-)1699
5218 y(wor)m(ds[],)16 b(va)p 2084 5218 V 29 w(list)21
b(var)m(gs)p Fj(\))208 5300 y Fr(Identical)28 b(to)h
Fj(PyArg_ParseTupleAndKeywords\(\))p Fr(,)d(e)o(xcept)i(that)i(it)f
(accepts)g(a)h(v)n(a)p 3017 5300 V 29 w(list)g(rather)f(than)f(a)i(v)n
(ariable)208 5400 y(number)18 b(of)i(ar)o(guments.)p
0 5549 3901 4 v 0 5649 a Fn(30)3078 b(Chapter)24 b(5.)51
b(Utilities)p eop end
%%Page: 31 37
TeXDict begin 31 36 bop 0 83 a Fj(int)49 b Fg(PyArg_Parse)p
Fj(\()p Fo(PyObject)18 b(*ar)m(gs,)h(const)h(c)o(har)g(*format,)f(...)p
Fj(\))208 183 y Fr(Function)25 b(used)h(to)g(deconstruct)e(the)j(ar)o
(gument)d(lists)j(of)f(\223old-style\224)f(functions)g(\227)i(these)f
(are)h(functions)d(which)i(use)h(the)208 282 y Fj(METH_OLDARGS)f
Fr(parameter)g(parsing)h(method.)47 b(This)28 b(is)h(not)f(recommended)
d(for)i(use)h(in)g(parameter)f(parsing)g(in)h(ne)n(w)208
382 y(code,)19 b(and)h(most)g(code)g(in)g(the)h(standard)e(interpreter)
f(has)j(been)f(modi\002ed)f(to)h(no)g(longer)f(use)i(this)f(for)g(that)
g(purpose.)k(It)d(does)208 482 y(remain)e(a)h(con)m(v)o(enient)e(w)o
(ay)i(to)h(decompose)d(other)h(tuples,)h(ho)n(we)n(v)o(er)m(,)e(and)h
(may)h(continue)f(to)h(be)g(used)g(for)g(that)g(purpose.)0
628 y Fj(int)49 b Fg(PyArg_UnpackTuple)p Fj(\()p Fo(PyObject)17
b(*ar)m(gs,)i(const)h(c)o(har)g(*name)o(,)f(Py)p 2376
628 25 4 v 29 w(ssize)p 2561 628 V 31 w(t)i(min,)f(Py)p
2890 628 V 29 w(ssize)p 3075 628 V 31 w(t)h(max,)f(...)p
Fj(\))208 728 y Fr(A)h(simpler)g(form)f(of)h(parameter)f(retrie)n(v)n
(al)g(which)g(does)h(not)g(use)g(a)h(format)e(string)h(to)g(specify)g
(the)g(types)g(of)g(the)g(ar)o(guments.)208 828 y(Functions)16
b(which)g(use)h(this)g(method)f(to)h(retrie)n(v)o(e)f(their)g
(parameters)g(should)g(be)h(declared)e(as)j Fj(METH_VARARGS)d
Fr(in)i(function)208 927 y(or)29 b(method)f(tables.)54
b(The)29 b(tuple)h(containing)e(the)h(actual)h(parameters)e(should)h
(be)h(passed)f(as)i Fo(ar)m(gs)p Fr(;)j(it)d(must)f(actually)f(be)208
1027 y(a)i(tuple.)59 b(The)31 b(length)f(of)h(the)h(tuple)f(must)g(be)g
(at)h(least)g Fo(min)g Fr(and)f(no)g(more)f(than)h Fo(max)p
Fr(;)37 b Fo(min)32 b Fr(and)f Fo(max)g Fr(may)g(be)g(equal.)208
1127 y(Additional)d(ar)o(guments)g(must)i(be)g(passed)g(to)g(the)g
(function,)h(each)f(of)f(which)h(should)f(be)h(a)g(pointer)f(to)h(a)h
Fj(PyObject)3852 1142 y(*)208 1226 y Fr(v)n(ariable;)21
b(these)g(will)h(be)g(\002lled)f(in)h(with)g(the)f(v)n(alues)g(from)f
Fo(ar)m(gs)p Fr(;)j(the)o(y)d(will)j(contain)d(borro)n(wed)f
(references.)27 b(The)21 b(v)n(ariables)208 1326 y(which)i(correspond)f
(to)i(optional)f(parameters)g(not)h(gi)n(v)o(en)f(by)h
Fo(ar)m(gs)g Fr(will)h(not)f(be)g(\002lled)g(in;)j(these)d(should)f(be)
h(initialized)g(by)208 1425 y(the)c(caller)-5 b(.)28
b(This)21 b(function)e(returns)h(true)h(on)f(success)i(and)e(f)o(alse)h
(if)g Fo(ar)m(gs)g Fr(is)h(not)f(a)g(tuple)g(or)f(contains)g(the)h
(wrong)f(number)f(of)208 1525 y(elements;)h(an)g(e)o(xception)e(will)j
(be)f(set)h(if)f(there)g(w)o(as)h(a)g(f)o(ailure.)208
1654 y(This)27 b(is)g(an)g(e)o(xample)f(of)g(the)h(use)g(of)g(this)g
(function,)f(tak)o(en)h(from)f(the)h(sources)f(for)g(the)h
Fj(_weakref)f Fr(helper)g(module)f(for)208 1754 y(weak)19
b(references:)444 1974 y Fk(static)44 b(PyObject)1161
1987 y(*)444 2066 y(weakref_ref\(PyObject)1385 2079 y(*)1430
2066 y(self,)g(PyObject)2103 2079 y(*)2148 2066 y(args\))444
2157 y({)623 2248 y(PyObject)1027 2261 y(*)1072 2248
y(object;)623 2340 y(PyObject)1027 2353 y(*)1072 2340
y(callback)f(=)i(NULL;)623 2431 y(PyObject)1027 2444
y(*)1072 2431 y(result)e(=)i(NULL;)623 2613 y(if)g
(\(PyArg_UnpackTuple\(args,)40 b("ref",)k(1,)h(2,)f(&object,)g
(&callback\)\))f({)802 2705 y(result)h(=)h(PyWeakref_NewRef\(object,)c
(callback\);)623 2796 y(})623 2887 y(return)j(result;)444
2979 y(})208 3164 y Fr(The)d(call)i(to)g Fj(PyArg_UnpackTuple\(\))c
Fr(in)j(this)h(e)o(xample)e(is)i(entirely)e(equi)n(v)n(alent)g(to)h
(this)h(call)g(to)f Fj(PyArg_-)208 3264 y(ParseTuple\(\))p
Fr(:)444 3485 y Fk(PyArg_ParseTuple\(args,)f("O|O:ref",)i(&object,)h
(&callback\))208 3670 y Fr(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)0
3817 y Fj(PyObject)400 3832 y(*)498 3817 y Fg(Py_BuildValue)p
Fj(\()p Fo(const)f(c)o(har)h(*format,)h(...)p Fj(\))208
3917 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4016 y Fr(Create)27 b(a)h(ne)n(w)g(v)n(alue)e(based)i(on)f(a)h
(format)e(string)h(similar)h(to)g(those)f(accepted)g(by)g(the)g
Fj(PyArg_Parse)3411 4031 y(*)3461 4016 y(\(\))f Fr(f)o(amily)h(of)208
4116 y(functions)e(and)h(a)h(sequence)f(of)g(v)n(alues.)45
b(Returns)26 b(the)h(v)n(alue)f(or)h Fj(NULL)f Fr(in)h(the)g(case)g(of)
g(an)f(error;)k(an)c(e)o(xception)f(will)j(be)208 4216
y(raised)20 b(if)g Fj(NULL)g Fr(is)h(returned.)208 4345
y Fj(Py_BuildValue\(\))g Fr(does)j(not)g(al)o(w)o(ays)g(b)n(uild)f(a)i
(tuple.)36 b(It)24 b(b)n(uilds)g(a)g(tuple)g(only)f(if)h(its)h(format)e
(string)g(contains)h(tw)o(o)g(or)208 4444 y(more)18 b(format)f(units.)
25 b(If)18 b(the)h(format)f(string)g(is)i(empty)-5 b(,)17
b(it)j(returns)e Fj(None)p Fr(;)h(if)g(it)h(contains)e(e)o(xactly)f
(one)i(format)e(unit,)i(it)g(returns)208 4544 y(whate)n(v)o(er)i
(object)h(is)i(described)e(by)g(that)h(format)f(unit.)32
b(T)-7 b(o)23 b(force)f(it)i(to)f(return)e(a)j(tuple)e(of)h(size)g(0)g
(or)g(one,)f(parenthesize)g(the)208 4644 y(format)d(string.)208
4773 y(When)h(memory)e(b)n(uf)n(fers)h(are)h(passed)g(as)h(parameters)e
(to)i(supply)e(data)h(to)g(b)n(uild)g(objects,)g(as)h(for)e(the)h(`)p
Fj(s)p Fr(')g(and)g(`)p Fj(s#)p Fr(')g(formats,)208 4872
y(the)h(required)e(data)i(is)h(copied.)k(Buf)n(fers)20
b(pro)o(vided)f(by)h(the)h(caller)g(are)g(ne)n(v)o(er)f(referenced)f
(by)h(the)h(objects)g(created)f(by)h Fj(Py_-)208 4972
y(BuildValue\(\))p Fr(.)k(In)20 b(other)g(w)o(ords,)h(if)g(your)e(code)
h(in)m(v)n(ok)o(es)g Fj(malloc\(\))g Fr(and)g(passes)i(the)f(allocated)
f(memory)f(to)i Fj(Py_-)208 5072 y(BuildValue\(\))p Fr(,)j(your)g(code)
g(is)i(responsible)d(for)i(calling)f Fj(free\(\))h Fr(for)f(that)h
(memory)f(once)g Fj(Py_BuildValue\(\))208 5171 y Fr(returns.)208
5300 y(In)e(the)h(follo)n(wing)f(description,)g(the)h(quoted)e(form)h
(is)i(the)f(format)f(unit;)j(the)e(entry)f(in)h(\(round\))e
(parentheses)h(is)i(the)f(Python)208 5400 y(object)d(type)h(that)g(the)
h(format)e(unit)h(will)h(return;)f(and)f(the)i(entry)e(in)i([square])e
(brack)o(ets)g(is)i(the)g(type)e(of)h(the)h(C)g(v)n(alue\(s\))e(to)i
(be)p 0 5549 3901 4 v 0 5649 a Fn(5.5.)52 b(P)m(arsing)23
b(arguments)h(and)f(b)n(uilding)j(v)n(alues)2194 b(31)p
eop end
%%Page: 32 38
TeXDict begin 32 37 bop 208 83 a Fr(passed.)208 215 y(The)23
b(characters)f(space,)i(tab,)g(colon)f(and)g(comma)f(are)h(ignored)f
(in)i(format)e(strings)h(\(b)n(ut)g(not)h(within)f(format)f(units)i
(such)f(as)208 315 y(`)p Fj(s#)p Fr('\).)h(This)c(can)g(be)g(used)g(to)
g(mak)o(e)g(long)f(format)h(strings)g(a)g(tad)h(more)e(readable.)208
526 y Fp(`)p Fg(s)p Fp(')g(\(string\))h([char)g(*])o
Fr(Con)m(v)o(ert)28 b(a)i(null-terminated)d(C)k(string)e(to)h(a)f
(Python)g(object.)52 b(If)30 b(the)f(C)i(string)e(pointer)f(is)j
Fj(NULL)p Fr(,)390 626 y Fj(None)20 b Fr(is)h(used.)208
757 y Fp(`)p Fg(s#)p Fp(')e(\(string\))h([char)g(*,)g(int])o
Fr(Con)m(v)o(ert)h(a)h(C)h(string)f(and)f(its)j(length)d(to)h(a)g
(Python)f(object.)30 b(If)22 b(the)g(C)h(string)f(pointer)f(is)i
Fj(NULL)p Fr(,)390 857 y(the)d(length)g(is)h(ignored)d(and)i
Fj(None)g Fr(is)h(returned.)208 988 y Fp(`)p Fg(z)p Fp(')e(\(string)h
(or)g Fg(None)p Fp(\))g([char)g(*])o Fr(Same)g(as)h(`)p
Fj(s)p Fr('.)208 1119 y Fp(`)p Fg(z#)p Fp(')e(\(string)h(or)g
Fg(None)p Fp(\))g([char)g(*,)g(int])o Fr(Same)h(as)f(`)p
Fj(s#)p Fr('.)208 1250 y Fp(`)p Fg(u)p Fp(')f(\(Unicode)h(string\))g
([Py)p 1054 1250 25 4 v 29 w(UNICODE)h(*])o Fr(Con)m(v)o(ert)c(a)i
(null-terminated)d(b)n(uf)n(fer)h(of)h(Unicode)f(\(UCS-2)i(or)f
(UCS-4\))g(data)g(to)390 1350 y(a)j(Python)e(Unicode)g(object.)24
b(If)c(the)h(Unicode)e(b)n(uf)n(fer)f(pointer)h(is)i
Fj(NULL)p Fr(,)f Fj(None)g Fr(is)h(returned.)208 1481
y Fp(`)p Fg(u#)p Fp(')e(\(Unicode)h(string\))g([Py)p
1104 1481 V 29 w(UNICODE)h(*,)f(int])o Fr(Con)m(v)o(ert)i(a)i(Unicode)f
(\(UCS-2)g(or)h(UCS-4\))f(data)h(b)n(uf)n(fer)e(and)h(its)h(length)390
1581 y(to)k(a)g(Python)f(Unicode)f(object.)47 b(If)27
b(the)h(Unicode)f(b)n(uf)n(fer)f(pointer)g(is)j Fj(NULL)p
Fr(,)e(the)h(length)f(is)h(ignored)e(and)h Fj(None)h
Fr(is)390 1680 y(returned.)208 1812 y Fp(`)p Fg(i)p Fp(')19
b(\(integer\))g([int])p Fr(Con)m(v)o(ert)f(a)j(plain)f(C)h
Fj(int)f Fr(to)g(a)h(Python)e(inte)o(ger)g(object.)208
1943 y Fp(`)p Fg(b)p Fp(')g(\(integer\))g([char])o Fr(Con)m(v)o(ert)g
(a)h(plain)g(C)h Fj(char)f Fr(to)h(a)f(Python)f(inte)o(ger)g(object.)
208 2074 y Fp(`)p Fg(h)p Fp(')g(\(integer\))g([short)h(int])p
Fr(Con)m(v)o(ert)f(a)h(plain)g(C)h Fj(short)49 b(int)20
b Fr(to)g(a)h(Python)e(inte)o(ger)g(object.)208 2205
y Fp(`)p Fg(l)p Fp(')g(\(integer\))g([long)h(int])p Fr(Con)m(v)o(ert)e
(a)j(C)g Fj(long)49 b(int)20 b Fr(to)h(a)f(Python)f(inte)o(ger)g
(object.)208 2336 y Fp(`)p Fg(B)p Fp(')g(\(integer\))g([unsigned)i
(char])o Fr(Con)m(v)o(ert)e(a)i(C)g Fj(unsigned)48 b(char)20
b Fr(to)g(a)h(Python)e(inte)o(ger)g(object.)208 2467
y Fp(`)p Fg(H)p Fp(')g(\(integer\))g([unsigned)i(short)f(int])p
Fr(Con)m(v)o(ert)f(a)h(C)h Fj(unsigned)49 b(short)g(int)20
b Fr(to)g(a)h(Python)e(inte)o(ger)g(object.)208 2599
y Fp(`)p Fg(I)p Fp(')g(\(integer/long\))g([unsigned)i(int])o
Fr(Con)m(v)o(ert)28 b(a)j(C)f Fj(unsigned)49 b(int)29
b Fr(to)h(a)h(Python)d(inte)o(ger)h(object)g(or)h(a)g(Python)e(long)390
2698 y(inte)o(ger)19 b(object,)h(if)g(it)h(is)g(lar)o(ger)e(than)h
Fj(sys.maxint)p Fr(.)208 2829 y Fp(`)p Fg(k)p Fp(')f(\(integer/long\))g
([unsigned)i(long])n Fr(Con)m(v)o(ert)f(a)h(C)h Fj(unsigned)49
b(long)21 b Fr(to)g(a)g(Python)f(inte)o(ger)g(object)g(or)h(a)h(Python)
d(long)390 2929 y(inte)o(ger)g(object,)h(if)g(it)h(is)g(lar)o(ger)e
(than)h Fj(sys.maxint)p Fr(.)208 3060 y Fp(`)p Fg(L)p
Fp(')f(\(long\))h([PY)p 706 3060 V 29 w(LONG)p 980 3060
V 29 w(LONG])o Fr(Con)m(v)o(ert)25 b(a)i(C)g Fj(long)49
b(long)26 b Fr(to)g(a)h(Python)e(long)g(inte)o(ger)g(object.)43
b(Only)25 b(a)n(v)n(ailable)h(on)390 3160 y(platforms)19
b(that)h(support)f Fj(long)49 b(long)p Fr(.)208 3291
y Fp(`)p Fg(K)p Fp(')19 b(\(long\))h([unsigned)h(PY)p
1045 3291 V 29 w(LONG)p 1319 3291 V 29 w(LONG])p Fr(Con)m(v)o(ert)g(a)i
(C)g Fj(unsigned)49 b(long)g(long)22 b Fr(to)h(a)g(Python)e(long)h
(inte)o(ger)f(ob-)390 3391 y(ject.)26 b(Only)19 b(a)n(v)n(ailable)h(on)
g(platforms)f(that)h(support)f Fj(unsigned)48 b(long)h(long)p
Fr(.)208 3522 y Fp(`)p Fg(n)p Fp(')19 b(\(int\))h([Py)p
632 3522 V 29 w(ssize)p 822 3522 V 30 w(t])p Fr(Con)m(v)o(ert)e(a)j(C)g
Fj(Py_ssize_t)e Fr(to)h(a)h(Python)e(inte)o(ger)g(or)h(long)f(inte)o
(ger)-5 b(.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.5.)208
3653 y Fp(`)p Fg(c)p Fp(')g(\(string)h(of)g(length)g(1\))g([char])o
Fr(Con)m(v)o(ert)f(a)h(C)h Fj(int)g Fr(representing)d(a)i(character)f
(to)i(a)f(Python)f(string)h(of)g(length)f(1.)208 3784
y Fp(`)p Fg(d)p Fp(')g(\(\003oat\))g([double])p Fr(Con)m(v)o(ert)f(a)j
(C)g Fj(double)f Fr(to)g(a)h(Python)e(\003oating)g(point)g(number)-5
b(.)208 3915 y Fp(`)p Fg(f)p Fp(')19 b(\(\003oat\))g([\003oat])n
Fr(Same)i(as)g(`)p Fj(d)p Fr('.)208 4047 y Fp(`)p Fg(D)p
Fp(')e(\(complex\))h([Py)p 831 4047 V 28 w(complex)g(*])o
Fr(Con)m(v)o(ert)f(a)i(C)g Fj(Py_complex)e Fr(structure)g(to)h(a)h
(Python)e(comple)o(x)f(number)-5 b(.)208 4178 y Fp(`)p
Fg(O)p Fp(')19 b(\(object\))g([PyObject)g(*])o Fr(P)o(ass)i(a)h(Python)
d(object)h(untouched)f(\(e)o(xcept)g(for)h(its)i(reference)d(count,)h
(which)g(is)i(incremented)390 4277 y(by)28 b(one\).)48
b(If)28 b(the)g(object)g(passed)g(in)h(is)g(a)f Fj(NULL)g
Fr(pointer)m(,)h(it)g(is)g(assumed)f(that)g(this)h(w)o(as)g(caused)e
(because)h(the)g(call)390 4377 y(producing)17 b(the)j(ar)o(gument)e
(found)g(an)i(error)e(and)i(set)g(an)g(e)o(xception.)j(Therefore,)18
b Fj(Py_BuildValue\(\))f Fr(will)k(return)390 4477 y
Fj(NULL)f Fr(b)n(ut)g(w)o(on')o(t)g(raise)g(an)g(e)o(xception.)j(If)d
(no)g(e)o(xception)e(has)j(been)e(raised)h(yet,)g Fj(SystemError)f
Fr(is)i(set.)208 4608 y Fp(`)p Fg(S)p Fp(')e(\(object\))g([PyObject)g
(*])o Fr(Same)h(as)h(`)p Fj(O)p Fr('.)208 4739 y Fp(`)p
Fg(N)p Fp(')e(\(object\))g([PyObject)g(*])o Fr(Same)27
b(as)h(`)p Fj(O)p Fr(',)f(e)o(xcept)g(it)h(doesn')o(t)e(increment)g
(the)i(reference)d(count)i(on)g(the)g(object.)47 b(Useful)390
4839 y(when)20 b(the)g(object)g(is)h(created)e(by)h(a)h(call)f(to)h(an)
f(object)f(constructor)g(in)h(the)g(ar)o(gument)e(list.)208
4970 y Fp(`)p Fg(O&)p Fp(')h(\(object\))g([)p Ff(con)m(v)o(erter)p
Fp(,)g Ff(anything)p Fp(])p Fr(Con)m(v)o(ert)c Fo(anything)g
Fr(to)i(a)g(Python)e(object)i(through)d(a)j Fo(con)m(verter)h
Fr(function.)k(The)17 b(func-)390 5070 y(tion)i(is)h(called)f(with)h
Fo(anything)d Fr(\(which)h(should)g(be)i(compatible)d(with)j
Fj(void)2705 5085 y(*)2755 5070 y Fr(\))f(as)h(its)g(ar)o(gument)d(and)
i(should)f(return)390 5169 y(a)j(\223ne)n(w\224)f(Python)f(object,)g
(or)h Fj(NULL)g Fr(if)g(an)h(error)e(occurred.)208 5300
y Fp(`)p Fg(\()p Ff(items)p Fg(\))p Fp(')g(\(tuple\))h([)p
Ff(matc)o(hing-items)p Fp(])n Fr(Con)m(v)o(ert)g(a)i(sequence)f(of)g(C)
i(v)n(alues)e(to)h(a)g(Python)f(tuple)g(with)h(the)g(same)g(number)e
(of)390 5400 y(items.)p 0 5549 3901 4 v 0 5649 a Fn(32)3078
b(Chapter)24 b(5.)51 b(Utilities)p eop end
%%Page: 33 39
TeXDict begin 33 38 bop 208 83 a Fp(`)p Fg([)p Ff(items)p
Fg(])p Fp(')19 b(\(list\))h([)p Ff(matc)o(hing-items)p
Fp(])n Fr(Con)m(v)o(ert)15 b(a)h(sequence)f(of)h(C)h(v)n(alues)f(to)g
(a)h(Python)d(list)k(with)e(the)g(same)g(number)f(of)g(items.)208
203 y Fp(`)p Fg({)p Ff(items)p Fg(})p Fp(')k(\(dictionary\))g([)p
Ff(matc)o(hing-items)p Fp(])n Fr(Con)m(v)o(ert)k(a)i(sequence)f(of)h(C)
g(v)n(alues)g(to)g(a)g(Python)f(dictionary)-5 b(.)37
b(Each)24 b(pair)h(of)390 303 y(consecuti)n(v)o(e)19
b(C)i(v)n(alues)f(adds)f(one)h(item)g(to)h(the)f(dictionary)-5
b(,)18 b(serving)h(as)i(k)o(e)o(y)e(and)h(v)n(alue,)f(respecti)n(v)o
(ely)-5 b(.)208 503 y(If)20 b(there)f(is)i(an)g(error)e(in)h(the)g
(format)f(string,)h(the)g Fj(SystemError)f Fr(e)o(xception)f(is)j(set)g
(and)f Fj(NULL)g Fr(returned.)0 825 y Fl(5.6)121 b(Str)r(ing)33
b(con)n(v)m(ersion)h(and)h(f)l(or)s(matting)0 1058 y
Fr(Functions)19 b(for)h(number)e(con)m(v)o(ersion)g(and)h(formatted)g
(string)h(output.)0 1205 y Fj(int)49 b Fg(PyOS_snprintf)p
Fj(\()p Fo(c)o(har)17 b(*str)-9 b(,)21 b(size)p 1359
1205 25 4 v 30 w(t)g(size)o(,)g(const)f(c)o(har)g(*format,)f(...)p
Fj(\))208 1304 y Fr(Output)k(not)h(more)g(than)g Fo(size)h
Fr(bytes)g(to)f Fo(str)k Fr(according)22 b(to)j(the)f(format)g(string)g
Fo(format)i Fr(and)e(the)g(e)o(xtra)g(ar)o(guments.)36
b(See)25 b(the)210 1404 y(U)t Fi(N)t(I)t(X)e Fr(man)c(page)h
Fo(snprintf)p Fr(\(2\).)0 1551 y Fj(int)49 b Fg(PyOS_vsnprintf)p
Fj(\()p Fo(c)o(har)17 b(*str)-9 b(,)21 b(size)p 1409
1551 V 30 w(t)g(size)o(,)g(const)f(c)o(har)g(*format,)f(va)p
2399 1551 V 29 w(list)j(va)p Fj(\))208 1651 y Fr(Output)h(not)g(more)g
(than)g Fo(size)i Fr(bytes)f(to)f Fo(str)k Fr(according)22
b(to)i(the)g(format)e(string)i Fo(format)h Fr(and)e(the)h(v)n(ariable)f
(ar)o(gument)e(list)k Fo(va)p Fr(.)210 1750 y(U)t Fi(N)t(I)t(X)e
Fr(man)c(page)h Fo(vsnprintf)p Fr(\(2\).)0 1897 y Fj(PyOS_snprintf)64
b Fr(and)i Fj(PyOS_vsnprintf)f Fr(wrap)g(the)i(Standard)e(C)i(library)e
(functions)g Fj(snprintf\(\))g Fr(and)0 1997 y Fj(vsnprintf\(\))p
Fr(.)36 b(Their)24 b(purpose)f(is)i(to)f(guarantee)f(consistent)h(beha)
n(vior)f(in)h(corner)f(cases,)j(which)e(the)h(Standard)e(C)i(functions)
0 2096 y(do)20 b(not.)0 2243 y(The)h(wrappers)e(ensure)i(that)g
Fo(str)r Fr([)p Fo(size)p Fr(-1])g(is)h(al)o(w)o(ays)f(`)p
Fq(n)p Fj(0)p Fr(')f(upon)g(return.)26 b(The)o(y)20 b(ne)n(v)o(er)f
(write)i(more)f(than)h Fo(size)h Fr(bytes)f(\(including)e(the)0
2343 y(trailing)h(`)p Fq(n)p Fj(0)p Fr(')f(into)h(str)-5
b(.)26 b(Both)20 b(functions)f(require)g(that)h Fo(str)52
b Fj(!=)e(NULL)p Fr(,)20 b Fo(size)50 b Fj(>)g(0)20 b
Fr(and)g Fo(format)50 b Fj(!=)g(NULL)p Fr(.)0 2490 y(If)19
b(the)h(platform)e(doesn')o(t)g(ha)n(v)o(e)h Fj(vsnprintf\(\))f
Fr(and)h(the)h(b)n(uf)n(fer)e(size)j(needed)d(to)i(a)n(v)n(oid)f
(truncation)f(e)o(xceeds)g Fo(size)j Fr(by)e(more)g(than)0
2589 y(512)g(bytes,)h(Python)f(aborts)h(with)g(a)h Fo(Py)p
1161 2589 V 29 w(F)-6 b(atalErr)l(or)r Fr(.)0 2736 y(The)20
b(return)f(v)n(alue)g(\()p Fo(rv)p Fr(\))i(for)e(these)h(functions)f
(should)g(be)i(interpreted)d(as)j(follo)n(ws:)125 2934
y Fq(\017)41 b Fr(When)21 b Fj(0)49 b(<=)h Fo(rv)g Fj(<)f
Fo(size)p Fr(,)23 b(the)f(output)e(con)m(v)o(ersion)e(w)o(as)23
b(successful)e(and)g Fo(rv)h Fr(characters)e(were)i(written)f(to)h
Fo(str)i Fr(\(e)o(xcluding)208 3034 y(the)c(trailing)f(`)p
Fq(n)p Fj(0)p Fr(')h(byte)f(at)i Fo(str)r Fr([)p Fo(rv)p
Fr(]\).)125 3187 y Fq(\017)41 b Fr(When)16 b Fo(rv)50
b Fj(>=)f Fo(size)p Fr(,)18 b(the)e(output)f(con)m(v)o(ersion)f(w)o(as)
j(truncated)e(and)h(a)g(b)n(uf)n(fer)f(with)i Fo(rv)50
b Fj(+)f(1)17 b Fr(bytes)f(w)o(ould)g(ha)n(v)o(e)f(been)h(needed)208
3287 y(to)k(succeed.)k Fo(str)r Fr([)p Fo(size)p Fr(-1])c(is)i(`)p
Fq(n)p Fj(0)p Fr(')d(in)h(this)h(case.)125 3440 y Fq(\017)41
b Fr(When)23 b Fo(rv)50 b Fj(<)g(0)p Fr(,)24 b(\223something)e(bad)h
(happened.)-6 b(\224)33 b Fo(str)r Fr([)p Fo(size)p Fr(-1])24
b(is)h(`)p Fq(n)p Fj(0)p Fr(')e(in)g(this)i(case)f(too,)g(b)n(ut)f(the)
h(rest)g(of)f Fo(str)k Fr(is)e(unde\002ned.)208 3540
y(The)19 b(e)o(xact)h(cause)g(of)g(the)g(error)f(depends)g(on)h(the)g
(underlying)e(platform.)0 3738 y(The)i(follo)n(wing)e(functions)h(pro)o
(vide)f(locale-independent)f(string)j(to)g(number)e(con)m(v)o(ersions.)
0 3885 y Fj(double)49 b Fg(PyOS_ascii_strtod)p Fj(\()p
Fo(const)16 b(c)o(har)k(*nptr)-9 b(,)19 b(c)o(har)h(**endptr)r
Fj(\))208 3985 y Fr(Con)m(v)o(ert)j(a)i(string)f(to)h(a)g
Fj(double)p Fr(.)38 b(This)25 b(function)e(beha)n(v)o(es)h(lik)o(e)h
(the)g(Standard)e(C)j(function)d Fj(strtod\(\))h Fr(does)g(in)h(the)g
(C)208 4084 y(locale.)f(It)d(does)f(this)g(without)g(changing)e(the)i
(current)f(locale,)h(since)g(that)h(w)o(ould)e(not)h(be)g(thread-safe.)
208 4211 y Fj(PyOS_ascii_strtod)j Fr(should)j(typically)f(be)i(used)f
(for)g(reading)f(con\002guration)e(\002les)28 b(or)e(other)f(non-user)g
(input)g(that)208 4310 y(should)19 b(be)h(locale)g(independent.)48
b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)208 4437 y(See)h(the)i(U)t
Fi(N)t(I)t(X)i Fr(man)19 b(page)h Fo(strtod)p Fr(\(2\))f(for)h
(details.)0 4584 y Fj(char)249 4599 y(*)349 4584 y Fg
(PyOS_ascii_formatd)p Fj(\()p Fo(c)o(har)c(*b)n(uf)o(fer)-9
b(,)19 b(size)p 1865 4584 V 30 w(t)i(b)n(uf)p 2044 4584
V 29 w(len,)f(const)g(c)o(har)g(*format,)g(double)e(d)r
Fj(\))208 4683 y Fr(Con)m(v)o(ert)e(a)j Fj(double)f Fr(to)h(a)g(string)
f(using)g(the)g(`)p Fj(.)p Fr(')24 b(as)c(the)e(decimal)g(separator)-5
b(.)23 b Fo(format)d Fr(is)g(a)f Fj(printf\(\))p Fr(-style)e(format)g
(string)208 4783 y(specifying)h(the)i(number)f(format.)24
b(Allo)n(wed)19 b(con)m(v)o(ersion)f(characters)h(are)h(`)p
Fj(e)p Fr(',)g(`)p Fj(E)p Fr(',)f(`)p Fj(f)p Fr(',)h(`)p
Fj(F)p Fr(',)g(`)p Fj(g)p Fr(')f(and)h(`)p Fj(G)p Fr('.)208
4909 y(The)27 b(return)g(v)n(alue)g(is)h(a)g(pointer)f(to)h
Fo(b)n(uf)o(fer)h Fr(with)f(the)g(con)m(v)o(erted)d(string)j(or)f(NULL)
h(if)g(the)g(con)m(v)o(ersion)d(f)o(ailed.)95 b(Ne)n(w)28
b(in)208 5009 y(v)o(ersion)18 b(2.4.)0 5156 y Fj(double)49
b Fg(PyOS_ascii_atof)p Fj(\()p Fo(const)17 b(c)o(har)i(*nptr)r
Fj(\))208 5256 y Fr(Con)m(v)o(ert)f(a)j(string)f(to)g(a)h
Fj(double)e Fr(in)i(a)f(locale-independent)d(w)o(ay)-5
b(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)208 5382
y(See)h(the)i(U)t Fi(N)t(I)t(X)i Fr(man)19 b(page)h Fo(atof)p
Fr(\(2\))f(for)g(details.)p 0 5549 3901 4 v 0 5649 a
Fn(5.6.)52 b(Str)q(ing)24 b(con)n(v)n(ersion)f(and)h(f)n(or)r(matting)
2426 b(33)p eop end
%%Page: 34 40
TeXDict begin 34 39 bop 0 5549 3901 4 v 0 5649 a Fn(34)p
eop end
%%Page: 35 41
TeXDict begin 35 40 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3707
427 y Fm(SIX)p 0 515 V 1766 978 a Fx(Abstr)n(act)58 b(Objects)f(La)-6
b(y)l(er)0 1466 y Fr(The)20 b(functions)e(in)i(this)h(chapter)e
(interact)g(with)h(Python)f(objects)h(re)o(gardless)e(of)i(their)g
(type,)f(or)h(with)g(wide)g(classes)h(of)e(object)h(types)0
1566 y(\(e.g.)39 b(all)26 b(numerical)e(types,)i(or)f(all)h(sequence)e
(types\).)39 b(When)25 b(used)g(on)g(object)g(types)g(for)g(which)f
(the)o(y)h(do)g(not)f(apply)-5 b(,)25 b(the)o(y)g(will)0
1665 y(raise)20 b(a)h(Python)e(e)o(xception.)0 1812 y(It)k(is)h(not)f
(possible)g(to)g(use)h(these)f(functions)f(on)g(objects)h(that)h(are)f
(not)f(properly)f(initialized,)j(such)e(as)i(a)g(list)g(object)f(that)g
(has)g(been)0 1912 y(created)c(by)h Fj(PyList_New\(\))p
Fr(,)e(b)n(ut)j(whose)f(items)g(ha)n(v)o(e)g(not)g(been)f(set)i(to)g
(some)f(non-)p Fj(NULL)e Fr(v)n(alue)h(yet.)0 2239 y
Fl(6.1)121 b(Object)33 b(Protocol)0 2458 y Fj(int)49
b Fg(PyObject_Print)p Fj(\()p Fo(PyObject)17 b(*o,)j(FILE)g(*fp,)f(int)
i(\003a)o(gs)p Fj(\))208 2558 y Fr(Print)g(an)g(object)g
Fo(o)p Fr(,)h(on)f(\002le)h Fo(fp)p Fr(.)28 b(Returns)21
b Fj(-1)h Fr(on)f(error)-5 b(.)28 b(The)21 b(\003ags)g(ar)o(gument)e
(is)k(used)e(to)g(enable)g(certain)g(printing)f(options.)208
2657 y(The)e(only)g(option)f(currently)g(supported)g(is)j
Fj(Py_PRINT_RAW)p Fr(;)d(if)i(gi)n(v)o(en,)f(the)g Fj(str\(\))h
Fr(of)f(the)h(object)f(is)i(written)e(instead)h(of)208
2757 y(the)h Fj(repr\(\))p Fr(.)0 2904 y Fj(int)49 b
Fg(PyObject_HasAttrString)p Fj(\()p Fo(PyObject)16 b(*o,)j(const)h(c)o
(har)g(*attr)p 2334 2904 25 4 v 29 w(name)p Fj(\))208
3003 y Fr(Returns)34 b Fj(1)i Fr(if)f Fo(o)g Fr(has)g(the)g(attrib)n
(ute)f Fo(attr)p 1468 3003 V 30 w(name)p Fr(,)k(and)c
Fj(0)i Fr(otherwise.)68 b(This)35 b(is)h(equi)n(v)n(alent)d(to)i(the)g
(Python)f(e)o(xpression)208 3103 y(`)p Fj(hasattr\()p
Fo(o)p Fj(,)47 b Fo(attr)p 900 3103 V 30 w(name)p Fj(\))p
Fr('.)23 b(This)e(function)d(al)o(w)o(ays)j(succeeds.)0
3250 y Fj(PyObject)400 3265 y(*)498 3250 y Fg(PyObject_GetAttrString)p
Fj(\()p Fo(PyObject)16 b(*o,)j(const)h(c)o(har)g(*attr)p
2633 3250 V 29 w(name)p Fj(\))208 3350 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3449 y Fr(Retrie)n(v)o(e)e(an)g
(attrib)n(ute)g(named)f Fo(attr)p 1261 3449 V 30 w(name)h
Fr(from)g(object)g Fo(o)p Fr(.)24 b(Returns)18 b(the)h(attrib)n(ute)f
(v)n(alue)g(on)g(success,)h(or)f Fj(NULL)g Fr(on)g(f)o(ailure.)208
3549 y(This)i(is)h(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f(e)o
(xpression)f(`)p Fo(o)p Fj(.)p Fo(attr)p 2024 3549 V
29 w(name)p Fr('.)0 3696 y Fj(int)49 b Fg(PyObject_HasAttr)p
Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*attr)p 1997
3696 V 29 w(name)p Fj(\))208 3795 y Fr(Returns)34 b Fj(1)i
Fr(if)f Fo(o)g Fr(has)g(the)g(attrib)n(ute)f Fo(attr)p
1468 3795 V 30 w(name)p Fr(,)k(and)c Fj(0)i Fr(otherwise.)68
b(This)35 b(is)h(equi)n(v)n(alent)d(to)i(the)g(Python)f(e)o(xpression)
208 3895 y(`)p Fj(hasattr\()p Fo(o)p Fj(,)47 b Fo(attr)p
900 3895 V 30 w(name)p Fj(\))p Fr('.)23 b(This)e(function)d(al)o(w)o
(ays)j(succeeds.)0 4042 y Fj(PyObject)400 4057 y(*)498
4042 y Fg(PyObject_GetAttr)p Fj(\()p Fo(PyObject)c(*o,)i(PyObject)h
(*attr)p 2296 4042 V 29 w(name)p Fj(\))208 4141 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4241 y Fr(Retrie)n(v)o(e)e(an)g
(attrib)n(ute)g(named)f Fo(attr)p 1261 4241 V 30 w(name)h
Fr(from)g(object)g Fo(o)p Fr(.)24 b(Returns)18 b(the)h(attrib)n(ute)f
(v)n(alue)g(on)g(success,)h(or)f Fj(NULL)g Fr(on)g(f)o(ailure.)208
4341 y(This)i(is)h(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f(e)o
(xpression)f(`)p Fo(o)p Fj(.)p Fo(attr)p 2024 4341 V
29 w(name)p Fr('.)0 4488 y Fj(int)49 b Fg(PyObject_SetAttrString)p
Fj(\()p Fo(PyObject)16 b(*o,)j(const)h(c)o(har)g(*attr)p
2334 4488 V 29 w(name)o(,)g(PyObject)f(*v)p Fj(\))208
4587 y Fr(Set)24 b(the)g(v)n(alue)g(of)f(the)i(attrib)n(ute)e(named)g
Fo(attr)p 1557 4587 V 30 w(name)p Fr(,)h(for)g(object)f
Fo(o)p Fr(,)i(to)f(the)g(v)n(alue)g Fo(v)p Fr(.)37 b(Returns)23
b Fj(-1)i Fr(on)e(f)o(ailure.)36 b(This)25 b(is)g(the)208
4687 y(equi)n(v)n(alent)18 b(of)i(the)g(Python)f(statement)h(`)p
Fo(o)p Fj(.)p Fo(attr)p 1622 4687 V 29 w(name)49 b Fj(=)g
Fo(v)p Fr('.)0 4834 y Fj(int)g Fg(PyObject_SetAttr)p
Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*attr)p 1997
4834 V 29 w(name)o(,)g(PyObject)g(*v)p Fj(\))208 4933
y Fr(Set)k(the)g(v)n(alue)g(of)f(the)i(attrib)n(ute)e(named)g
Fo(attr)p 1557 4933 V 30 w(name)p Fr(,)h(for)g(object)f
Fo(o)p Fr(,)i(to)f(the)g(v)n(alue)g Fo(v)p Fr(.)37 b(Returns)23
b Fj(-1)i Fr(on)e(f)o(ailure.)36 b(This)25 b(is)g(the)208
5033 y(equi)n(v)n(alent)18 b(of)i(the)g(Python)f(statement)h(`)p
Fo(o)p Fj(.)p Fo(attr)p 1622 5033 V 29 w(name)49 b Fj(=)g
Fo(v)p Fr('.)0 5180 y Fj(int)g Fg(PyObject_DelAttrString)p
Fj(\()p Fo(PyObject)16 b(*o,)j(const)h(c)o(har)g(*attr)p
2334 5180 V 29 w(name)p Fj(\))208 5279 y Fr(Delete)28
b(attrib)n(ute)g(named)g Fo(attr)p 1133 5279 V 29 w(name)p
Fr(,)i(for)e(object)g Fo(o)p Fr(.)49 b(Returns)29 b Fj(-1)f
Fr(on)g(f)o(ailure.)49 b(This)29 b(is)g(the)f(equi)n(v)n(alent)f(of)h
(the)h(Python)208 5379 y(statement:)c(`)p Fj(del)48 b
Fo(o)p Fj(.)p Fo(attr)p 1018 5379 V 30 w(name)p Fr('.)p
0 5549 3901 4 v 3808 5649 a Fn(35)p eop end
%%Page: 36 42
TeXDict begin 36 41 bop 0 83 a Fj(int)49 b Fg(PyObject_DelAttr)p
Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*attr)p 1997
83 25 4 v 29 w(name)p Fj(\))208 183 y Fr(Delete)28 b(attrib)n(ute)g
(named)g Fo(attr)p 1133 183 V 29 w(name)p Fr(,)i(for)e(object)g
Fo(o)p Fr(.)49 b(Returns)29 b Fj(-1)f Fr(on)g(f)o(ailure.)49
b(This)29 b(is)g(the)f(equi)n(v)n(alent)f(of)h(the)h(Python)208
282 y(statement)20 b(`)p Fj(del)48 b Fo(o)p Fj(.)p Fo(attr)p
990 282 V 30 w(name)p Fr('.)0 429 y Fj(PyObject)400 444
y(*)498 429 y Fg(PyObject_RichCompare)p Fj(\()p Fo(PyObject)16
b(*o1,)j(PyObject)h(*o2,)f(int)h(opid)r Fj(\))208 529
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 628 y Fr(Compare)j(the)h(v)n(alues)h(of)f Fo(o1)g
Fr(and)g Fo(o2)g Fr(using)g(the)g(operation)f(speci\002ed)h(by)g
Fo(opid)r Fr(,)h(which)f(must)g(be)h(one)f(of)g Fj(Py_LT)p
Fr(,)g Fj(Py_-)208 728 y(LE)p Fr(,)h Fj(Py_EQ)p Fr(,)g
Fj(Py_NE)p Fr(,)g Fj(Py_GT)p Fr(,)g(or)h Fj(Py_GE)p Fr(,)f
(corresponding)d(to)k Fj(<)p Fr(,)h Fj(<=)p Fr(,)g Fj(==)p
Fr(,)g Fj(!=)p Fr(,)g Fj(>)p Fr(,)g(or)f Fj(>=)g Fr(respecti)n(v)o(ely)
-5 b(.)39 b(This)26 b(is)h(the)208 828 y(equi)n(v)n(alent)20
b(of)h(the)h(Python)f(e)o(xpression)f(`)p Fo(o1)48 b
Fj(op)i Fo(o2)p Fr(',)21 b(where)g Fj(op)h Fr(is)h(the)f(operator)e
(corresponding)e(to)k Fo(opid)r Fr(.)29 b(Returns)22
b(the)208 927 y(v)n(alue)d(of)h(the)g(comparison)e(on)i(success,)h(or)e
Fj(NULL)h Fr(on)g(f)o(ailure.)0 1074 y Fj(int)49 b Fg
(PyObject_RichCompareBool)p Fj(\()p Fo(PyObject)15 b(*o1,)k(PyObject)h
(*o2,)f(int)h(opid)r Fj(\))208 1174 y Fr(Compare)f(the)i(v)n(alues)g
(of)f Fo(o1)g Fr(and)h Fo(o2)f Fr(using)g(the)h(operation)e
(speci\002ed)i(by)f Fo(opid)r Fr(,)g(which)h(must)f(be)h(one)f(of)h
Fj(Py_LT)p Fr(,)f Fj(Py_LE)p Fr(,)208 1273 y Fj(Py_EQ)p
Fr(,)25 b Fj(Py_NE)p Fr(,)h Fj(Py_GT)p Fr(,)f(or)h Fj(Py_GE)p
Fr(,)g(corresponding)c(to)27 b Fj(<)p Fr(,)h Fj(<=)p
Fr(,)f Fj(==)p Fr(,)h Fj(!=)p Fr(,)g Fj(>)p Fr(,)f(or)f
Fj(>=)h Fr(respecti)n(v)o(ely)-5 b(.)41 b(Returns)26
b Fj(-1)g Fr(on)208 1373 y(error)m(,)c Fj(0)j Fr(if)f(the)f(result)h
(is)h(f)o(alse,)g Fj(1)f Fr(otherwise.)35 b(This)23 b(is)i(the)f(equi)n
(v)n(alent)e(of)h(the)h(Python)f(e)o(xpression)f(`)p
Fo(o1)48 b Fj(op)i Fo(o2)p Fr(',)23 b(where)208 1473
y Fj(op)d Fr(is)h(the)f(operator)f(corresponding)d(to)21
b Fo(opid)r Fr(.)0 1620 y Fj(int)49 b Fg(PyObject_Cmp)p
Fj(\()p Fo(PyObject)18 b(*o1,)h(PyObject)g(*o2,)g(int)i(*r)m(esult)q
Fj(\))208 1719 y Fr(Compare)c(the)h(v)n(alues)f(of)h
Fo(o1)g Fr(and)f Fo(o2)h Fr(using)f(a)i(routine)e(pro)o(vided)e(by)j
Fo(o1)p Fr(,)g(if)g(one)f(e)o(xists,)i(otherwise)f(with)g(a)g(routine)f
(pro)o(vided)208 1819 y(by)23 b Fo(o2)p Fr(.)37 b(The)24
b(result)g(of)g(the)g(comparison)e(is)k(returned)c(in)i
Fo(r)m(esult)q Fr(.)39 b(Returns)24 b Fj(-1)g Fr(on)g(f)o(ailure.)36
b(This)25 b(is)g(the)f(equi)n(v)n(alent)f(of)h(the)208
1918 y(Python)19 b(statement)h(`)p Fo(r)m(esult)51 b
Fj(=)e(cmp\()p Fo(o1)p Fj(,)f Fo(o2)p Fj(\))p Fr('.)0
2065 y Fj(int)h Fg(PyObject_Compare)p Fj(\()p Fo(PyObject)17
b(*o1,)i(PyObject)g(*o2)p Fj(\))208 2165 y Fr(Compare)e(the)h(v)n
(alues)f(of)h Fo(o1)g Fr(and)f Fo(o2)h Fr(using)f(a)i(routine)e(pro)o
(vided)e(by)j Fo(o1)p Fr(,)g(if)g(one)f(e)o(xists,)i(otherwise)f(with)g
(a)g(routine)f(pro)o(vided)208 2265 y(by)g Fo(o2)p Fr(.)24
b(Returns)18 b(the)g(result)g(of)g(the)g(comparison)e(on)i(success.)24
b(On)19 b(error)m(,)d(the)i(v)n(alue)g(returned)e(is)j(unde\002ned;)e
(use)h Fj(PyErr_-)208 2364 y(Occurred\(\))g Fr(to)j(detect)f(an)g
(error)-5 b(.)24 b(This)d(is)g(equi)n(v)n(alent)d(to)i(the)h(Python)e
(e)o(xpression)f(`)p Fj(cmp\()p Fo(o1)p Fj(,)48 b Fo(o2)p
Fj(\))p Fr('.)0 2511 y Fj(PyObject)400 2526 y(*)498 2511
y Fg(PyObject_Repr)p Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208
2611 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2710 y Fr(Compute)d(a)i(string)f(representation)f(of)h(object)
g Fo(o)p Fr(.)25 b(Returns)18 b(the)h(string)f(representation)f(on)h
(success,)h Fj(NULL)f Fr(on)h(f)o(ailure.)k(This)208
2810 y(is)f(the)f(equi)n(v)n(alent)f(of)h(the)h(Python)e(e)o(xpression)
g(`)p Fj(repr\()p Fo(o)p Fj(\))p Fr('.)26 b(Called)c(by)f(the)g
Fj(repr\(\))g Fr(b)n(uilt-in)g(function)f(and)h(by)g(re)n(v)o(erse)208
2910 y(quotes.)0 3056 y Fj(PyObject)400 3071 y(*)498
3056 y Fg(PyObject_Str)p Fj(\()p Fo(PyObject)c(*o)p Fj(\))208
3156 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3256 y Fr(Compute)d(a)i(string)f(representation)f(of)h(object)
g Fo(o)p Fr(.)25 b(Returns)18 b(the)h(string)f(representation)f(on)h
(success,)h Fj(NULL)f Fr(on)h(f)o(ailure.)k(This)208
3355 y(is)d(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)g(e)o(xpression)
e(`)p Fj(str\()p Fo(o)p Fj(\))p Fr('.)23 b(Called)d(by)f(the)g
Fj(str\(\))g Fr(b)n(uilt-in)g(function)f(and)h(by)g(the)g
Fj(print)208 3455 y Fr(statement.)0 3602 y Fj(PyObject)400
3617 y(*)498 3602 y Fg(PyObject_Unicode)p Fj(\()p Fo(PyObject)e(*o)p
Fj(\))208 3701 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3801 y Fr(Compute)27 b(a)h(Unicode)f(string)h(representation)e
(of)i(object)g Fo(o)p Fr(.)49 b(Returns)28 b(the)g(Unicode)f(string)h
(representation)e(on)h(success,)208 3901 y Fj(NULL)21
b Fr(on)h(f)o(ailure.)29 b(This)22 b(is)h(the)e(equi)n(v)n(alent)g(of)g
(the)h(Python)f(e)o(xpression)f(`)p Fj(unicode\()p Fo(o)p
Fj(\))p Fr('.)27 b(Called)22 b(by)g(the)g Fj(unicode\(\))208
4000 y Fr(b)n(uilt-in)d(function.)0 4147 y Fj(int)49
b Fg(PyObject_IsInstance)p Fj(\()p Fo(PyObject)16 b(*inst,)k(PyObject)g
(*cls)p Fj(\))208 4247 y Fr(Returns)h Fj(1)h Fr(if)g
Fo(inst)i Fr(is)f(an)e(instance)g(of)h(the)g(class)g
Fo(cls)h Fr(or)e(a)h(subclass)g(of)g Fo(cls)p Fr(,)g(or)g
Fj(0)g Fr(if)g(not.)29 b(On)22 b(error)m(,)e(returns)h
Fj(-1)h Fr(and)f(sets)i(an)208 4346 y(e)o(xception.)g(If)d
Fo(cls)i Fr(is)f(a)g(type)f(object)g(rather)f(than)h(a)h(class)g
(object,)f Fj(PyObject_IsInstance\(\))d Fr(returns)j
Fj(1)g Fr(if)h Fo(inst)i Fr(is)e(of)208 4446 y(type)d
Fo(cls)p Fr(.)25 b(If)19 b Fo(cls)h Fr(is)g(a)f(tuple,)g(the)g(check)f
(will)h(be)g(done)f(against)g(e)n(v)o(ery)g(entry)g(in)h
Fo(cls)p Fr(.)25 b(The)19 b(result)g(will)h(be)e Fj(1)i
Fr(when)e(at)h(least)h(one)208 4546 y(of)g(the)h(checks)g(returns)f
Fj(1)p Fr(,)i(otherwise)e(it)i(will)g(be)f Fj(0)p Fr(.)28
b(If)21 b Fo(inst)i Fr(is)f(not)f(a)g(class)h(instance)f(and)g
Fo(cls)g Fr(is)h(neither)f(a)g(type)g(object,)f(nor)208
4645 y(a)i(class)i(object,)e(nor)f(a)i(tuple,)f Fo(inst)j
Fr(must)d(ha)n(v)o(e)g(a)h Fj(__class__)e Fr(attrib)n(ute)h(\227)h(the)
f(class)h(relationship)e(of)h(the)h(v)n(alue)e(of)h(that)208
4745 y(attrib)n(ute)c(with)h Fo(cls)h Fr(will)g(be)f(used)f(to)i
(determine)d(the)i(result)g(of)g(this)g(function.)48
b(Ne)n(w)20 b(in)f(v)o(ersion)e(2.1.)75 b(Changed)18
b(in)h(v)o(ersion)208 4845 y(2.2:)g(Support)g(for)g(a)i(tuple)f(as)h
(the)f(second)f(ar)o(gument)f(added.)0 4991 y(Subclass)h(determination)
e(is)j(done)e(in)i(a)f(f)o(airly)g(straightforw)o(ard)e(w)o(ay)-5
b(,)19 b(b)n(ut)g(includes)f(a)i(wrinkle)e(that)h(implementors)f(of)h
(e)o(xtensions)0 5091 y(to)26 b(the)f(class)i(system)e(may)g(w)o(ant)h
(to)g(be)f(a)o(w)o(are)g(of.)41 b(If)25 b Fj(A)h Fr(and)f
Fj(B)h Fr(are)g(class)g(objects,)g Fj(B)g Fr(is)h(a)f(subclass)f(of)h
Fj(A)g Fr(if)f(it)i(inherits)e(from)f Fj(A)0 5191 y Fr(either)h
(directly)f(or)h(indirectly)-5 b(.)38 b(If)25 b(either)g(is)h(not)f(a)g
(class)h(object,)g(a)f(more)g(general)f(mechanism)g(is)i(used)e(to)i
(determine)d(the)j(class)0 5290 y(relationship)20 b(of)h(the)g(tw)o(o)h
(objects.)28 b(When)21 b(testing)g(if)h Fo(B)f Fr(is)h(a)g(subclass)g
(of)f Fo(A)p Fr(,)g(if)g Fo(A)h Fr(is)g Fo(B)p Fr(,)g
Fj(PyObject_IsSubclass\(\))17 b Fr(returns)0 5390 y(true.)54
b(If)30 b Fo(A)g Fr(and)g Fo(B)g Fr(are)g(dif)n(ferent)e(objects,)k
Fo(B)p Fr(')-5 b(s)31 b Fj(__bases__)e Fr(attrib)n(ute)h(is)h(searched)
e(in)h(a)g(depth-\002rst)f(f)o(ashion)g(for)h Fo(A)g
Fr(\227)h(the)p 0 5549 3901 4 v 0 5649 a Fn(36)2511 b(Chapter)23
b(6.)52 b(Abstr)o(act)23 b(Objects)f(La)n(y)n(er)p eop
end
%%Page: 37 43
TeXDict begin 37 42 bop 0 83 a Fr(presence)19 b(of)h(the)g
Fj(__bases__)f Fr(attrib)n(ute)h(is)h(considered)e(suf)n(\002cient)g
(for)h(this)h(determination.)0 230 y Fj(int)49 b Fg
(PyObject_IsSubclass)p Fj(\()p Fo(PyObject)16 b(*derived,)j(PyObject)h
(*cls)p Fj(\))208 330 y Fr(Returns)25 b Fj(1)i Fr(if)f(the)g(class)i
Fo(derived)f Fr(is)g(identical)f(to)g(or)g(deri)n(v)o(ed)e(from)h(the)i
(class)g Fo(cls)p Fr(,)h(otherwise)d(returns)g Fj(0)p
Fr(.)43 b(In)26 b(case)h(of)f(an)208 429 y(error)m(,)18
b(returns)h Fj(-1)p Fr(.)24 b(If)c Fo(cls)h Fr(is)f(a)g(tuple,)g(the)f
(check)g(will)i(be)e(done)g(against)g(e)n(v)o(ery)f(entry)h(in)h
Fo(cls)p Fr(.)26 b(The)19 b(result)h(will)g(be)g Fj(1)g
Fr(when)f(at)208 529 y(least)j(one)f(of)g(the)h(checks)f(returns)g
Fj(1)p Fr(,)h(otherwise)f(it)i(will)f(be)g Fj(0)p Fr(.)29
b(If)22 b(either)f Fo(derived)j Fr(or)d Fo(cls)h Fr(is)h(not)e(an)h
(actual)f(class)i(object)e(\(or)208 628 y(tuple\),)e(this)h(function)f
(uses)h(the)h(generic)e(algorithm)f(described)h(abo)o(v)o(e.)49
b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.1.)76 b(Changed)19
b(in)h(v)o(ersion)f(2.3:)208 728 y(Older)g(v)o(ersions)h(of)f(Python)h
(did)f(not)h(support)f(a)i(tuple)e(as)i(the)g(second)e(ar)o(gument.)0
875 y Fj(int)49 b Fg(PyCallable_Check)p Fj(\()p Fo(PyObject)17
b(*o)p Fj(\))208 975 y Fr(Determine)23 b(if)i(the)f(object)g
Fo(o)g Fr(is)h(callable.)38 b(Return)24 b Fj(1)g Fr(if)h(the)f(object)g
(is)h(callable)g(and)e Fj(0)i Fr(otherwise.)37 b(This)24
b(function)f(al)o(w)o(ays)208 1074 y(succeeds.)0 1221
y Fj(PyObject)400 1236 y(*)498 1221 y Fg(PyObject_Call)p
Fj(\()p Fo(PyObject)17 b(*callable)p 1841 1221 25 4 v
28 w(object,)i(PyObject)h(*ar)m(gs,)g(PyObject)f(*kw)p
Fj(\))208 1321 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1420 y Fr(Call)28 b(a)g(callable)f(Python)f(object)h
Fo(callable)p 1493 1420 V 29 w(object)q Fr(,)i(with)e(ar)o(guments)f
(gi)n(v)o(en)g(by)h(the)g(tuple)g Fo(ar)m(gs)p Fr(,)i(and)e(named)g(ar)
o(guments)208 1520 y(gi)n(v)o(en)20 b(by)i(the)g(dictionary)e
Fo(kw)p Fr(.)32 b(If)21 b(no)h(named)f(ar)o(guments)f(are)i(needed,)f
Fo(kw)i Fr(may)e(be)h Fj(NULL)p Fr(.)g Fo(ar)m(gs)g Fr(must)g(not)g(be)
g Fj(NULL)p Fr(,)f(use)208 1620 y(an)h(empty)g(tuple)g(if)h(no)f(ar)o
(guments)e(are)j(needed.)30 b(Returns)23 b(the)f(result)h(of)f(the)h
(call)g(on)f(success,)h(or)g Fj(NULL)f Fr(on)g(f)o(ailure.)31
b(This)208 1719 y(is)22 b(the)g(equi)n(v)n(alent)e(of)h(the)h(Python)e
(e)o(xpression)g(`)p Fj(apply\()p Fo(callable)p 2223
1719 V 27 w(object)q Fj(,)49 b Fo(ar)m(gs)p Fj(,)g Fo(kw)p
Fj(\))p Fr(')22 b(or)g(`)p Fo(callable)p 3379 1719 V
28 w(object)q Fj(\()3657 1734 y(*)3707 1719 y Fo(ar)m(gs)p
Fj(,)208 1834 y(**)308 1819 y Fo(kw)p Fj(\))p Fr('.)50
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 1966 y Fj(PyObject)400
1981 y(*)498 1966 y Fg(PyObject_CallObject)p Fj(\()p
Fo(PyObject)d(*callable)p 2140 1966 V 28 w(object,)j(PyObject)h(*ar)m
(gs)p Fj(\))208 2065 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 2165 y Fr(Call)31 b(a)g(callable)f(Python)g
(object)g Fo(callable)p 1509 2165 V 28 w(object)q Fr(,)j(with)d(ar)o
(guments)f(gi)n(v)o(en)g(by)h(the)h(tuple)f Fo(ar)m(gs)p
Fr(.)56 b(If)30 b(no)g(ar)o(guments)f(are)208 2265 y(needed,)h(then)f
Fo(ar)m(gs)g Fr(may)g(be)h Fj(NULL)p Fr(.)f(Returns)g(the)g(result)h
(of)f(the)g(call)h(on)f(success,)j(or)d Fj(NULL)h Fr(on)f(f)o(ailure.)
52 b(This)29 b(is)i(the)208 2364 y(equi)n(v)n(alent)18
b(of)i(the)g(Python)f(e)o(xpression)g(`)p Fj(apply\()p
Fo(callable)p 2015 2364 V 27 w(object)q Fj(,)49 b Fo(ar)m(gs)p
Fj(\))p Fr(')19 b(or)h(`)p Fo(callable)p 2975 2364 V
28 w(object)q Fj(\()3253 2379 y(*)3303 2364 y Fo(ar)m(gs)p
Fj(\))p Fr('.)0 2511 y Fj(PyObject)400 2526 y(*)498 2511
y Fg(PyObject_CallFunction)p Fj(\()p Fo(PyObject)c(*callable)o(,)i(c)o
(har)i(*format,)g(...)p Fj(\))208 2611 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2710 y Fr(Call)i(a)h(callable)e
(Python)g(object)h Fo(callable)p Fr(,)f(with)h(a)g(v)n(ariable)f
(number)f(of)i(C)h(ar)o(guments.)28 b(The)21 b(C)i(ar)o(guments)d(are)i
(described)208 2810 y(using)g(a)h Fj(Py_BuildValue\(\))e
Fr(style)i(format)f(string.)33 b(The)23 b(format)f(may)g(be)h
Fj(NULL)p Fr(,)g(indicating)e(that)i(no)g(ar)o(guments)e(are)208
2910 y(pro)o(vided.)41 b(Returns)26 b(the)h(result)f(of)g(the)h(call)g
(on)f(success,)i(or)e Fj(NULL)h Fr(on)f(f)o(ailure.)43
b(This)26 b(is)i(the)e(equi)n(v)n(alent)f(of)h(the)h(Python)208
3009 y(e)o(xpression)d(`)p Fj(apply\()p Fo(callable)p
Fj(,)47 b Fo(ar)m(gs)p Fj(\))p Fr(')25 b(or)h(`)p Fo(callable)p
Fj(\()1973 3024 y(*)2023 3009 y Fo(ar)m(gs)p Fj(\))p
Fr('.)40 b(Note)26 b(that)g(if)g(you)f(only)g(pass)i
Fj(PyObject)3666 3024 y(*)3742 3009 y Fr(ar)o(gs,)208
3109 y Fj(PyObject_CallFunctionObjArgs)15 b Fr(is)21
b(a)g(f)o(aster)f(alternati)n(v)o(e.)0 3256 y Fj(PyObject)400
3271 y(*)498 3256 y Fg(PyObject_CallMethod)p Fj(\()p
Fo(PyObject)c(*o,)k(c)o(har)f(*method,)g(c)o(har)g(*format,)h(...)p
Fj(\))208 3355 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3455 y Fr(Call)32 b(the)f(method)f(named)g Fo(method)i
Fr(of)f(object)g Fo(o)g Fr(with)g(a)h(v)n(ariable)e(number)g(of)h(C)h
(ar)o(guments.)56 b(The)30 b(C)i(ar)o(guments)e(are)208
3555 y(described)d(by)i(a)h Fj(Py_BuildValue\(\))c Fr(format)i(string)h
(that)g(should)g(produce)e(a)i(tuple.)52 b(The)28 b(format)g(may)h(be)g
Fj(NULL)p Fr(,)208 3654 y(indicating)22 b(that)i(no)g(ar)o(guments)e
(are)i(pro)o(vided.)34 b(Returns)24 b(the)g(result)g(of)g(the)g(call)g
(on)g(success,)h(or)f Fj(NULL)g Fr(on)f(f)o(ailure.)36
b(This)208 3754 y(is)24 b(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f
(e)o(xpression)g(`)p Fo(o)p Fj(.)p Fo(method)r Fj(\()p
Fo(ar)m(gs)p Fj(\))p Fr('.)31 b(Note)23 b(that)g(if)h(you)e(only)h
(pass)g Fj(PyObject)3669 3769 y(*)3742 3754 y Fr(ar)o(gs,)208
3853 y Fj(PyObject_CallMethodObjArgs)15 b Fr(is)22 b(a)e(f)o(aster)h
(alternati)n(v)o(e.)0 4000 y Fj(PyObject)400 4015 y(*)498
4000 y Fg(PyObject_CallFunctionObjArgs)p Fj(\()p Fo(PyObject)14
b(*callable)o(,)19 b(...,)h Fd(NULL)q Fj(\))208 4100
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4200 y Fr(Call)k(a)g(callable)f(Python)f(object)h
Fo(callable)p Fr(,)g(with)h(a)f(v)n(ariable)g(number)e(of)i
Fj(PyObject)2804 4215 y(*)2877 4200 y Fr(ar)o(guments.)32
b(The)23 b(ar)o(guments)f(are)208 4299 y(pro)o(vided)h(as)28
b(a)e(v)n(ariable)g(number)e(of)j(parameters)e(follo)n(wed)g(by)h
Fj(NULL)p Fr(.)g(Returns)g(the)h(result)f(of)g(the)h(call)g(on)f
(success,)i(or)208 4399 y Fj(NULL)20 b Fr(on)f(f)o(ailure.)50
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 4546 y Fj(PyObject)400
4561 y(*)498 4546 y Fg(PyObject_CallMethodObjArgs)p Fj(\()p
Fo(PyObject)c(*o,)k(PyObject)h(*name)o(,)f(...,)h Fd(NULL)q
Fj(\))208 4645 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4745 y Fr(Calls)k(a)f(method)f(of)h(the)g(object)g
Fo(o)p Fr(,)g(where)g(the)g(name)f(of)h(the)g(method)f(is)i(gi)n(v)o
(en)e(as)h(a)h(Python)e(string)h(object)f(in)h Fo(name)p
Fr(.)33 b(It)24 b(is)208 4845 y(called)c(with)h(a)g(v)n(ariable)e
(number)g(of)i Fj(PyObject)1706 4860 y(*)1775 4845 y
Fr(ar)o(guments.)j(The)d(ar)o(guments)d(are)j(pro)o(vided)d(as)j(a)g(v)
n(ariable)f(number)f(of)208 4944 y(parameters)j(follo)n(wed)h(by)h
Fj(NULL)p Fr(.)f(Returns)h(the)g(result)g(of)g(the)g(call)h(on)e
(success,)j(or)e Fj(NULL)f Fr(on)h(f)o(ailure.)73 b(Ne)n(w)25
b(in)f(v)o(ersion)208 5044 y(2.2.)0 5191 y Fj(long)49
b Fg(PyObject_Hash)p Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208
5290 y Fr(Compute)23 b(and)g(return)g(the)h(hash)g(v)n(alue)f(of)h(an)f
(object)h Fo(o)p Fr(.)36 b(On)24 b(f)o(ailure,)g(return)f
Fj(-1)p Fr(.)37 b(This)24 b(is)h(the)f(equi)n(v)n(alent)e(of)i(the)g
(Python)208 5390 y(e)o(xpression)18 b(`)p Fj(hash\()p
Fo(o)p Fj(\))p Fr('.)p 0 5549 3901 4 v 0 5649 a Fn(6.1.)52
b(Object)23 b(Protocol)3051 b(37)p eop end
%%Page: 38 44
TeXDict begin 38 43 bop 0 83 a Fj(int)49 b Fg(PyObject_IsTrue)p
Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208 183 y Fr(Returns)22
b Fj(1)g Fr(if)h(the)f(object)g Fo(o)g Fr(is)i(considered)c(to)j(be)f
(true,)g(and)g Fj(0)g Fr(otherwise.)31 b(This)22 b(is)i(equi)n(v)n
(alent)c(to)j(the)f(Python)f(e)o(xpression)208 282 y(`)p
Fj(not)48 b(not)i Fo(o)p Fr('.)24 b(On)d(f)o(ailure,)e(return)g
Fj(-1)p Fr(.)0 429 y Fj(int)49 b Fg(PyObject_Not)p Fj(\()p
Fo(PyObject)18 b(*o)p Fj(\))208 529 y Fr(Returns)k Fj(0)g
Fr(if)h(the)f(object)g Fo(o)g Fr(is)i(considered)c(to)j(be)f(true,)g
(and)g Fj(1)g Fr(otherwise.)31 b(This)22 b(is)i(equi)n(v)n(alent)c(to)j
(the)f(Python)f(e)o(xpression)208 628 y(`)p Fj(not)48
b Fo(o)p Fr('.)25 b(On)20 b(f)o(ailure,)g(return)f Fj(-1)p
Fr(.)0 775 y Fj(PyObject)400 790 y(*)498 775 y Fg(PyObject_Type)p
Fj(\()p Fo(PyObject)e(*o)p Fj(\))208 875 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 975 y Fr(When)29
b Fo(o)g Fr(is)h(non-)p Fj(NULL)p Fr(,)d(returns)i(a)h(type)e(object)h
(corresponding)d(to)k(the)f(object)g(type)g(of)g(object)f
Fo(o)p Fr(.)53 b(On)29 b(f)o(ailure,)i(raises)208 1074
y Fj(SystemError)25 b Fr(and)h(returns)f Fj(NULL)p Fr(.)h(This)h(is)g
(equi)n(v)n(alent)e(to)i(the)f(Python)g(e)o(xpression)f
Fj(type\()p Fo(o)p Fj(\))p Fr(.)42 b(This)27 b(function)e(in-)208
1174 y(crements)h(the)h(reference)e(count)h(of)h(the)g(return)f(v)n
(alue.)45 b(There')-5 b(s)26 b(really)h(no)f(reason)h(to)g(use)g(this)h
(function)d(instead)i(of)g(the)208 1273 y(common)17 b(e)o(xpression)h
Fo(o)p Fj(->ob_type)p Fr(,)g(which)h(returns)f(a)i(pointer)f(of)g(type)
g Fj(PyTypeObject)3061 1288 y(*)3111 1273 y Fr(,)e(e)o(xcept)i(when)g
(the)g(incre-)208 1373 y(mented)g(reference)f(count)h(is)j(needed.)0
1520 y Fj(int)49 b Fg(PyObject_TypeCheck)p Fj(\()p Fo(PyObject)16
b(*o,)k(PyT)-6 b(ypeObject)19 b(*type)p Fj(\))208 1620
y Fr(Return)24 b(true)h(if)h(the)f(object)g Fo(o)h Fr(is)g(of)f(type)g
Fo(type)g Fr(or)g(a)h(subtype)e(of)h Fo(type)p Fr(.)41
b(Both)25 b(parameters)f(must)i(be)f(non-)p Fj(NULL)p
Fr(.)49 b(Ne)n(w)25 b(in)208 1719 y(v)o(ersion)18 b(2.2.)0
1866 y Fj(Py_ssize_t)48 b Fg(PyObject_Length)p Fj(\()p
Fo(PyObject)17 b(*o)p Fj(\))0 1966 y(Py_ssize_t)48 b
Fg(PyObject_Size)p Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208
2065 y Fr(Return)j(the)h(length)f(of)h(object)g Fo(o)p
Fr(.)27 b(If)21 b(the)h(object)e Fo(o)h Fr(pro)o(vides)f(either)g(the)h
(sequence)f(and)h(mapping)e(protocols,)h(the)h(sequence)208
2165 y(length)e(is)i(returned.)i(On)d(error)m(,)f Fj(-1)h
Fr(is)h(returned.)i(This)e(is)g(the)f(equi)n(v)n(alent)f(to)h(the)g
(Python)f(e)o(xpression)g(`)p Fj(len\()p Fo(o)p Fj(\))p
Fr('.)0 2312 y Fj(PyObject)400 2327 y(*)498 2312 y Fg(PyObject_GetItem)
p Fj(\()p Fo(PyObject)e(*o,)i(PyObject)h(*k)o(e)n(y)p
Fj(\))208 2411 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2511 y Fr(Return)k(element)h(of)f Fo(o)i Fr(corresponding)21
b(to)k(the)g(object)g Fo(k)o(e)n(y)g Fr(or)g Fj(NULL)g
Fr(on)f(f)o(ailure.)39 b(This)25 b(is)h(the)g(equi)n(v)n(alent)d(of)i
(the)g(Python)208 2611 y(e)o(xpression)18 b(`)p Fo(o)p
Fj([)p Fo(k)o(e)n(y)p Fj(])p Fr('.)0 2758 y Fj(int)49
b Fg(PyObject_SetItem)p Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*k)o
(e)n(y)-5 b(,)20 b(PyObject)f(*v)p Fj(\))208 2857 y Fr(Map)f(the)h
(object)g Fo(k)o(e)n(y)g Fr(to)g(the)g(v)n(alue)f Fo(v)p
Fr(.)25 b(Returns)19 b Fj(-1)g Fr(on)g(f)o(ailure.)24
b(This)19 b(is)h(the)f(equi)n(v)n(alent)e(of)i(the)g(Python)f
(statement)h(`)p Fo(o)p Fj([)p Fo(k)o(e)n(y)p Fj(])208
2957 y(=)49 b Fo(v)p Fr('.)0 3104 y Fj(int)g Fg(PyObject_DelItem)p
Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*k)o(e)n(y)p
Fj(\))208 3203 y Fr(Delete)h(the)h(mapping)d(for)i Fo(k)o(e)n(y)g
Fr(from)f Fo(o)p Fr(.)29 b(Returns)21 b Fj(-1)g Fr(on)g(f)o(ailure.)28
b(This)22 b(is)g(the)f(equi)n(v)n(alent)f(of)h(the)h(Python)e
(statement)h(`)p Fj(del)208 3303 y Fo(o)p Fj([)p Fo(k)o(e)n(y)p
Fj(])p Fr('.)0 3450 y Fj(int)49 b Fg(PyObject_AsFileDescriptor)p
Fj(\()p Fo(PyObject)15 b(*o)p Fj(\))208 3549 y Fr(Deri)n(v)o(es)23
b(a)i(\002le-descriptor)d(from)h(a)i(Python)e(object.)36
b(If)24 b(the)g(object)f(is)i(an)g(inte)o(ger)e(or)g(long)h(inte)o(ger)
m(,)f(its)i(v)n(alue)f(is)h(returned.)208 3649 y(If)e(not,)h(the)f
(object')-5 b(s)24 b Fj(fileno\(\))e Fr(method)g(is)j(called)e(if)h(it)
g(e)o(xists;)i(the)d(method)g(must)g(return)f(an)i(inte)o(ger)e(or)i
(long)e(inte)o(ger)m(,)208 3749 y(which)d(is)i(returned)e(as)i(the)f
(\002le)h(descriptor)d(v)n(alue.)25 b(Returns)20 b Fj(-1)g
Fr(on)g(f)o(ailure.)0 3896 y Fj(PyObject)400 3911 y(*)498
3896 y Fg(PyObject_Dir)p Fj(\()p Fo(PyObject)d(*o)p Fj(\))208
3995 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4095 y Fr(This)k(is)h(equi)n(v)n(alent)e(to)i(the)f(Python)f
(e)o(xpression)g(`)p Fj(dir\()p Fo(o)p Fj(\))p Fr(',)g(returning)g(a)i
(\(possibly)e(empty\))g(list)i(of)g(strings)f(appropriate)208
4194 y(for)16 b(the)i(object)f(ar)o(gument,)e(or)i Fj(NULL)g
Fr(if)h(there)f(w)o(as)h(an)f(error)-5 b(.)24 b(If)17
b(the)g(ar)o(gument)e(is)j Fj(NULL)p Fr(,)f(this)h(is)h(lik)o(e)e(the)h
(Python)e(`)p Fj(dir\(\))p Fr(',)208 4294 y(returning)i(the)j(names)f
(of)h(the)g(current)e(locals;)j(in)f(this)g(case,)g(if)g(no)f(e)o(x)o
(ecution)f(frame)h(is)i(acti)n(v)o(e)e(then)g Fj(NULL)h
Fr(is)h(returned)d(b)n(ut)208 4394 y Fj(PyErr_Occurred\(\))e
Fr(will)k(return)e(f)o(alse.)0 4541 y Fj(PyObject)400
4556 y(*)498 4541 y Fg(PyObject_GetIter)p Fj(\()p Fo(PyObject)e(*o)p
Fj(\))208 4640 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4740 y Fr(This)g(is)h(equi)n(v)n(alent)d(to)j(the)f(Python)f
(e)o(xpression)f(`)p Fj(iter\()p Fo(o)p Fj(\))p Fr('.)23
b(It)e(returns)e(a)i(ne)n(w)f(iterator)f(for)g(the)i(object)e(ar)o
(gument,)f(or)i(the)208 4839 y(object)k(itself)h(if)f(the)h(object)f
(is)h(already)f(an)g(iterator)-5 b(.)38 b(Raises)26 b
Fj(TypeError)d Fr(and)h(returns)g Fj(NULL)g Fr(if)h(the)f(object)g
(cannot)g(be)208 4939 y(iterated.)p 0 5549 3901 4 v 0
5649 a Fn(38)2511 b(Chapter)23 b(6.)52 b(Abstr)o(act)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 39 45
TeXDict begin 39 44 bop 0 86 a Fl(6.2)121 b(Number)34
b(Protocol)0 298 y Fj(int)49 b Fg(PyNumber_Check)p Fj(\()p
Fo(PyObject)17 b(*o)p Fj(\))208 397 y Fr(Returns)j Fj(1)g
Fr(if)h(the)f(object)g Fo(o)g Fr(pro)o(vides)e(numeric)h(protocols,)g
(and)g(f)o(alse)i(otherwise.)j(This)c(function)f(al)o(w)o(ays)i
(succeeds.)0 544 y Fj(PyObject)400 559 y(*)498 544 y
Fg(PyNumber_Add)p Fj(\()p Fo(PyObject)c(*o1,)i(PyObject)h(*o2)p
Fj(\))208 644 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 743 y Fr(Returns)h(the)g(result)g(of)g(adding)f
Fo(o1)g Fr(and)h Fo(o2)p Fr(,)g(or)g Fj(NULL)g Fr(on)f(f)o(ailure.)28
b(This)21 b(is)h(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f(e)o
(xpression)f(`)p Fo(o1)208 843 y Fj(+)49 b Fo(o2)p Fr('.)0
990 y Fj(PyObject)400 1005 y(*)498 990 y Fg(PyNumber_Subtract)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p Fj(\))208
1089 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1189 y Fr(Returns)e(the)g(result)h(of)f(subtracting)f
Fo(o2)h Fr(from)f Fo(o1)p Fr(,)i(or)f Fj(NULL)g Fr(on)g(f)o(ailure.)24
b(This)19 b(is)g(the)f(equi)n(v)n(alent)f(of)h(the)h(Python)e(e)o
(xpression)208 1289 y(`)p Fo(o1)48 b Fj(-)i Fo(o2)p Fr('.)0
1435 y Fj(PyObject)400 1450 y(*)498 1435 y Fg(PyNumber_Multiply)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p Fj(\))208
1535 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1635 y Fr(Returns)f(the)h(result)g(of)f(multiplying)f
Fo(o1)h Fr(and)g Fo(o2)p Fr(,)h(or)f Fj(NULL)h Fr(on)f(f)o(ailure.)24
b(This)c(is)h(the)e(equi)n(v)n(alent)f(of)i(the)g(Python)e(e)o
(xpression)208 1734 y(`)p Fo(o1)368 1749 y Fj(*)468 1734
y Fo(o2)p Fr('.)0 1881 y Fj(PyObject)400 1896 y(*)498
1881 y Fg(PyNumber_Divide)p Fj(\()p Fo(PyObject)f(*o1,)i(PyObject)h
(*o2)p Fj(\))208 1981 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 2081 y Fr(Returns)g(the)h(result)f(of)h(di)n
(viding)e Fo(o1)h Fr(by)g Fo(o2)p Fr(,)g(or)h Fj(NULL)f
Fr(on)g(f)o(ailure.)26 b(This)21 b(is)g(the)g(equi)n(v)n(alent)e(of)h
(the)h(Python)e(e)o(xpression)g(`)p Fo(o1)208 2180 y
Fj(/)49 b Fo(o2)p Fr('.)0 2327 y Fj(PyObject)400 2342
y(*)498 2327 y Fg(PyNumber_FloorDivide)p Fj(\()p Fo(PyObject)16
b(*o1,)j(PyObject)h(*o2)p Fj(\))208 2427 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2526 y Fr(Return)f(the)h(\003oor)
f(of)g Fo(o1)g Fr(di)n(vided)g(by)g Fo(o2)p Fr(,)g(or)h
Fj(NULL)f Fr(on)h(f)o(ailure.)k(This)c(is)g(equi)n(v)n(alent)e(to)i
(the)g(\223classic\224)g(di)n(vision)f(of)h(inte)o(gers.)208
2626 y(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)0 2773 y Fj(PyObject)400
2788 y(*)498 2773 y Fg(PyNumber_TrueDivide)p Fj(\()p
Fo(PyObject)d(*o1,)j(PyObject)h(*o2)p Fj(\))208 2872
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2972 y Fr(Return)25 b(a)h(reasonable)e(approximation)f(for)i
(the)h(mathematical)e(v)n(alue)h(of)h Fo(o1)f Fr(di)n(vided)f(by)h
Fo(o2)p Fr(,)i(or)e Fj(NULL)h Fr(on)f(f)o(ailure.)41
b(The)208 3072 y(return)31 b(v)n(alue)h(is)h(\223approximate\224)d
(because)i(binary)f(\003oating)h(point)g(numbers)f(are)i(approximate;)j
(it)d(is)h(not)e(possible)g(to)208 3171 y(represent)17
b(all)j(real)e(numbers)g(in)h(base)f(tw)o(o.)25 b(This)19
b(function)e(can)i(return)e(a)j(\003oating)e(point)g(v)n(alue)g(when)g
(passed)h(tw)o(o)g(inte)o(gers.)208 3271 y(Ne)n(w)h(in)g(v)o(ersion)f
(2.2.)0 3418 y Fj(PyObject)400 3433 y(*)498 3418 y Fg
(PyNumber_Remainder)p Fj(\()p Fo(PyObject)d(*o1,)j(PyObject)h(*o2)p
Fj(\))208 3517 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3617 y Fr(Returns)f(the)h(remainder)d(of)j(di)n(viding)e
Fo(o1)h Fr(by)g Fo(o2)p Fr(,)g(or)g Fj(NULL)h Fr(on)f(f)o(ailure.)24
b(This)c(is)g(the)g(equi)n(v)n(alent)e(of)h(the)h(Python)e(e)o
(xpression)208 3717 y(`)p Fo(o1)48 b Fj(\045)i Fo(o2)p
Fr('.)0 3863 y Fj(PyObject)400 3878 y(*)498 3863 y Fg(PyNumber_Divmod)p
Fj(\()p Fo(PyObject)17 b(*o1,)i(PyObject)h(*o2)p Fj(\))208
3963 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4063 y Fr(See)h(the)f(b)n(uilt-in)g(function)f
Fj(divmod\(\))p Fr(.)25 b(Returns)20 b Fj(NULL)h Fr(on)f(f)o(ailure.)25
b(This)c(is)h(the)e(equi)n(v)n(alent)f(of)h(the)h(Python)e(e)o
(xpression)208 4162 y(`)p Fj(divmod\()p Fo(o1)p Fj(,)47
b Fo(o2)p Fj(\))p Fr('.)0 4309 y Fj(PyObject)400 4324
y(*)498 4309 y Fg(PyNumber_Power)p Fj(\()p Fo(PyObject)17
b(*o1,)i(PyObject)h(*o2,)f(PyObject)g(*o3)p Fj(\))208
4409 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4509 y Fr(See)28 b(the)g(b)n(uilt-in)f(function)g
Fj(pow\(\))p Fr(.)48 b(Returns)28 b Fj(NULL)g Fr(on)f(f)o(ailure.)48
b(This)28 b(is)h(the)f(equi)n(v)n(alent)f(of)g(the)h(Python)f(e)o
(xpression)208 4608 y(`)p Fj(pow\()p Fo(o1)p Fj(,)47
b Fo(o2)p Fj(,)i Fo(o3)p Fj(\))p Fr(',)21 b(where)g Fo(o3)g
Fr(is)i(optional.)28 b(If)22 b Fo(o3)f Fr(is)i(to)f(be)f(ignored,)f
(pass)j Fj(Py_None)e Fr(in)g(its)i(place)f(\(passing)f
Fj(NULL)208 4708 y Fr(for)e Fo(o3)h Fr(w)o(ould)f(cause)i(an)f(ille)o
(gal)f(memory)g(access\).)0 4855 y Fj(PyObject)400 4870
y(*)498 4855 y Fg(PyNumber_Negative)p Fj(\()p Fo(PyObject)d(*o)p
Fj(\))208 4954 y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 5054 y Fr(Returns)g(the)g(ne)o(gation)e(of)i
Fo(o)g Fr(on)g(success,)g(or)g Fj(NULL)g Fr(on)g(f)o(ailure.)k(This)d
(is)g(the)f(equi)n(v)n(alent)e(of)i(the)h(Python)e(e)o(xpression)f(`)p
Fj(-)p Fo(o)p Fr('.)0 5201 y Fj(PyObject)400 5216 y(*)498
5201 y Fg(PyNumber_Positive)p Fj(\()p Fo(PyObject)e(*o)p
Fj(\))208 5300 y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 5400 y Fr(Returns)g Fo(o)g Fr(on)g(success,)g(or)g
Fj(NULL)g Fr(on)g(f)o(ailure.)k(This)d(is)g(the)f(equi)n(v)n(alent)e
(of)i(the)g(Python)f(e)o(xpression)g(`)p Fj(+)p Fo(o)p
Fr('.)p 0 5549 3901 4 v 0 5649 a Fn(6.2.)52 b(Number)23
b(Protocol)2996 b(39)p eop end
%%Page: 40 46
TeXDict begin 40 45 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyNumber_Absolute)p Fj(\()p Fo(PyObject)16 b(*o)p
Fj(\))208 183 y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 282 y Fr(Returns)f(the)g(absolute)f(v)n(alue)h(of)g
Fo(o)p Fr(,)g(or)g Fj(NULL)g Fr(on)f(f)o(ailure.)24 b(This)c(is)g(the)f
(equi)n(v)n(alent)e(of)i(the)g(Python)f(e)o(xpression)g(`)p
Fj(abs\()p Fo(o)p Fj(\))p Fr('.)0 429 y Fj(PyObject)400
444 y(*)498 429 y Fg(PyNumber_Invert)p Fj(\()p Fo(PyObject)f(*o)p
Fj(\))208 529 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 628 y Fr(Returns)d(the)g(bitwise)h(ne)o(gation)e(of)h
Fo(o)h Fr(on)f(success,)h(or)f Fj(NULL)h Fr(on)f(f)o(ailure.)23
b(This)18 b(is)h(the)e(equi)n(v)n(alent)f(of)h(the)h(Python)e(e)o
(xpression)208 728 y(`)p Fj(\230)p Fo(o)p Fr('.)0 875
y Fj(PyObject)400 890 y(*)498 875 y Fg(PyNumber_Lshift)p
Fj(\()p Fo(PyObject)h(*o1,)i(PyObject)h(*o2)p Fj(\))208
975 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1074 y Fr(Returns)h(the)h(result)f(of)g(left)h(shifting)f
Fo(o1)g Fr(by)g Fo(o2)h Fr(on)f(success,)h(or)f Fj(NULL)h
Fr(on)f(f)o(ailure.)28 b(This)22 b(is)g(the)g(equi)n(v)n(alent)e(of)h
(the)h(Python)208 1174 y(e)o(xpression)c(`)p Fo(o1)49
b Fj(<<)g Fo(o2)p Fr('.)0 1321 y Fj(PyObject)400 1336
y(*)498 1321 y Fg(PyNumber_Rshift)p Fj(\()p Fo(PyObject)17
b(*o1,)i(PyObject)h(*o2)p Fj(\))208 1420 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1520 y Fr(Returns)f(the)g(result)
h(of)f(right)g(shifting)g Fo(o1)g Fr(by)g Fo(o2)g Fr(on)g(success,)h
(or)f Fj(NULL)g Fr(on)h(f)o(ailure.)k(This)19 b(is)i(the)e(equi)n(v)n
(alent)f(of)h(the)h(Python)208 1620 y(e)o(xpression)e(`)p
Fo(o1)49 b Fj(>>)g Fo(o2)p Fr('.)0 1766 y Fj(PyObject)400
1781 y(*)498 1766 y Fg(PyNumber_And)p Fj(\()p Fo(PyObject)17
b(*o1,)i(PyObject)h(*o2)p Fj(\))208 1866 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1966 y Fr(Returns)k(the)h
(\223bitwise)g(and\224)f(of)h Fo(o1)f Fr(and)g Fo(o2)h
Fr(on)f(success)h(and)g Fj(NULL)f Fr(on)h(f)o(ailure.)38
b(This)25 b(is)h(the)e(equi)n(v)n(alent)f(of)i(the)g(Python)208
2065 y(e)o(xpression)18 b(`)p Fo(o1)49 b Fj(&)g Fo(o2)p
Fr('.)0 2212 y Fj(PyObject)400 2227 y(*)498 2212 y Fg(PyNumber_Xor)p
Fj(\()p Fo(PyObject)17 b(*o1,)i(PyObject)h(*o2)p Fj(\))208
2312 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2411 y Fr(Returns)26 b(the)h(\223bitwise)g(e)o(xclusi)n(v)o(e)
e(or\224)h(of)h Fo(o1)f Fr(by)g Fo(o2)h Fr(on)f(success,)j(or)d
Fj(NULL)h Fr(on)f(f)o(ailure.)44 b(This)27 b(is)g(the)g(equi)n(v)n
(alent)e(of)i(the)208 2511 y(Python)19 b(e)o(xpression)f(`)p
Fo(o1)49 b Fj(\210)g Fo(o2)p Fr('.)0 2658 y Fj(PyObject)400
2673 y(*)498 2658 y Fg(PyNumber_Or)p Fj(\()p Fo(PyObject)18
b(*o1,)h(PyObject)g(*o2)p Fj(\))208 2758 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2857 y Fr(Returns)28
b(the)g(\223bitwise)h(or\224)f(of)g Fo(o1)g Fr(and)g
Fo(o2)g Fr(on)g(success,)i(or)e Fj(NULL)h Fr(on)e(f)o(ailure.)49
b(This)29 b(is)g(the)g(equi)n(v)n(alent)d(of)i(the)h(Python)208
2957 y(e)o(xpression)18 b(`)p Fo(o1)49 b Fj(|)g Fo(o2)p
Fr('.)0 3104 y Fj(PyObject)400 3119 y(*)498 3104 y Fg
(PyNumber_InPlaceAdd)p Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p
Fj(\))208 3203 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3303 y Fr(Returns)f(the)h(result)g(of)g(adding)f
Fo(o1)g Fr(and)h Fo(o2)p Fr(,)f(or)h Fj(NULL)f Fr(on)h(f)o(ailure.)k
(The)c(operation)e(is)j(done)e Fo(in-place)f Fr(when)i
Fo(o1)f Fr(supports)g(it.)208 3403 y(This)h(is)h(the)f(equi)n(v)n
(alent)f(of)h(the)g(Python)f(statement)h(`)p Fo(o1)48
b Fj(+=)i Fo(o2)p Fr('.)0 3549 y Fj(PyObject)400 3564
y(*)498 3549 y Fg(PyNumber_InPlaceSubtract)p Fj(\()p
Fo(PyObject)15 b(*o1,)k(PyObject)h(*o2)p Fj(\))208 3649
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3749 y Fr(Returns)30 b(the)g(result)g(of)g(subtracting)e
Fo(o2)i Fr(from)f Fo(o1)p Fr(,)j(or)e Fj(NULL)g Fr(on)f(f)o(ailure.)55
b(The)29 b(operation)g(is)i(done)e Fo(in-place)f Fr(when)i
Fo(o1)208 3848 y Fr(supports)19 b(it.)25 b(This)c(is)g(the)f(equi)n(v)n
(alent)e(of)i(the)h(Python)e(statement)h(`)p Fo(o1)48
b Fj(-=)i Fo(o2)p Fr('.)0 3995 y Fj(PyObject)400 4010
y(*)498 3995 y Fg(PyNumber_InPlaceMultiply)p Fj(\()p
Fo(PyObject)15 b(*o1,)k(PyObject)h(*o2)p Fj(\))208 4095
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4194 y Fr(Returns)15 b(the)h(result)g(of)g(multiplying)e
Fo(o1)h Fr(and)g Fo(o2)p Fr(,)i(or)e Fj(NULL)h Fr(on)f(f)o(ailure.)23
b(The)16 b(operation)e(is)j(done)d Fo(in-place)h Fr(when)g
Fo(o1)h Fr(supports)208 4294 y(it.)25 b(This)c(is)g(the)f(equi)n(v)n
(alent)e(of)i(the)g(Python)g(statement)g(`)p Fo(o1)1997
4309 y Fj(*)2047 4294 y(=)49 b Fo(o2)p Fr('.)0 4441 y
Fj(PyObject)400 4456 y(*)498 4441 y Fg(PyNumber_InPlaceDivide)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)g(*o2)p Fj(\))208
4541 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4640 y Fr(Returns)f(the)g(result)g(of)h(di)n(viding)d
Fo(o1)i Fr(by)g Fo(o2)p Fr(,)g(or)g Fj(NULL)g Fr(on)g(f)o(ailure.)24
b(The)19 b(operation)f(is)i(done)e Fo(in-place)g Fr(when)h
Fo(o1)g Fr(supports)f(it.)208 4740 y(This)i(is)h(the)f(equi)n(v)n
(alent)f(of)h(the)g(Python)f(statement)h(`)p Fo(o1)48
b Fj(/=)i Fo(o2)p Fr('.)0 4887 y Fj(PyObject)400 4902
y(*)498 4887 y Fg(PyNumber_InPlaceFloorDivide)p Fj(\()p
Fo(PyObject)15 b(*o1,)k(PyObject)g(*o2)p Fj(\))208 4986
y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 5086 y Fr(Returns)h(the)h(mathematical)f(\003oor)h(of)f(di)n
(viding)g Fo(o1)g Fr(by)h Fo(o2)p Fr(,)g(or)g Fj(NULL)f
Fr(on)h(f)o(ailure.)30 b(The)21 b(operation)g(is)i(done)e
Fo(in-place)f Fr(when)208 5186 y Fo(o1)f Fr(supports)g(it.)26
b(This)20 b(is)i(the)e(equi)n(v)n(alent)e(of)i(the)g(Python)f
(statement)h(`)p Fo(o1)49 b Fj(//=)g Fo(o2)p Fr('.)h(Ne)n(w)20
b(in)h(v)o(ersion)e(2.2.)0 5332 y Fj(PyObject)400 5347
y(*)498 5332 y Fg(PyNumber_InPlaceTrueDivide)p Fj(\()p
Fo(PyObject)c(*o1,)k(PyObject)g(*o2)p Fj(\))p 0 5549
3901 4 v 0 5649 a Fn(40)2511 b(Chapter)23 b(6.)52 b(Abstr)o(act)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 41 47
TeXDict begin 41 46 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(Return)25
b(a)h(reasonable)e(approximation)f(for)i(the)h(mathematical)e(v)n(alue)
h(of)h Fo(o1)f Fr(di)n(vided)f(by)h Fo(o2)p Fr(,)i(or)e
Fj(NULL)h Fr(on)f(f)o(ailure.)41 b(The)208 282 y(return)31
b(v)n(alue)h(is)h(\223approximate\224)d(because)i(binary)f(\003oating)h
(point)g(numbers)f(are)i(approximate;)j(it)d(is)h(not)e(possible)g(to)
208 382 y(represent)17 b(all)j(real)e(numbers)g(in)h(base)f(tw)o(o.)25
b(This)19 b(function)e(can)i(return)e(a)j(\003oating)e(point)g(v)n
(alue)g(when)g(passed)h(tw)o(o)g(inte)o(gers.)208 482
y(The)g(operation)g(is)i(done)e Fo(in-place)g Fr(when)g
Fo(o1)h Fr(supports)f(it.)52 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)0
628 y Fj(PyObject)400 643 y(*)498 628 y Fg(PyNumber_InPlaceRemainder)p
Fj(\()p Fo(PyObject)c(*o1,)k(PyObject)h(*o2)p Fj(\))208
728 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 828 y Fr(Returns)31 b(the)g(remainder)e(of)i(di)n(viding)e
Fo(o1)i Fr(by)g Fo(o2)p Fr(,)i(or)e Fj(NULL)g Fr(on)f(f)o(ailure.)57
b(The)31 b(operation)f(is)i(done)e Fo(in-place)f Fr(when)i
Fo(o1)208 927 y Fr(supports)19 b(it.)25 b(This)c(is)g(the)f(equi)n(v)n
(alent)e(of)i(the)h(Python)e(statement)h(`)p Fo(o1)48
b Fj(\045=)i Fo(o2)p Fr('.)0 1074 y Fj(PyObject)400 1089
y(*)498 1074 y Fg(PyNumber_InPlacePower)p Fj(\()p Fo(PyObject)16
b(*o1,)j(PyObject)g(*o2,)g(PyObject)h(*o3)p Fj(\))208
1174 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1273 y Fr(See)25 b(the)f(b)n(uilt-in)g(function)f
Fj(pow\(\))p Fr(.)37 b(Returns)25 b Fj(NULL)f Fr(on)g(f)o(ailure.)38
b(The)24 b(operation)e(is)k(done)d Fo(in-place)h Fr(when)g
Fo(o1)g Fr(supports)208 1373 y(it.)40 b(This)26 b(is)g(the)f(equi)n(v)n
(alent)e(of)i(the)g(Python)f(statement)h(`)p Fo(o1)2052
1388 y Fj(**)2152 1373 y(=)49 b Fo(o2)p Fr(')24 b(when)h(o3)g(is)h
Fj(Py_None)p Fr(,)f(or)g(an)g(in-place)g(v)n(ariant)208
1473 y(of)f(`)p Fj(pow\()p Fo(o1)p Fj(,)48 b Fo(o2)p
Fj(,)g Fo(o3)p Fj(\))p Fr(')25 b(otherwise.)38 b(If)25
b Fo(o3)g Fr(is)h(to)f(be)g(ignored,)f(pass)h Fj(Py_None)g
Fr(in)g(its)h(place)f(\(passing)f Fj(NULL)h Fr(for)f
Fo(o3)208 1572 y Fr(w)o(ould)19 b(cause)h(an)g(ille)o(gal)g(memory)e
(access\).)0 1719 y Fj(PyObject)400 1734 y(*)498 1719
y Fg(PyNumber_InPlaceLshift)p Fj(\()p Fo(PyObject)e(*o1,)j(PyObject)g
(*o2)p Fj(\))208 1819 y Fo(Return)g(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 1918 y Fr(Returns)f(the)h(result)g(of)g(left)
g(shifting)f Fo(o1)g Fr(by)h Fo(o2)f Fr(on)h(success,)g(or)f
Fj(NULL)h Fr(on)f(f)o(ailure.)25 b(The)19 b(operation)f(is)j(done)e
Fo(in-place)f Fr(when)208 2018 y Fo(o1)h Fr(supports)g(it.)26
b(This)20 b(is)i(the)e(equi)n(v)n(alent)e(of)i(the)g(Python)f
(statement)h(`)p Fo(o1)49 b Fj(<<=)g Fo(o2)p Fr('.)0
2165 y Fj(PyObject)400 2180 y(*)498 2165 y Fg(PyNumber_InPlaceRshift)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)g(*o2)p Fj(\))208
2265 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2364 y Fr(Returns)d(the)g(result)h(of)f(right)g(shifting)f
Fo(o1)h Fr(by)g Fo(o2)h Fr(on)f(success,)h(or)f Fj(NULL)g
Fr(on)g(f)o(ailure.)24 b(The)17 b(operation)e(is)k(done)d
Fo(in-place)g Fr(when)208 2464 y Fo(o1)j Fr(supports)g(it.)26
b(This)20 b(is)i(the)e(equi)n(v)n(alent)e(of)i(the)g(Python)f
(statement)h(`)p Fo(o1)49 b Fj(>>=)g Fo(o2)p Fr('.)0
2611 y Fj(PyObject)400 2626 y(*)498 2611 y Fg(PyNumber_InPlaceAnd)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p Fj(\))208
2710 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2810 y Fr(Returns)j(the)g(\223bitwise)g(and\224)g(of)g
Fo(o1)f Fr(and)h Fo(o2)g Fr(on)g(success)g(and)g Fj(NULL)g
Fr(on)g(f)o(ailure.)33 b(The)23 b(operation)e(is)j(done)e
Fo(in-place)g Fr(when)208 2910 y Fo(o1)d Fr(supports)g(it.)26
b(This)20 b(is)i(the)e(equi)n(v)n(alent)e(of)i(the)g(Python)f
(statement)h(`)p Fo(o1)49 b Fj(&=)g Fo(o2)p Fr('.)0 3056
y Fj(PyObject)400 3071 y(*)498 3056 y Fg(PyNumber_InPlaceXor)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p Fj(\))208
3156 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3256 y Fr(Returns)i(the)h(\223bitwise)f(e)o(xclusi)n(v)o(e)g
(or\224)g(of)g Fo(o1)g Fr(by)h Fo(o2)f Fr(on)g(success,)h(or)g
Fj(NULL)f Fr(on)g(f)o(ailure.)32 b(The)22 b(operation)f(is)i(done)f
Fo(in-place)208 3355 y Fr(when)d Fo(o1)h Fr(supports)f(it.)26
b(This)20 b(is)h(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f
(statement)h(`)p Fo(o1)48 b Fj(\210=)i Fo(o2)p Fr('.)0
3502 y Fj(PyObject)400 3517 y(*)498 3502 y Fg(PyNumber_InPlaceOr)p
Fj(\()p Fo(PyObject)16 b(*o1,)j(PyObject)h(*o2)p Fj(\))208
3602 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3701 y Fr(Returns)h(the)h(\223bitwise)h(or\224)e(of)h
Fo(o1)f Fr(and)h Fo(o2)f Fr(on)h(success,)h(or)e Fj(NULL)h
Fr(on)g(f)o(ailure.)29 b(The)22 b(operation)e(is)j(done)e
Fo(in-place)g Fr(when)g Fo(o1)208 3801 y Fr(supports)e(it.)25
b(This)c(is)g(the)f(equi)n(v)n(alent)e(of)i(the)h(Python)e(statement)h
(`)p Fo(o1)48 b Fj(|=)i Fo(o2)p Fr('.)0 3948 y Fj(int)f
Fg(PyNumber_Coerce)p Fj(\()p Fo(PyObject)17 b(**p1,)h(PyObject)i(**p2)p
Fj(\))208 4048 y Fr(This)k(function)f(tak)o(es)i(the)g(addresses)f(of)g
(tw)o(o)h(v)n(ariables)f(of)g(type)g Fj(PyObject)2575
4063 y(*)2625 4048 y Fr(.)37 b(If)24 b(the)h(objects)f(pointed)f(to)i
(by)3622 4063 y Fj(*)3672 4048 y Fo(p1)f Fr(and)208 4162
y Fj(*)258 4147 y Fo(p2)c Fr(ha)n(v)o(e)g(the)h(same)g(type,)f
(increment)f(their)i(reference)e(count)h(and)g(return)g
Fj(0)h Fr(\(success\).)27 b(If)20 b(the)h(objects)g(can)f(be)h(con)m(v)
o(erted)208 4247 y(to)i(a)h(common)e(numeric)g(type,)h(replace)1420
4262 y Fj(*)1470 4247 y(p1)g Fr(and)1737 4262 y Fj(*)1787
4247 y(p2)h Fr(by)f(their)g(con)m(v)o(erted)e(v)n(alue)i(\(with)g('ne)n
(w')f(reference)g(counts\),)h(and)208 4346 y(return)c
Fj(0)p Fr(.)28 b(If)21 b(no)g(con)m(v)o(ersion)d(is)k(possible,)e(or)h
(if)g(some)g(other)f(error)g(occurs,)h(return)e Fj(-1)j
Fr(\(f)o(ailure\))d(and)i(don')o(t)e(increment)h(the)208
4446 y(reference)f(counts.)26 b(The)20 b(call)i Fj
(PyNumber_Coerce\(&o1,)46 b(&o2\))21 b Fr(is)g(equi)n(v)n(alent)e(to)i
(the)g(Python)f(statement)h(`)p Fo(o1)p Fj(,)48 b Fo(o2)208
4546 y Fj(=)h(coerce\()p Fo(o1)p Fj(,)f Fo(o2)p Fj(\))p
Fr('.)0 4693 y Fj(PyObject)400 4708 y(*)498 4693 y Fg(PyNumber_Int)p
Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208 4792 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4892 y Fr(Returns)c(the)h
Fo(o)g Fr(con)m(v)o(erted)e(to)i(an)g(inte)o(ger)e(object)i(on)f
(success,)i(or)f Fj(NULL)f Fr(on)h(f)o(ailure.)23 b(If)17
b(the)g(ar)o(gument)e(is)i(outside)g(the)g(inte)o(ger)208
4991 y(range)i(a)h(long)g(object)f(will)i(be)f(returned)f(instead.)24
b(This)d(is)g(the)f(equi)n(v)n(alent)f(of)h(the)g(Python)f(e)o
(xpression)f(`)p Fj(int\()p Fo(o)p Fj(\))p Fr('.)0 5138
y Fj(PyObject)400 5153 y(*)498 5138 y Fg(PyNumber_Long)p
Fj(\()p Fo(PyObject)f(*o)p Fj(\))208 5238 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5338 y Fr(Returns)25
b(the)g Fo(o)g Fr(con)m(v)o(erted)d(to)k(a)f(long)f(inte)o(ger)g
(object)h(on)g(success,)h(or)f Fj(NULL)g Fr(on)g(f)o(ailure.)39
b(This)25 b(is)h(the)f(equi)n(v)n(alent)f(of)h(the)p
0 5549 3901 4 v 0 5649 a Fn(6.2.)52 b(Number)23 b(Protocol)2996
b(41)p eop end
%%Page: 42 48
TeXDict begin 42 47 bop 208 83 a Fr(Python)19 b(e)o(xpression)f(`)p
Fj(long\()p Fo(o)p Fj(\))p Fr('.)0 230 y Fj(PyObject)400
245 y(*)498 230 y Fg(PyNumber_Float)p Fj(\()p Fo(PyObject)f(*o)p
Fj(\))208 330 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 429 y Fr(Returns)k(the)h Fo(o)g Fr(con)m(v)o(erted)d(to)j(a)g
(\003oat)h(object)e(on)g(success,)j(or)d Fj(NULL)h Fr(on)f(f)o(ailure.)
39 b(This)25 b(is)g(the)g(equi)n(v)n(alent)e(of)i(the)g(Python)208
529 y(e)o(xpression)18 b(`)p Fj(float\()p Fo(o)p Fj(\))p
Fr('.)0 676 y Fj(PyObject)400 691 y(*)498 676 y Fg(PyNumber_Index)p
Fj(\()p Fo(PyObject)f(*o)p Fj(\))208 775 y Fr(Returns)g(the)h
Fo(o)f Fr(con)m(v)o(erted)e(to)j(a)g(Python)f(int)h(or)f(long)g(on)g
(success)h(or)f Fj(NULL)h Fr(with)g(a)g(T)-7 b(ypeError)15
b(e)o(xception)h(raised)h(on)g(f)o(ailure.)208 875 y(Ne)n(w)j(in)g(v)o
(ersion)f(2.5.)0 1022 y Fj(Py_ssize_t)48 b Fg(PyNumber_AsSsize_t)p
Fj(\()p Fo(PyObject)16 b(*o,)k(PyObject)f(*e)n(xc)p Fj(\))208
1121 y Fr(Returns)h Fo(o)h Fr(con)m(v)o(erted)c(to)k(a)g(Py)p
1130 1121 25 4 v 30 w(ssize)p 1321 1121 V 30 w(t)g(v)n(alue)f(if)h
Fo(o)g Fr(can)f(be)g(interpreted)f(as)i(an)g(inte)o(ger)-5
b(.)25 b(If)c Fo(o)f Fr(can)h(be)f(con)m(v)o(erted)e(to)j(a)g(Python)
208 1221 y(int)30 b(or)f(long)g(b)n(ut)h(the)g(attempt)f(to)h(con)m(v)o
(ert)e(to)i(a)g(Py)p 1774 1221 V 30 w(ssize)p 1965 1221
V 30 w(t)h(v)n(alue)e(w)o(ould)g(raise)h(an)g Fj(OverflowError)p
Fr(,)g(then)f(the)h Fo(e)n(xc)208 1321 y Fr(ar)o(gument)c(is)k(the)f
(type)f(of)h(e)o(xception)e(that)i(will)h(be)e(raised)h(\(usually)f
Fj(IndexError)g Fr(or)g Fj(OverflowError)p Fr(\).)49
b(If)29 b Fo(e)n(xc)208 1420 y Fr(is)e Fj(NULL)p Fr(,)f(then)g(the)h(e)
o(xception)d(is)k(cleared)d(and)h(the)h(v)n(alue)e(is)j(clipped)d(to)i
Fo(PY)p 2561 1420 V 30 w(SSIZE)p 2800 1420 V 28 w(T)p
2874 1420 V 30 w(MIN)32 b Fr(for)26 b(a)h(ne)o(gati)n(v)o(e)d(inte)o
(ger)i(or)208 1520 y Fo(PY)p 310 1520 V 29 w(SSIZE)p
548 1520 V 29 w(T)p 623 1520 V 30 w(MAX)e Fr(for)19 b(a)i(positi)n(v)o
(e)e(inte)o(ger)-5 b(.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.5.)0
1667 y Fj(int)49 b Fg(PyIndex_Check)p Fj(\()p Fo(PyObject)17
b(*o)p Fj(\))208 1766 y Fr(Returns)26 b(T)m(rue)g(if)g
Fo(o)h Fr(is)g(an)g(inde)o(x)e(inte)o(ger)g(\(has)h(the)h(nb)p
1857 1766 V 29 w(inde)o(x)e(slot)i(of)f(the)h(tp)p 2533
1766 V 29 w(as)p 2631 1766 V 30 w(number)e(structure)g(\002lled)i
(in\).)88 b(Ne)n(w)26 b(in)208 1866 y(v)o(ersion)18 b(2.5.)0
2193 y Fl(6.3)121 b(Sequence)35 b(Protocol)0 2412 y Fj(int)49
b Fg(PySequence_Check)p Fj(\()p Fo(PyObject)17 b(*o)p
Fj(\))208 2512 y Fr(Return)i Fj(1)i Fr(if)f(the)h(object)e(pro)o(vides)
g(sequence)g(protocol,)f(and)i Fj(0)g Fr(otherwise.)k(This)d(function)d
(al)o(w)o(ays)j(succeeds.)0 2659 y Fj(Py_ssize_t)48 b
Fg(PySequence_Size)p Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208
2758 y Fr(Returns)27 b(the)h(number)d(of)j(objects)f(in)h(sequence)e
Fo(o)i Fr(on)f(success,)j(and)d Fj(-1)h Fr(on)f(f)o(ailure.)47
b(F)o(or)27 b(objects)g(that)h(do)f(not)h(pro)o(vide)208
2858 y(sequence)19 b(protocol,)f(this)j(is)g(equi)n(v)n(alent)d(to)i
(the)h(Python)e(e)o(xpression)f(`)p Fj(len\()p Fo(o)p
Fj(\))p Fr('.)0 3005 y Fj(Py_ssize_t)48 b Fg(PySequence_Length)p
Fj(\()p Fo(PyObject)16 b(*o)p Fj(\))208 3104 y Fr(Alternate)j(name)h
(for)f Fj(PySequence_Size\(\))p Fr(.)0 3251 y Fj(PyObject)400
3266 y(*)498 3251 y Fg(PySequence_Concat)p Fj(\()p Fo(PyObject)d(*o1,)j
(PyObject)h(*o2)p Fj(\))208 3351 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3451 y Fr(Return)k(the)h
(concatenation)e(of)i Fo(o1)g Fr(and)g Fo(o2)f Fr(on)h(success,)i(and)d
Fj(NULL)h Fr(on)g(f)o(ailure.)40 b(This)25 b(is)h(the)f(equi)n(v)n
(alent)f(of)h(the)g(Python)208 3550 y(e)o(xpression)18
b(`)p Fo(o1)49 b Fj(+)g Fo(o2)p Fr('.)0 3697 y Fj(PyObject)400
3712 y(*)498 3697 y Fg(PySequence_Repeat)p Fj(\()p Fo(PyObject)16
b(*o,)k(Py)p 1942 3697 V 29 w(ssize)p 2127 3697 V 31
w(t)h(count)q Fj(\))208 3797 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3896 y Fr(Return)i(the)h(result)h
(of)f(repeating)e(sequence)h(object)h Fo(o)g(count)h
Fr(times,)g(or)f Fj(NULL)g Fr(on)f(f)o(ailure.)34 b(This)23
b(is)h(the)f(equi)n(v)n(alent)f(of)h(the)208 3996 y(Python)c(e)o
(xpression)f(`)p Fo(o)957 4011 y Fj(*)1057 3996 y Fo(count)q
Fr('.)0 4143 y Fj(PyObject)400 4158 y(*)498 4143 y Fg
(PySequence_InPlaceConcat)p Fj(\()p Fo(PyObject)d(*o1,)k(PyObject)h
(*o2)p Fj(\))208 4242 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 4342 y Fr(Return)j(the)g(concatenation)e(of)j
Fo(o1)f Fr(and)g Fo(o2)g Fr(on)g(success,)i(and)d Fj(NULL)i
Fr(on)f(f)o(ailure.)34 b(The)23 b(operation)f(is)j(done)d
Fo(in-place)g Fr(when)208 4442 y Fo(o1)d Fr(supports)g(it.)26
b(This)20 b(is)i(the)e(equi)n(v)n(alent)e(of)i(the)g(Python)f(e)o
(xpression)g(`)p Fo(o1)49 b Fj(+=)g Fo(o2)p Fr('.)0 4589
y Fj(PyObject)400 4604 y(*)498 4589 y Fg(PySequence_InPlaceRepeat)p
Fj(\()p Fo(PyObject)15 b(*o,)20 b(Py)p 2291 4589 V 29
w(ssize)p 2476 4589 V 31 w(t)h(count)q Fj(\))208 4688
y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4788 y Fr(Return)d(the)i(result)f(of)g(repeating)f(sequence)g
(object)h Fo(o)h(count)g Fr(times,)g(or)f Fj(NULL)g Fr(on)g(f)o
(ailure.)24 b(The)18 b(operation)e(is)k(done)d Fo(in-place)208
4887 y Fr(when)i Fo(o)h Fr(supports)g(it.)25 b(This)c(is)g(the)f(equi)n
(v)n(alent)e(of)i(the)g(Python)f(e)o(xpression)g(`)p
Fo(o)2556 4902 y Fj(*)2606 4887 y(=)49 b Fo(count)q Fr('.)0
5034 y Fj(PyObject)400 5049 y(*)498 5034 y Fg(PySequence_GetItem)p
Fj(\()p Fo(PyObject)16 b(*o,)k(Py)p 1992 5034 V 29 w(ssize)p
2177 5034 V 31 w(t)h(i)p Fj(\))208 5134 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5234 y Fr(Return)f(the)i
Fo(i)p Fr(th)f(element)g(of)f Fo(o)p Fr(,)h(or)g Fj(NULL)g
Fr(on)g(f)o(ailure.)25 b(This)20 b(is)h(the)f(equi)n(v)n(alent)f(of)h
(the)g(Python)f(e)o(xpression)f(`)p Fo(o)p Fj([)p Fo(i)p
Fj(])p Fr('.)0 5380 y Fj(PyObject)400 5395 y(*)498 5380
y Fg(PySequence_GetSlice)p Fj(\()p Fo(PyObject)e(*o,)k(Py)p
2042 5380 V 29 w(ssize)p 2227 5380 V 31 w(t)h(i1,)f(Py)p
2496 5380 V 29 w(ssize)p 2681 5380 V 31 w(t)h(i2)p Fj(\))p
0 5549 3901 4 v 0 5649 a Fn(42)2511 b(Chapter)23 b(6.)52
b(Abstr)o(act)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 43 49
TeXDict begin 43 48 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(Return)e(the)g(slice)i
(of)e(sequence)f(object)h Fo(o)h Fr(between)f Fo(i1)h
Fr(and)f Fo(i2)p Fr(,)g(or)h Fj(NULL)f Fr(on)g(f)o(ailure.)24
b(This)19 b(is)g(the)g(equi)n(v)n(alent)e(of)h(the)h(Python)208
282 y(e)o(xpression)f(`)p Fo(o)p Fj([)p Fo(i1)p Fj(:)p
Fo(i2)p Fj(])p Fr('.)0 429 y Fj(int)49 b Fg(PySequence_SetItem)p
Fj(\()p Fo(PyObject)16 b(*o,)k(Py)p 1693 429 25 4 v 29
w(ssize)p 1878 429 V 31 w(t)h(i,)g(PyObject)e(*v)p Fj(\))208
529 y Fr(Assign)24 b(object)g Fo(v)h Fr(to)f(the)h Fo(i)p
Fr(th)f(element)g(of)g Fo(o)p Fr(.)38 b(Returns)24 b
Fj(-1)h Fr(on)f(f)o(ailure.)37 b(This)25 b(is)g(the)f(equi)n(v)n(alent)
f(of)h(the)h(Python)e(statement)208 628 y(`)p Fo(o)p
Fj([)p Fo(i)p Fj(])48 b(=)i Fo(v)p Fr('.)25 b(This)20
b(function)f Fo(does)h(not)f Fr(steal)i(a)g(reference)e(to)h
Fo(v)p Fr(.)0 775 y Fj(int)49 b Fg(PySequence_DelItem)p
Fj(\()p Fo(PyObject)16 b(*o,)k(Py)p 1693 775 V 29 w(ssize)p
1878 775 V 31 w(t)h(i)p Fj(\))208 875 y Fr(Delete)i(the)f
Fo(i)p Fr(th)h(element)g(of)f(object)h Fo(o)p Fr(.)32
b(Returns)23 b Fj(-1)g Fr(on)f(f)o(ailure.)33 b(This)23
b(is)g(the)g(equi)n(v)n(alent)e(of)i(the)g(Python)e(statement)i(`)p
Fj(del)208 975 y Fo(o)p Fj([)p Fo(i)p Fj(])p Fr('.)0
1121 y Fj(int)49 b Fg(PySequence_SetSlice)p Fj(\()p Fo(PyObject)16
b(*o,)k(Py)p 1743 1121 V 29 w(ssize)p 1928 1121 V 31
w(t)h(i1,)f(Py)p 2197 1121 V 29 w(ssize)p 2382 1121 V
31 w(t)h(i2,)f(PyObject)g(*v)p Fj(\))208 1221 y Fr(Assign)g(the)g
(sequence)f(object)g Fo(v)h Fr(to)g(the)g(slice)h(in)f(sequence)f
(object)h Fo(o)g Fr(from)f Fo(i1)h Fr(to)g Fo(i2)p Fr(.)25
b(This)20 b(is)h(the)f(equi)n(v)n(alent)e(of)i(the)g(Python)208
1321 y(statement)g(`)p Fo(o)p Fj([)p Fo(i1)p Fj(:)p Fo(i2)p
Fj(])47 b(=)j Fo(v)p Fr('.)0 1468 y Fj(int)f Fg(PySequence_DelSlice)p
Fj(\()p Fo(PyObject)16 b(*o,)k(Py)p 1743 1468 V 29 w(ssize)p
1928 1468 V 31 w(t)h(i1,)f(Py)p 2197 1468 V 29 w(ssize)p
2382 1468 V 31 w(t)h(i2)p Fj(\))208 1567 y Fr(Delete)h(the)h(slice)g
(in)g(sequence)e(object)h Fo(o)h Fr(from)e Fo(i1)i Fr(to)f
Fo(i2)p Fr(.)32 b(Returns)23 b Fj(-1)f Fr(on)g(f)o(ailure.)32
b(This)22 b(is)i(the)e(equi)n(v)n(alent)f(of)h(the)h(Python)208
1667 y(statement)d(`)p Fj(del)48 b Fo(o)p Fj([)p Fo(i1)p
Fj(:)p Fo(i2)p Fj(])p Fr('.)0 1814 y Fj(Py_ssize_t)g
Fg(PySequence_Count)p Fj(\()p Fo(PyObject)16 b(*o,)k(PyObject)g(*value)
p Fj(\))208 1913 y Fr(Return)e(the)h(number)e(of)h(occurrences)f(of)h
Fo(value)h Fr(in)g Fo(o)p Fr(,)f(that)h(is,)h(return)e(the)g(number)f
(of)i(k)o(e)o(ys)f(for)h(which)f Fo(o)p Fj([)p Fo(k)o(e)n(y)p
Fj(])48 b(==)h Fo(value)p Fr(.)208 2013 y(On)20 b(f)o(ailure,)f(return)
g Fj(-1)p Fr(.)25 b(This)c(is)g(equi)n(v)n(alent)d(to)j(the)f(Python)f
(e)o(xpression)f(`)p Fo(o)p Fj(.count\()p Fo(value)p
Fj(\))p Fr('.)0 2160 y Fj(int)49 b Fg(PySequence_Contains)p
Fj(\()p Fo(PyObject)16 b(*o,)k(PyObject)f(*value)p Fj(\))208
2259 y Fr(Determine)k(if)h Fo(o)g Fr(contains)f Fo(value)p
Fr(.)36 b(If)24 b(an)g(item)h(in)f Fo(o)g Fr(is)h(equal)f(to)g
Fo(value)p Fr(,)g(return)f Fj(1)p Fr(,)i(otherwise)e(return)g
Fj(0)p Fr(.)37 b(On)24 b(error)m(,)g(return)208 2359
y Fj(-1)p Fr(.)h(This)20 b(is)h(equi)n(v)n(alent)e(to)h(the)g(Python)f
(e)o(xpression)g(`)p Fo(value)48 b Fj(in)i Fo(o)p Fr('.)0
2506 y Fj(Py_ssize_t)e Fg(PySequence_Index)p Fj(\()p
Fo(PyObject)16 b(*o,)k(PyObject)g(*value)p Fj(\))208
2606 y Fr(Return)31 b(the)i(\002rst)g(inde)o(x)e Fo(i)i
Fr(for)f(which)f Fo(o)p Fj([)p Fo(i)p Fj(])50 b(==)f
Fo(value)p Fr(.)61 b(On)32 b(error)m(,)i(return)d Fj(-1)p
Fr(.)61 b(This)33 b(is)g(equi)n(v)n(alent)e(to)h(the)h(Python)208
2705 y(e)o(xpression)18 b(`)p Fo(o)p Fj(.index\()p Fo(value)p
Fj(\))p Fr('.)0 2852 y Fj(PyObject)400 2867 y(*)498 2852
y Fg(PySequence_List)p Fj(\()p Fo(PyObject)f(*o)p Fj(\))208
2952 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3051 y Fr(Return)d(a)i(list)h(object)d(with)i(the)f(same)h
(contents)e(as)j(the)e(arbitrary)f(sequence)g Fo(o)p
Fr(.)24 b(The)18 b(returned)f(list)i(is)g(guaranteed)e(to)h(be)g(ne)n
(w)-5 b(.)0 3198 y Fj(PyObject)400 3213 y(*)498 3198
y Fg(PySequence_Tuple)p Fj(\()p Fo(PyObject)17 b(*o)p
Fj(\))208 3298 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3397 y Fr(Return)26 b(a)i(tuple)e(object)h(with)g(the)g(same)g
(contents)f(as)i(the)f(arbitrary)f(sequence)g Fo(o)h
Fr(or)f Fj(NULL)h Fr(on)g(f)o(ailure.)45 b(If)27 b Fo(o)g
Fr(is)h(a)f(tuple,)208 3497 y(a)f(ne)n(w)f(reference)f(will)i(be)g
(returned,)f(otherwise)g(a)h(tuple)f(will)h(be)g(constructed)e(with)i
(the)f(appropriate)e(contents.)41 b(This)26 b(is)208
3597 y(equi)n(v)n(alent)18 b(to)i(the)h(Python)e(e)o(xpression)f(`)p
Fj(tuple\()p Fo(o)p Fj(\))p Fr('.)0 3744 y Fj(PyObject)400
3759 y(*)498 3744 y Fg(PySequence_Fast)p Fj(\()p Fo(PyObject)f(*o,)i
(const)h(c)o(har)g(*m)p Fj(\))208 3843 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3943 y Fr(Returns)35
b(the)h(sequence)f Fo(o)h Fr(as)h(a)g(tuple,)i(unless)d(it)h(is)g
(already)e(a)h(tuple)g(or)f(list,)41 b(in)36 b(which)g(case)g
Fo(o)g Fr(is)h(returned.)71 b(Use)208 4042 y Fj
(PySequence_Fast_GET_ITEM\(\))23 b Fr(to)28 b(access)g(the)f(members)g
(of)g(the)h(result.)47 b(Returns)27 b Fj(NULL)h Fr(on)f(f)o(ailure.)46
b(If)28 b(the)208 4142 y(object)19 b(is)i(not)f(a)h(sequence,)e(raises)
h Fj(TypeError)f Fr(with)i Fo(m)g Fr(as)f(the)h(message)f(te)o(xt.)0
4289 y Fj(PyObject)400 4304 y(*)498 4289 y Fg(PySequence_Fast_GET_ITEM)
p Fj(\()p Fo(PyObject)15 b(*o,)20 b(Py)p 2291 4289 V
29 w(ssize)p 2476 4289 V 31 w(t)h(i)p Fj(\))208 4389
y Fo(Return)e(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p
Fo(.)208 4488 y Fr(Return)g(the)g Fo(i)p Fr(th)h(element)f(of)g
Fo(o)p Fr(,)h(assuming)f(that)g Fo(o)h Fr(w)o(as)g(returned)e(by)h
Fj(PySequence_Fast\(\))p Fr(,)e Fo(o)j Fr(is)g(not)f
Fj(NULL)p Fr(,)g(and)g(that)208 4588 y Fo(i)g Fr(is)i(within)d(bounds.)
0 4735 y Fj(PyObject)400 4750 y(**)548 4735 y Fg(PySequence_Fast_ITEMS)
p Fj(\()p Fo(PyObject)d(*o)p Fj(\))208 4834 y Fr(Return)25
b(the)i(underlying)d(array)h(of)h(PyObject)g(pointers.)43
b(Assumes)26 b(that)h Fo(o)f Fr(w)o(as)i(returned)c(by)i
Fj(PySequence_Fast\(\))208 4934 y Fr(and)19 b Fo(o)h
Fr(is)i(not)d Fj(NULL)p Fr(.)41 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0
5081 y Fj(PyObject)400 5096 y(*)498 5081 y Fg(PySequence_ITEM)p
Fj(\()p Fo(PyObject)e(*o,)i(Py)p 1842 5081 V 30 w(ssize)p
2028 5081 V 31 w(t)h(i)p Fj(\))208 5180 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5280 y Fr(Return)31
b(the)h Fo(i)p Fr(th)g(element)f(of)h Fo(o)g Fr(or)f
Fj(NULL)h Fr(on)f(f)o(ailure.)59 b(Macro)31 b(form)g(of)h
Fj(PySequence_GetItem\(\))c Fr(b)n(ut)k(without)208 5380
y(checking)19 b(that)i Fj(PySequence_Check\()p Fo(o)p
Fj(\))d Fr(is)k(true)f(and)f(without)g(adjustment)g(for)h(ne)o(gati)n
(v)o(e)e(indices.)55 b(Ne)n(w)22 b(in)f(v)o(ersion)p
0 5549 3901 4 v 0 5649 a Fn(6.3.)52 b(Sequence)24 b(Protocol)2917
b(43)p eop end
%%Page: 44 50
TeXDict begin 44 49 bop 208 83 a Fr(2.3.)0 230 y Fj(Py_ssize_t)48
b Fg(PySequence_Fast_GET_SIZE)p Fj(\()p Fo(PyObject)15
b(*o)p Fj(\))208 330 y Fr(Returns)20 b(the)h(length)f(of)g
Fo(o)p Fr(,)h(assuming)f(that)g Fo(o)h Fr(w)o(as)h(returned)d(by)h
Fj(PySequence_Fast\(\))e Fr(and)i(that)h Fo(o)g Fr(is)g(not)g
Fj(NULL)p Fr(.)f(The)208 429 y(size)i(can)g(also)h(be)f(gotten)f(by)h
(calling)f Fj(PySequence_Size\(\))f Fr(on)h Fo(o)p Fr(,)i(b)n(ut)f
Fj(PySequence_Fast_GET_SIZE\(\))c Fr(is)208 529 y(f)o(aster)i(because)f
(it)i(can)f(assume)g Fo(o)h Fr(is)g(a)f(list)i(or)e(tuple.)0
856 y Fl(6.4)121 b(Mapping)34 b(Protocol)0 1075 y Fj(int)49
b Fg(PyMapping_Check)p Fj(\()p Fo(PyObject)17 b(*o)p
Fj(\))208 1175 y Fr(Return)i Fj(1)i Fr(if)f(the)h(object)e(pro)o(vides)
g(mapping)f(protocol,)g(and)i Fj(0)g Fr(otherwise.)25
b(This)20 b(function)f(al)o(w)o(ays)h(succeeds.)0 1321
y Fj(Py_ssize_t)48 b Fg(PyMapping_Length)p Fj(\()p Fo(PyObject)16
b(*o)p Fj(\))208 1421 y Fr(Returns)21 b(the)h(number)e(of)h(k)o(e)o(ys)
g(in)h(object)f Fo(o)h Fr(on)f(success,)i(and)e Fj(-1)h
Fr(on)f(f)o(ailure.)29 b(F)o(or)21 b(objects)g(that)h(do)f(not)h(pro)o
(vide)d(mapping)208 1521 y(protocol,)f(this)i(is)i(equi)n(v)n(alent)c
(to)i(the)h(Python)e(e)o(xpression)f(`)p Fj(len\()p Fo(o)p
Fj(\))p Fr('.)0 1668 y Fj(int)49 b Fg(PyMapping_DelItemString)p
Fj(\()p Fo(PyObject)15 b(*o,)20 b(c)o(har)g(*k)o(e)n(y)p
Fj(\))208 1767 y Fr(Remo)o(v)o(e)j(the)h(mapping)f(for)g(object)h
Fo(k)o(e)n(y)g Fr(from)g(the)g(object)g Fo(o)p Fr(.)37
b(Return)24 b Fj(-1)h Fr(on)f(f)o(ailure.)36 b(This)25
b(is)g(equi)n(v)n(alent)e(to)h(the)h(Python)208 1867
y(statement)20 b(`)p Fj(del)48 b Fo(o)p Fj([)p Fo(k)o(e)n(y)p
Fj(])p Fr('.)0 2014 y Fj(int)h Fg(PyMapping_DelItem)p
Fj(\()p Fo(PyObject)17 b(*o,)i(PyObject)h(*k)o(e)n(y)p
Fj(\))208 2113 y Fr(Remo)o(v)o(e)j(the)h(mapping)f(for)g(object)h
Fo(k)o(e)n(y)g Fr(from)g(the)g(object)g Fo(o)p Fr(.)37
b(Return)24 b Fj(-1)h Fr(on)f(f)o(ailure.)36 b(This)25
b(is)g(equi)n(v)n(alent)e(to)h(the)h(Python)208 2213
y(statement)20 b(`)p Fj(del)48 b Fo(o)p Fj([)p Fo(k)o(e)n(y)p
Fj(])p Fr('.)0 2360 y Fj(int)h Fg(PyMapping_HasKeyString)p
Fj(\()p Fo(PyObject)16 b(*o,)j(c)o(har)h(*k)o(e)n(y)p
Fj(\))208 2459 y Fr(On)25 b(success,)h(return)e Fj(1)i
Fr(if)g(the)f(mapping)e(object)i(has)g(the)g(k)o(e)o(y)g
Fo(k)o(e)n(y)g Fr(and)f Fj(0)i Fr(otherwise.)39 b(This)26
b(is)g(equi)n(v)n(alent)d(to)j(the)f(Python)208 2559
y(e)o(xpression)18 b(`)p Fo(o)p Fj(.has_key\()p Fo(k)o(e)n(y)p
Fj(\))p Fr('.)k(This)e(function)f(al)o(w)o(ays)h(succeeds.)0
2706 y Fj(int)49 b Fg(PyMapping_HasKey)p Fj(\()p Fo(PyObject)17
b(*o,)i(PyObject)h(*k)o(e)n(y)p Fj(\))208 2806 y Fr(Return)25
b Fj(1)h Fr(if)h(the)f(mapping)e(object)h(has)h(the)g(k)o(e)o(y)g
Fo(k)o(e)n(y)g Fr(and)f Fj(0)h Fr(otherwise.)42 b(This)26
b(is)h(equi)n(v)n(alent)d(to)i(the)g(Python)f(e)o(xpression)208
2905 y(`)p Fo(o)p Fj(.has_key\()p Fo(k)o(e)n(y)p Fj(\))p
Fr('.)c(This)g(function)d(al)o(w)o(ays)j(succeeds.)0
3052 y Fj(PyObject)400 3067 y(*)498 3052 y Fg(PyMapping_Keys)p
Fj(\()p Fo(PyObject)c(*o)p Fj(\))208 3152 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3251 y Fr(On)29
b(success,)j(return)d(a)h(list)h(of)e(the)h(k)o(e)o(ys)f(in)h(object)f
Fo(o)p Fr(.)53 b(On)29 b(f)o(ailure,)j(return)c Fj(NULL)p
Fr(.)h(This)h(is)g(equi)n(v)n(alent)e(to)i(the)g(Python)208
3351 y(e)o(xpression)18 b(`)p Fo(o)p Fj(.keys\(\))p Fr('.)0
3498 y Fj(PyObject)400 3513 y(*)498 3498 y Fg(PyMapping_Values)p
Fj(\()p Fo(PyObject)f(*o)p Fj(\))208 3597 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3697 y Fr(On)27
b(success,)h(return)e(a)i(list)g(of)e(the)h(v)n(alues)g(in)g(object)f
Fo(o)p Fr(.)45 b(On)27 b(f)o(ailure,)h(return)e Fj(NULL)p
Fr(.)g(This)i(is)f(equi)n(v)n(alent)f(to)h(the)g(Python)208
3797 y(e)o(xpression)18 b(`)p Fo(o)p Fj(.values\(\))p
Fr('.)0 3944 y Fj(PyObject)400 3959 y(*)498 3944 y Fg(PyMapping_Items)p
Fj(\()p Fo(PyObject)f(*o)p Fj(\))208 4043 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4143 y Fr(On)26
b(success,)i(return)d(a)i(list)h(of)e(the)g(items)h(in)g(object)e
Fo(o)p Fr(,)j(where)e(each)g(item)g(is)i(a)f(tuple)f(containing)e(a)j
(k)o(e)o(y-v)n(alue)d(pair)-5 b(.)44 b(On)208 4242 y(f)o(ailure,)19
b(return)g Fj(NULL)p Fr(.)h(This)g(is)h(equi)n(v)n(alent)e(to)h(the)g
(Python)f(e)o(xpression)g(`)p Fo(o)p Fj(.items\(\))p
Fr('.)0 4389 y Fj(PyObject)400 4404 y(*)498 4389 y Fg
(PyMapping_GetItemString)p Fj(\()p Fo(PyObject)c(*o,)20
b(c)o(har)g(*k)o(e)n(y)p Fj(\))208 4489 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4589 y Fr(Return)k(element)h(of)f
Fo(o)i Fr(corresponding)21 b(to)k(the)g(object)g Fo(k)o(e)n(y)g
Fr(or)g Fj(NULL)g Fr(on)f(f)o(ailure.)39 b(This)25 b(is)h(the)g(equi)n
(v)n(alent)d(of)i(the)g(Python)208 4688 y(e)o(xpression)18
b(`)p Fo(o)p Fj([)p Fo(k)o(e)n(y)p Fj(])p Fr('.)0 4835
y Fj(int)49 b Fg(PyMapping_SetItemString)p Fj(\()p Fo(PyObject)15
b(*o,)20 b(c)o(har)g(*k)o(e)n(y)-5 b(,)19 b(PyObject)h(*v)p
Fj(\))208 4935 y Fr(Map)29 b(the)h(object)f Fo(k)o(e)n(y)h
Fr(to)g(the)g(v)n(alue)f Fo(v)i Fr(in)f(object)f Fo(o)p
Fr(.)54 b(Returns)30 b Fj(-1)g Fr(on)g(f)o(ailure.)53
b(This)30 b(is)h(the)f(equi)n(v)n(alent)e(of)i(the)g(Python)208
5034 y(statement)20 b(`)p Fo(o)p Fj([)p Fo(k)o(e)n(y)p
Fj(])47 b(=)j Fo(v)p Fr('.)p 0 5549 3901 4 v 0 5649 a
Fn(44)2511 b(Chapter)23 b(6.)52 b(Abstr)o(act)23 b(Objects)f(La)n(y)n
(er)p eop end
%%Page: 45 51
TeXDict begin 45 50 bop 0 86 a Fl(6.5)121 b(Iter)o(ator)34
b(Protocol)0 319 y Fr(Ne)n(w)20 b(in)h(v)o(ersion)e(2.2.)0
466 y(There)g(are)h(only)g(a)g(couple)g(of)f(functions)g
(speci\002cally)h(for)g(w)o(orking)e(with)j(iterators.)0
613 y Fj(int)49 b Fg(PyIter_Check)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 713 y Fr(Return)h(true)h(if)h(the)f(object)f
Fo(o)i Fr(supports)e(the)h(iterator)g(protocol.)0 859
y Fj(PyObject)400 874 y(*)498 859 y Fg(PyIter_Next)p
Fj(\()p Fo(PyObject)e(*o)p Fj(\))208 959 y Fo(Return)h(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1059 y Fr(Return)28
b(the)g(ne)o(xt)g(v)n(alue)g(from)g(the)g(iteration)g
Fo(o)p Fr(.)50 b(If)29 b(the)f(object)g(is)i(an)e(iterator)m(,)i(this)f
(retrie)n(v)o(es)f(the)g(ne)o(xt)g(v)n(alue)g(from)g(the)208
1158 y(iteration,)18 b(and)h(returns)g Fj(NULL)g Fr(with)h(no)f(e)o
(xception)e(set)j(if)g(there)f(are)g(no)g(remaining)f(items.)25
b(If)20 b(the)f(object)g(is)h(not)f(an)h(iterator)m(,)208
1258 y Fj(TypeError)c Fr(is)i(raised,)g(or)f(if)h(there)f(is)h(an)g
(error)e(in)i(retrie)n(ving)d(the)j(item,)g(returns)e
Fj(NULL)i Fr(and)f(passes)h(along)e(the)i(e)o(xception.)0
1405 y(T)-7 b(o)20 b(write)h(a)f(loop)g(which)f(iterates)i(o)o(v)o(er)e
(an)h(iterator)m(,)f(the)h(C)h(code)f(should)f(look)g(something)g(lik)o
(e)h(this:)236 1643 y Fk(PyObject)640 1656 y(*)685 1643
y(iterator)43 b(=)i(PyObject_GetIter\(obj\);)236 1734
y(PyObject)640 1747 y(*)685 1734 y(item;)236 1917 y(if)g(\(iterator)e
(==)i(NULL\))f({)416 2008 y(/)461 2021 y(*)550 2008 y(propagate)f
(error)1267 2021 y(*)1312 2008 y(/)236 2100 y(})236 2282
y(while)h(\(item)g(=)h(PyIter_Next\(iterator\)\))c({)416
2374 y(/)461 2387 y(*)550 2374 y(do)k(something)e(with)h(item)1581
2387 y(*)1626 2374 y(/)416 2465 y(...)416 2556 y(/)461
2569 y(*)550 2556 y(release)g(reference)f(when)h(done)1805
2569 y(*)1850 2556 y(/)416 2648 y(Py_DECREF\(item\);)236
2739 y(})236 2922 y(Py_DECREF\(iterator\);)236 3104 y(if)h
(\(PyErr_Occurred\(\)\))d({)416 3195 y(/)461 3208 y(*)550
3195 y(propagate)h(error)1267 3208 y(*)1312 3195 y(/)236
3287 y(})236 3378 y(else)h({)416 3469 y(/)461 3482 y(*)550
3469 y(continue)g(doing)g(useful)f(work)1761 3482 y(*)1806
3469 y(/)236 3561 y(})0 4009 y Fl(6.6)121 b(Buff)l(er)34
b(Protocol)0 4228 y Fj(int)49 b Fg(PyObject_AsCharBuffer)p
Fj(\()p Fo(PyObject)16 b(*obj,)j(const)h(c)o(har)g(**b)n(uf)o(fer)-9
b(,)18 b(Py)p 2585 4228 25 4 v 30 w(ssize)p 2771 4228
V 30 w(t)j(*b)n(uf)o(fer)p 3083 4228 V 29 w(len)p Fj(\))208
4327 y Fr(Returns)26 b(a)i(pointer)e(to)h(a)g(read-only)e(memory)h
(location)g(useable)g(as)i(character)n(-)e(based)h(input.)44
b(The)27 b Fo(obj)g Fr(ar)o(gument)e(must)208 4427 y(support)19
b(the)h(single-se)o(gment)f(character)g(b)n(uf)n(fer)g(interf)o(ace.)26
b(On)20 b(success,)h(returns)f Fj(0)p Fr(,)h(sets)g Fo(b)n(uf)o(fer)h
Fr(to)f(the)g(memory)e(location)208 4526 y(and)g Fo(b)n(uf)o(fer)p
549 4526 V 29 w(len)h Fr(to)h(the)f(b)n(uf)n(fer)f(length.)24
b(Returns)c Fj(-1)g Fr(and)g(sets)h(a)g Fj(TypeError)e
Fr(on)h(error)-5 b(.)50 b(Ne)n(w)20 b(in)g(v)o(ersion)f(1.6.)0
4673 y Fj(int)49 b Fg(PyObject_AsReadBuffer)p Fj(\()p
Fo(PyObject)16 b(*obj,)j(const)h(void)g(**b)n(uf)o(fer)-9
b(,)18 b(Py)p 2577 4673 V 30 w(ssize)p 2763 4673 V 30
w(t)j(*b)n(uf)o(fer)p 3075 4673 V 29 w(len)p Fj(\))208
4773 y Fr(Returns)27 b(a)h(pointer)f(to)h(a)g(read-only)d(memory)h
(location)h(containing)f(arbitrary)g(data.)48 b(The)27
b Fo(obj)h Fr(ar)o(gument)d(must)j(support)208 4873 y(the)h(single-se)o
(gment)e(readable)h(b)n(uf)n(fer)g(interf)o(ace.)51 b(On)30
b(success,)h(returns)e Fj(0)p Fr(,)i(sets)g Fo(b)n(uf)o(fer)g
Fr(to)e(the)g(memory)f(location)g(and)208 4972 y Fo(b)n(uf)o(fer)p
409 4972 V 29 w(len)20 b Fr(to)g(the)g(b)n(uf)n(fer)f(length.)24
b(Returns)c Fj(-1)h Fr(and)e(sets)j(a)e Fj(TypeError)f
Fr(on)h(error)-5 b(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(1.6.)0
5119 y Fj(int)49 b Fg(PyObject_CheckReadBuffer)p Fj(\()p
Fo(PyObject)15 b(*o)p Fj(\))208 5219 y Fr(Returns)20
b Fj(1)g Fr(if)h Fo(o)f Fr(supports)f(the)h(single-se)o(gment)e
(readable)h(b)n(uf)n(fer)g(interf)o(ace.)24 b(Otherwise)c(returns)g
Fj(0)p Fr(.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)0
5366 y Fj(int)49 b Fg(PyObject_AsWriteBuffer)p Fj(\()p
Fo(PyObject)16 b(*obj,)j(void)g(**b)n(uf)o(fer)-9 b(,)19
b(Py)p 2431 5366 V 29 w(ssize)p 2616 5366 V 31 w(t)i(*b)n(uf)o(fer)p
2929 5366 V 29 w(len)p Fj(\))p 0 5549 3901 4 v 0 5649
a Fn(6.5.)52 b(Iter)o(ator)23 b(Protocol)3029 b(45)p
eop end
%%Page: 46 52
TeXDict begin 46 51 bop 208 83 a Fr(Returns)19 b(a)g(pointer)f(to)h(a)h
(writeable)e(memory)g(location.)23 b(The)c Fo(obj)g Fr(ar)o(gument)e
(must)i(support)f(the)h(single-se)o(gment,)e(character)208
183 y(b)n(uf)n(fer)23 b(interf)o(ace.)36 b(On)24 b(success,)i(returns)e
Fj(0)p Fr(,)h(sets)h Fo(b)n(uf)o(fer)g Fr(to)e(the)h(memory)d(location)
i(and)f Fo(b)n(uf)o(fer)p 3081 183 25 4 v 29 w(len)i
Fr(to)f(the)h(b)n(uf)n(fer)e(length.)208 282 y(Returns)d
Fj(-1)g Fr(and)g(sets)h(a)g Fj(TypeError)e Fr(on)g(error)-5
b(.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(1.6.)p 0 5549
3901 4 v 0 5649 a Fn(46)2511 b(Chapter)23 b(6.)52 b(Abstr)o(act)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 47 53
TeXDict begin 47 52 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3495
427 y Fm(SEVEN)p 0 515 V 1683 978 a Fx(Concrete)58 b(Objects)f(La)-6
b(y)l(er)0 1466 y Fr(The)22 b(functions)f(in)i(this)g(chapter)f(are)g
(speci\002c)h(to)g(certain)f(Python)f(object)h(types.)32
b(P)o(assing)23 b(them)f(an)g(object)g(of)h(the)f(wrong)g(type)g(is)0
1566 y(not)i(a)h(good)e(idea;)k(if)d(you)g(recei)n(v)o(e)f(an)i(object)
f(from)f(a)i(Python)e(program)g(and)g(you)h(are)g(not)h(sure)f(that)g
(it)i(has)e(the)h(right)f(type,)g(you)0 1665 y(must)h(perform)e(a)j
(type)e(check)h(\002rst;)j(for)c(e)o(xample,)h(to)g(check)g(that)g(an)g
(object)f(is)j(a)e(dictionary)-5 b(,)24 b(use)h Fj(PyDict_Check\(\))p
Fr(.)38 b(The)0 1765 y(chapter)19 b(is)i(structured)e(lik)o(e)h(the)h
(\223f)o(amily)e(tree\224)h(of)g(Python)f(object)h(types.)0
1912 y Fp(W)-5 b(ar)o(ning:)32 b Fr(While)24 b(the)g(functions)f
(described)f(in)i(this)h(chapter)e(carefully)f(check)i(the)g(type)f(of)
h(the)g(objects)f(which)h(are)g(passed)g(in,)0 2012 y(man)o(y)17
b(of)i(them)f(do)g(not)h(check)e(for)h Fj(NULL)h Fr(being)f(passed)g
(instead)h(of)f(a)h(v)n(alid)f(object.)24 b(Allo)n(wing)18
b Fj(NULL)g Fr(to)h(be)g(passed)f(in)h(can)g(cause)0
2111 y(memory)f(access)j(violations)f(and)f(immediate)g(termination)g
(of)h(the)g(interpreter)-5 b(.)0 2439 y Fl(7.1)121 b(Fundamental)36
b(Objects)0 2671 y Fr(This)20 b(section)g(describes)g(Python)f(type)h
(objects)g(and)f(the)i(singleton)e(object)g Fj(None)p
Fr(.)0 2956 y Fh(7.1.1)100 b(T)-12 b(ype)28 b(Objects)0
3159 y Fg(PyTypeObject)208 3259 y Fr(The)19 b(C)j(structure)d(of)h(the)
g(objects)g(used)g(to)g(describe)g(b)n(uilt-in)f(types.)0
3406 y Fj(PyObject)400 3421 y(*)498 3406 y Fg(PyType_Type)208
3505 y Fr(This)24 b(is)i(the)f(type)f(object)g(for)g(type)g(objects;)j
(it)e(is)g(the)g(same)g(object)f(as)h Fj(type)g Fr(and)f
Fj(types.TypeType)e Fr(in)j(the)g(Python)208 3605 y(layer)-5
b(.)0 3752 y Fj(int)49 b Fg(PyType_Check)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 3851 y Fr(Return)23 b(true)g(if)h(the)g(object)f
Fo(o)h Fr(is)h(a)f(type)f(object,)h(including)e(instances)i(of)f(types)
h(deri)n(v)o(ed)e(from)h(the)g(standard)g(type)g(object.)208
3951 y(Return)c(f)o(alse)i(in)f(all)h(other)e(cases.)0
4098 y Fj(int)49 b Fg(PyType_CheckExact)p Fj(\()p Fo(PyObject)17
b(*o)p Fj(\))208 4198 y Fr(Return)h(true)h(if)g(the)g(object)g
Fo(o)g Fr(is)h(a)g(type)e(object,)h(b)n(ut)g(not)g(a)g(subtype)f(of)h
(the)g(standard)f(type)g(object.)24 b(Return)19 b(f)o(alse)h(in)f(all)g
(other)208 4297 y(cases.)51 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.2.)0
4444 y Fj(int)49 b Fg(PyType_HasFeature)p Fj(\()p Fo(PyObject)17
b(*o,)i(int)i(featur)m(e)p Fj(\))208 4544 y Fr(Return)e(true)h(if)h
(the)f(type)g(object)f Fo(o)h Fr(sets)i(the)e(feature)f
Fo(featur)m(e)p Fr(.)25 b(T)-7 b(ype)20 b(features)f(are)h(denoted)f
(by)h(single)g(bit)g(\003ags.)0 4691 y Fj(int)49 b Fg(PyType_IS_GC)p
Fj(\()p Fo(PyObject)18 b(*o)p Fj(\))208 4790 y Fr(Return)23
b(true)g(if)i(the)e(type)h(object)f(includes)g(support)g(for)g(the)h(c)
o(ycle)f(detector;)i(this)f(tests)h(the)f(type)f(\003ag)h
Fj(Py_TPFLAGS_-)208 4890 y(HAVE_GC)p Fr(.)40 b(Ne)n(w)20
b(in)g(v)o(ersion)f(2.0.)0 5037 y Fj(int)49 b Fg(PyType_IsSubtype)p
Fj(\()p Fo(PyT)-6 b(ypeObject)16 b(*a,)k(PyT)-6 b(ypeObject)18
b(*b)p Fj(\))208 5136 y Fr(Return)h(true)h(if)h Fo(a)f
Fr(is)h(a)g(subtype)e(of)h Fo(b)p Fr(.)50 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.2.)0 5283 y Fj(PyObject)400 5298
y(*)498 5283 y Fg(PyType_GenericAlloc)p Fj(\()p Fo(PyT)-6
b(ypeObject)15 b(*type)o(,)20 b(Py)p 2293 5283 25 4 v
29 w(ssize)p 2478 5283 V 31 w(t)h(nitems)p Fj(\))208
5383 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)p 0 5549 3901 4 v 3808 5649 a Fn(47)p eop end
%%Page: 48 54
TeXDict begin 48 53 bop 208 83 a Fr(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)
0 230 y Fj(PyObject)400 245 y(*)498 230 y Fg(PyType_GenericNew)p
Fj(\()p Fo(PyT)-6 b(ypeObject)16 b(*type)o(,)j(PyObject)h(*ar)m(gs,)f
(PyObject)h(*kwds)p Fj(\))208 330 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 429 y Fr(Ne)n(w)g(in)g(v)o
(ersion)f(2.2.)0 576 y Fj(int)49 b Fg(PyType_Ready)p
Fj(\()p Fo(PyT)-6 b(ypeObject)17 b(*type)p Fj(\))208
676 y Fr(Finalize)26 b(a)g(type)f(object.)42 b(This)26
b(should)f(be)h(called)g(on)f(all)i(type)e(objects)h(to)g(\002nish)g
(their)g(initialization.)41 b(This)26 b(function)f(is)208
775 y(responsible)e(for)h(adding)g(inherited)g(slots)h(from)f(a)h
(type')-5 b(s)25 b(base)g(class.)40 b(Return)25 b Fj(0)g
Fr(on)f(success,)j(or)d(return)g Fj(-1)h Fr(and)g(sets)h(an)208
875 y(e)o(xception)18 b(on)i(error)-5 b(.)50 b(Ne)n(w)20
b(in)g(v)o(ersion)f(2.2.)0 1160 y Fh(7.1.2)100 b(The)29
b(None)f(Object)0 1363 y Fr(Note)f(that)g(the)g Fj(PyTypeObject)f
Fr(for)g Fj(None)h Fr(is)h(not)f(directly)f(e)o(xposed)f(in)j(the)f
(Python/C)f(API.)h(Since)g Fj(None)g Fr(is)h(a)g(singleton,)0
1462 y(testing)j(for)f(object)g(identity)g(\(using)g(`)p
Fj(==)p Fr(')g(in)h(C\))g(is)g(suf)n(\002cient.)56 b(There)30
b(is)i(no)e Fj(PyNone_Check\(\))f Fr(function)g(for)h(the)g(same)0
1562 y(reason.)0 1709 y Fj(PyObject)400 1724 y(*)498
1709 y Fg(Py_None)208 1808 y Fr(The)18 b(Python)f Fj(None)h
Fr(object,)g(denoting)e(lack)j(of)f(v)n(alue.)23 b(This)c(object)f(has)
g(no)g(methods.)24 b(It)18 b(needs)g(to)h(be)f(treated)g(just)h(lik)o
(e)f(an)o(y)208 1908 y(other)h(object)h(with)g(respect)g(to)g
(reference)f(counts.)0 2055 y Fg(Py_RETURN_NONE)208 2155
y Fr(Properly)f(handle)h(returning)f Fj(Py_None)i Fr(from)f(within)h(a)
h(C)g(function.)49 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0
2482 y Fl(7.2)121 b(Numer)r(ic)33 b(Objects)0 2731 y
Fh(7.2.1)100 b(Plain)29 b(Integer)g(Objects)0 2934 y
Fg(PyIntObject)208 3034 y Fr(This)20 b(subtype)f(of)h
Fj(PyObject)f Fr(represents)g(a)i(Python)e(inte)o(ger)g(object.)0
3181 y Fj(PyTypeObject)48 b Fg(PyInt_Type)208 3280 y
Fr(This)20 b(instance)g(of)g Fj(PyTypeObject)e Fr(represents)h(the)h
(Python)f(plain)h(inte)o(ger)f(type.)25 b(This)20 b(is)h(the)f(same)g
(object)g(as)h Fj(int)f Fr(and)208 3380 y Fj(types.IntType)p
Fr(.)0 3527 y Fj(int)49 b Fg(PyInt_Check)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 3627 y Fr(Return)25 b(true)h(if)g Fo(o)h
Fr(is)g(of)e(type)h Fj(PyInt_Type)f Fr(or)h(a)g(subtype)f(of)h
Fj(PyInt_Type)p Fr(.)85 b(Changed)25 b(in)h(v)o(ersion)f(2.2:)g(Allo)n
(wed)208 3726 y(subtypes)19 b(to)h(be)g(accepted.)0 3873
y Fj(int)49 b Fg(PyInt_CheckExact)p Fj(\()p Fo(PyObject)17
b(*o)p Fj(\))208 3973 y Fr(Return)i(true)h(if)h Fo(o)f
Fr(is)h(of)f(type)g Fj(PyInt_Type)p Fr(,)e(b)n(ut)i(not)g(a)h(subtype)e
(of)h Fj(PyInt_Type)p Fr(.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
4120 y Fj(PyObject)400 4135 y(*)498 4120 y Fg(PyInt_FromString)p
Fj(\()p Fo(c)o(har)e(*str)-9 b(,)20 b(c)o(har)g(**pend,)e(int)i(base)p
Fj(\))208 4219 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4319 y Fr(Return)d(a)h(ne)n(w)g Fj(PyIntObject)f
Fr(or)g Fj(PyLongObject)f Fr(based)i(on)g(the)f(string)h(v)n(alue)f(in)
h Fo(str)r Fr(,)i(which)d(is)i(interpreted)d(accord-)208
4418 y(ing)24 b(to)h(the)g(radix)f(in)h Fo(base)p Fr(.)38
b(If)25 b Fo(pend)h Fr(is)g(non-)p Fj(NULL)p Fr(,)1802
4433 y Fj(*)1852 4418 y Fo(pend)g Fr(will)g(point)e(to)h(the)g(\002rst)
g(character)f(in)h Fo(str)j Fr(which)c(follo)n(ws)h(the)208
4518 y(representation)20 b(of)j(the)g(number)-5 b(.)32
b(If)23 b Fo(base)g Fr(is)h Fj(0)p Fr(,)f(the)g(radix)g(will)g(be)g
(determined)e(based)i(on)g(the)g(leading)f(characters)g(of)g
Fo(str)r Fr(:)208 4618 y(if)i Fo(str)k Fr(starts)d(with)f
Fj('0x')h Fr(or)f Fj('0X')p Fr(,)g(radix)f(16)h(will)h(be)f(used;)j(if)
d Fo(str)k Fr(starts)d(with)f Fj('0')p Fr(,)i(radix)d(8)i(will)g(be)f
(used;)i(otherwise)208 4717 y(radix)e(10)i(will)g(be)f(used.)41
b(If)26 b Fo(base)f Fr(is)i(not)e Fj(0)p Fr(,)i(it)g(must)e(be)h
(between)f Fj(2)h Fr(and)f Fj(36)p Fr(,)i(inclusi)n(v)o(e.)40
b(Leading)24 b(spaces)i(are)g(ignored.)208 4817 y(If)c(there)g(are)g
(no)g(digits,)h Fj(ValueError)e Fr(will)j(be)e(raised.)32
b(If)22 b(the)g(string)g(represents)g(a)h(number)e(too)h(lar)o(ge)f(to)
i(be)f(contained)208 4917 y(within)c(the)h(machine')-5
b(s)18 b Fj(long)50 b(int)18 b Fr(type)h(and)f(o)o(v)o(er\003o)n(w)f(w)
o(arnings)i(are)f(being)g(suppressed,)g(a)i Fj(PyLongObject)d
Fr(will)j(be)208 5016 y(returned.)j(If)d(o)o(v)o(er\003o)n(w)e(w)o
(arnings)h(are)h(not)g(being)g(suppressed,)e Fj(NULL)i
Fr(will)h(be)f(returned)f(in)h(this)h(case.)0 5163 y
Fj(PyObject)400 5178 y(*)498 5163 y Fg(PyInt_FromLong)p
Fj(\()p Fo(long)c(ival)p Fj(\))208 5263 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5362 y Fr(Create)g(a)h(ne)n(w)f
(inte)o(ger)f(object)g(with)i(a)f(v)n(alue)g(of)g Fo(ival)p
Fr(.)p 0 5549 3901 4 v 0 5649 a Fn(48)2478 b(Chapter)23
b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 49 55
TeXDict begin 49 54 bop 208 83 a Fr(The)24 b(current)f(implementation)f
(k)o(eeps)i(an)g(array)f(of)h(inte)o(ger)g(objects)g(for)f(all)i(inte)o
(gers)f(between)f Fj(-5)i Fr(and)f Fj(256)p Fr(,)h(when)e(you)208
183 y(create)e(an)i(int)f(in)g(that)h(range)e(you)g(actually)h(just)g
(get)g(back)g(a)h(reference)d(to)i(the)h(e)o(xisting)e(object.)30
b(So)23 b(it)g(should)e(be)h(possible)208 282 y(to)e(change)f(the)h(v)n
(alue)f(of)h Fj(1)p Fr(.)26 b(I)20 b(suspect)g(the)g(beha)n(viour)f(of)
g(Python)h(in)g(this)h(case)f(is)h(unde\002ned.)i(:-\))0
429 y Fj(PyObject)400 444 y(*)498 429 y Fg(PyInt_FromSsize_t)p
Fj(\()p Fo(Py)p 1491 429 25 4 v 26 w(ssize)p 1673 429
V 31 w(t)e(ival)p Fj(\))208 529 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 628 y Fr(Create)30
b(a)g(ne)n(w)g(inte)o(ger)f(object)h(with)g(a)g(v)n(alue)g(of)f
Fo(ival)p Fr(.)55 b(If)30 b(the)g(v)n(alue)f(e)o(xceeds)h
Fj(LONG_MAX)p Fr(,)e(a)j(long)e(inte)o(ger)g(object)h(is)208
728 y(returned.)208 861 y(Ne)n(w)20 b(in)g(v)o(ersion)f(2.5.)0
1008 y Fj(long)49 b Fg(PyInt_AsLong)p Fj(\()p Fo(PyObject)17
b(*io)p Fj(\))208 1107 y Fr(W)m(ill)26 b(\002rst)g(attempt)f(to)h(cast)
g(the)f(object)g(to)h(a)g Fj(PyIntObject)p Fr(,)f(if)h(it)g(is)g(not)g
(already)e(one,)i(and)f(then)g(return)f(its)j(v)n(alue.)40
b(If)208 1207 y(there)23 b(is)h(an)f(error)m(,)g Fj(-1)h
Fr(is)g(returned,)e(and)h(the)h(caller)f(should)g(check)f
Fj(PyErr_Occurred\(\))g Fr(to)h(\002nd)g(out)h(whether)e(there)208
1307 y(w)o(as)f(an)f(error)m(,)e(or)i(whether)f(the)h(v)n(alue)g(just)h
(happened)d(to)i(be)g(-1.)0 1453 y Fj(long)49 b Fg(PyInt_AS_LONG)p
Fj(\()p Fo(PyObject)17 b(*io)p Fj(\))208 1553 y Fr(Return)i(the)i(v)n
(alue)e(of)h(the)g(object)g Fo(io)p Fr(.)25 b(No)20 b(error)f(checking)
g(is)i(performed.)0 1700 y Fj(unsigned)48 b(long)h Fg
(PyInt_AsUnsignedLongMask)p Fj(\()p Fo(PyObject)15 b(*io)p
Fj(\))208 1800 y Fr(W)m(ill)22 b(\002rst)h(attempt)f(to)g(cast)g(the)g
(object)g(to)g(a)g Fj(PyIntObject)f Fr(or)g Fj(PyLongObject)p
Fr(,)g(if)h(it)h(is)g(not)e(already)g(one,)h(and)f(then)208
1899 y(return)e(its)i(v)n(alue)e(as)i(unsigned)e(long.)24
b(This)c(function)f(does)h(not)f(check)h(for)f(o)o(v)o(er\003o)n(w)-5
b(.)49 b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.3.)0 2046 y
Fj(unsigned)48 b(PY_LONG_LONG)g Fg(PyInt_AsUnsignedLongLongMask)p
Fj(\()p Fo(PyObje)o(ct)15 b(*io)p Fj(\))208 2146 y Fr(W)m(ill)22
b(\002rst)h(attempt)f(to)g(cast)g(the)g(object)g(to)g(a)g
Fj(PyIntObject)f Fr(or)g Fj(PyLongObject)p Fr(,)g(if)h(it)h(is)g(not)e
(already)g(one,)h(and)f(then)208 2245 y(return)e(its)i(v)n(alue)e(as)i
(unsigned)e(long)g(long,)g(without)h(checking)e(for)i(o)o(v)o(er\003o)n
(w)-5 b(.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.3.)0 2392
y Fj(Py_ssize_t)48 b Fg(PyInt_AsSsize_t)p Fj(\()p Fo(PyObject)17
b(*io)p Fj(\))208 2492 y Fr(W)m(ill)22 b(\002rst)h(attempt)f(to)g(cast)
g(the)g(object)g(to)g(a)g Fj(PyIntObject)f Fr(or)g Fj(PyLongObject)p
Fr(,)g(if)h(it)h(is)g(not)e(already)g(one,)h(and)f(then)208
2591 y(return)e(its)i(v)n(alue)e(as)i Fj(Py_ssize_t)p
Fr(.)50 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.5.)0 2738 y
Fj(long)49 b Fg(PyInt_GetMax)p Fj(\(\))208 2838 y Fr(Return)19
b(the)h(system')-5 b(s)21 b(idea)f(of)g(the)g(lar)o(gest)g(inte)o(ger)f
(it)i(can)f(handle)f(\()p Fj(LONG_MAX)p Fr(,)f(as)j(de\002ned)e(in)i
(the)f(system)g(header)f(\002les\).)0 3123 y Fh(7.2.2)100
b(Boolean)30 b(Objects)0 3326 y Fr(Booleans)23 b(in)h(Python)e(are)i
(implemented)d(as)k(a)e(subclass)h(of)g(inte)o(gers.)34
b(There)22 b(are)i(only)f(tw)o(o)g(booleans,)g Fj(Py_False)g
Fr(and)g Fj(Py_-)0 3425 y(True)p Fr(.)61 b(As)33 b(such,)h(the)f
(normal)d(creation)i(and)f(deletion)g(functions)g(don')o(t)g(apply)g
(to)h(booleans.)60 b(The)32 b(follo)n(wing)e(macros)i(are)0
3525 y(a)n(v)n(ailable,)19 b(ho)n(we)n(v)o(er)-5 b(.)0
3672 y Fj(int)49 b Fg(PyBool_Check)p Fj(\()p Fo(PyObject)18
b(*o)p Fj(\))208 3772 y Fr(Return)h(true)h(if)h Fo(o)f
Fr(is)h(of)f(type)g Fj(PyBool_Type)p Fr(.)49 b(Ne)n(w)20
b(in)h(v)o(ersion)e(2.3.)0 3918 y Fj(PyObject)400 3933
y(*)498 3918 y Fg(Py_False)208 4018 y Fr(The)24 b(Python)g
Fj(False)h Fr(object.)39 b(This)25 b(object)g(has)g(no)g(methods.)38
b(It)26 b(needs)e(to)i(be)f(treated)f(just)i(lik)o(e)f(an)o(y)g(other)f
(object)g(with)208 4118 y(respect)19 b(to)i(reference)d(counts.)0
4265 y Fj(PyObject)400 4280 y(*)498 4265 y Fg(Py_True)208
4364 y Fr(The)26 b(Python)h Fj(True)g Fr(object.)45 b(This)28
b(object)e(has)i(no)f(methods.)45 b(It)27 b(needs)g(to)h(be)f(treated)f
(just)i(lik)o(e)g(an)o(y)e(other)h(object)f(with)208
4464 y(respect)19 b(to)i(reference)d(counts.)0 4611 y
Fg(Py_RETURN_FALSE)208 4710 y Fr(Return)h Fj(Py_False)h
Fr(from)f(a)h(function,)f(properly)f(incrementing)f(its)22
b(reference)c(count.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0
4857 y Fg(Py_RETURN_TRUE)208 4957 y Fr(Return)g Fj(Py_True)h
Fr(from)f(a)i(function,)d(properly)g(incrementing)g(its)j(reference)d
(count.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0 5104
y Fj(PyObject)400 5119 y(*)498 5104 y Fg(PyBool_FromLong)p
Fj(\()p Fo(long)e(v)p Fj(\))208 5203 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5303 y Fr(Return)f(a)i(ne)n(w)f
(reference)e(to)j Fj(Py_True)e Fr(or)h Fj(Py_False)f
Fr(depending)f(on)i(the)g(truth)g(v)n(alue)f(of)h Fo(v)p
Fr(.)51 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.3.)p 0 5549
3901 4 v 0 5649 a Fn(7.2.)52 b(Numer)q(ic)23 b(Objects)3003
b(49)p eop end
%%Page: 50 56
TeXDict begin 50 55 bop 0 83 a Fh(7.2.3)100 b(Long)29
b(Integer)g(Objects)0 286 y Fg(PyLongObject)208 386 y
Fr(This)20 b(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i(Python)e
(long)g(inte)o(ger)h(object.)0 532 y Fj(PyTypeObject)48
b Fg(PyLong_Type)208 632 y Fr(This)18 b(instance)g(of)g
Fj(PyTypeObject)e Fr(represents)i(the)g(Python)f(long)g(inte)o(ger)g
(type.)24 b(This)19 b(is)g(the)f(same)g(object)g(as)h
Fj(long)f Fr(and)208 732 y Fj(types.LongType)p Fr(.)0
879 y Fj(int)49 b Fg(PyLong_Check)p Fj(\()p Fo(PyObject)18
b(*p)p Fj(\))208 978 y Fr(Return)k(true)h(if)g(its)i(ar)o(gument)20
b(is)k(a)g Fj(PyLongObject)d Fr(or)i(a)h(subtype)e(of)h
Fj(PyLongObject)p Fr(.)66 b(Changed)22 b(in)h(v)o(ersion)f(2.2:)208
1078 y(Allo)n(wed)d(subtypes)g(to)i(be)f(accepted.)0
1225 y Fj(int)49 b Fg(PyLong_CheckExact)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 1324 y Fr(Return)i(true)h(if)h(its)g(ar)o(gument)d(is)
j(a)f Fj(PyLongObject)p Fr(,)f(b)n(ut)h(not)g(a)g(subtype)f(of)h
Fj(PyLongObject)p Fr(.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
1471 y Fj(PyObject)400 1486 y(*)498 1471 y Fg(PyLong_FromLong)p
Fj(\()p Fo(long)e(v)p Fj(\))208 1571 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1670 y Fr(Return)f(a)i(ne)n(w)f
Fj(PyLongObject)e Fr(object)i(from)f Fo(v)p Fr(,)i(or)f
Fj(NULL)g Fr(on)f(f)o(ailure.)0 1817 y Fj(PyObject)400
1832 y(*)498 1817 y Fg(PyLong_FromUnsignedLong)p Fj(\()p
Fo(unsigned)14 b(long)20 b(v)p Fj(\))208 1917 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2017 y Fr(Return)f(a)i(ne)n(w)f
Fj(PyLongObject)e Fr(object)i(from)f(a)i(C)g Fj(unsigned)48
b(long)p Fr(,)20 b(or)g Fj(NULL)g Fr(on)g(f)o(ailure.)0
2163 y Fj(PyObject)400 2178 y(*)498 2163 y Fg(PyLong_FromLongLong)p
Fj(\()p Fo(PY)p 1600 2163 25 4 v 26 w(LONG)p 1847 2163
V 30 w(LONG)i(v)p Fj(\))208 2263 y Fo(Return)d(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2363 y Fr(Return)f(a)i(ne)n(w)f
Fj(PyLongObject)e Fr(object)i(from)f(a)i(C)g Fj(long)49
b(long)p Fr(,)20 b(or)g Fj(NULL)g Fr(on)g(f)o(ailure.)0
2510 y Fj(PyObject)400 2525 y(*)498 2510 y Fg
(PyLong_FromUnsignedLongLong)p Fj(\()p Fo(unsign)o(ed)14
b(PY)p 2315 2510 V 30 w(LONG)p 2566 2510 V 31 w(LONG)21
b(v)p Fj(\))208 2609 y Fo(Return)e(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 2709 y Fr(Return)f(a)i(ne)n(w)f
Fj(PyLongObject)e Fr(object)i(from)f(a)i(C)g Fj(unsigned)48
b(long)h(long)p Fr(,)20 b(or)g Fj(NULL)g Fr(on)g(f)o(ailure.)0
2856 y Fj(PyObject)400 2871 y(*)498 2856 y Fg(PyLong_FromDouble)p
Fj(\()p Fo(double)c(v)p Fj(\))208 2955 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3055 y Fr(Return)f(a)i(ne)n(w)f
Fj(PyLongObject)e Fr(object)i(from)f(the)h(inte)o(ger)f(part)h(of)g
Fo(v)p Fr(,)h(or)f Fj(NULL)g Fr(on)f(f)o(ailure.)0 3202
y Fj(PyObject)400 3217 y(*)498 3202 y Fg(PyLong_FromString)p
Fj(\()p Fo(c)o(har)d(*str)-9 b(,)21 b(c)o(har)f(**pend,)e(int)i(base)p
Fj(\))208 3301 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3401 y Fr(Return)j(a)h(ne)n(w)f Fj(PyLongObject)f
Fr(based)h(on)g(the)g(string)g(v)n(alue)g(in)h Fo(str)r
Fr(,)h(which)e(is)h(interpreted)e(according)g(to)h(the)h(radix)e(in)208
3501 y Fo(base)p Fr(.)k(If)21 b Fo(pend)h Fr(is)g(non-)p
Fj(NULL)p Fr(,)1141 3516 y Fj(*)1191 3501 y Fo(pend)f
Fr(will)h(point)e(to)h(the)g(\002rst)h(character)d(in)i
Fo(str)j Fr(which)d(follo)n(ws)f(the)h(representation)e(of)i(the)208
3600 y(number)-5 b(.)23 b(If)d Fo(base)f Fr(is)i Fj(0)p
Fr(,)f(the)g(radix)e(will)j(be)f(determined)e(based)h(on)g(the)h
(leading)f(characters)g(of)g Fo(str)r Fr(:)26 b(if)20
b Fo(str)j Fr(starts)e(with)f Fj('0x')208 3700 y Fr(or)25
b Fj('0X')p Fr(,)g(radix)g(16)g(will)h(be)g(used;)i(if)e
Fo(str)i Fr(starts)f(with)e Fj('0')p Fr(,)i(radix)e(8)h(will)g(be)f
(used;)j(otherwise)d(radix)g(10)g(will)i(be)e(used.)208
3800 y(If)h Fo(base)g Fr(is)i(not)e Fj(0)p Fr(,)i(it)f(must)g(be)f
(between)g Fj(2)h Fr(and)f Fj(36)p Fr(,)i(inclusi)n(v)o(e.)43
b(Leading)25 b(spaces)i(are)g(ignored.)42 b(If)26 b(there)g(are)h(no)f
(digits,)208 3899 y Fj(ValueError)18 b Fr(will)j(be)g(raised.)0
4046 y Fj(PyObject)400 4061 y(*)498 4046 y Fg(PyLong_FromUnicode)p
Fj(\()p Fo(Py)p 1541 4046 V 26 w(UNICODE)g(*u,)e(Py)p
2169 4046 V 30 w(ssize)p 2355 4046 V 30 w(t)i(length,)e(int)i(base)p
Fj(\))208 4146 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4245 y Fr(Con)m(v)o(ert)i(a)i(sequence)e(of)i(Unicode)e
(digits)i(to)g(a)g(Python)e(long)h(inte)o(ger)f(v)n(alue.)35
b(The)23 b(\002rst)i(parameter)m(,)d Fo(u)p Fr(,)i(points)f(to)h(the)g
(\002rst)208 4345 y(character)19 b(of)i(the)g(Unicode)f(string,)g
Fo(length)g Fr(gi)n(v)o(es)h(the)g(number)e(of)h(characters,)g(and)h
Fo(base)f Fr(is)i(the)f(radix)f(for)h(the)g(con)m(v)o(ersion.)208
4445 y(The)e(radix)h(must)g(be)g(in)g(the)h(range)e([2,)g(36];)h(if)g
(it)h(is)h(out)d(of)h(range,)f Fj(ValueError)g Fr(will)i(be)f(raised.)
51 b(Ne)n(w)20 b(in)g(v)o(ersion)f(1.6.)0 4591 y Fj(PyObject)400
4606 y(*)498 4591 y Fg(PyLong_FromVoidPtr)p Fj(\()p Fo(void)d(*p)p
Fj(\))208 4691 y Fo(Return)j(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4791 y Fr(Create)f(a)h(Python)f(inte)o(ger)f(or)h(long)g(inte)
o(ger)f(from)h(the)g(pointer)g Fo(p)p Fr(.)24 b(The)c(pointer)e(v)n
(alue)h(can)g(be)h(retrie)n(v)o(ed)d(from)i(the)g(resulting)208
4890 y(v)n(alue)g(using)h Fj(PyLong_AsVoidPtr\(\))p Fr(.)49
b(Ne)n(w)21 b(in)g(v)o(ersion)e(1.5.2.)77 b(Changed)19
b(in)i(v)o(ersion)e(2.5:)h(If)g(the)g(inte)o(ger)g(is)h(lar)o(ger)208
4990 y(than)e(LONG)p 607 4990 V 30 w(MAX,)h(a)h(positi)n(v)o(e)e(long)g
(inte)o(ger)g(is)i(returned.)0 5137 y Fj(long)49 b Fg(PyLong_AsLong)p
Fj(\()p Fo(PyObject)17 b(*pylong)p Fj(\))208 5236 y Fr(Return)41
b(a)i(C)g Fj(long)f Fr(representation)e(of)i(the)g(contents)g(of)g
Fo(pylong)p Fr(.)90 b(If)42 b Fo(pylong)e Fr(is)k(greater)d(than)h
Fj(LONG_MAX)p Fr(,)f(an)208 5336 y Fj(OverflowError)18
b Fr(is)j(raised.)p 0 5549 3901 4 v 0 5649 a Fn(50)2478
b(Chapter)23 b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p
eop end
%%Page: 51 57
TeXDict begin 51 56 bop 0 83 a Fj(unsigned)48 b(long)h
Fg(PyLong_AsUnsignedLong)p Fj(\()p Fo(PyObject)16 b(*pylong)p
Fj(\))208 183 y Fr(Return)j(a)i(C)g Fj(unsigned)48 b(long)20
b Fr(representation)e(of)h(the)h(contents)g(of)f Fo(pylong)p
Fr(.)24 b(If)c Fo(pylong)e Fr(is)j(greater)e(than)h Fj(ULONG_MAX)p
Fr(,)208 282 y(an)g Fj(OverflowError)e Fr(is)j(raised.)0
429 y Fj(PY_LONG_LONG)48 b Fg(PyLong_AsLongLong)p Fj(\()p
Fo(PyObject)16 b(*pylong)p Fj(\))208 529 y Fr(Return)26
b(a)h(C)g Fj(long)49 b(long)27 b Fr(from)f(a)h(Python)e(long)h(inte)o
(ger)-5 b(.)44 b(If)26 b Fo(pylong)f Fr(cannot)h(be)g(represented)f(as)
j(a)f Fj(long)49 b(long)p Fr(,)28 b(an)208 628 y Fj(OverflowError)18
b Fr(will)j(be)f(raised.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
775 y Fj(unsigned)48 b(PY_LONG_LONG)g Fg(PyLong_AsUnsignedLongLong)p
Fj(\()p Fo(PyObject)15 b(*pylong)p Fj(\))208 875 y Fr(Return)32
b(a)i(C)g Fj(unsigned)49 b(long)g(long)33 b Fr(from)f(a)i(Python)e
(long)h(inte)o(ger)-5 b(.)63 b(If)34 b Fo(pylong)e Fr(cannot)g(be)h
(represented)f(as)i(an)208 975 y Fj(unsigned)48 b(long)h(long)p
Fr(,)34 b(an)d Fj(OverflowError)f Fr(will)i(be)g(raised)f(if)h(the)g(v)
n(alue)f(is)h(positi)n(v)o(e,)h(or)f(a)g Fj(TypeError)208
1074 y Fr(will)20 b(be)h(raised)f(if)g(the)g(v)n(alue)g(is)h(ne)o(gati)
n(v)o(e.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 1221
y Fj(unsigned)48 b(long)h Fg(PyLong_AsUnsignedLongMask)p
Fj(\()p Fo(PyObject)15 b(*io)p Fj(\))208 1321 y Fr(Return)k(a)h(C)h
Fj(unsigned)48 b(long)20 b Fr(from)e(a)i(Python)f(long)g(inte)o(ger)m
(,)f(without)h(checking)f(for)h(o)o(v)o(er\003o)n(w)-5
b(.)48 b(Ne)n(w)20 b(in)g(v)o(ersion)e(2.3.)0 1468 y
Fj(unsigned)48 b(PY_LONG_LONG)g Fg(PyLong_AsUnsignedLongLongMask)p
Fj(\()p Fo(PyOb)o(ject)15 b(*io)p Fj(\))208 1567 y Fr(Return)27
b(a)i(C)g Fj(unsigned)48 b(long)h(long)28 b Fr(from)f(a)i(Python)e
(long)g(inte)o(ger)m(,)i(without)e(checking)f(for)i(o)o(v)o(er\003o)n
(w)-5 b(.)96 b(Ne)n(w)28 b(in)208 1667 y(v)o(ersion)18
b(2.3.)0 1814 y Fj(double)49 b Fg(PyLong_AsDouble)p Fj(\()p
Fo(PyObject)16 b(*pylong)p Fj(\))208 1913 y Fr(Return)j(a)h(C)h
Fj(double)e Fr(representation)e(of)j(the)f(contents)g(of)h
Fo(pylong)p Fr(.)j(If)d Fo(pylong)e Fr(cannot)g(be)i(approximately)d
(represented)h(as)208 2013 y(a)i Fj(double)p Fr(,)g(an)g
Fj(OverflowError)e Fr(e)o(xception)g(is)j(raised)f(and)g
Fj(-1.0)g Fr(will)h(be)f(returned.)0 2160 y Fj(void)200
2175 y(*)299 2160 y Fg(PyLong_AsVoidPtr)p Fj(\()p Fo(PyObject)c
(*pylong)p Fj(\))208 2259 y Fr(Con)m(v)o(ert)31 b(a)j(Python)e(inte)o
(ger)h(or)g(long)f(inte)o(ger)h Fo(pylong)f Fr(to)h(a)h(C)g
Fj(void)f Fr(pointer)-5 b(.)64 b(If)33 b Fo(pylong)f
Fr(cannot)h(be)g(con)m(v)o(erted,)h(an)208 2359 y Fj(OverflowError)25
b Fr(will)i(be)g(raised.)45 b(This)27 b(is)g(only)f(assured)h(to)g
(produce)e(a)i(usable)f Fj(void)h Fr(pointer)f(for)g(v)n(alues)g
(created)208 2459 y(with)k Fj(PyLong_FromVoidPtr\(\))p
Fr(.)107 b(Ne)n(w)30 b(in)h(v)o(ersion)e(1.5.2.)164 b(Changed)29
b(in)h(v)o(ersion)f(2.5:)h(F)o(or)f(v)n(alues)h(outside)208
2558 y(0..LONG)p 528 2558 25 4 v 28 w(MAX,)20 b(both)g(signed)f(and)h
(unsigned)e(inte)o(gers)i(are)g(acccepted.)0 2843 y Fh(7.2.4)100
b(Floating)29 b(P)-5 b(oint)29 b(Objects)0 3046 y Fg(PyFloatObject)208
3146 y Fr(This)20 b(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i
(Python)e(\003oating)h(point)f(object.)0 3293 y Fj(PyTypeObject)48
b Fg(PyFloat_Type)208 3392 y Fr(This)21 b(instance)f(of)h
Fj(PyTypeObject)e Fr(represents)h(the)g(Python)g(\003oating)g(point)g
(type.)27 b(This)21 b(is)g(the)g(same)g(object)f(as)i
Fj(float)208 3492 y Fr(and)d Fj(types.FloatType)p Fr(.)0
3639 y Fj(int)49 b Fg(PyFloat_Check)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 3738 y Fr(Return)25 b(true)g(if)h(its)h(ar)o(gument)c
(is)k(a)f Fj(PyFloatObject)e Fr(or)h(a)h(subtype)f(of)g
Fj(PyFloatObject)p Fr(.)82 b(Changed)24 b(in)i(v)o(ersion)208
3838 y(2.2:)19 b(Allo)n(wed)h(subtypes)f(to)h(be)h(accepted.)0
3985 y Fj(int)49 b Fg(PyFloat_CheckExact)p Fj(\()p Fo(PyObject)16
b(*p)p Fj(\))208 4084 y Fr(Return)22 b(true)h(if)h(its)g(ar)o(gument)d
(is)k(a)f Fj(PyFloatObject)p Fr(,)e(b)n(ut)h(not)g(a)h(subtype)e(of)h
Fj(PyFloatObject)p Fr(.)68 b(Ne)n(w)23 b(in)h(v)o(ersion)208
4184 y(2.2.)0 4331 y Fj(PyObject)400 4346 y(*)498 4331
y Fg(PyFloat_FromString)p Fj(\()p Fo(PyObject)16 b(*str)-9
b(,)21 b(c)o(har)e(**pend)r Fj(\))208 4431 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4530 y Fr(Create)i(a)h
Fj(PyFloatObject)e Fr(object)h(based)g(on)g(the)g(string)h(v)n(alue)e
(in)i Fo(str)r Fr(,)h(or)e Fj(NULL)g Fr(on)g(f)o(ailure.)32
b(The)22 b Fo(pend)i Fr(ar)o(gument)c(is)208 4630 y(ignored.)j(It)d
(remains)g(only)f(for)h(backw)o(ard)e(compatibility)-5
b(.)0 4777 y Fj(PyObject)400 4792 y(*)498 4777 y Fg(PyFloat_FromDouble)
p Fj(\()p Fo(double)15 b(v)p Fj(\))208 4876 y Fo(Return)k(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4976 y Fr(Create)g(a)h
Fj(PyFloatObject)d Fr(object)i(from)f Fo(v)p Fr(,)h(or)g
Fj(NULL)g Fr(on)g(f)o(ailure.)0 5123 y Fj(double)49 b
Fg(PyFloat_AsDouble)p Fj(\()p Fo(PyObject)16 b(*py\003oat)q
Fj(\))208 5222 y Fr(Return)j(a)i(C)g Fj(double)f Fr(representation)e
(of)i(the)g(contents)f(of)h Fo(py\003oat)q Fr(.)0 5369
y Fj(double)49 b Fg(PyFloat_AS_DOUBLE)p Fj(\()p Fo(PyObject)16
b(*py\003oat)q Fj(\))p 0 5549 3901 4 v 0 5649 a Fn(7.2.)52
b(Numer)q(ic)23 b(Objects)3003 b(51)p eop end
%%Page: 52 58
TeXDict begin 52 57 bop 208 83 a Fr(Return)19 b(a)i(C)g
Fj(double)f Fr(representation)e(of)i(the)g(contents)f(of)h
Fo(py\003oat)q Fr(,)f(b)n(ut)h(without)g(error)f(checking.)0
368 y Fh(7.2.5)100 b(Comple)m(x)29 b(Number)g(Objects)0
571 y Fr(Python')-5 b(s)27 b(comple)o(x)g(number)f(objects)j(are)f
(implemented)e(as)j(tw)o(o)g(distinct)f(types)g(when)g(vie)n(wed)f
(from)g(the)i(C)g(API:)g(one)e(is)j(the)0 670 y(Python)18
b(object)g(e)o(xposed)f(to)i(Python)f(programs,)f(and)h(the)h(other)f
(is)i(a)f(C)h(structure)e(which)g(represents)g(the)h(actual)f(comple)o
(x)f(number)0 770 y(v)n(alue.)24 b(The)c(API)h(pro)o(vides)d(functions)
h(for)g(w)o(orking)g(with)h(both.)0 1038 y Fn(Comple)n(x)j(Numbers)g
(as)g(C)g(Str)q(uctures)0 1241 y Fr(Note)i(that)g(the)g(functions)e
(which)h(accept)h(these)g(structures)f(as)i(parameters)d(and)i(return)e
(them)i(as)g(results)h(do)e(so)h Fo(by)g(value)f Fr(rather)0
1341 y(than)c(dereferencing)d(them)j(through)e(pointers.)24
b(This)c(is)h(consistent)f(throughout)d(the)j(API.)0
1488 y Fg(Py_complex)208 1587 y Fr(The)31 b(C)i(structure)f(which)f
(corresponds)f(to)j(the)f(v)n(alue)f(portion)g(of)h(a)g(Python)f
(comple)o(x)g(number)f(object.)60 b(Most)33 b(of)f(the)208
1687 y(functions)d(for)h(dealing)g(with)h(comple)o(x)d(number)h
(objects)i(use)g(structures)f(of)g(this)i(type)e(as)h(input)f(or)h
(output)e(v)n(alues,)k(as)208 1787 y(appropriate.)22
b(It)f(is)g(de\002ned)e(as:)444 1919 y Fk(typedef)43
b(struct)h({)578 2011 y(double)g(real;)578 2102 y(double)g(imag;)444
2193 y(})g(Py_complex;)0 2397 y Fj(Py_complex)k Fg(_Py_c_sum)p
Fj(\()p Fo(Py)p 1141 2397 25 4 v 28 w(comple)n(x)19 b(left,)i(Py)p
1700 2397 V 29 w(comple)n(x)f(right)q Fj(\))208 2497
y Fr(Return)f(the)i(sum)f(of)g(tw)o(o)g(comple)o(x)e(numbers,)h(using)h
(the)g(C)h Fj(Py_complex)e Fr(representation.)0 2644
y Fj(Py_complex)48 b Fg(_Py_c_diff)p Fj(\()p Fo(Py)p
1191 2644 V 27 w(comple)n(x)20 b(left,)h(Py)p 1750 2644
V 29 w(comple)n(x)f(right)q Fj(\))208 2743 y Fr(Return)f(the)i(dif)n
(ference)d(between)h(tw)o(o)i(comple)o(x)d(numbers,)g(using)i(the)g(C)h
Fj(Py_complex)e Fr(representation.)0 2890 y Fj(Py_complex)48
b Fg(_Py_c_neg)p Fj(\()p Fo(Py)p 1141 2890 V 28 w(comple)n(x)19
b(comple)n(x)p Fj(\))208 2990 y Fr(Return)g(the)i(ne)o(gation)d(of)h
(the)i(comple)o(x)d(number)g Fo(comple)n(x)p Fr(,)i(using)g(the)g(C)h
Fj(Py_complex)e Fr(representation.)0 3137 y Fj(Py_complex)48
b Fg(_Py_c_prod)p Fj(\()p Fo(Py)p 1191 3137 V 27 w(comple)n(x)20
b(left,)h(Py)p 1750 3137 V 29 w(comple)n(x)f(right)q
Fj(\))208 3236 y Fr(Return)f(the)i(product)d(of)i(tw)o(o)g(comple)o(x)f
(numbers,)f(using)i(the)g(C)h Fj(Py_complex)e Fr(representation.)0
3383 y Fj(Py_complex)48 b Fg(_Py_c_quot)p Fj(\()p Fo(Py)p
1191 3383 V 27 w(comple)n(x)20 b(dividend,)f(Py)p 1930
3383 V 29 w(comple)n(x)h(divisor)r Fj(\))208 3483 y Fr(Return)f(the)i
(quotient)d(of)i(tw)o(o)h(comple)o(x)d(numbers,)h(using)g(the)i(C)g
Fj(Py_complex)e Fr(representation.)0 3630 y Fj(Py_complex)48
b Fg(_Py_c_pow)p Fj(\()p Fo(Py)p 1141 3630 V 28 w(comple)n(x)19
b(num,)h(Py)p 1737 3630 V 29 w(comple)n(x)g(e)n(xp)p
Fj(\))208 3729 y Fr(Return)f(the)i(e)o(xponentiation)16
b(of)k Fo(num)g Fr(by)g Fo(e)n(xp)p Fr(,)g(using)g(the)g(C)h
Fj(Py_complex)e Fr(representation.)0 3998 y Fn(Comple)n(x)k(Numbers)g
(as)g(Python)g(Objects)0 4186 y Fg(PyComplexObject)208
4286 y Fr(This)d(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i
(Python)e(comple)o(x)g(number)f(object.)0 4433 y Fj(PyTypeObject)48
b Fg(PyComplex_Type)208 4533 y Fr(This)35 b(instance)h(of)f
Fj(PyTypeObject)f Fr(represents)h(the)h(Python)e(comple)o(x)g(number)g
(type.)71 b(It)36 b(is)h(the)f(same)g(object)f(as)208
4632 y Fj(complex)19 b Fr(and)h Fj(types.ComplexType)p
Fr(.)0 4779 y Fj(int)49 b Fg(PyComplex_Check)p Fj(\()p
Fo(PyObject)17 b(*p)p Fj(\))208 4879 y Fr(Return)28 b(true)h(if)h(its)h
(ar)o(gument)c(is)j(a)g Fj(PyComplexObject)d Fr(or)i(a)h(subtype)e(of)h
Fj(PyComplexObject)p Fr(.)103 b(Changed)28 b(in)208 4978
y(v)o(ersion)18 b(2.2:)i(Allo)n(wed)g(subtypes)f(to)h(be)h(accepted.)0
5125 y Fj(int)49 b Fg(PyComplex_CheckExact)p Fj(\()p
Fo(PyObject)16 b(*p)p Fj(\))208 5225 y Fr(Return)26 b(true)g(if)h(its)h
(ar)o(gument)c(is)k(a)f Fj(PyComplexObject)p Fr(,)f(b)n(ut)h(not)f(a)h
(subtype)f(of)g Fj(PyComplexObject)p Fr(.)87 b(Ne)n(w)27
b(in)208 5324 y(v)o(ersion)18 b(2.2.)p 0 5549 3901 4
v 0 5649 a Fn(52)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 53 59
TeXDict begin 53 58 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyComplex_FromCComplex)p Fj(\()p Fo(Py)p 1741
83 25 4 v 25 w(comple)n(x)20 b(v)p Fj(\))208 183 y Fo(Return)f(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 282 y Fr(Create)g(a)h(ne)n(w)f
(Python)f(comple)o(x)f(number)g(object)i(from)f(a)i(C)g
Fj(Py_complex)e Fr(v)n(alue.)0 429 y Fj(PyObject)400
444 y(*)498 429 y Fg(PyComplex_FromDoubles)p Fj(\()p
Fo(double)c(r)m(eal,)20 b(double)f(ima)o(g)p Fj(\))208
529 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 628 y Fr(Return)f(a)i(ne)n(w)f Fj(PyComplexObject)e
Fr(object)i(from)f Fo(r)m(eal)h Fr(and)g Fo(ima)o(g)p
Fr(.)0 775 y Fj(double)49 b Fg(PyComplex_RealAsDouble)p
Fj(\()p Fo(PyObject)15 b(*op)p Fj(\))208 875 y Fr(Return)k(the)i(real)f
(part)g(of)f Fo(op)h Fr(as)h(a)g(C)g Fj(double)p Fr(.)0
1022 y Fj(double)49 b Fg(PyComplex_ImagAsDouble)p Fj(\()p
Fo(PyObject)15 b(*op)p Fj(\))208 1121 y Fr(Return)k(the)i(imaginary)d
(part)i(of)g Fo(op)f Fr(as)i(a)g(C)g Fj(double)p Fr(.)0
1268 y Fj(Py_complex)48 b Fg(PyComplex_AsCComplex)p Fj(\()p
Fo(PyObject)16 b(*op)p Fj(\))208 1368 y Fr(Return)j(the)i
Fj(Py_complex)d Fr(v)n(alue)i(of)g(the)g(comple)o(x)e(number)h
Fo(op)p Fr(.)0 1695 y Fl(7.3)121 b(Sequence)35 b(Objects)0
1928 y Fr(Generic)26 b(operations)g(on)g(sequence)g(objects)h(were)g
(discussed)f(in)h(the)g(pre)n(vious)f(chapter;)j(this)e(section)g
(deals)g(with)g(the)g(speci\002c)0 2028 y(kinds)20 b(of)g(sequence)f
(objects)h(that)g(are)g(intrinsic)g(to)g(the)g(Python)f(language.)0
2313 y Fh(7.3.1)100 b(Str)q(ing)30 b(Objects)0 2516 y
Fr(These)20 b(functions)f(raise)h Fj(TypeError)f Fr(when)h(e)o
(xpecting)e(a)j(string)f(parameter)e(and)i(are)g(called)g(with)h(a)f
(non-string)e(parameter)-5 b(.)0 2662 y Fg(PyStringObject)208
2762 y Fr(This)20 b(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i
(Python)e(string)h(object.)0 2909 y Fj(PyTypeObject)48
b Fg(PyString_Type)208 3009 y Fr(This)40 b(instance)g(of)g
Fj(PyTypeObject)e Fr(represents)i(the)g(Python)f(string)h(type;)50
b(it)41 b(is)g(the)f(same)g(object)g(as)h Fj(str)f Fr(and)208
3108 y Fj(types.StringType)17 b Fr(in)k(the)f(Python)f(layer)-5
b(.)25 b(.)0 3255 y Fj(int)49 b Fg(PyString_Check)p Fj(\()p
Fo(PyObject)17 b(*o)p Fj(\))208 3355 y Fr(Return)k(true)i(if)f(the)h
(object)e Fo(o)i Fr(is)g(a)g(string)f(object)g(or)g(an)g(instance)g(of)
g(a)h(subtype)e(of)h(the)h(string)f(type.)63 b(Changed)21
b(in)i(v)o(ersion)208 3454 y(2.2:)c(Allo)n(wed)h(subtypes)f(to)h(be)h
(accepted.)0 3601 y Fj(int)49 b Fg(PyString_CheckExact)p
Fj(\()p Fo(PyObject)16 b(*o)p Fj(\))208 3701 y Fr(Return)k(true)g(if)h
(the)g(object)f Fo(o)h Fr(is)h(a)f(string)g(object,)f(b)n(ut)h(not)f
(an)h(instance)f(of)h(a)g(subtype)e(of)i(the)g(string)f(type.)54
b(Ne)n(w)21 b(in)g(v)o(ersion)208 3800 y(2.2.)0 3947
y Fj(PyObject)400 3962 y(*)498 3947 y Fg(PyString_FromString)p
Fj(\()p Fo(const)16 b(c)o(har)k(*v)p Fj(\))208 4047 y
Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208
4147 y Fr(Return)g(a)i(ne)n(w)e(string)h(object)g(with)g(a)g(cop)o(y)f
(of)h(the)g(string)g Fo(v)g Fr(as)h(v)n(alue)e(on)h(success,)h(and)e
Fj(NULL)h Fr(on)g(f)o(ailure.)26 b(The)21 b(parameter)208
4246 y Fo(v)f Fr(must)g(not)g(be)g Fj(NULL)p Fr(;)g(it)h(will)g(not)f
(be)g(check)o(ed.)0 4393 y Fj(PyObject)400 4408 y(*)498
4393 y Fg(PyString_FromStringAndSize)p Fj(\()p Fo(const)15
b(c)o(har)20 b(*v)-6 b(,)20 b(Py)p 2418 4393 V 29 w(ssize)p
2603 4393 V 31 w(t)h(len)p Fj(\))208 4493 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4592 y Fr(Return)h(a)h(ne)n(w)g
(string)f(object)g(with)h(a)h(cop)o(y)e(of)g(the)h(string)f
Fo(v)i Fr(as)f(v)n(alue)f(and)h(length)e Fo(len)i Fr(on)g(success,)g
(and)f Fj(NULL)h Fr(on)f(f)o(ailure.)208 4692 y(If)f
Fo(v)g Fr(is)h Fj(NULL)p Fr(,)f(the)g(contents)g(of)g(the)g(string)g
(are)g(uninitialized.)0 4839 y Fj(PyObject)400 4854 y(*)498
4839 y Fg(PyString_FromFormat)p Fj(\()p Fo(const)c(c)o(har)k(*format,)g
(...)p Fj(\))208 4938 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 5038 y Fr(T)-7 b(ak)o(e)20
b(a)g(C)h Fj(printf\(\))p Fr(-style)e Fo(format)i Fr(string)f(and)f(a)i
(v)n(ariable)e(number)f(of)i(ar)o(guments,)d(calculate)j(the)g(size)h
(of)e(the)h(resulting)208 5138 y(Python)26 b(string)i(and)g(return)f(a)
h(string)g(with)g(the)g(v)n(alues)g(formatted)f(into)g(it.)50
b(The)28 b(v)n(ariable)f(ar)o(guments)f(must)i(be)g(C)h(types)208
5237 y(and)21 b(must)h(correspond)e(e)o(xactly)h(to)h(the)g(format)g
(characters)f(in)h(the)g Fo(format)i Fr(string.)30 b(The)22
b(follo)n(wing)e(format)h(characters)h(are)208 5337 y(allo)n(wed:)p
0 5549 3901 4 v 0 5649 a Fn(7.3.)52 b(Sequence)24 b(Objects)2939
b(53)p eop end
%%Page: 54 60
TeXDict begin 54 59 bop 257 161 a Fp(F)n(ormat)19 b(Characters)p
988 191 4 100 v 99 w(T)-6 b(ype)p 1556 191 V 393 w(Comment)p
208 194 7488 4 v 257 264 a Fj(\045\045)p 988 294 4 100
v 683 w Fo(n/a)p 1556 294 V 460 w Fr(The)20 b(literal)h(\045)g
(character)-5 b(.)257 364 y Fj(\045c)p 988 394 V 683
w Fr(int)p 1556 394 V 479 w(A)21 b(single)f(character)m(,)f
(represented)f(as)j(an)f(C)h(int.)257 463 y Fj(\045d)p
988 493 V 683 w Fr(int)p 1556 493 V 479 w(Exactly)f(equi)n(v)n(alent)e
(to)j Fj(printf\("\045d"\))p Fr(.)257 563 y Fj(\045u)p
988 593 V 683 w Fr(unsigned)d(int)p 1556 593 V 159 w(Exactly)i(equi)n
(v)n(alent)e(to)j Fj(printf\("\045u"\))p Fr(.)257 663
y Fj(\045ld)p 988 692 V 633 w Fr(long)p 1556 692 V 418
w(Exactly)f(equi)n(v)n(alent)e(to)j Fj(printf\("\045ld"\))p
Fr(.)257 762 y Fj(\045lu)p 988 792 V 633 w Fr(unsigned)d(long)p
1556 792 V 98 w(Exactly)i(equi)n(v)n(alent)e(to)j Fj
(printf\("\045lu"\))p Fr(.)257 862 y Fj(\045zd)p 988
892 V 633 w Fr(Py)p 1133 862 25 4 v 29 w(ssize)p 1323
862 V 30 w(t)p 1556 892 4 100 v 236 w(Exactly)f(equi)n(v)n(alent)e(to)j
Fj(printf\("\045zd"\))p Fr(.)257 961 y Fj(\045zu)p 988
991 V 633 w Fr(size)p 1174 961 25 4 v 30 w(t)p 1556 991
4 100 v 385 w(Exactly)f(equi)n(v)n(alent)e(to)j Fj(printf\("\045zu"\))p
Fr(.)257 1061 y Fj(\045i)p 988 1091 V 683 w Fr(int)p
1556 1091 V 479 w(Exactly)f(equi)n(v)n(alent)e(to)j Fj
(printf\("\045i"\))p Fr(.)257 1161 y Fj(\045x)p 988 1191
V 683 w Fr(int)p 1556 1191 V 479 w(Exactly)f(equi)n(v)n(alent)e(to)j
Fj(printf\("\045x"\))p Fr(.)257 1260 y Fj(\045s)p 988
1290 V 683 w Fr(char*)p 1556 1290 V 381 w(A)g(null-terminated)d(C)j
(character)e(array)-5 b(.)257 1360 y Fj(\045p)p 988 1390
V 683 w Fr(v)n(oid*)p 1556 1390 V 378 w(The)20 b(he)o(x)g
(representation)e(of)i(a)g(C)h(pointer)-5 b(.)24 b(Mostly)d(equi)n(v)n
(alent)d(to)i Fj(printf\("\045p"\))f Fr(e)o(xcept)g(that)h(it)h(is)g
(guaranteed)d(to)j(start)f(with)h(the)f(literal)g Fj(0x)h
Fr(re)o(gardless)d(of)i(what)h(the)f(platform')-5 b(s)19
b Fj(printf)g Fr(yields.)208 1482 y(An)j(unrecognized)d(format)j
(character)f(causes)i(all)g(the)g(rest)g(of)f(the)h(format)e(string)h
(to)h(be)g(copied)e(as-is)i(to)g(the)g(result)f(string,)208
1581 y(and)d(an)o(y)h(e)o(xtra)f(ar)o(guments)f(discarded.)0
1728 y Fj(PyObject)400 1743 y(*)498 1728 y Fg(PyString_FromFormatV)p
Fj(\()p Fo(const)e(c)o(har)k(*format,)f(va)p 2300 1728
25 4 v 30 w(list)i(var)m(gs)p Fj(\))208 1828 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1927 y Fr(Identical)f(to)h
Fj(PyString_FromFormat\(\))d Fr(e)o(xcept)i(that)h(it)h(tak)o(es)g(e)o
(xactly)e(tw)o(o)i(ar)o(guments.)0 2074 y Fj(Py_ssize_t)48
b Fg(PyString_Size)p Fj(\()p Fo(PyObject)17 b(*string)p
Fj(\))208 2174 y Fr(Return)i(the)i(length)e(of)h(the)g(string)g(in)g
(string)g(object)g Fo(string)p Fr(.)0 2321 y Fj(Py_ssize_t)48
b Fg(PyString_GET_SIZE)p Fj(\()p Fo(PyObject)16 b(*string)p
Fj(\))208 2420 y Fr(Macro)j(form)g(of)h Fj(PyString_Size\(\))e
Fr(b)n(ut)i(without)g(error)f(checking.)0 2567 y Fj(char)200
2582 y(*)299 2567 y Fg(PyString_AsString)p Fj(\()p Fo(PyObject)d
(*string)p Fj(\))208 2667 y Fr(Return)30 b(a)i(NUL-terminated)d
(representation)g(of)i(the)g(contents)g(of)f Fo(string)p
Fr(.)59 b(The)30 b(pointer)g(refers)h(to)g(the)h(internal)e(b)n(uf)n
(fer)208 2766 y(of)h Fo(string)p Fr(,)k(not)c(a)h(cop)o(y)-5
b(.)58 b(The)32 b(data)f(must)h(not)f(be)h(modi\002ed)f(in)g(an)o(y)g
(w)o(ay)-5 b(,)34 b(unless)e(the)g(string)f(w)o(as)i(just)f(created)f
(using)208 2866 y Fj(PyString_FromStringAndSize\(NULL,)43
b Fo(size)p Fj(\))p Fr(.)25 b(It)18 b(must)g(not)f(be)g(deallocated.)23
b(If)17 b Fo(string)h Fr(is)g(a)g(Unicode)e(object,)208
2966 y(this)22 b(function)e(computes)g(the)i(def)o(ault)e(encoding)g
(of)h Fo(string)h Fr(and)f(operates)g(on)g(that.)30 b(If)21
b Fo(string)h Fr(is)g(not)g(a)g(string)f(object)g(at)h(all,)208
3065 y Fj(PyString_AsString\(\))17 b Fr(returns)i Fj(NULL)h
Fr(and)g(raises)h Fj(TypeError)p Fr(.)0 3212 y Fj(char)200
3227 y(*)299 3212 y Fg(PyString_AS_STRING)p Fj(\()p Fo(PyObject)16
b(*string)p Fj(\))208 3312 y Fr(Macro)23 b(form)g(of)g
Fj(PyString_AsString\(\))e Fr(b)n(ut)j(without)g(error)f(checking.)34
b(Only)24 b(string)f(objects)h(are)g(supported;)g(no)208
3411 y(Unicode)19 b(objects)h(should)f(be)h(passed.)0
3558 y Fj(int)49 b Fg(PyString_AsStringAndSize)p Fj(\()p
Fo(PyObject)15 b(*obj,)k(c)o(har)h(**b)n(uf)o(fer)-9
b(,)19 b(Py)p 2539 3558 V 29 w(ssize)p 2724 3558 V 31
w(t)i(*length)p Fj(\))208 3658 y Fr(Return)c(a)h(NUL-terminated)e
(representation)f(of)j(the)f(contents)g(of)h(the)f(object)h
Fo(obj)f Fr(through)f(the)h(output)g(v)n(ariables)g Fo(b)n(uf)o(fer)i
Fr(and)208 3758 y Fo(length)p Fr(.)208 3884 y(The)c(function)g(accepts)
h(both)g(string)g(and)f(Unicode)g(objects)h(as)h(input.)23
b(F)o(or)16 b(Unicode)f(objects)h(it)h(returns)f(the)g(def)o(ault)f
(encoded)208 3984 y(v)o(ersion)25 b(of)g(the)i(object.)42
b(If)26 b Fo(length)g Fr(is)h Fj(NULL)p Fr(,)f(the)g(resulting)f(b)n
(uf)n(fer)g(may)h(not)g(contain)f(NUL)h(characters;)j(if)d(it)h(does,)h
(the)208 4083 y(function)18 b(returns)h Fj(-1)i Fr(and)e(a)i
Fj(TypeError)e Fr(is)i(raised.)208 4210 y(The)28 b(b)n(uf)n(fer)f
(refers)g(to)i(an)f(internal)g(string)g(b)n(uf)n(fer)f(of)h
Fo(obj)p Fr(,)i(not)e(a)h(cop)o(y)-5 b(.)48 b(The)28
b(data)g(must)h(not)f(be)g(modi\002ed)f(in)i(an)o(y)e(w)o(ay)-5
b(,)208 4309 y(unless)24 b(the)h(string)f(w)o(as)i(just)f(created)f
(using)g Fj(PyString_FromStringAndSize\(NULL,)44 b Fo(size)p
Fj(\))p Fr(.)39 b(It)25 b(must)f(not)h(be)208 4409 y(deallocated.)40
b(If)25 b Fo(string)h Fr(is)h(a)f(Unicode)f(object,)h(this)g(function)e
(computes)g(the)i(def)o(ault)f(encoding)f(of)h Fo(string)h
Fr(and)f(operates)208 4509 y(on)32 b(that.)61 b(If)32
b Fo(string)h Fr(is)g(not)g(a)f(string)g(object)g(at)h(all,)j
Fj(PyString_AsStringAndSize\(\))28 b Fr(returns)k Fj(-1)g
Fr(and)g(raises)208 4608 y Fj(TypeError)p Fr(.)0 4755
y Fj(void)49 b Fg(PyString_Concat)p Fj(\()p Fo(PyObject)17
b(**string)o(,)i(PyObject)h(*ne)o(wpart)q Fj(\))208 4855
y Fr(Create)h(a)g(ne)n(w)f(string)h(object)f(in)h Fo(*string)g
Fr(containing)e(the)i(contents)f(of)g Fo(ne)o(wpart)i
Fr(appended)c(to)j Fo(string)p Fr(;)h(the)f(caller)g(will)g(o)n(wn)208
4954 y(the)i(ne)n(w)g(reference.)34 b(The)23 b(reference)f(to)i(the)f
(old)g(v)n(alue)g(of)g Fo(string)h Fr(will)h(be)e(stolen.)35
b(If)23 b(the)h(ne)n(w)f(string)h(cannot)e(be)i(created,)208
5054 y(the)g(old)g(reference)f(to)h Fo(string)h Fr(will)g(still)g(be)f
(discarded)f(and)h(the)h(v)n(alue)e(of)h Fo(*string)g
Fr(will)i(be)e(set)h(to)f Fj(NULL)p Fr(;)h(the)f(appropriate)208
5154 y(e)o(xception)18 b(will)j(be)f(set.)0 5300 y Fj(void)49
b Fg(PyString_ConcatAndDel)p Fj(\()p Fo(PyObject)16 b(**string)o(,)j
(PyObject)h(*ne)o(wpart)q Fj(\))208 5400 y Fr(Create)32
b(a)h(ne)n(w)f(string)f(object)h(in)g Fo(*string)g Fr(containing)f(the)
h(contents)f(of)h Fo(ne)o(wpart)h Fr(appended)d(to)i
Fo(string)p Fr(.)61 b(This)33 b(v)o(ersion)p 0 5549 3901
4 v 0 5649 a Fn(54)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 55 61
TeXDict begin 55 60 bop 208 83 a Fr(decrements)18 b(the)j(reference)d
(count)h(of)h Fo(ne)o(wpart)q Fr(.)0 230 y Fj(int)49
b Fg(_PyString_Resize)p Fj(\()p Fo(PyObject)17 b(**string)o(,)i(Py)p
1786 230 25 4 v 30 w(ssize)p 1972 230 V 30 w(t)i(ne)o(wsize)p
Fj(\))208 330 y Fr(A)28 b(w)o(ay)f(to)h(resize)f(a)h(string)f(object)g
(e)n(v)o(en)g(though)e(it)k(is)f(\223immutable\224.)45
b(Only)27 b(use)h(this)g(to)g(b)n(uild)f(up)g(a)h(brand)e(ne)n(w)h
(string)208 429 y(object;)h(don')o(t)d(use)h(this)h(if)g(the)f(string)g
(may)g(already)f(be)h(kno)n(wn)f(in)h(other)f(parts)h(of)g(the)h(code.)
42 b(It)27 b(is)g(an)f(error)f(to)h(call)h(this)208 529
y(function)20 b(if)j(the)f(refcount)f(on)h(the)g(input)g(string)g
(object)g(is)h(not)g(one.)31 b(P)o(ass)23 b(the)f(address)g(of)g(an)h
(e)o(xisting)f(string)g(object)f(as)j(an)208 628 y(lv)n(alue)19
b(\(it)i(may)f(be)g(written)g(into\),)g(and)f(the)i(ne)n(w)f(size)h
(desired.)j(On)d(success,)f Fo(*string)g Fr(holds)g(the)g(resized)g
(string)g(object)g(and)208 728 y Fj(0)i Fr(is)h(returned;)f(the)g
(address)g(in)g Fo(*string)g Fr(may)g(dif)n(fer)f(from)g(its)i(input)e
(v)n(alue.)31 b(If)22 b(the)g(reallocation)f(f)o(ails,)i(the)f
(original)f(string)208 828 y(object)e(at)i Fo(*string)f
Fr(is)h(deallocated,)e Fo(*string)h Fr(is)h(set)g(to)f
Fj(NULL)p Fr(,)g(a)h(memory)d(e)o(xception)g(is)j(set,)g(and)f
Fj(-1)g Fr(is)h(returned.)0 975 y Fj(PyObject)400 990
y(*)498 975 y Fg(PyString_Format)p Fj(\()p Fo(PyObject)c(*format,)i
(PyObject)h(*ar)m(gs)p Fj(\))208 1074 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1174 y Fr(Return)h(a)i(ne)n(w)f
(string)g(object)g(from)f Fo(format)j Fr(and)e Fo(ar)m(gs)p
Fr(.)31 b(Analogous)21 b(to)h Fo(format)51 b Fj(\045)f
Fo(ar)m(gs)p Fr(.)31 b(The)22 b Fo(ar)m(gs)h Fr(ar)o(gument)d(must)i
(be)g(a)208 1273 y(tuple.)0 1420 y Fj(void)49 b Fg
(PyString_InternInPlace)p Fj(\()p Fo(PyObject)15 b(**string)p
Fj(\))208 1520 y Fr(Intern)g(the)i(ar)o(gument)d Fo(*string)i
Fr(in)h(place.)23 b(The)17 b(ar)o(gument)d(must)j(be)f(the)h(address)f
(of)g(a)h(pointer)f(v)n(ariable)f(pointing)g(to)i(a)g(Python)208
1620 y(string)j(object.)25 b(If)c(there)f(is)h(an)g(e)o(xisting)f
(interned)f(string)h(that)h(is)g(the)g(same)g(as)g Fo(*string)p
Fr(,)f(it)h(sets)h Fo(*string)e Fr(to)h(it)g(\(decrementing)208
1719 y(the)h(reference)f(count)h(of)g(the)h(old)f(string)g(object)g
(and)g(incrementing)e(the)j(reference)e(count)g(of)i(the)f(interned)f
(string)i(object\),)208 1819 y(otherwise)h(it)h(lea)n(v)o(es)g
Fo(*string)f Fr(alone)g(and)g(interns)g(it)i(\(incrementing)c(its)j
(reference)e(count\).)37 b(\(Clari\002cation:)d(e)n(v)o(en)23
b(though)208 1918 y(there)18 b(is)h(a)g(lot)g(of)f(talk)h(about)e
(reference)g(counts,)h(think)g(of)g(this)h(function)e(as)i
(reference-count-neutral;)14 b(you)k(o)n(wn)g(the)g(object)208
2018 y(after)h(the)i(call)f(if)h(and)e(only)h(if)g(you)g(o)n(wned)f(it)
h(before)f(the)h(call.\))0 2165 y Fj(PyObject)400 2180
y(*)498 2165 y Fg(PyString_InternFromString)p Fj(\()p
Fo(const)15 b(c)o(har)20 b(*v)p Fj(\))208 2265 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2364 y Fr(A)29
b(combination)d(of)i Fj(PyString_FromString\(\))e Fr(and)i
Fj(PyString_InternInPlace\(\))p Fr(,)e(returning)h(either)h(a)208
2464 y(ne)n(w)22 b(string)g(object)g(that)g(has)h(been)e(interned,)h
(or)g(a)h(ne)n(w)f(\(\223o)n(wned\224\))e(reference)h(to)h(an)h
(earlier)e(interned)g(string)i(object)e(with)208 2563
y(the)f(same)g(v)n(alue.)0 2710 y Fj(PyObject)400 2725
y(*)498 2710 y Fg(PyString_Decode)p Fj(\()p Fo(const)d(c)o(har)j(*s,)g
(Py)p 1871 2710 V 30 w(ssize)p 2057 2710 V 30 w(t)h(size)o(,)g(const)f
(c)o(har)g(*encoding)o(,)e(const)i(c)o(har)f(*err)l(or)o(s)p
Fj(\))208 2810 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2910 y Fr(Create)c(an)f(object)g(by)h(decoding)d
Fo(size)k Fr(bytes)f(of)f(the)h(encoded)e(b)n(uf)n(fer)g
Fo(s)j Fr(using)e(the)h(codec)f(re)o(gistered)f(for)h
Fo(encoding)p Fr(.)22 b Fo(encoding)208 3009 y Fr(and)j
Fo(err)l(or)o(s)i Fr(ha)n(v)o(e)e(the)h(same)g(meaning)e(as)j(the)e
(parameters)g(of)g(the)h(same)g(name)f(in)h(the)g Fj(unicode\(\))e
Fr(b)n(uilt-in)i(function.)208 3109 y(The)21 b(codec)f(to)i(be)f(used)g
(is)i(look)o(ed)d(up)h(using)g(the)g(Python)g(codec)f(re)o(gistry)-5
b(.)28 b(Return)21 b Fj(NULL)g Fr(if)h(an)f(e)o(xception)e(w)o(as)k
(raised)e(by)208 3208 y(the)f(codec.)0 3355 y Fj(PyObject)400
3370 y(*)498 3355 y Fg(PyString_AsDecodedObject)p Fj(\()p
Fo(PyObject)15 b(*str)-9 b(,)21 b(const)f(c)o(har)f(*encoding)o(,)f
(const)i(c)o(har)g(*err)l(or)o(s)p Fj(\))208 3455 y Fo(Return)f(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 3555 y Fr(Decode)g(a)h(string)
g(object)g(by)g(passing)f(it)i(to)g(the)f(codec)f(re)o(gistered)g(for)g
Fo(encoding)g Fr(and)g(return)g(the)h(result)g(as)h(Python)e(object.)
208 3654 y Fo(encoding)29 b Fr(and)i Fo(err)l(or)o(s)i
Fr(ha)n(v)o(e)e(the)g(same)h(meaning)e(as)i(the)f(parameters)f(of)h
(the)h(same)g(name)e(in)i(the)f(string)g Fj(encode\(\))208
3754 y Fr(method.)f(The)22 b(codec)g(to)h(be)f(used)h(is)g(look)o(ed)f
(up)g(using)g(the)g(Python)g(codec)g(re)o(gistry)-5 b(.)30
b(Return)22 b Fj(NULL)h Fr(if)g(an)f(e)o(xception)f(w)o(as)208
3853 y(raised)f(by)f(the)i(codec.)0 4000 y Fj(PyObject)400
4015 y(*)498 4000 y Fg(PyString_Encode)p Fj(\()p Fo(const)c(c)o(har)j
(*s,)g(Py)p 1871 4000 V 30 w(ssize)p 2057 4000 V 30 w(t)h(size)o(,)g
(const)f(c)o(har)g(*encoding)o(,)e(const)i(c)o(har)f(*err)l(or)o(s)p
Fj(\))208 4100 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4200 y Fr(Encode)e(the)i Fj(char)f Fr(b)n(uf)n(fer)g(of)g(the)
h(gi)n(v)o(en)f(size)h(by)g(passing)f(it)h(to)g(the)g(codec)f(re)o
(gistered)g(for)g Fo(encoding)f Fr(and)h(return)f(a)j(Python)208
4299 y(object.)i Fo(encoding)15 b Fr(and)h Fo(err)l(or)o(s)i
Fr(ha)n(v)o(e)e(the)h(same)g(meaning)f(as)h(the)g(parameters)f(of)g
(the)h(same)g(name)f(in)h(the)g(string)f Fj(encode\(\))208
4399 y Fr(method.)30 b(The)22 b(codec)g(to)h(be)f(used)h(is)g(look)o
(ed)f(up)g(using)g(the)g(Python)g(codec)g(re)o(gistry)-5
b(.)30 b(Return)22 b Fj(NULL)h Fr(if)g(an)f(e)o(xception)f(w)o(as)208
4498 y(raised)f(by)f(the)i(codec.)0 4645 y Fj(PyObject)400
4660 y(*)498 4645 y Fg(PyString_AsEncodedObject)p Fj(\()p
Fo(PyObject)15 b(*str)-9 b(,)21 b(const)f(c)o(har)f(*encoding)o(,)f
(const)i(c)o(har)g(*err)l(or)o(s)p Fj(\))208 4745 y Fo(Return)f(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 4845 y Fr(Encode)f(a)j(string)
f(object)f(using)h(the)g(codec)f(re)o(gistered)g(for)h
Fo(encoding)e Fr(and)h(return)g(the)h(result)h(as)f(Python)f(object.)28
b Fo(encoding)208 4944 y Fr(and)23 b Fo(err)l(or)o(s)i
Fr(ha)n(v)o(e)e(the)h(same)g(meaning)e(as)i(the)g(parameters)f(of)g
(the)h(same)g(name)f(in)h(the)g(string)f Fj(encode\(\))g
Fr(method.)34 b(The)208 5044 y(codec)21 b(to)i(be)g(used)f(is)i(look)o
(ed)d(up)i(using)f(the)h(Python)e(codec)h(re)o(gistry)-5
b(.)31 b(Return)22 b Fj(NULL)h Fr(if)g(an)f(e)o(xception)f(w)o(as)j
(raised)e(by)h(the)208 5143 y(codec.)p 0 5549 3901 4
v 0 5649 a Fn(7.3.)52 b(Sequence)24 b(Objects)2939 b(55)p
eop end
%%Page: 56 62
TeXDict begin 56 61 bop 0 83 a Fh(7.3.2)100 b(Unicode)29
b(Objects)0 286 y Fr(These)20 b(are)g(the)g(basic)h(Unicode)e(object)g
(types)h(used)g(for)g(the)g(Unicode)f(implementation)f(in)i(Python:)0
433 y Fg(Py_UNICODE)208 532 y Fr(This)h(type)h(represents)f(the)g
(storage)g(type)h(which)f(is)h(used)g(by)f(Python)g(internally)f(as)j
(basis)f(for)f(holding)f(Unicode)h(ordinals.)208 632
y(Python')-5 b(s)21 b(def)o(ault)h(b)n(uilds)g(use)g(a)h(16-bit)e(type)
h(for)f Fj(Py_UNICODE)g Fr(and)h(store)g(Unicode)f(v)n(alues)h
(internally)f(as)i(UCS2.)32 b(It)23 b(is)208 732 y(also)j(possible)h
(to)f(b)n(uild)g(a)h(UCS4)h(v)o(ersion)d(of)h(Python)f(\(most)i(recent)
f(Linux)f(distrib)n(utions)h(come)g(with)g(UCS4)h(b)n(uilds)g(of)208
831 y(Python\).)d(These)c(b)n(uilds)h(then)f(use)g(a)h(32-bit)f(type)g
(for)f Fj(Py_UNICODE)h Fr(and)g(store)g(Unicode)f(data)i(internally)e
(as)i(UCS4.)27 b(On)208 931 y(platforms)d(where)h Fj(wchar_t)g
Fr(is)i(a)n(v)n(ailable)e(and)g(compatible)f(with)i(the)g(chosen)f
(Python)f(Unicode)h(b)n(uild)g(v)n(ariant,)h Fj(Py_-)208
1031 y(UNICODE)g Fr(is)i(a)f(typedef)e(alias)j(for)e
Fj(wchar_t)g Fr(to)i(enhance)d(nati)n(v)o(e)h(platform)f(compatibility)
-5 b(.)44 b(On)26 b(all)i(other)e(platforms,)208 1130
y Fj(Py_UNICODE)18 b Fr(is)k(a)e(typedef)f(alias)i(for)e(either)h
Fj(unsigned)49 b(short)19 b Fr(\(UCS2\))h(or)g Fj(unsigned)49
b(long)20 b Fr(\(UCS4\).)0 1277 y(Note)f(that)f(UCS2)h(and)f(UCS4)h
(Python)f(b)n(uilds)g(are)h(not)f(binary)f(compatible.)23
b(Please)c(k)o(eep)f(this)h(in)g(mind)f(when)g(writing)g(e)o(xtensions)
0 1377 y(or)i(interf)o(aces.)0 1524 y Fg(PyUnicodeObject)208
1623 y Fr(This)g(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i
(Python)e(Unicode)g(object.)0 1770 y Fj(PyTypeObject)48
b Fg(PyUnicode_Type)208 1870 y Fr(This)36 b(instance)f(of)h
Fj(PyTypeObject)e Fr(represents)h(the)h(Python)f(Unicode)g(type.)72
b(It)36 b(is)h(e)o(xposed)e(to)h(Python)f(code)g(as)208
1969 y Fj(unicode)19 b Fr(and)h Fj(types.UnicodeType)p
Fr(.)0 2116 y(The)26 b(follo)n(wing)f(APIs)i(are)f(really)g(C)h(macros)
f(and)f(can)i(be)f(used)g(to)g(do)g(f)o(ast)h(checks)f(and)g(to)g
(access)h(internal)f(read-only)e(data)i(of)0 2216 y(Unicode)19
b(objects:)0 2363 y Fj(int)49 b Fg(PyUnicode_Check)p
Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208 2462 y Fr(Return)23
b(true)h(if)h(the)f(object)g Fo(o)g Fr(is)i(a)e(Unicode)g(object)f(or)h
(an)h(instance)f(of)g(a)g(Unicode)f(subtype.)75 b(Changed)23
b(in)h(v)o(ersion)f(2.2:)208 2562 y(Allo)n(wed)c(subtypes)g(to)i(be)f
(accepted.)0 2709 y Fj(int)49 b Fg(PyUnicode_CheckExact)p
Fj(\()p Fo(PyObject)16 b(*o)p Fj(\))208 2808 y Fr(Return)j(true)h(if)h
(the)f(object)f Fo(o)i Fr(is)g(a)g(Unicode)e(object,)g(b)n(ut)h(not)g
(an)g(instance)g(of)g(a)g(subtype.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e
(2.2.)0 2955 y Fj(Py_ssize_t)48 b Fg(PyUnicode_GET_SIZE)p
Fj(\()p Fo(PyObject)16 b(*o)p Fj(\))208 3055 y Fr(Return)j(the)i(size)f
(of)g(the)g(object.)25 b Fo(o)20 b Fr(has)h(to)f(be)g(a)h
Fj(PyUnicodeObject)d Fr(\(not)h(check)o(ed\).)0 3202
y Fj(Py_ssize_t)48 b Fg(PyUnicode_GET_DATA_SIZE)p Fj(\()p
Fo(PyObject)15 b(*o)p Fj(\))208 3301 y Fr(Return)k(the)i(size)f(of)g
(the)g(object')-5 b(s)21 b(internal)e(b)n(uf)n(fer)g(in)h(bytes.)25
b Fo(o)20 b Fr(has)h(to)f(be)g(a)h Fj(PyUnicodeObject)d
Fr(\(not)h(check)o(ed\).)0 3448 y Fj(Py_UNICODE)500 3463
y(*)598 3448 y Fg(PyUnicode_AS_UNICODE)p Fj(\()p Fo(PyObject)d(*o)p
Fj(\))208 3548 y Fr(Return)25 b(a)i(pointer)e(to)h(the)g(internal)f
Fj(Py_UNICODE)g Fr(b)n(uf)n(fer)g(of)h(the)g(object.)42
b Fo(o)26 b Fr(has)h(to)f(be)g(a)g Fj(PyUnicodeObject)e
Fr(\(not)208 3648 y(check)o(ed\).)0 3794 y Fj(const)49
b(char)499 3809 y(*)598 3794 y Fg(PyUnicode_AS_DATA)p
Fj(\()p Fo(PyObject)16 b(*o)p Fj(\))208 3894 y Fr(Return)j(a)i(pointer)
e(to)h(the)g(internal)g(b)n(uf)n(fer)f(of)h(the)g(object.)k
Fo(o)c Fr(has)h(to)f(be)g(a)h Fj(PyUnicodeObject)d Fr(\(not)h(check)o
(ed\).)0 4041 y(Unicode)f(pro)o(vides)f(man)o(y)g(dif)n(ferent)g
(character)h(properties.)23 b(The)18 b(most)h(often)f(needed)f(ones)i
(are)f(a)n(v)n(ailable)h(through)d(these)j(macros)0 4141
y(which)h(are)g(mapped)e(to)j(C)g(functions)e(depending)e(on)j(the)g
(Python)f(con\002guration.)0 4287 y Fj(int)49 b Fg(Py_UNICODE_ISSPACE)p
Fj(\()p Fo(Py)p 1242 4287 25 4 v 26 w(UNICODE)21 b(c)o(h)p
Fj(\))208 4387 y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(a)g(whitespace)f(character)-5 b(.)0
4534 y Fj(int)49 b Fg(Py_UNICODE_ISLOWER)p Fj(\()p Fo(Py)p
1242 4534 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 4634
y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(a)g(lo)n(wercase)f(character)-5 b(.)0
4780 y Fj(int)49 b Fg(Py_UNICODE_ISUPPER)p Fj(\()p Fo(Py)p
1242 4780 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 4880
y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(an)f(uppercase)f(character)-5 b(.)0
5027 y Fj(int)49 b Fg(Py_UNICODE_ISTITLE)p Fj(\()p Fo(Py)p
1242 5027 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 5127
y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(a)g(titlecase)g(character)-5 b(.)0
5273 y Fj(int)49 b Fg(Py_UNICODE_ISLINEBREAK)p Fj(\()p
Fo(Py)p 1442 5273 V 25 w(UNICODE)21 b(c)o(h)p Fj(\))208
5373 y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(a)g(linebreak)e(character)-5 b(.)p
0 5549 3901 4 v 0 5649 a Fn(56)2478 b(Chapter)23 b(7.)52
b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 57 63
TeXDict begin 57 62 bop 0 83 a Fj(int)49 b Fg(Py_UNICODE_ISDECIMAL)p
Fj(\()p Fo(Py)p 1342 83 25 4 v 26 w(UNICODE)21 b(c)o(h)p
Fj(\))208 183 y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(a)g(decimal)f(character)-5 b(.)0 330
y Fj(int)49 b Fg(Py_UNICODE_ISDIGIT)p Fj(\()p Fo(Py)p
1242 330 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 429 y
Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f Fo(c)o(h)h
Fr(is)h(a)g(digit)f(character)-5 b(.)0 576 y Fj(int)49
b Fg(Py_UNICODE_ISNUMERIC)p Fj(\()p Fo(Py)p 1342 576
V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 676 y Fr(Return)e(1)i(or)e(0)i
(depending)c(on)j(whether)f Fo(c)o(h)h Fr(is)h(a)g(numeric)e(character)
-5 b(.)0 823 y Fj(int)49 b Fg(Py_UNICODE_ISALPHA)p Fj(\()p
Fo(Py)p 1242 823 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208
922 y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(an)f(alphabetic)f(character)-5 b(.)0
1069 y Fj(int)49 b Fg(Py_UNICODE_ISALNUM)p Fj(\()p Fo(Py)p
1242 1069 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 1169
y Fr(Return)e(1)i(or)e(0)i(depending)c(on)j(whether)f
Fo(c)o(h)h Fr(is)h(an)f(alphanumeric)e(character)-5 b(.)0
1316 y(These)20 b(APIs)h(can)f(be)g(used)g(for)f(f)o(ast)i(direct)f
(character)f(con)m(v)o(ersions:)0 1462 y Fj(Py_UNICODE)48
b Fg(Py_UNICODE_TOLOWER)p Fj(\()p Fo(Py)p 1591 1462 V
26 w(UNICODE)21 b(c)o(h)p Fj(\))208 1562 y Fr(Return)e(the)i(character)
d Fo(c)o(h)i Fr(con)m(v)o(erted)e(to)i(lo)n(wer)g(case.)0
1709 y Fj(Py_UNICODE)48 b Fg(Py_UNICODE_TOUPPER)p Fj(\()p
Fo(Py)p 1591 1709 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208
1808 y Fr(Return)e(the)i(character)d Fo(c)o(h)i Fr(con)m(v)o(erted)e
(to)i(upper)f(case.)0 1955 y Fj(Py_UNICODE)48 b Fg(Py_UNICODE_TOTITLE)p
Fj(\()p Fo(Py)p 1591 1955 V 26 w(UNICODE)21 b(c)o(h)p
Fj(\))208 2055 y Fr(Return)e(the)i(character)d Fo(c)o(h)i
Fr(con)m(v)o(erted)e(to)i(title)h(case.)0 2202 y Fj(int)49
b Fg(Py_UNICODE_TODECIMAL)p Fj(\()p Fo(Py)p 1342 2202
V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 2301 y Fr(Return)j(the)h
(character)e Fo(c)o(h)i Fr(con)m(v)o(erted)d(to)j(a)g(decimal)g(positi)
n(v)o(e)f(inte)o(ger)-5 b(.)38 b(Return)24 b Fj(-1)h
Fr(if)g(this)h(is)f(not)g(possible.)39 b(This)25 b(macro)208
2401 y(does)19 b(not)h(raise)h(e)o(xceptions.)0 2548
y Fj(int)49 b Fg(Py_UNICODE_TODIGIT)p Fj(\()p Fo(Py)p
1242 2548 V 26 w(UNICODE)21 b(c)o(h)p Fj(\))208 2648
y Fr(Return)d(the)h(character)e Fo(c)o(h)i Fr(con)m(v)o(erted)d(to)j(a)
g(single)g(digit)g(inte)o(ger)-5 b(.)23 b(Return)c Fj(-1)g
Fr(if)g(this)g(is)h(not)e(possible.)25 b(This)18 b(macro)g(does)h(not)
208 2747 y(raise)h(e)o(xceptions.)0 2894 y Fj(double)49
b Fg(Py_UNICODE_TONUMERIC)p Fj(\()p Fo(Py)p 1492 2894
V 25 w(UNICODE)21 b(c)o(h)p Fj(\))208 2994 y Fr(Return)i(the)h
(character)f Fo(c)o(h)h Fr(con)m(v)o(erted)d(to)j(a)h(double.)35
b(Return)23 b Fj(-1.0)h Fr(if)g(this)h(is)g(not)e(possible.)37
b(This)24 b(macro)f(does)h(not)f(raise)208 3093 y(e)o(xceptions.)0
3240 y(T)-7 b(o)20 b(create)g(Unicode)f(objects)h(and)g(access)h(their)
f(basic)g(sequence)f(properties,)g(use)h(these)g(APIs:)0
3387 y Fj(PyObject)400 3402 y(*)498 3387 y Fg(PyUnicode_FromUnicode)p
Fj(\()p Fo(const)c(Py)p 1883 3387 V 30 w(UNICODE)k(*u,)g(Py)p
2515 3387 V 29 w(ssize)p 2700 3387 V 31 w(t)h(size)p
Fj(\))208 3487 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3586 y Fr(Create)j(a)g(Unicode)f(Object)h(from)f(the)h(Py)p
1461 3586 V 29 w(UNICODE)g(b)n(uf)n(fer)f Fo(u)h Fr(of)f(the)h(gi)n(v)o
(en)f(size.)34 b Fo(u)23 b Fr(may)f(be)h Fj(NULL)g Fr(which)f(causes)i
(the)208 3686 y(contents)f(to)h(be)g(unde\002ned.)35
b(It)24 b(is)h(the)f(user')-5 b(s)25 b(responsibility)d(to)j(\002ll)g
(in)f(the)g(needed)f(data.)36 b(The)24 b(b)n(uf)n(fer)f(is)i(copied)e
(into)h(the)208 3786 y(ne)n(w)d(object.)27 b(If)22 b(the)f(b)n(uf)n
(fer)f(is)i(not)f Fj(NULL)p Fr(,)g(the)g(return)f(v)n(alue)h(might)g
(be)g(a)g(shared)g(object.)28 b(Therefore,)19 b(modi\002cation)h(of)h
(the)208 3885 y(resulting)e(Unicode)g(object)h(is)h(only)e(allo)n(wed)h
(when)f Fo(u)h Fr(is)i Fj(NULL)p Fr(.)0 4032 y Fj(Py_UNICODE)500
4047 y(*)598 4032 y Fg(PyUnicode_AsUnicode)p Fj(\()p
Fo(PyObject)16 b(*unicode)p Fj(\))208 4132 y Fr(Return)29
b(a)h(read-only)e(pointer)h(to)h(the)g(Unicode)f(object')-5
b(s)30 b(internal)f Fj(Py_UNICODE)g Fr(b)n(uf)n(fer)m(,)h
Fj(NULL)g Fr(if)g Fo(unicode)f Fr(is)h(not)g(a)208 4231
y(Unicode)19 b(object.)0 4378 y Fj(Py_ssize_t)48 b Fg
(PyUnicode_GetSize)p Fj(\()p Fo(PyObject)16 b(*unicode)p
Fj(\))208 4478 y Fr(Return)j(the)i(length)e(of)h(the)g(Unicode)f
(object.)0 4625 y Fj(PyObject)400 4640 y(*)498 4625 y
Fg(PyUnicode_FromEncodedObject)p Fj(\()p Fo(PyObject)c(*obj,)k(const)h
(c)o(har)f(*encoding)o(,)f(const)i(c)o(har)g(*err)l(or)o(s)p
Fj(\))208 4724 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4824 y Fr(Coerce)f(an)i(encoded)d(object)i Fo(obj)f
Fr(to)i(an)f(Unicode)f(object)h(and)f(return)g(a)i(reference)d(with)j
(incremented)d(refcount.)208 4950 y(String)g(and)h(other)f(char)g(b)n
(uf)n(fer)g(compatible)g(objects)g(are)h(decoded)f(according)f(to)i
(the)g(gi)n(v)o(en)f(encoding)f(and)h(using)h(the)g(error)208
5049 y(handling)g(de\002ned)i(by)h(errors.)28 b(Both)22
b(can)g(be)f Fj(NULL)h Fr(to)g(ha)n(v)o(e)f(the)h(interf)o(ace)f(use)h
(the)g(def)o(ault)f(v)n(alues)g(\(see)h(the)g(ne)o(xt)f(section)208
5149 y(for)e(details\).)208 5274 y(All)h(other)g(objects,)f(including)g
(Unicode)g(objects,)h(cause)g(a)g Fj(TypeError)f Fr(to)i(be)f(set.)208
5400 y(The)f(API)i(returns)e Fj(NULL)h Fr(if)h(there)e(w)o(as)i(an)g
(error)-5 b(.)24 b(The)c(caller)g(is)h(responsible)e(for)g(decref)5
b('ing)18 b(the)i(returned)e(objects.)p 0 5549 3901 4
v 0 5649 a Fn(7.3.)52 b(Sequence)24 b(Objects)2939 b(57)p
eop end
%%Page: 58 64
TeXDict begin 58 63 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyUnicode_FromObject)p Fj(\()p Fo(PyObject)16
b(*obj)p Fj(\))208 183 y Fo(Return)j(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 282 y Fr(Shortcut)j(for)g Fj
(PyUnicode_FromEncodedObject\(obj,)44 b(NULL,)49 b("strict"\))23
b Fr(which)h(is)h(used)f(throughout)208 382 y(the)c(interpreter)e
(whene)n(v)o(er)g(coercion)h(to)h(Unicode)f(is)j(needed.)0
529 y(If)32 b(the)g(platform)e(supports)h Fj(wchar_t)g
Fr(and)h(pro)o(vides)e(a)i(header)f(\002le)i(wchar)-5
b(.h,)34 b(Python)c(can)i(interf)o(ace)f(directly)g(to)i(this)f(type)0
628 y(using)23 b(the)h(follo)n(wing)e(functions.)34 b(Support)22
b(is)j(optimized)e(if)h(Python')-5 b(s)23 b(o)n(wn)g
Fj(Py_UNICODE)f Fr(type)h(is)i(identical)e(to)h(the)g(system')-5
b(s)0 728 y Fj(wchar_t)p Fr(.)0 875 y Fj(PyObject)400
890 y(*)498 875 y Fg(PyUnicode_FromWideChar)p Fj(\()p
Fo(const)16 b(wc)o(har)p 2052 875 25 4 v 29 w(t)21 b(*w)-6
b(,)20 b(Py)p 2345 875 V 30 w(ssize)p 2531 875 V 30 w(t)h(size)p
Fj(\))208 975 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1074 y Fr(Create)g(a)h(Unicode)e(object)g(from)g(the)i
Fj(wchar_t)e Fr(b)n(uf)n(fer)g Fo(w)i Fr(of)f(the)g(gi)n(v)o(en)f
(size.)26 b(Return)19 b Fj(NULL)h Fr(on)g(f)o(ailure.)0
1221 y Fj(Py_ssize_t)48 b Fg(PyUnicode_AsWideChar)p Fj(\()p
Fo(PyUnicodeOb)o(ject)15 b(*unicode)o(,)j(wc)o(har)p
2762 1221 V 29 w(t)j(*w)-6 b(,)20 b(Py)p 3055 1221 V
30 w(ssize)p 3241 1221 V 30 w(t)h(size)p Fj(\))208 1321
y Fr(Cop)o(y)j(the)h(Unicode)e(object)i(contents)f(into)g(the)h
Fj(wchar_t)f Fr(b)n(uf)n(fer)f Fo(w)p Fr(.)40 b(At)25
b(most)g Fo(size)h Fj(wchar_t)e Fr(characters)g(are)h(copied)208
1420 y(\(e)o(xcluding)d(a)k(possibly)f(trailing)g(0-termination)e
(character\).)40 b(Return)25 b(the)g(number)f(of)h Fj(wchar_t)g
Fr(characters)f(copied)h(or)208 1520 y(-1)30 b(in)h(case)h(of)e(an)h
(error)-5 b(.)57 b(Note)31 b(that)g(the)g(resulting)f
Fj(wchar_t)g Fr(string)g(may)h(or)g(may)f(not)h(be)f(0-terminated.)55
b(It)32 b(is)g(the)208 1620 y(responsibility)20 b(of)h(the)g(caller)g
(to)h(mak)o(e)f(sure)g(that)g(the)h Fj(wchar_t)e Fr(string)h(is)i
(0-terminated)c(in)i(case)h(this)g(is)g(required)e(by)h(the)208
1719 y(application.)0 1987 y Fn(Built-in)k(Codecs)0 2190
y Fr(Python)18 b(pro)o(vides)f(a)i(set)h(of)e(b)n(uiltin)h(codecs)f
(which)g(are)h(written)g(in)g(C)h(for)e(speed.)24 b(All)19
b(of)g(these)g(codecs)f(are)h(directly)f(usable)h(via)g(the)0
2290 y(follo)n(wing)g(functions.)0 2437 y(Man)o(y)h(of)g(the)h(follo)n
(wing)f(APIs)h(tak)o(e)g(tw)o(o)g(ar)o(guments)e(encoding)g(and)h
(errors.)26 b(These)21 b(parameters)e(encoding)g(and)h(errors)g(ha)n(v)
o(e)h(the)0 2536 y(same)f(semantics)h(as)f(the)h(ones)f(of)g(the)g(b)n
(uiltin)g(unicode\(\))e(Unicode)h(object)g(constructor)-5
b(.)0 2683 y(Setting)26 b(encoding)e(to)j Fj(NULL)f Fr(causes)g(the)g
(def)o(ault)g(encoding)e(to)i(be)h(used)f(which)f(is)k
Fi(A)t(S)t(C)t(I)t(I)r Fr(.)45 b(The)26 b(\002le)h(system)f(calls)h
(should)e(use)0 2783 y Fj(Py_FileSystemDefaultEncoding)g
Fr(as)30 b(the)g(encoding)d(for)i(\002le)i(names.)53
b(This)29 b(v)n(ariable)g(should)g(be)g(treated)g(as)h(read-)0
2883 y(only:)h(On)23 b(some)h(systems,)g(it)g(will)h(be)e(a)h(pointer)e
(to)i(a)g(static)g(string,)g(on)f(others,)g(it)h(will)h(change)d(at)i
(run-time)e(\(such)h(as)h(when)f(the)0 2982 y(application)c(in)m(v)n
(ok)o(es)g(setlocale\).)0 3129 y(Error)25 b(handling)g(is)j(set)f(by)f
(errors)g(which)g(may)g(also)h(be)g(set)g(to)g Fj(NULL)f
Fr(meaning)f(to)i(use)g(the)f(def)o(ault)g(handling)f(de\002ned)h(for)g
(the)0 3229 y(codec.)e(Def)o(ault)c(error)f(handling)f(for)i(all)h(b)n
(uiltin)f(codecs)f(is)i(\223strict\224)g(\()p Fj(ValueError)e
Fr(is)i(raised\).)0 3376 y(The)f(codecs)g(all)g(use)h(a)f(similar)h
(interf)o(ace.)j(Only)c(de)n(viation)e(from)h(the)i(follo)n(wing)d
(generic)h(ones)h(are)g(documented)e(for)h(simplicity)-5
b(.)0 3522 y(These)20 b(are)g(the)g(generic)f(codec)h(APIs:)0
3669 y Fj(PyObject)400 3684 y(*)498 3669 y Fg(PyUnicode_Decode)p
Fj(\()p Fo(const)d(c)o(har)j(*s,)g(Py)p 1921 3669 V 29
w(ssize)p 2106 3669 V 31 w(t)h(size)o(,)g(const)f(c)o(har)g(*encoding)o
(,)d(const)j(c)o(har)g(*err)l(or)o(s)p Fj(\))208 3769
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3869 y Fr(Create)27 b(a)h(Unicode)f(object)g(by)g(decoding)e
Fo(size)k Fr(bytes)e(of)g(the)h(encoded)e(string)h Fo(s)p
Fr(.)47 b Fo(encoding)26 b Fr(and)h Fo(err)l(or)o(s)i
Fr(ha)n(v)o(e)e(the)g(same)208 3968 y(meaning)g(as)i(the)g(parameters)f
(of)g(the)h(same)g(name)f(in)h(the)g Fj(unicode\(\))f
Fr(b)n(uiltin)g(function.)49 b(The)28 b(codec)g(to)h(be)g(used)g(is)208
4068 y(look)o(ed)18 b(up)i(using)g(the)g(Python)f(codec)h(re)o(gistry)
-5 b(.)23 b(Return)d Fj(NULL)g Fr(if)g(an)g(e)o(xception)f(w)o(as)i
(raised)f(by)f(the)i(codec.)0 4215 y Fj(PyObject)400
4230 y(*)498 4215 y Fg(PyUnicode_Encode)p Fj(\()p Fo(const)13
b(Py)p 1630 4215 V 30 w(UNICODE)k(*s,)g(Py)p 2246 4215
V 29 w(ssize)p 2431 4215 V 31 w(t)g(size)o(,)h(const)f(c)o(har)f
(*encoding)o(,)e(const)i(c)o(har)g(*er)n(-)1348 4314
y(r)l(or)o(s)p Fj(\))208 4390 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4489 y Fr(Encode)f(the)j
Fj(Py_UNICODE)e Fr(b)n(uf)n(fer)g(of)h(the)g(gi)n(v)o(en)f(size)i(and)f
(return)f(a)i(Python)e(string)h(object.)28 b Fo(encoding)19
b Fr(and)i Fo(err)l(or)o(s)i Fr(ha)n(v)o(e)208 4589 y(the)j(same)g
(meaning)f(as)h(the)h(parameters)e(of)g(the)h(same)h(name)e(in)i(the)f
(Unicode)f Fj(encode\(\))g Fr(method.)41 b(The)26 b(codec)f(to)i(be)208
4689 y(used)19 b(is)j(look)o(ed)d(up)g(using)h(the)g(Python)f(codec)h
(re)o(gistry)-5 b(.)23 b(Return)d Fj(NULL)g Fr(if)g(an)g(e)o(xception)f
(w)o(as)i(raised)f(by)g(the)g(codec.)0 4835 y Fj(PyObject)400
4850 y(*)498 4835 y Fg(PyUnicode_AsEncodedString)p Fj(\()p
Fo(PyObject)15 b(*unicode)o(,)j(const)i(c)o(har)g(*encoding)o(,)d
(const)j(c)o(har)g(*err)l(or)o(s)p Fj(\))208 4935 y Fo(Return)f(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 5035 y Fr(Encode)28
b(a)j(Unicode)e(object)h(and)f(return)g(the)i(result)f(as)h(Python)e
(string)h(object.)54 b Fo(encoding)28 b Fr(and)i Fo(err)l(or)o(s)i
Fr(ha)n(v)o(e)d(the)h(same)208 5134 y(meaning)d(as)j(the)g(parameters)e
(of)h(the)g(same)h(name)f(in)g(the)h(Unicode)e Fj(encode\(\))g
Fr(method.)51 b(The)29 b(codec)g(to)g(be)h(used)f(is)208
5234 y(look)o(ed)18 b(up)i(using)g(the)g(Python)f(codec)h(re)o(gistry)
-5 b(.)23 b(Return)d Fj(NULL)g Fr(if)g(an)g(e)o(xception)f(w)o(as)i
(raised)f(by)f(the)i(codec.)0 5381 y(These)f(are)g(the)g(UTF-8)g(codec)
f(APIs:)p 0 5549 3901 4 v 0 5649 a Fn(58)2478 b(Chapter)23
b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 59 65
TeXDict begin 59 64 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyUnicode_DecodeUTF8)p Fj(\()p Fo(const)16 b(c)o(har)k(*s,)g
(Py)p 2120 83 25 4 v 30 w(ssize)p 2306 83 V 30 w(t)h(size)o(,)g(const)f
(c)o(har)g(*err)l(or)o(s)p Fj(\))208 183 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 282 y Fr(Create)25
b(a)g(Unicode)f(object)h(by)g(decoding)e Fo(size)j Fr(bytes)f(of)f(the)
h(UTF-8)g(encoded)e(string)i Fo(s)p Fr(.)41 b(Return)24
b Fj(NULL)h Fr(if)g(an)g(e)o(xception)208 382 y(w)o(as)c(raised)f(by)f
(the)i(codec.)0 529 y Fj(PyObject)400 544 y(*)498 529
y Fg(PyUnicode_DecodeUTF8Stateful)p Fj(\()p Fo(const)12
b(c)o(har)17 b(*s,)h(Py)p 2511 529 V 30 w(ssize)p 2697
529 V 30 w(t)h(size)o(,)g(const)e(c)o(har)g(*err)l(or)o(s,)i(Py)p
3666 529 V 29 w(ssize)p 3851 529 V 31 w(t)1948 628 y(*con)o(sumed)q
Fj(\))208 704 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 803 y Fr(If)i Fo(consumed)h Fr(is)h Fj(NULL)p
Fr(,)e(beha)n(v)o(e)f(lik)o(e)i Fj(PyUnicode_DecodeUTF8\(\))p
Fr(.)28 b(If)22 b Fo(consumed)h Fr(is)h(not)e Fj(NULL)p
Fr(,)g(trailing)g(incom-)208 903 y(plete)f(UTF-8)g(byte)g(sequences)g
(will)h(not)f(be)g(treated)g(as)i(an)e(error)-5 b(.)28
b(Those)21 b(bytes)g(will)i(not)e(be)g(decoded)f(and)h(the)g(number)f
(of)208 1003 y(bytes)g(that)g(ha)n(v)o(e)f(been)h(decoded)e(will)j(be)f
(stored)g(in)g Fo(consumed)r Fr(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e
(2.4.)0 1149 y Fj(PyObject)400 1164 y(*)498 1149 y Fg
(PyUnicode_EncodeUTF8)p Fj(\()p Fo(const)d(Py)p 1833
1149 V 30 w(UNICODE)k(*s,)h(Py)p 2456 1149 V 29 w(ssize)p
2641 1149 V 31 w(t)g(size)o(,)g(const)f(c)o(har)g(*err)l(or)o(s)p
Fj(\))208 1249 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1349 y Fr(Encode)d(the)h Fj(Py_UNICODE)f Fr(b)n(uf)n(fer)g(of)
i(the)f(gi)n(v)o(en)f(size)i(using)f(UTF-8)g(and)g(return)g(a)g(Python)
g(string)g(object.)24 b(Return)18 b Fj(NULL)208 1448
y Fr(if)i(an)g(e)o(xception)e(w)o(as)j(raised)f(by)g(the)g(codec.)0
1595 y Fj(PyObject)400 1610 y(*)498 1595 y Fg(PyUnicode_AsUTF8String)p
Fj(\()p Fo(PyObject)c(*unicode)p Fj(\))208 1695 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1794 y Fr(Encode)g(a)h(Unicode)g
(objects)g(using)g(UTF-8)g(and)g(return)f(the)h(result)h(as)g(Python)e
(string)h(object.)28 b(Error)21 b(handling)e(is)j(\223strict\224.)208
1894 y(Return)d Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 2041 y(These)g(are)g(the)g(UTF-16)g(codec)f(APIs:)
0 2188 y Fj(PyObject)400 2203 y(*)498 2188 y Fg(PyUnicode_DecodeUTF16)p
Fj(\()p Fo(const)d(c)o(har)k(*s,)g(Py)p 2170 2188 V 30
w(ssize)p 2356 2188 V 30 w(t)h(size)o(,)g(const)f(c)o(har)g(*err)l(or)o
(s,)h(int)f(*byteor)m(der)r Fj(\))208 2287 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2387 y Fr(Decode)f
Fo(length)h Fr(bytes)g(from)g(a)h(UTF-16)f(encoded)e(b)n(uf)n(fer)i
(string)g(and)g(return)f(the)i(corresponding)c(Unicode)i(object.)26
b Fo(err)l(or)o(s)208 2487 y Fr(\(if)20 b(non-)p Fj(NULL)p
Fr(\))e(de\002nes)h(the)i(error)e(handling.)k(It)d(def)o(aults)g(to)g
(\223strict\224.)208 2620 y(If)g Fo(byteor)m(der)h Fr(is)g(non-)p
Fj(NULL)p Fr(,)d(the)i(decoder)f(starts)i(decoding)d(using)i(the)g(gi)n
(v)o(en)f(byte)g(order:)578 2857 y Fk(*)623 2844 y(byteorder)43
b(==)i(-1:)f(little)g(endian)578 2948 y(*)623 2935 y(byteorder)f(==)i
(0:)89 b(native)44 b(order)578 3039 y(*)623 3026 y(byteorder)f(==)i(1:)
89 b(big)45 b(endian)208 3216 y Fr(and)25 b(then)g(switches)h(if)g(the)
g(\002rst)h(tw)o(o)f(bytes)f(of)h(the)g(input)f(data)g(are)h(a)g(byte)f
(order)g(mark)g(\(BOM\))h(and)f(the)h(speci\002ed)f(byte)208
3315 y(order)18 b(is)i(nati)n(v)o(e)f(order)-5 b(.)24
b(This)19 b(BOM)h(is)h(not)e(copied)f(into)h(the)h(resulting)e(Unicode)
g(string.)25 b(After)19 b(completion,)e Fo(*byteor)m(der)k
Fr(is)208 3415 y(set)g(to)f(the)g(current)f(byte)h(order)f(at)h(the.)
208 3548 y(If)g Fo(byteor)m(der)h Fr(is)g Fj(NULL)p Fr(,)f(the)g(codec)
f(starts)i(in)g(nati)n(v)o(e)e(order)g(mode.)208 3681
y(Return)g Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f(by)g
(the)g(codec.)0 3828 y Fj(PyObject)400 3843 y(*)498 3828
y Fg(PyUnicode_DecodeUTF16Stateful)p Fj(\()p Fo(con)o(st)c(c)o(har)k
(*s,)g(Py)p 2569 3828 V 30 w(ssize)p 2755 3828 V 30 w(t)h(size)o(,)h
(const)e(c)o(har)g(*err)l(or)o(s,)h(int)f(*by-)1998 3927
y(teor)m(der)-9 b(,)14 b(Py)p 2359 3927 V 30 w(ssize)p
2545 3927 V 30 w(t)21 b(*consumed)r Fj(\))208 4011 y
Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208
4110 y Fr(If)58 b Fo(consumed)i Fr(is)f Fj(NULL)p Fr(,)g(beha)n(v)o(e)e
(lik)o(e)i Fj(PyUnicode_DecodeUTF16\(\))p Fr(.)137 b(If)58
b Fo(consumed)i Fr(is)g(not)e Fj(NULL)p Fr(,)208 4210
y Fj(PyUnicode_DecodeUTF16Stateful\(\))19 b Fr(will)26
b(not)f(treat)g(trailing)f(incomplete)g(UTF-16)g(byte)g(sequences)g
(\(such)208 4309 y(as)19 b(an)h(odd)e(number)f(of)i(bytes)g(or)g(a)g
(split)h(surrogate)d(pair\))i(as)h(an)f(error)-5 b(.)24
b(Those)18 b(bytes)h(will)h(not)f(be)g(decoded)f(and)g(the)h(number)208
4409 y(of)g(bytes)h(that)h(ha)n(v)o(e)e(been)h(decoded)e(will)j(be)f
(stored)g(in)g Fo(consumed)r Fr(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)d
(2.4.)0 4556 y Fj(PyObject)400 4571 y(*)498 4556 y Fg
(PyUnicode_EncodeUTF16)p Fj(\()p Fo(const)j(Py)p 1888
4556 V 29 w(UNICODE)26 b(*s,)g(Py)p 2521 4556 V 29 w(ssize)p
2706 4556 V 31 w(t)g(size)o(,)h(const)e(c)o(har)f(*err)l(or)o(s,)j(int)
e(byte-)1598 4656 y(or)m(der)r Fj(\))208 4731 y Fo(Return)19
b(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 4830
y Fr(Return)f(a)h(Python)e(string)h(object)g(holding)f(the)i(UTF-16)f
(encoded)e(v)n(alue)i(of)h(the)f(Unicode)g(data)g(in)h
Fo(s)p Fr(.)25 b(If)20 b Fo(byteor)m(der)h Fr(is)f(not)f
Fj(0)p Fr(,)208 4930 y(output)g(is)i(written)f(according)e(to)i(the)g
(follo)n(wing)f(byte)h(order:)578 5063 y Fk(byteorder)44
b(==)g(-1:)g(little)g(endian)578 5154 y(byteorder)g(==)g(0:)89
b(native)44 b(byte)g(order)g(\(writes)g(a)h(BOM)f(mark\))578
5246 y(byteorder)g(==)g(1:)89 b(big)45 b(endian)p 0 5549
3901 4 v 0 5649 a Fn(7.3.)52 b(Sequence)24 b(Objects)2939
b(59)p eop end
%%Page: 60 66
TeXDict begin 60 65 bop 208 83 a Fr(If)23 b(byteorder)f(is)i
Fj(0)p Fr(,)h(the)f(output)e(string)i(will)g(al)o(w)o(ays)g(start)g
(with)g(the)g(Unicode)f(BOM)h(mark)f(\(U+FEFF\).)g(In)h(the)f(other)g
(tw)o(o)208 183 y(modes,)c(no)h(BOM)g(mark)g(is)h(prepended.)208
315 y(If)i Fo(Py)p 380 315 25 4 v 29 w(UNICODE)p 778
315 V 30 w(WIDE)i Fr(is)f(de\002ned,)f(a)g(single)g Fj(Py_UNICODE)f
Fr(v)n(alue)h(may)g(get)g(represented)e(as)j(a)g(surrogate)d(pair)-5
b(.)34 b(If)23 b(it)208 415 y(is)e(not)f(de\002ned,)e(each)i
Fj(Py_UNICODE)f Fr(v)n(alues)h(is)h(interpreted)e(as)h(an)h(UCS-2)f
(character)-5 b(.)208 548 y(Return)19 b Fj(NULL)h Fr(if)h(an)f(e)o
(xception)e(w)o(as)j(raised)f(by)g(the)g(codec.)0 695
y Fj(PyObject)400 710 y(*)498 695 y Fg(PyUnicode_AsUTF16String)p
Fj(\()p Fo(PyObject)15 b(*unicode)p Fj(\))208 794 y Fo(Return)k(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 894 y Fr(Return)j(a)i(Python)e
(string)h(using)f(the)h(UTF-16)g(encoding)e(in)i(nati)n(v)o(e)f(byte)h
(order)-5 b(.)36 b(The)24 b(string)f(al)o(w)o(ays)i(starts)g(with)f(a)h
(BOM)208 994 y(mark.)f(Error)19 b(handling)f(is)j(\223strict\224.)k
(Return)20 b Fj(NULL)g Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 1141 y(These)g(are)g(the)g(\223Unicode)f
(Escape\224)h(codec)f(APIs:)0 1287 y Fj(PyObject)400
1302 y(*)498 1287 y Fg(PyUnicode_DecodeUnicodeEscape)p
Fj(\()p Fo(con)o(st)d(c)o(har)j(*s,)i(Py)p 2569 1287
V 29 w(ssize)p 2754 1287 V 31 w(t)g(size)o(,)g(const)f(c)o(har)f(*err)l
(or)o(s)p Fj(\))208 1387 y Fo(Return)g(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 1487 y Fr(Create)26 b(a)h(Unicode)f(object)g
(by)g(decoding)f Fo(size)i Fr(bytes)g(of)f(the)h(Unicode-Escape)d
(encoded)h(string)h Fo(s)p Fr(.)45 b(Return)26 b Fj(NULL)h
Fr(if)g(an)208 1586 y(e)o(xception)18 b(w)o(as)j(raised)f(by)g(the)g
(codec.)0 1733 y Fj(PyObject)400 1748 y(*)498 1733 y
Fg(PyUnicode_EncodeUnicodeEscape)p Fj(\()p Fo(con)o(st)c(Py)p
2282 1733 V 29 w(UNICODE)21 b(*s,)f(Py)p 2904 1733 V
30 w(ssize)p 3090 1733 V 30 w(t)h(size)p Fj(\))208 1833
y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1932 y Fr(Encode)27 b(the)h Fj(Py_UNICODE)f
Fr(b)n(uf)n(fer)h(of)g(the)h(gi)n(v)o(en)e(size)i(using)f
(Unicode-Escape)e(and)i(return)g(a)h(Python)e(string)h(object.)208
2032 y(Return)19 b Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j
(raised)f(by)g(the)g(codec.)0 2179 y Fj(PyObject)400
2194 y(*)498 2179 y Fg(PyUnicode_AsUnicodeEscapeString)p
Fj(\()p Fo(PyOb)o(ject)15 b(*unicode)p Fj(\))208 2279
y Fo(Return)k(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2378 y Fr(Encode)d(a)j(Unicode)e(objects)h(using)g
(Unicode-Escape)e(and)i(return)f(the)h(result)h(as)g(Python)e(string)h
(object.)24 b(Error)18 b(handling)g(is)208 2478 y(\223strict\224.)25
b(Return)20 b Fj(NULL)g Fr(if)g(an)g(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 2625 y(These)g(are)g(the)g(\223Ra)o(w)h(Unicode)e
(Escape\224)h(codec)f(APIs:)0 2772 y Fj(PyObject)400
2787 y(*)498 2772 y Fg(PyUnicode_DecodeRawUnicodeEscape)p
Fj(\()p Fo(co)o(nst)c(c)o(har)20 b(*s,)g(Py)p 2718 2772
V 29 w(ssize)p 2903 2772 V 31 w(t)h(size)o(,)g(const)f(c)o(har)g(*err)l
(or)o(s)p Fj(\))208 2871 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 2971 y Fr(Create)i(a)h(Unicode)f(object)g(by)
g(decoding)e Fo(size)k Fr(bytes)e(of)h(the)f(Ra)o(w-Unicode-Escape)e
(encoded)h(string)h Fo(s)p Fr(.)33 b(Return)22 b Fj(NULL)g
Fr(if)208 3070 y(an)e(e)o(xception)e(w)o(as)j(raised)f(by)g(the)g
(codec.)0 3217 y Fj(PyObject)400 3232 y(*)498 3217 y
Fg(PyUnicode_EncodeRawUnicodeEscape)p Fj(\()p Fo(co)o(nst)27
b(Py)p 2443 3217 V 30 w(UNICODE)33 b(*s,)i(Py)p 3093
3217 V 30 w(ssize)p 3279 3217 V 30 w(t)e(size)o(,)k(const)32
b(c)o(har)2148 3317 y(*)o(err)l(or)o(s)p Fj(\))208 3392
y Fo(Return)19 b(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3492 y Fr(Encode)15 b(the)h Fj(Py_UNICODE)g
Fr(b)n(uf)n(fer)f(of)h(the)h(gi)n(v)o(en)f(size)h(using)f(Ra)o
(w-Unicode-Escape)e(and)i(return)f(a)i(Python)f(string)g(object.)208
3591 y(Return)j Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 3738 y Fj(PyObject)400 3753 y(*)498
3738 y Fg(PyUnicode_AsRawUnicodeEscapeString)p Fj(\()p
Fo(P)o(yObjec)o(t)15 b(*unicode)p Fj(\))208 3838 y Fo(Return)k(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 3938 y Fr(Encode)31
b(a)h(Unicode)g(objects)g(using)g(Ra)o(w-Unicode-Escape)d(and)j(return)
f(the)i(result)f(as)h(Python)f(string)g(object.)61 b(Error)208
4037 y(handling)18 b(is)j(\223strict\224.)k(Return)20
b Fj(NULL)g Fr(if)g(an)h(e)o(xception)d(w)o(as)j(raised)f(by)g(the)g
(codec.)0 4184 y(These)j(are)f(the)h(Latin-1)f(codec)g(APIs:)31
b(Latin-1)22 b(corresponds)e(to)j(the)g(\002rst)g(256)f(Unicode)g
(ordinals)g(and)g(only)g(these)h(are)g(accepted)0 4284
y(by)d(the)g(codecs)g(during)e(encoding.)0 4431 y Fj(PyObject)400
4446 y(*)498 4431 y Fg(PyUnicode_DecodeLatin1)p Fj(\()p
Fo(const)e(c)o(har)k(*s,)g(Py)p 2220 4431 V 29 w(ssize)p
2405 4431 V 31 w(t)h(size)o(,)g(const)f(c)o(har)g(*err)l(or)o(s)p
Fj(\))208 4530 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4630 y Fr(Create)k(a)h(Unicode)e(object)g(by)h(decoding)e
Fo(size)j Fr(bytes)f(of)g(the)g(Latin-1)f(encoded)g(string)h
Fo(s)p Fr(.)37 b(Return)24 b Fj(NULL)g Fr(if)g(an)g(e)o(xception)208
4729 y(w)o(as)d(raised)f(by)f(the)i(codec.)0 4876 y Fj(PyObject)400
4891 y(*)498 4876 y Fg(PyUnicode_EncodeLatin1)p Fj(\()p
Fo(const)16 b(Py)p 1933 4876 V 29 w(UNICODE)21 b(*s,)f(Py)p
2555 4876 V 30 w(ssize)p 2741 4876 V 31 w(t)g(size)o(,)i(const)e(c)o
(har)f(*err)l(or)o(s)p Fj(\))208 4976 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5076 y Fr(Encode)15
b(the)j Fj(Py_UNICODE)e Fr(b)n(uf)n(fer)g(of)h(the)g(gi)n(v)o(en)f
(size)i(using)f(Latin-1)f(and)h(return)f(a)i(Python)e(string)h(object.)
24 b(Return)17 b Fj(NULL)208 5175 y Fr(if)j(an)g(e)o(xception)e(w)o(as)
j(raised)f(by)g(the)g(codec.)0 5322 y Fj(PyObject)400
5337 y(*)498 5322 y Fg(PyUnicode_AsLatin1String)p Fj(\()p
Fo(PyObject)15 b(*unicode)p Fj(\))p 0 5549 3901 4 v 0
5649 a Fn(60)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 61 67
TeXDict begin 61 66 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(Encode)f(a)h(Unicode)g
(objects)g(using)g(Latin-1)f(and)h(return)g(the)g(result)g(as)i(Python)
d(string)h(object.)25 b(Error)19 b(handling)g(is)i(\223strict\224.)208
282 y(Return)e Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 429 y(These)g(are)g(the)i Fi(A)t(S)t(C)t(I)t(I)i
Fr(codec)19 b(APIs.)26 b(Only)20 b(7-bit)h Fi(A)t(S)t(C)t(I)t(I)j
Fr(data)c(is)h(accepted.)j(All)d(other)e(codes)h(generate)f(errors.)0
576 y Fj(PyObject)400 591 y(*)498 576 y Fg(PyUnicode_DecodeASCII)p
Fj(\()p Fo(const)d(c)o(har)k(*s,)g(Py)p 2170 576 25 4
v 30 w(ssize)p 2356 576 V 30 w(t)h(size)o(,)g(const)f(c)o(har)g(*err)l
(or)o(s)p Fj(\))208 676 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 775 y Fr(Create)f(a)h(Unicode)d(object)i(by)g
(decoding)e Fo(size)j Fr(bytes)f(of)g(the)i Fi(A)t(S)t(C)t(I)t(I)i
Fr(encoded)17 b(string)i Fo(s)p Fr(.)25 b(Return)19 b
Fj(NULL)g Fr(if)g(an)g(e)o(xception)f(w)o(as)208 875
y(raised)i(by)f(the)i(codec.)0 1022 y Fj(PyObject)400
1037 y(*)498 1022 y Fg(PyUnicode_EncodeASCII)p Fj(\()p
Fo(const)16 b(Py)p 1883 1022 V 30 w(UNICODE)k(*s,)h(Py)p
2506 1022 V 29 w(ssize)p 2691 1022 V 31 w(t)g(size)o(,)g(const)f(c)o
(har)f(*err)l(or)o(s)p Fj(\))208 1121 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1221 y Fr(Encode)f(the)h
Fj(Py_UNICODE)f Fr(b)n(uf)n(fer)g(of)h(the)h(gi)n(v)o(en)e(size)i
(using)h Fi(A)t(S)t(C)t(I)t(I)i Fr(and)19 b(return)h(a)g(Python)g
(string)g(object.)25 b(Return)20 b Fj(NULL)208 1321 y
Fr(if)g(an)g(e)o(xception)e(w)o(as)j(raised)f(by)g(the)g(codec.)0
1468 y Fj(PyObject)400 1483 y(*)498 1468 y Fg(PyUnicode_AsASCIIString)p
Fj(\()p Fo(PyObject)15 b(*unicode)p Fj(\))208 1567 y
Fo(Return)k(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208
1667 y Fr(Encode)h(a)j(Unicode)e(objects)h(using)h Fi(A)t(S)t(C)t(I)t
(I)j Fr(and)22 b(return)g(the)h(result)h(as)f(Python)f(string)h
(object.)33 b(Error)22 b(handling)f(is)j(\223strict\224.)208
1766 y(Return)19 b Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j
(raised)f(by)g(the)g(codec.)0 1913 y(These)g(are)g(the)g(mapping)f
(codec)g(APIs:)0 2060 y(This)24 b(codec)e(is)j(special)e(in)h(that)f
(it)i(can)e(be)g(used)g(to)h(implement)e(man)o(y)g(dif)n(ferent)g
(codecs)h(\(and)g(this)h(is)g(in)g(f)o(act)f(what)h(w)o(as)g(done)e(to)
0 2160 y(obtain)j(most)g(of)g(the)g(standard)g(codecs)g(included)e(in)j
(the)f Fj(encodings)g Fr(package\).)38 b(The)25 b(codec)g(uses)h
(mapping)d(to)j(encode)e(and)0 2259 y(decode)19 b(characters.)0
2406 y(Decoding)25 b(mappings)g(must)i(map)f(single)h(string)f
(characters)g(to)g(single)h(Unicode)e(characters,)i(inte)o(gers)f
(\(which)g(are)h(then)f(inter)n(-)0 2506 y(preted)19
b(as)i(Unicode)e(ordinals\))g(or)h(None)g(\(meaning)e(\224unde\002ned)g
(mapping\224)g(and)i(causing)f(an)h(error\).)0 2653 y(Encoding)25
b(mappings)g(must)i(map)g(single)f(Unicode)g(characters)g(to)h(single)g
(string)g(characters,)g(inte)o(gers)f(\(which)g(are)h(then)g(inter)n(-)
0 2752 y(preted)19 b(as)i(Latin-1)e(ordinals\))g(or)h(None)g(\(meaning)
e(\224unde\002ned)g(mapping\224)g(and)i(causing)f(an)h(error\).)0
2899 y(The)g(mapping)e(objects)i(pro)o(vided)e(must)i(only)f(support)g
(the)p 1779 2899 V 1809 2899 V 80 w(getitem)p 2089 2899
V 2118 2899 V 80 w(mapping)f(interf)o(ace.)0 3046 y(If)28
b(a)h(character)e(lookup)g(f)o(ails)i(with)f(a)h(LookupError)m(,)d(the)
i(character)f(is)j(copied)d(as-is)i(meaning)e(that)h(its)i(ordinal)d(v)
n(alue)h(will)h(be)0 3146 y(interpreted)18 b(as)j(Unicode)e(or)h
(Latin-1)g(ordinal)f(resp.)24 b(Because)d(of)f(this,)g(mappings)f(only)
g(need)h(to)g(contain)f(those)h(mappings)f(which)0 3245
y(map)h(characters)f(to)h(dif)n(ferent)f(code)g(points.)0
3392 y Fj(PyObject)400 3407 y(*)498 3392 y Fg(PyUnicode_DecodeCharmap)p
Fj(\()p Fo(const)d(c)o(har)k(*s,)h(Py)p 2271 3392 V 29
w(ssize)p 2456 3392 V 31 w(t)g(size)o(,)h(PyObject)e(*mapping)o(,)e
(const)i(c)o(har)g(*er)n(-)1698 3492 y(r)l(or)o(s)p Fj(\))208
3567 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3667 y Fr(Create)h(a)g(Unicode)f(object)h(by)f(decoding)f
Fo(size)k Fr(bytes)e(of)f(the)h(encoded)f(string)g Fo(s)i
Fr(using)f(the)g(gi)n(v)o(en)f Fo(mapping)f Fr(object.)27
b(Return)208 3766 y Fj(NULL)c Fr(if)g(an)h(e)o(xception)d(w)o(as)j
(raised)g(by)f(the)g(codec.)34 b(If)23 b Fo(mapping)e
Fr(is)k Fj(NULL)e Fr(latin-1)g(decoding)e(will)j(be)f(done.)34
b(Else)24 b(it)g(can)208 3866 y(be)h(a)g(dictionary)e(mapping)h(byte)g
(or)h(a)h(unicode)d(string,)j(which)e(is)i(treated)f(as)h(a)f(lookup)f
(table.)39 b(Byte)26 b(v)n(alues)e(greater)g(that)208
3966 y(the)c(length)f(of)g(the)h(string)g(and)f(U+FFFE)i
(\224characters\224)d(are)i(treated)g(as)g(\224unde\002ned)e
(mapping\224.)49 b(Changed)18 b(in)i(v)o(ersion)f(2.4:)208
4065 y(Allo)n(wed)g(unicode)g(string)h(as)h(mapping)d(ar)o(gument.)0
4212 y Fj(PyObject)400 4227 y(*)498 4212 y Fg(PyUnicode_EncodeCharmap)p
Fj(\()p Fo(const)d(Py)p 1982 4212 V 30 w(UNICODE)20 b(*s,)g(Py)p
2604 4212 V 29 w(ssize)p 2789 4212 V 31 w(t)g(size)o(,)h(PyObject)e
(*mapping)o(,)f(const)1698 4312 y(c)o(har)d(*err)l(or)o(s)p
Fj(\))208 4387 y Fo(Return)k(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4487 y Fr(Encode)j(the)h Fj(Py_UNICODE)g Fr(b)n(uf)n(fer)f(of)
h(the)h(gi)n(v)o(en)e(size)j(using)e(the)h(gi)n(v)o(en)e
Fo(mapping)g Fr(object)h(and)g(return)f(a)i(Python)f(string)208
4586 y(object.)g(Return)c Fj(NULL)g Fr(if)g(an)g(e)o(xception)f(w)o(as)
i(raised)f(by)f(the)i(codec.)0 4733 y Fj(PyObject)400
4748 y(*)498 4733 y Fg(PyUnicode_AsCharmapString)p Fj(\()p
Fo(PyObject)15 b(*unicode)o(,)j(PyObject)i(*mapping)p
Fj(\))208 4833 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4932 y Fr(Encode)i(a)j(Unicode)f(objects)g(using)g(the)g(gi)n
(v)o(en)f Fo(mapping)g Fr(object)g(and)h(return)g(the)g(result)g(as)h
(Python)f(string)g(object.)37 b(Error)208 5032 y(handling)18
b(is)j(\223strict\224.)k(Return)20 b Fj(NULL)g Fr(if)g(an)h(e)o
(xception)d(w)o(as)j(raised)f(by)g(the)g(codec.)0 5179
y(The)g(follo)n(wing)e(codec)i(API)g(is)h(special)g(in)f(that)g(maps)g
(Unicode)f(to)i(Unicode.)0 5326 y Fj(PyObject)400 5341
y(*)498 5326 y Fg(PyUnicode_TranslateCharmap)p Fj(\()p
Fo(const)11 b(Py)p 2128 5326 V 29 w(UNICODE)17 b(*s,)f(Py)p
2742 5326 V 30 w(ssize)p 2928 5326 V 31 w(t)g(size)o(,)i(PyObject)d
(*table)o(,)h(const)1848 5425 y(c)o(har)f(*err)l(or)o(s)p
Fj(\))p 0 5549 3901 4 v 0 5649 a Fn(7.3.)52 b(Sequence)24
b(Objects)2939 b(61)p eop end
%%Page: 62 68
TeXDict begin 62 67 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(T)m(ranslate)g(a)i
Fj(Py_UNICODE)e Fr(b)n(uf)n(fer)g(of)h(the)g(gi)n(v)o(en)f(length)g(by)
h(applying)e(a)j(character)e(mapping)f Fo(table)i Fr(to)g(it)h(and)f
(return)f(the)208 282 y(resulting)f(Unicode)g(object.)24
b(Return)c Fj(NULL)g Fr(when)g(an)g(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)208 412 y(The)f Fo(mapping)e Fr(table)i(must)h(map)f
(Unicode)f(ordinal)g(inte)o(gers)h(to)g(Unicode)g(ordinal)f(inte)o
(gers)g(or)h(None)g(\(causing)f(deletion)h(of)208 512
y(the)h(character\).)208 642 y(Mapping)30 b(tables)j(need)f(only)g(pro)
o(vide)e(the)j Fj(__getitem__\(\))d Fr(interf)o(ace;)38
b(dictionaries)32 b(and)g(sequences)f(w)o(ork)h(well.)208
742 y(Unmapped)18 b(character)h(ordinals)g(\(ones)g(which)h(cause)g(a)h
Fj(LookupError)p Fr(\))d(are)i(left)h(untouched)c(and)j(are)g(copied)f
(as-is.)0 889 y(These)f(are)h(the)g(MBCS)h(codec)d(APIs.)25
b(The)o(y)18 b(are)g(currently)f(only)h(a)n(v)n(ailable)g(on)g(W)m
(indo)n(ws)g(and)h(use)f(the)h(W)m(in32)f(MBCS)i(con)m(v)o(erters)0
988 y(to)i(implement)e(the)i(con)m(v)o(ersions.)27 b(Note)22
b(that)g(MBCS)h(\(or)e(DBCS\))i(is)f(a)h(class)f(of)g(encodings,)e(not)
h(just)h(one.)29 b(The)22 b(tar)o(get)f(encoding)0 1088
y(is)g(de\002ned)e(by)h(the)g(user)g(settings)h(on)f(the)g(machine)f
(running)f(the)i(codec.)0 1235 y Fj(PyObject)400 1250
y(*)498 1235 y Fg(PyUnicode_DecodeMBCS)p Fj(\()p Fo(const)c(c)o(har)k
(*s,)g(Py)p 2120 1235 25 4 v 30 w(ssize)p 2306 1235 V
30 w(t)h(size)o(,)g(const)f(c)o(har)g(*err)l(or)o(s)p
Fj(\))208 1335 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1434 y Fr(Create)25 b(a)g(Unicode)f(object)g(by)g(decoding)f
Fo(size)j Fr(bytes)f(of)f(the)h(MBCS)h(encoded)d(string)i
Fo(s)p Fr(.)40 b(Return)24 b Fj(NULL)h Fr(if)g(an)f(e)o(xception)208
1534 y(w)o(as)d(raised)f(by)f(the)i(codec.)0 1681 y Fj(PyObject)400
1696 y(*)498 1681 y Fg(PyUnicode_DecodeMBCSStateful)p
Fj(\()p Fo(const)15 b(c)o(har)k(*s,)i(int)f(size)o(,)h(const)f(c)o(har)
g(*err)l(or)o(s,)h(int)g(*consumed)r Fj(\))208 1780 y
Fr(If)d Fo(consumed)h Fr(is)h Fj(NULL)p Fr(,)e(beha)n(v)o(e)g(lik)o(e)g
Fj(PyUnicode_DecodeMBCS\(\))p Fr(.)j(If)e Fo(consumed)g
Fr(is)h(not)e Fj(NULL)p Fr(,)g Fj(PyUnicode_-)208 1880
y(DecodeMBCSStateful\(\))c Fr(will)k(not)g(decode)e(trailing)h(lead)h
(byte)f(and)g(the)h(number)e(of)h(bytes)h(that)f(ha)n(v)o(e)g(been)g
(decoded)208 1980 y(will)j(be)h(stored)e(in)i Fo(consumed)r
Fr(.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.5.)0 2126 y
Fj(PyObject)400 2141 y(*)498 2126 y Fg(PyUnicode_EncodeMBCS)p
Fj(\()p Fo(const)d(Py)p 1833 2126 V 30 w(UNICODE)k(*s,)h(Py)p
2456 2126 V 29 w(ssize)p 2641 2126 V 31 w(t)g(size)o(,)g(const)f(c)o
(har)g(*err)l(or)o(s)p Fj(\))208 2226 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2326 y Fr(Encode)c(the)i
Fj(Py_UNICODE)f Fr(b)n(uf)n(fer)g(of)h(the)g(gi)n(v)o(en)f(size)i
(using)f(MBCS)h(and)f(return)f(a)h(Python)f(string)h(object.)24
b(Return)18 b Fj(NULL)208 2425 y Fr(if)i(an)g(e)o(xception)e(w)o(as)j
(raised)f(by)g(the)g(codec.)0 2572 y Fj(PyObject)400
2587 y(*)498 2572 y Fg(PyUnicode_AsMBCSString)p Fj(\()p
Fo(PyObject)c(*unicode)p Fj(\))208 2672 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2771 y Fr(Encode)f(a)j(Unicode)e
(objects)h(using)f(MBCS)j(and)e(return)f(the)h(result)g(as)h(Python)e
(string)h(object.)27 b(Error)20 b(handling)f(is)j(\223strict\224.)208
2871 y(Return)d Fj(NULL)h Fr(if)h(an)f(e)o(xception)e(w)o(as)j(raised)f
(by)g(the)g(codec.)0 3137 y Fn(Methods)j(and)h(Slot)g(Functions)0
3340 y Fr(The)g(follo)n(wing)e(APIs)i(are)g(capable)f(of)h(handling)e
(Unicode)h(objects)g(and)h(strings)g(on)f(input)g(\(we)h(refer)f(to)h
(them)g(as)h(strings)e(in)i(the)0 3440 y(descriptions\))19
b(and)g(return)g(Unicode)g(objects)h(or)g(inte)o(gers)g(as)g
(appropriate.)0 3586 y(The)o(y)f(all)i(return)e Fj(NULL)h
Fr(or)g Fj(-1)g Fr(if)h(an)f(e)o(xception)e(occurs.)0
3733 y Fj(PyObject)400 3748 y(*)498 3733 y Fg(PyUnicode_Concat)p
Fj(\()p Fo(PyObject)f(*left,)j(PyObject)f(*right)q Fj(\))208
3833 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3933 y Fr(Concat)g(tw)o(o)g(strings)g(gi)n(ving)f(a)i(ne)n(w)f
(Unicode)f(string.)0 4079 y Fj(PyObject)400 4094 y(*)498
4079 y Fg(PyUnicode_Split)p Fj(\()p Fo(PyObject)e(*s,)j(PyObject)g
(*sep,)g(Py)p 2357 4079 V 29 w(ssize)p 2542 4079 V 31
w(t)h(maxsplit)q Fj(\))208 4179 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4279 y Fr(Split)g(a)g(string)g
(gi)n(ving)f(a)h(list)h(of)f(Unicode)f(strings.)25 b(If)20
b(sep)g(is)h Fj(NULL)p Fr(,)e(splitting)h(will)h(be)f(done)f(at)h(all)h
(whitespace)f(substrings.)208 4378 y(Otherwise,)i(splits)h(occur)e(at)i
(the)g(gi)n(v)o(en)e(separator)-5 b(.)30 b(At)23 b(most)g
Fo(maxsplit)g Fr(splits)h(will)f(be)f(done.)30 b(If)23
b(ne)o(gati)n(v)o(e,)d(no)i(limit)h(is)g(set.)208 4478
y(Separators)c(are)h(not)g(included)e(in)j(the)f(resulting)f(list.)0
4625 y Fj(PyObject)400 4640 y(*)498 4625 y Fg(PyUnicode_Splitlines)p
Fj(\()p Fo(PyObject)d(*s,)k(int)h(k)o(eepend)r Fj(\))208
4724 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4824 y Fr(Split)28 b(a)g(Unicode)f(string)g(at)h(line)g
(breaks,)h(returning)d(a)i(list)h(of)e(Unicode)g(strings.)48
b(CRLF)29 b(is)g(considered)d(to)h(be)h(one)f(line)208
4924 y(break.)c(If)d Fo(k)o(eepend)i Fr(is)f(0,)f(the)g(Line)g(break)f
(characters)g(are)h(not)g(included)f(in)h(the)h(resulting)e(strings.)0
5071 y Fj(PyObject)400 5086 y(*)498 5071 y Fg(PyUnicode_Translate)p
Fj(\()p Fo(PyObject)d(*str)-9 b(,)21 b(PyObject)e(*table)o(,)g(const)h
(c)o(har)g(*err)l(or)o(s)p Fj(\))208 5170 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5270 y Fr(T)m(ranslate)f(a)i
(string)f(by)g(applying)e(a)j(character)d(mapping)h(table)h(to)g(it)h
(and)f(return)f(the)h(resulting)f(Unicode)g(object.)208
5400 y(The)g(mapping)e(table)i(must)h(map)f(Unicode)f(ordinal)g(inte)o
(gers)h(to)g(Unicode)g(ordinal)f(inte)o(gers)g(or)h(None)g(\(causing)f
(deletion)h(of)p 0 5549 3901 4 v 0 5649 a Fn(62)2478
b(Chapter)23 b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p
eop end
%%Page: 63 69
TeXDict begin 63 68 bop 208 83 a Fr(the)20 b(character\).)208
211 y(Mapping)30 b(tables)j(need)f(only)g(pro)o(vide)e(the)j
Fj(__getitem__\(\))d Fr(interf)o(ace;)38 b(dictionaries)32
b(and)g(sequences)f(w)o(ork)h(well.)208 311 y(Unmapped)18
b(character)h(ordinals)g(\(ones)g(which)h(cause)g(a)h
Fj(LookupError)p Fr(\))d(are)i(left)h(untouched)c(and)j(are)g(copied)f
(as-is.)208 439 y Fo(err)l(or)o(s)i Fr(has)g(the)f(usual)g(meaning)f
(for)g(codecs.)25 b(It)20 b(may)g(be)g Fj(NULL)g Fr(which)g(indicates)f
(to)i(use)f(the)g(def)o(ault)g(error)f(handling.)0 586
y Fj(PyObject)400 601 y(*)498 586 y Fg(PyUnicode_Join)p
Fj(\()p Fo(PyObject)e(*separ)o(ator)-9 b(,)18 b(PyObject)i(*seq)p
Fj(\))208 686 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 785 y Fr(Join)g(a)g(sequence)f(of)h(strings)g(using)g(the)g
(gi)n(v)o(en)f(separator)g(and)h(return)f(the)h(resulting)f(Unicode)g
(string.)0 932 y Fj(int)49 b Fg(PyUnicode_Tailmatch)p
Fj(\()p Fo(PyObject)16 b(*str)-9 b(,)21 b(PyObject)e(*substr)-9
b(,)20 b(Py)p 2386 932 25 4 v 30 w(ssize)p 2572 932 V
30 w(t)h(start,)g(Py)p 2928 932 V 29 w(ssize)p 3113 932
V 31 w(t)g(end,)e(int)i(dir)m(ection)p Fj(\))208 1032
y Fr(Return)29 b(1)i(if)f Fo(substr)j Fr(matches)c Fo(str)r
Fr([)p Fo(start)q Fr(:)p Fo(end)r Fr(])i(at)g(the)f(gi)n(v)o(en)f(tail)
h(end)g(\()p Fo(dir)m(ection)f Fr(==)i(-1)e(means)h(to)h(do)e(a)i
(pre\002x)e(match,)208 1131 y Fo(dir)m(ection)19 b Fr(==)h(1)h(a)f(suf)
n(\002x)g(match\),)f(0)h(otherwise.)25 b(Return)19 b
Fj(-1)i Fr(if)f(an)g(error)g(occurred.)0 1278 y Fj(Py_ssize_t)48
b Fg(PyUnicode_Find)p Fj(\()p Fo(PyObject)17 b(*str)-9
b(,)20 b(PyObject)g(*substr)-9 b(,)20 b(Py)p 2486 1278
V 29 w(ssize)p 2671 1278 V 31 w(t)h(start,)g(Py)p 3028
1278 V 29 w(ssize)p 3213 1278 V 31 w(t)g(end,)e(int)h(dir)m(ection)p
Fj(\))208 1378 y Fr(Return)30 b(the)h(\002rst)h(position)f(of)f
Fo(substr)k Fr(in)d Fo(str)r Fr([)p Fo(start)q Fr(:)p
Fo(end)r Fr(])h(using)e(the)h(gi)n(v)o(en)f Fo(dir)m(ection)h
Fr(\()p Fo(dir)m(ection)f Fr(==)h(1)g(means)g(to)g(do)g(a)208
1477 y(forw)o(ard)20 b(search,)i Fo(dir)m(ection)g Fr(==)g(-1)g(a)g
(backw)o(ard)f(search\).)30 b(The)22 b(return)f(v)n(alue)g(is)i(the)f
(inde)o(x)f(of)h(the)g(\002rst)h(match;)g(a)f(v)n(alue)g(of)208
1577 y Fj(-1)e Fr(indicates)g(that)g(no)g(match)g(w)o(as)h(found,)d
(and)h Fj(-2)i Fr(indicates)f(that)g(an)g(error)f(occurred)f(and)i(an)g
(e)o(xception)e(has)j(been)e(set.)0 1724 y Fj(Py_ssize_t)48
b Fg(PyUnicode_Count)p Fj(\()p Fo(PyObject)17 b(*str)-9
b(,)20 b(PyObject)g(*substr)-9 b(,)20 b(Py)p 2536 1724
V 29 w(ssize)p 2721 1724 V 31 w(t)h(start,)f(Py)p 3077
1724 V 30 w(ssize)p 3263 1724 V 31 w(t)g(end)r Fj(\))208
1824 y Fr(Return)e(the)h(number)e(of)i(non-o)o(v)o(erlapping)13
b(occurrences)k(of)i Fo(substr)i Fr(in)e Fo(str)r Fj([)p
Fo(start)q Fj(:)p Fo(end)r Fj(])p Fr(.)25 b(Return)19
b Fj(-1)g Fr(if)g(an)g(error)f(occurred.)0 1970 y Fj(PyObject)400
1985 y(*)498 1970 y Fg(PyUnicode_Replace)p Fj(\()p Fo(PyObject)e(*str)
-9 b(,)21 b(PyObject)f(*substr)-9 b(,)19 b(PyObject)h(*r)m(eplstr)-9
b(,)20 b(Py)p 3207 1970 V 30 w(ssize)p 3393 1970 V 30
w(t)h(maxcount)q Fj(\))208 2070 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2170 y Fr(Replace)28
b(at)i(most)f Fo(maxcount)g Fr(occurrences)e(of)h Fo(substr)k
Fr(in)d Fo(str)j Fr(with)d Fo(r)m(eplstr)i Fr(and)e(return)f(the)h
(resulting)f(Unicode)f(object.)208 2269 y Fo(maxcount)20
b Fr(==)g(-1)g(means)g(replace)f(all)i(occurrences.)0
2416 y Fj(int)49 b Fg(PyUnicode_Compare)p Fj(\()p Fo(PyObject)17
b(*left,)j(PyObject)f(*right)q Fj(\))208 2516 y Fr(Compare)g(tw)o(o)h
(strings)g(and)g(return)f(-1,)h(0,)g(1)g(for)f(less)j(than,)d(equal,)h
(and)f(greater)g(than,)h(respecti)n(v)o(ely)-5 b(.)0
2663 y Fj(int)49 b Fg(PyUnicode_RichCompare)p Fj(\()p
Fo(PyObject)16 b(*left,)k(PyObject)g(*right,)f(int)i(op)p
Fj(\))208 2762 y Fr(Rich)f(compare)f(tw)o(o)h(unicode)f(strings)h(and)g
(return)f(one)g(of)h(the)g(follo)n(wing:)349 2919 y Fq(\017)o
Fj(NULL)g Fr(in)h(case)f(an)g(e)o(xception)f(w)o(as)i(raised)349
3043 y Fq(\017)o Fj(Py_True)f Fr(or)g Fj(Py_False)f Fr(for)g
(successful)h(comparisons)349 3166 y Fq(\017)o Fj(Py_NotImplemented)e
Fr(in)i(case)h(the)f(type)g(combination)e(is)j(unkno)n(wn)208
3323 y(Note)32 b(that)h Fj(Py_EQ)f Fr(and)g Fj(Py_NE)g
Fr(comparisons)e(can)j(cause)f(a)h Fj(UnicodeWarning)d
Fr(in)j(case)g(the)g(con)m(v)o(ersion)c(of)k(the)208
3422 y(ar)o(guments)18 b(to)i(Unicode)f(f)o(ails)i(with)f(a)h
Fj(UnicodeDecodeError)p Fr(.)208 3551 y(Possible)f(v)n(alues)g(for)f
Fo(op)h Fr(are)g Fj(Py_GT)p Fr(,)g Fj(Py_GE)p Fr(,)g
Fj(Py_EQ)p Fr(,)f Fj(Py_NE)p Fr(,)h Fj(Py_LT)p Fr(,)f(and)h
Fj(Py_LE)p Fr(.)0 3697 y Fj(PyObject)400 3712 y(*)498
3697 y Fg(PyUnicode_Format)p Fj(\()p Fo(PyObject)d(*format,)i(PyObject)
h(*ar)m(gs)p Fj(\))208 3797 y Fo(Return)f(value:)25 b
Ff(New)20 b(ref)o(erence)p Fo(.)208 3897 y Fr(Return)g(a)h(ne)n(w)f
(string)h(object)f(from)g Fo(format)i Fr(and)e Fo(ar)m(gs)p
Fr(;)h(this)h(is)f(analogous)e(to)i Fo(format)51 b Fj(\045)e
Fo(ar)m(gs)p Fr(.)27 b(The)20 b Fo(ar)m(gs)h Fr(ar)o(gument)e(must)208
3996 y(be)h(a)g(tuple.)0 4143 y Fj(int)49 b Fg(PyUnicode_Contains)p
Fj(\()p Fo(PyObject)16 b(*container)-9 b(,)18 b(PyObject)i(*element)q
Fj(\))208 4243 y Fr(Check)f(whether)h Fo(element)h Fr(is)g(contained)e
(in)h Fo(container)h Fr(and)f(return)f(true)g(or)h(f)o(alse)h
(accordingly)-5 b(.)208 4371 y Fo(element)21 b Fr(has)f(to)h(coerce)e
(to)h(a)h(one)f(element)f(Unicode)g(string.)25 b Fj(-1)20
b Fr(is)h(returned)e(if)h(there)g(w)o(as)h(an)f(error)-5
b(.)0 4652 y Fh(7.3.3)100 b(Buff)m(er)29 b(Objects)0
4855 y Fr(Python)18 b(objects)h(implemented)f(in)h(C)h(can)f(e)o(xport)
f(a)i(group)e(of)h(functions)e(called)j(the)f(\223b)n(uf)n(fer)f
(interf)o(ace.)-6 b(\224)24 b(These)19 b(functions)f(can)h(be)0
4954 y(used)h(by)f(an)h(object)g(to)g(e)o(xpose)f(its)i(data)f(in)g(a)h
(ra)o(w)-5 b(,)19 b(byte-oriented)e(format.)24 b(Clients)d(of)f(the)g
(object)f(can)h(use)g(the)h(b)n(uf)n(fer)d(interf)o(ace)h(to)0
5054 y(access)i(the)f(object)g(data)g(directly)-5 b(,)18
b(without)i(needing)f(to)h(cop)o(y)f(it)i(\002rst.)0
5201 y(T)-7 b(w)o(o)17 b(e)o(xamples)f(of)g(objects)h(that)g(support)e
(the)i(b)n(uf)n(fer)f(interf)o(ace)g(are)g(strings)h(and)f(arrays.)24
b(The)16 b(string)h(object)f(e)o(xposes)g(the)h(character)0
5300 y(contents)j(in)g(the)h(b)n(uf)n(fer)e(interf)o(ace')-5
b(s)19 b(byte-oriented)f(form.)24 b(An)d(array)e(can)h(also)h(e)o
(xpose)e(its)j(contents,)d(b)n(ut)h(it)h(should)f(be)g(noted)f(that)0
5400 y(array)g(elements)h(may)g(be)g(multi-byte)f(v)n(alues.)p
0 5549 3901 4 v 0 5649 a Fn(7.3.)52 b(Sequence)24 b(Objects)2939
b(63)p eop end
%%Page: 64 70
TeXDict begin 64 69 bop 0 83 a Fr(An)28 b(e)o(xample)e(user)i(of)g(the)
f(b)n(uf)n(fer)g(interf)o(ace)g(is)i(the)f(\002le)g(object')-5
b(s)28 b Fj(write\(\))f Fr(method.)46 b(An)o(y)28 b(object)f(that)h
(can)f(e)o(xport)g(a)h(series)0 183 y(of)j(bytes)h(through)d(the)j(b)n
(uf)n(fer)e(interf)o(ace)h(can)g(be)h(written)f(to)h(a)g(\002le.)60
b(There)31 b(are)h(a)g(number)d(of)j(format)e(codes)i(to)f
Fj(PyArg_-)0 282 y(ParseTuple\(\))19 b Fr(that)h(operate)f(against)g
(an)i(object')-5 b(s)20 b(b)n(uf)n(fer)e(interf)o(ace,)i(returning)e
(data)i(from)f(the)h(tar)o(get)f(object.)0 429 y(More)25
b(information)d(on)j(the)g(b)n(uf)n(fer)f(interf)o(ace)g(is)i(pro)o
(vided)d(in)i(the)g(section)g(\223Buf)n(fer)f(Object)i(Structures\224)e
(\(section)g(10.7\),)h(under)0 529 y(the)20 b(description)f(for)g
Fj(PyBufferProcs)p Fr(.)0 676 y(A)i(\223b)n(uf)n(fer)d(object\224)h(is)
i(de\002ned)e(in)i(the)f(`)p Fs(b)o(uff)n(erobject.h)p
Fr(')15 b(header)j(\(included)h(by)g(`)p Fs(Python.h)p
Fr('\).)j(These)e(objects)g(look)f(v)o(ery)g(similar)h(to)0
775 y(string)d(objects)g(at)g(the)h(Python)e(programming)d(le)n(v)o
(el:)24 b(the)o(y)16 b(support)g(slicing,)h(inde)o(xing,)f
(concatenation,)f(and)h(some)h(other)g(standard)0 875
y(string)23 b(operations.)32 b(Ho)n(we)n(v)o(er)m(,)22
b(their)h(data)g(can)g(come)g(from)f(one)h(of)g(tw)o(o)g(sources:)31
b(from)22 b(a)i(block)e(of)h(memory)-5 b(,)22 b(or)h(from)f(another)0
975 y(object)e(which)f(e)o(xports)g(the)h(b)n(uf)n(fer)f(interf)o(ace.)
0 1121 y(Buf)n(fer)g(objects)g(are)h(useful)f(as)h(a)g(w)o(ay)g(to)g(e)
o(xpose)e(the)i(data)f(from)g(another)f(object')-5 b(s)20
b(b)n(uf)n(fer)e(interf)o(ace)h(to)g(the)h(Python)e(programmer)-5
b(.)0 1221 y(The)o(y)26 b(can)h(also)g(be)g(used)g(as)h(a)f(zero-cop)o
(y)e(slicing)i(mechanism.)45 b(Using)27 b(their)f(ability)h(to)h
(reference)d(a)i(block)g(of)f(memory)-5 b(,)27 b(it)h(is)0
1321 y(possible)21 b(to)h(e)o(xpose)e(an)o(y)h(data)h(to)f(the)h
(Python)e(programmer)f(quite)i(easily)-5 b(.)29 b(The)21
b(memory)f(could)h(be)g(a)h(lar)o(ge,)f(constant)g(array)f(in)i(a)0
1420 y(C)i(e)o(xtension,)e(it)i(could)e(be)h(a)g(ra)o(w)g(block)f(of)g
(memory)g(for)g(manipulation)f(before)g(passing)i(to)g(an)g(operating)e
(system)i(library)-5 b(,)22 b(or)h(it)0 1520 y(could)c(be)h(used)g(to)h
(pass)f(around)f(structured)f(data)i(in)h(its)g(nati)n(v)o(e,)e
(in-memory)f(format.)0 1667 y Fg(PyBufferObject)208 1766
y Fr(This)i(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i(b)n(uf)n
(fer)e(object.)0 1913 y Fj(PyTypeObject)48 b Fg(PyBuffer_Type)208
2013 y Fr(The)17 b(instance)h(of)g Fj(PyTypeObject)e
Fr(which)i(represents)f(the)h(Python)f(b)n(uf)n(fer)g(type;)i(it)g(is)g
(the)f(same)g(object)g(as)h Fj(buffer)e Fr(and)208 2113
y Fj(types.BufferType)g Fr(in)k(the)f(Python)f(layer)-5
b(.)25 b(.)0 2259 y Fj(int)49 b Fg(Py_END_OF_BUFFER)208
2359 y Fr(This)43 b(constant)f(may)g(be)h(passed)f(as)i(the)f
Fo(size)h Fr(parameter)d(to)i Fj(PyBuffer_FromObject\(\))c
Fr(or)k Fj(PyBuffer_-)208 2459 y(FromReadWriteObject\(\))p
Fr(.)23 b(It)e(indicates)f(that)h(the)f(ne)n(w)h Fj(PyBufferObject)e
Fr(should)g(refer)h(to)h Fo(base)f Fr(object)h(from)208
2558 y(the)26 b(speci\002ed)g Fo(of)o(fset)i Fr(to)f(the)f(end)g(of)g
(its)i(e)o(xported)c(b)n(uf)n(fer)-5 b(.)42 b(Using)27
b(this)g(enables)f(the)g(caller)h(to)f(a)n(v)n(oid)g(querying)e(the)j
Fo(base)208 2658 y Fr(object)19 b(for)h(its)h(length.)0
2805 y Fj(int)49 b Fg(PyBuffer_Check)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 2904 y Fr(Return)i(true)h(if)h(the)f(ar)o(gument)e
(has)i(type)g Fj(PyBuffer_Type)p Fr(.)0 3051 y Fj(PyObject)400
3066 y(*)498 3051 y Fg(PyBuffer_FromObject)p Fj(\()p
Fo(PyObject)c(*base)o(,)j(Py)p 2151 3051 25 4 v 30 w(ssize)p
2337 3051 V 31 w(t)h(of)o(fset,)g(Py)p 2719 3051 V 30
w(ssize)p 2905 3051 V 31 w(t)g(size)p Fj(\))208 3151
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3251 y Fr(Return)27 b(a)i(ne)n(w)f(read-only)e(b)n(uf)n(fer)h
(object.)49 b(This)28 b(raises)h Fj(TypeError)e Fr(if)i
Fo(base)f Fr(doesn')o(t)f(support)g(the)h(read-only)e(b)n(uf)n(fer)208
3350 y(protocol)16 b(or)i(doesn')o(t)f(pro)o(vide)g(e)o(xactly)g(one)h
(b)n(uf)n(fer)f(se)o(gment,)h(or)g(it)h(raises)g Fj(ValueError)f
Fr(if)g Fo(of)o(fset)i Fr(is)g(less)f(than)f(zero.)24
b(The)208 3450 y(b)n(uf)n(fer)h(will)i(hold)f(a)g(reference)f(to)i(the)
f Fo(base)h Fr(object,)g(and)f(the)g(b)n(uf)n(fer')-5
b(s)26 b(contents)f(will)j(refer)d(to)i(the)f Fo(base)h
Fr(object')-5 b(s)26 b(b)n(uf)n(fer)208 3549 y(interf)o(ace,)18
b(starting)g(as)i(position)e Fo(of)o(fset)j Fr(and)d(e)o(xtending)f
(for)h Fo(size)j Fr(bytes.)j(If)19 b Fo(size)h Fr(is)g
Fj(Py_END_OF_BUFFER)p Fr(,)c(then)j(the)g(ne)n(w)208
3649 y(b)n(uf)n(fer')-5 b(s)19 b(contents)g(e)o(xtend)g(to)h(the)h
(length)e(of)h(the)g Fo(base)g Fr(object')-5 b(s)20 b(e)o(xported)e(b)n
(uf)n(fer)h(data.)0 3796 y Fj(PyObject)400 3811 y(*)498
3796 y Fg(PyBuffer_FromReadWriteObject)p Fj(\()p Fo(PyObject)14
b(*base)o(,)20 b(Py)p 2600 3796 V 29 w(ssize)p 2785 3796
V 31 w(t)h(of)o(fset,)f(Py)p 3168 3796 V 29 w(ssize)p
3353 3796 V 31 w(t)h(size)p Fj(\))208 3896 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3995 y Fr(Return)38
b(a)h(ne)n(w)f(writable)g(b)n(uf)n(fer)g(object.)79 b(P)o(arameters)38
b(and)g(e)o(xceptions)f(are)i(similar)g(to)f(those)h(for)f
Fj(PyBuffer_-)208 4095 y(FromObject\(\))p Fr(.)23 b(If)d(the)g
Fo(base)g Fr(object)g(does)g(not)f(e)o(xport)g(the)h(writeable)g(b)n
(uf)n(fer)f(protocol,)f(then)i Fj(TypeError)f Fr(is)i(raised.)0
4242 y Fj(PyObject)400 4257 y(*)498 4242 y Fg(PyBuffer_FromMemory)p
Fj(\()p Fo(void)16 b(*ptr)-9 b(,)20 b(Py)p 1922 4242
V 29 w(ssize)p 2107 4242 V 31 w(t)h(size)p Fj(\))208
4341 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4441 y Fr(Return)g(a)i(ne)n(w)f(read-only)e(b)n(uf)n(fer)g
(object)i(that)g(reads)g(from)f(a)i(speci\002ed)e(location)h(in)g
(memory)-5 b(,)19 b(with)i(a)h(speci\002ed)f(size.)28
b(The)208 4541 y(caller)21 b(is)h(responsible)e(for)h(ensuring)f(that)h
(the)h(memory)e(b)n(uf)n(fer)m(,)f(passed)j(in)f(as)h
Fo(ptr)r Fr(,)g(is)g(not)f(deallocated)g(while)g(the)g(returned)208
4640 y(b)n(uf)n(fer)g(object)i(e)o(xists.)33 b(Raises)24
b Fj(ValueError)e Fr(if)h Fo(size)h Fr(is)g(less)g(than)e(zero.)33
b(Note)23 b(that)g Fj(Py_END_OF_BUFFER)d Fr(may)j Fo(not)208
4740 y Fr(be)d(passed)g(for)f(the)i Fo(size)g Fr(parameter;)e
Fj(ValueError)f Fr(will)j(be)g(raised)f(in)g(that)g(case.)0
4887 y Fj(PyObject)400 4902 y(*)498 4887 y Fg
(PyBuffer_FromReadWriteMemory)p Fj(\()p Fo(void)14 b(*ptr)-9
b(,)20 b(Py)p 2370 4887 V 30 w(ssize)p 2556 4887 V 30
w(t)h(size)p Fj(\))208 4986 y Fo(Return)e(value:)25 b
Ff(New)20 b(ref)o(erence)p Fo(.)208 5086 y Fr(Similar)g(to)g
Fj(PyBuffer_FromMemory\(\))p Fr(,)d(b)n(ut)j(the)g(returned)f(b)n(uf)n
(fer)f(is)j(writable.)0 5233 y Fj(PyObject)400 5248 y(*)498
5233 y Fg(PyBuffer_New)p Fj(\()p Fo(Py)p 1241 5233 V
27 w(ssize)p 1424 5233 V 31 w(t)g(size)p Fj(\))208 5332
y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)p 0 5549 3901 4 v 0 5649 a Fn(64)2478 b(Chapter)23
b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 65 71
TeXDict begin 65 70 bop 208 83 a Fr(Return)35 b(a)i(ne)n(w)f(writable)g
(b)n(uf)n(fer)f(object)g(that)i(maintains)e(its)j(o)n(wn)d(memory)g(b)n
(uf)n(fer)g(of)h Fo(size)h Fr(bytes.)73 b Fj(ValueError)208
183 y Fr(is)39 b(returned)f(if)h Fo(size)h Fr(is)g(not)e(zero)h(or)f
(positi)n(v)o(e.)80 b(Note)39 b(that)g(the)g(memory)e(b)n(uf)n(fer)h
(\(as)h(returned)e(by)i Fj(PyObject_-)208 282 y(AsWriteBuffer\(\))p
Fr(\))17 b(is)k(not)f(speci\002cally)g(aligned.)0 567
y Fh(7.3.4)100 b(T)-12 b(uple)29 b(Objects)0 770 y Fg(PyTupleObject)208
870 y Fr(This)20 b(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i
(Python)e(tuple)h(object.)0 1017 y Fj(PyTypeObject)48
b Fg(PyTuple_Type)208 1116 y Fr(This)35 b(instance)g(of)h
Fj(PyTypeObject)e Fr(represents)g(the)i(Python)e(tuple)i(type;)42
b(it)37 b(is)f(the)g(same)g(object)f(as)h Fj(tuple)f
Fr(and)208 1216 y Fj(types.TupleType)18 b Fr(in)i(the)g(Python)f(layer)
-5 b(..)0 1363 y Fj(int)49 b Fg(PyTuple_Check)p Fj(\()p
Fo(PyObject)17 b(*p)p Fj(\))208 1462 y Fr(Return)i(true)h(if)g
Fo(p)h Fr(is)g(a)f(tuple)g(object)g(or)f(an)i(instance)e(of)h(a)h
(subtype)e(of)h(the)g(tuple)f(type.)51 b(Changed)18 b(in)j(v)o(ersion)e
(2.2:)g(Allo)n(wed)208 1562 y(subtypes)g(to)h(be)g(accepted.)0
1709 y Fj(int)49 b Fg(PyTuple_CheckExact)p Fj(\()p Fo(PyObject)16
b(*p)p Fj(\))208 1808 y Fr(Return)j(true)h(if)h Fo(p)f
Fr(is)h(a)g(tuple)e(object,)h(b)n(ut)g(not)g(an)g(instance)g(of)g(a)g
(subtype)f(of)h(the)h(tuple)e(type.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f
(2.2.)0 1955 y Fj(PyObject)400 1970 y(*)498 1955 y Fg(PyTuple_New)p
Fj(\()p Fo(Py)p 1191 1955 25 4 v 27 w(ssize)p 1374 1955
V 31 w(t)i(len)p Fj(\))208 2055 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2155 y Fr(Return)f(a)i(ne)n(w)f
(tuple)g(object)f(of)h(size)h Fo(len)p Fr(,)f(or)g Fj(NULL)g
Fr(on)g(f)o(ailure.)0 2301 y Fj(PyObject)400 2316 y(*)498
2301 y Fg(PyTuple_Pack)p Fj(\()p Fo(Py)p 1241 2301 V
27 w(ssize)p 1424 2301 V 31 w(t)h(n,)f(...)p Fj(\))208
2401 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2501 y Fr(Return)36 b(a)i(ne)n(w)f(tuple)f(object)h(of)g(size)
h Fo(n)p Fr(,)j(or)c Fj(NULL)g Fr(on)f(f)o(ailure.)75
b(The)37 b(tuple)g(v)n(alues)g(are)g(initialized)f(to)i(the)f(subse-)
208 2600 y(quent)d Fo(n)h Fr(C)g(ar)o(guments)e(pointing)h(to)h(Python)
f(objects.)69 b(`)p Fj(PyTuple_Pack\(2,)46 b Fo(a)p Fj(,)j
Fo(b)p Fj(\))p Fr(')35 b(is)h(equi)n(v)n(alent)d(to)i(`)p
Fj(Py_-)208 2700 y(BuildValue\("\(OO\)",)46 b Fo(a)p
Fj(,)j Fo(b)p Fj(\))p Fr('.)h(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0
2847 y Fj(Py_ssize_t)48 b Fg(PyTuple_Size)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 2946 y Fr(T)-7 b(ak)o(e)20 b(a)g(pointer)f(to)i(a)f
(tuple)g(object,)g(and)f(return)g(the)h(size)h(of)f(that)g(tuple.)0
3093 y Fj(Py_ssize_t)48 b Fg(PyTuple_GET_SIZE)p Fj(\()p
Fo(PyObject)16 b(*p)p Fj(\))208 3193 y Fr(Return)j(the)i(size)f(of)g
(the)g(tuple)g Fo(p)p Fr(,)g(which)g(must)g(be)g(non-)p
Fj(NULL)e Fr(and)i(point)g(to)g(a)h(tuple;)e(no)h(error)f(checking)g
(is)i(performed.)0 3340 y Fj(PyObject)400 3355 y(*)498
3340 y Fg(PyTuple_GetItem)p Fj(\()p Fo(PyObject)c(*p,)i(Py)p
1842 3340 V 30 w(ssize)p 2028 3340 V 31 w(t)h(pos)p Fj(\))208
3439 y Fo(Return)f(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p
Fo(.)208 3539 y Fr(Return)i(the)h(object)f(at)h(position)f
Fo(pos)g Fr(in)h(the)g(tuple)f(pointed)g(to)h(by)f Fo(p)p
Fr(.)32 b(If)23 b Fo(pos)g Fr(is)g(out)g(of)f(bounds,)g(return)f
Fj(NULL)i Fr(and)f(sets)i(an)208 3639 y Fj(IndexError)18
b Fr(e)o(xception.)0 3786 y Fj(PyObject)400 3801 y(*)498
3786 y Fg(PyTuple_GET_ITEM)p Fj(\()p Fo(PyObject)f(*p,)i(Py)p
1892 3786 V 30 w(ssize)p 2078 3786 V 30 w(t)i(pos)p Fj(\))208
3885 y Fo(Return)e(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p
Fo(.)208 3985 y Fr(Lik)o(e)g Fj(PyTuple_GetItem\(\))p
Fr(,)d(b)n(ut)j(does)g(no)g(checking)e(of)i(its)h(ar)o(guments.)0
4132 y Fj(PyObject)400 4147 y(*)498 4132 y Fg(PyTuple_GetSlice)p
Fj(\()p Fo(PyObject)c(*p,)i(Py)p 1892 4132 V 30 w(ssize)p
2078 4132 V 30 w(t)i(low)-6 b(,)21 b(Py)p 2396 4132 V
29 w(ssize)p 2581 4132 V 31 w(t)g(high)p Fj(\))208 4231
y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4331 y Fr(T)-7 b(ak)o(e)20 b(a)g(slice)h(of)f(the)g(tuple)g
(pointed)f(to)h(by)g Fo(p)g Fr(from)g Fo(low)g Fr(to)h
Fo(high)e Fr(and)h(return)f(it)i(as)g(a)f(ne)n(w)g(tuple.)0
4478 y Fj(int)49 b Fg(PyTuple_SetItem)p Fj(\()p Fo(PyObject)17
b(*p,)i(Py)p 1543 4478 V 30 w(ssize)p 1729 4478 V 31
w(t)h(pos,)g(PyObject)g(*o)p Fj(\))208 4577 y Fr(Insert)27
b(a)h(reference)d(to)j(object)f Fo(o)h Fr(at)g(position)e
Fo(pos)i Fr(of)f(the)g(tuple)g(pointed)f(to)i(by)f Fo(p)p
Fr(.)47 b(Return)27 b Fj(0)h Fr(on)f(success.)47 b Fp(Note:)39
b Fr(This)208 4677 y(function)18 b(\223steals\224)j(a)g(reference)d(to)
i Fo(o)p Fr(.)0 4824 y Fj(void)49 b Fg(PyTuple_SET_ITEM)p
Fj(\()p Fo(PyObject)17 b(*p,)i(Py)p 1643 4824 V 30 w(ssize)p
1829 4824 V 30 w(t)i(pos,)f(PyObject)g(*o)p Fj(\))208
4924 y Fr(Lik)o(e)h Fj(PyTuple_SetItem\(\))p Fr(,)d(b)n(ut)k(does)f(no)
f(error)h(checking,)e(and)i(should)f Fo(only)h Fr(be)g(used)g(to)g
(\002ll)i(in)e(brand)f(ne)n(w)h(tuples.)208 5023 y Fp(Note:)j
Fr(This)c(function)f(\223steals\224)i(a)f(reference)f(to)h
Fo(o)p Fr(.)0 5170 y Fj(int)49 b Fg(_PyTuple_Resize)p
Fj(\()p Fo(PyObject)17 b(**p,)i(Py)p 1585 5170 V 29 w(ssize)p
1770 5170 V 31 w(t)i(ne)o(wsize)p Fj(\))208 5270 y Fr(Can)j(be)h(used)f
(to)g(resize)h(a)g(tuple.)37 b Fo(ne)o(wsize)25 b Fr(will)g(be)f(the)h
(ne)n(w)f(length)f(of)h(the)h(tuple.)37 b(Because)25
b(tuples)f(are)g Fo(supposed)f Fr(to)i(be)208 5369 y(immutable,)18
b(this)j(should)e(only)g(be)h(used)g(if)g(there)g(is)h(only)e(one)h
(reference)e(to)j(the)f(object.)k(Do)c Fo(not)g Fr(use)g(this)h(if)f
(the)g(tuple)g(may)p 0 5549 3901 4 v 0 5649 a Fn(7.3.)52
b(Sequence)24 b(Objects)2939 b(65)p eop end
%%Page: 66 72
TeXDict begin 66 71 bop 208 83 a Fr(already)19 b(be)h(kno)n(wn)f(to)h
(some)g(other)g(part)g(of)g(the)g(code.)25 b(The)20 b(tuple)g(will)h
(al)o(w)o(ays)g(gro)n(w)e(or)h(shrink)g(at)h(the)f(end.)25
b(Think)19 b(of)h(this)208 183 y(as)26 b(destro)o(ying)e(the)i(old)g
(tuple)f(and)h(creating)e(a)j(ne)n(w)e(one,)i(only)e(more)g(ef)n
(\002ciently)-5 b(.)41 b(Returns)26 b Fj(0)g Fr(on)f(success.)43
b(Client)26 b(code)208 282 y(should)19 b(ne)n(v)o(er)g(assume)i(that)f
(the)h(resulting)e(v)n(alue)h(of)1786 297 y Fj(*)1836
282 y Fo(p)h Fr(will)g(be)g(the)f(same)h(as)g(before)e(calling)h(this)h
(function.)j(If)d(the)f(object)208 382 y(referenced)15
b(by)676 397 y Fj(*)726 382 y Fo(p)j Fr(is)g(replaced,)e(the)h
(original)1574 397 y Fj(*)1624 382 y Fo(p)g Fr(is)i(destro)o(yed.)j(On)
17 b(f)o(ailure,)g(returns)g Fj(-1)g Fr(and)g(sets)3144
397 y Fj(*)3194 382 y Fo(p)g Fr(to)g Fj(NULL)p Fr(,)g(and)g(raises)208
482 y Fj(MemoryError)h Fr(or)i Fj(SystemError)p Fr(.)49
b(Changed)19 b(in)i(v)o(ersion)e(2.2:)g(Remo)o(v)o(ed)g(unused)g(third)
g(parameter)m(,)f Fo(last)p 3564 482 25 4 v 30 w(is)p
3649 482 V 30 w(stic)n(k)o(y)p Fr(.)0 766 y Fh(7.3.5)100
b(List)28 b(Objects)0 969 y Fg(PyListObject)208 1069
y Fr(This)20 b(subtype)f(of)h Fj(PyObject)f Fr(represents)g(a)i(Python)
e(list)i(object.)0 1216 y Fj(PyTypeObject)48 b Fg(PyList_Type)208
1315 y Fr(This)35 b(instance)f(of)h Fj(PyTypeObject)e
Fr(represents)h(the)h(Python)e(list)j(type.)69 b(This)35
b(is)h(the)f(same)g(object)f(as)h Fj(list)g Fr(and)208
1415 y Fj(types.ListType)18 b Fr(in)i(the)g(Python)f(layer)-5
b(.)0 1562 y Fj(int)49 b Fg(PyList_Check)p Fj(\()p Fo(PyObject)18
b(*p)p Fj(\))208 1662 y Fr(Return)24 b(true)h(if)g Fo(p)g
Fr(is)h(a)f(list)h(object)e(or)h(an)g(instance)f(of)h(a)g(subtype)f(of)
h(the)g(list)h(type.)78 b(Changed)24 b(in)h(v)o(ersion)f(2.2:)g(Allo)n
(wed)208 1761 y(subtypes)19 b(to)h(be)g(accepted.)0 1908
y Fj(int)49 b Fg(PyList_CheckExact)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 2008 y Fr(Return)i(true)h(if)h Fo(p)f
Fr(is)h(a)g(list)g(object,)e(b)n(ut)i(not)e(an)i(instance)e(of)h(a)h
(subtype)e(of)h(the)g(list)h(type.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f
(2.2.)0 2155 y Fj(PyObject)400 2170 y(*)498 2155 y Fg(PyList_New)p
Fj(\()p Fo(Py)p 1141 2155 V 28 w(ssize)p 1325 2155 V
30 w(t)i(len)p Fj(\))208 2254 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2354 y Fr(Return)f(a)i(ne)n(w)f
(list)h(of)f(length)f Fo(len)i Fr(on)e(success,)i(or)f
Fj(NULL)g Fr(on)g(f)o(ailure.)k Fp(Note:)g Fr(If)c Fo(length)g
Fr(is)h(greater)e(than)h(zero,)f(the)h(returned)208 2453
y(list)33 b(object')-5 b(s)33 b(items)g(are)g(set)g(to)g
Fj(NULL)p Fr(.)f(Thus)g(you)g(cannot)g(use)h(abstract)f(API)h
(functions)e(such)i(as)g Fj(PySequence_-)208 2553 y(SetItem\(\))28
b Fr(or)h(e)o(xpose)g(the)h(object)f(to)g(Python)g(code)g(before)f
(setting)i(all)g(items)g(to)g(a)g(real)g(object)f(with)g
Fj(PyList_-)208 2653 y(SetItem\(\))p Fr(.)0 2800 y Fj(Py_ssize_t)48
b Fg(PyList_Size)p Fj(\()p Fo(PyObject)17 b(*list)q Fj(\))208
2899 y Fr(Return)i(the)i(length)e(of)h(the)g(list)h(object)f(in)g
Fo(list)q Fr(;)i(this)f(is)g(equi)n(v)n(alent)d(to)j(`)p
Fj(len\()p Fo(list)q Fj(\))p Fr(')f(on)g(a)g(list)i(object.)0
3046 y Fj(Py_ssize_t)48 b Fg(PyList_GET_SIZE)p Fj(\()p
Fo(PyObject)17 b(*list)q Fj(\))208 3146 y Fr(Macro)i(form)g(of)h
Fj(PyList_Size\(\))e Fr(without)i(error)f(checking.)0
3293 y Fj(PyObject)400 3308 y(*)498 3293 y Fg(PyList_GetItem)p
Fj(\()p Fo(PyObject)e(*list,)k(Py)p 1853 3293 V 29 w(ssize)p
2038 3293 V 31 w(t)g(inde)n(x)p Fj(\))208 3392 y Fo(Return)e(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 3492
y Fr(Return)d(the)i(object)f(at)g(position)g Fo(pos)g
Fr(in)h(the)f(list)i(pointed)d(to)h(by)g Fo(p)p Fr(.)24
b(The)18 b(position)g(must)g(be)h(positi)n(v)o(e,)e(inde)o(xing)f(from)
i(the)g(end)208 3591 y(of)h(the)i(list)g(is)g(not)f(supported.)j(If)d
Fo(pos)g Fr(is)h(out)f(of)g(bounds,)e(return)h Fj(NULL)h
Fr(and)g(set)h(an)f Fj(IndexError)f Fr(e)o(xception.)0
3738 y Fj(PyObject)400 3753 y(*)498 3738 y Fg(PyList_GET_ITEM)p
Fj(\()p Fo(PyObject)e(*list,)j(Py)p 1902 3738 V 30 w(ssize)p
2088 3738 V 31 w(t)g(i)p Fj(\))208 3838 y Fo(Return)f(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 3938
y Fr(Macro)f(form)g(of)h Fj(PyList_GetItem\(\))e Fr(without)h(error)g
(checking.)0 4084 y Fj(int)49 b Fg(PyList_SetItem)p Fj(\()p
Fo(PyObject)17 b(*list,)k(Py)p 1554 4084 V 29 w(ssize)p
1739 4084 V 31 w(t)g(inde)n(x,)e(PyObject)h(*item)p Fj(\))208
4184 y Fr(Set)i(the)g(item)f(at)i(inde)o(x)d Fo(inde)n(x)i
Fr(in)g(list)g(to)g Fo(item)p Fr(.)30 b(Return)22 b Fj(0)g
Fr(on)f(success)h(or)g Fj(-1)f Fr(on)h(f)o(ailure.)29
b Fp(Note:)e Fr(This)22 b(function)e(\223steals\224)i(a)208
4284 y(reference)c(to)i Fo(item)h Fr(and)f(discards)g(a)g(reference)f
(to)h(an)g(item)h(already)e(in)h(the)g(list)h(at)g(the)f(af)n(fected)f
(position.)0 4431 y Fj(void)49 b Fg(PyList_SET_ITEM)p
Fj(\()p Fo(PyObject)17 b(*list,)j(Py)p 1653 4431 V 30
w(ssize)p 1839 4431 V 30 w(t)h(i,)g(PyObject)f(*o)p Fj(\))208
4530 y Fr(Macro)k(form)f(of)i Fj(PyList_SetItem\(\))d
Fr(without)i(error)g(checking.)36 b(This)25 b(is)h(normally)d(only)h
(used)g(to)h(\002ll)h(in)f(ne)n(w)f(lists)208 4630 y(where)g(there)h
(is)h(no)f(pre)n(vious)f(content.)39 b Fp(Note:)34 b
Fr(This)25 b(function)f(\223steals\224)i(a)g(reference)d(to)j
Fo(item)p Fr(,)g(and,)g(unlik)o(e)e Fj(PyList_-)208 4729
y(SetItem\(\))p Fr(,)e(does)g Fo(not)g Fr(discard)g(a)h(reference)e(to)
i(an)o(y)f(item)h(that)g(it)g(being)f(replaced;)h(an)o(y)f(reference)f
(in)i Fo(list)i Fr(at)e(position)f Fo(i)208 4829 y Fr(will)e(be)h(leak)
o(ed.)0 4976 y Fj(int)49 b Fg(PyList_Insert)p Fj(\()p
Fo(PyObject)17 b(*list,)k(Py)p 1504 4976 V 29 w(ssize)p
1689 4976 V 31 w(t)g(inde)n(x,)f(PyObject)f(*item)p Fj(\))208
5076 y Fr(Insert)g(the)g(item)h Fo(item)g Fr(into)f(list)i
Fo(list)h Fr(in)e(front)f(of)g(inde)o(x)f Fo(inde)n(x)p
Fr(.)25 b(Return)19 b Fj(0)h Fr(if)g(successful;)g(return)e
Fj(-1)i Fr(and)f(set)h(an)g(e)o(xception)d(if)208 5175
y(unsuccessful.)23 b(Analogous)c(to)h Fo(list)q Fj(.insert\()p
Fo(inde)n(x)p Fj(,)49 b Fo(item)p Fj(\))p Fr(.)0 5322
y Fj(int)g Fg(PyList_Append)p Fj(\()p Fo(PyObject)17
b(*list,)k(PyObject)f(*item)p Fj(\))p 0 5549 3901 4 v
0 5649 a Fn(66)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 67 73
TeXDict begin 67 72 bop 208 83 a Fr(Append)22 b(the)i(object)g
Fo(item)h Fr(at)f(the)g(end)g(of)g(list)h Fo(list)q Fr(.)38
b(Return)24 b Fj(0)h Fr(if)f(successful;)i(return)d Fj(-1)h
Fr(and)g(set)h(an)f(e)o(xception)e(if)j(unsuc-)208 183
y(cessful.)g(Analogous)18 b(to)i Fo(list)q Fj(.append\()p
Fo(item)p Fj(\))p Fr(.)0 330 y Fj(PyObject)400 345 y(*)498
330 y Fg(PyList_GetSlice)p Fj(\()p Fo(PyObject)d(*list,)j(Py)p
1902 330 25 4 v 30 w(ssize)p 2088 330 V 31 w(t)g(low)-6
b(,)21 b(Py)p 2406 330 V 29 w(ssize)p 2591 330 V 31 w(t)g(high)p
Fj(\))208 429 y Fo(Return)e(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 529 y Fr(Return)c(a)h(list)g(of)g(the)f(objects)h(in)f
Fo(list)j Fr(containing)c(the)i(objects)f Fo(between)g(low)h
Fr(and)f Fo(high)p Fr(.)23 b(Return)16 b Fj(NULL)h Fr(and)f(set)h(an)f
(e)o(xception)208 628 y(if)k(unsuccessful.)k(Analogous)18
b(to)j Fo(list)q Fj([)p Fo(low)p Fj(:)p Fo(high)p Fj(])p
Fr(.)0 775 y Fj(int)49 b Fg(PyList_SetSlice)p Fj(\()p
Fo(PyObject)17 b(*list,)j(Py)p 1603 775 V 30 w(ssize)p
1789 775 V 31 w(t)h(low)-6 b(,)20 b(Py)p 2107 775 V 29
w(ssize)p 2292 775 V 31 w(t)h(high,)e(PyObject)h(*itemlist)q
Fj(\))208 875 y Fr(Set)i(the)f(slice)h(of)f Fo(list)j
Fr(between)c Fo(low)i Fr(and)f Fo(high)f Fr(to)i(the)f(contents)g(of)g
Fo(itemlist)q Fr(.)30 b(Analogous)19 b(to)j Fo(list)q
Fj([)p Fo(low)p Fj(:)p Fo(high)p Fj(])49 b(=)g Fo(itemlist)q
Fr(.)208 975 y(The)20 b Fo(itemlist)j Fr(may)d(be)h Fj(NULL)p
Fr(,)f(indicating)g(the)g(assignment)g(of)g(an)h(empty)f(list)i
(\(slice)f(deletion\).)k(Return)20 b Fj(0)h Fr(on)f(success,)h
Fj(-1)208 1074 y Fr(on)e(f)o(ailure.)0 1221 y Fj(int)49
b Fg(PyList_Sort)p Fj(\()p Fo(PyObject)18 b(*list)q Fj(\))208
1321 y Fr(Sort)i(the)g(items)h(of)e Fo(list)k Fr(in)e(place.)j(Return)c
Fj(0)h Fr(on)e(success,)i Fj(-1)f Fr(on)g(f)o(ailure.)k(This)d(is)g
(equi)n(v)n(alent)d(to)j(`)p Fo(list)q Fj(.sort\(\))p
Fr('.)0 1468 y Fj(int)49 b Fg(PyList_Reverse)p Fj(\()p
Fo(PyObject)17 b(*list)q Fj(\))208 1567 y Fr(Re)n(v)o(erse)45
b(the)h(items)g(of)f Fo(list)k Fr(in)c(place.)102 b(Return)45
b Fj(0)h Fr(on)f(success,)53 b Fj(-1)45 b Fr(on)h(f)o(ailure.)101
b(This)46 b(is)g(the)g(equi)n(v)n(alent)e(of)208 1667
y(`)p Fo(list)q Fj(.reverse\(\))p Fr('.)0 1814 y Fj(PyObject)400
1829 y(*)498 1814 y Fg(PyList_AsTuple)p Fj(\()p Fo(PyObject)17
b(*list)q Fj(\))208 1913 y Fo(Return)i(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 2013 y Fr(Return)f(a)i(ne)n(w)f(tuple)g
(object)f(containing)g(the)h(contents)f(of)h Fo(list)q
Fr(;)i(equi)n(v)n(alent)d(to)h(`)p Fj(tuple\()p Fo(list)q
Fj(\))p Fr('.)0 2340 y Fl(7.4)121 b(Mapping)34 b(Objects)0
2590 y Fh(7.4.1)100 b(Dictionar)s(y)29 b(Objects)0 2793
y Fg(PyDictObject)208 2892 y Fr(This)20 b(subtype)f(of)h
Fj(PyObject)f Fr(represents)g(a)i(Python)e(dictionary)g(object.)0
3039 y Fj(PyTypeObject)48 b Fg(PyDict_Type)208 3139 y
Fr(This)23 b(instance)g(of)g Fj(PyTypeObject)f Fr(represents)g(the)h
(Python)f(dictionary)g(type.)34 b(This)23 b(is)h(e)o(xposed)e(to)h
(Python)f(programs)208 3238 y(as)e Fj(dict)g Fr(and)g
Fj(types.DictType)p Fr(.)0 3385 y Fj(int)49 b Fg(PyDict_Check)p
Fj(\()p Fo(PyObject)18 b(*p)p Fj(\))208 3485 y Fr(Return)k(true)h(if)h
Fo(p)f Fr(is)h(a)g(dict)f(object)g(or)g(an)g(instance)g(of)g(a)g
(subtype)f(of)h(the)h(dict)f(type.)68 b(Changed)22 b(in)i(v)o(ersion)e
(2.2:)g(Allo)n(wed)208 3585 y(subtypes)d(to)h(be)g(accepted.)0
3731 y Fj(int)49 b Fg(PyDict_CheckExact)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 3831 y Fr(Return)i(true)h(if)h Fo(p)f
Fr(is)h(a)g(dict)f(object,)f(b)n(ut)i(not)e(an)i(instance)e(of)h(a)h
(subtype)e(of)h(the)g(dict)g(type.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f
(2.4.)0 3978 y Fj(PyObject)400 3993 y(*)498 3978 y Fg(PyDict_New)p
Fj(\(\))208 4078 y Fo(Return)g(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 4177 y Fr(Return)f(a)i(ne)n(w)f(empty)f
(dictionary)-5 b(,)18 b(or)i Fj(NULL)g Fr(on)g(f)o(ailure.)0
4324 y Fj(PyObject)400 4339 y(*)498 4324 y Fg(PyDictProxy_New)p
Fj(\()p Fo(PyObject)d(*dict)q Fj(\))208 4424 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4523 y Fr(Return)e(a)h(proxy)e
(object)h(for)g(a)h(mapping)e(which)h(enforces)g(read-only)e(beha)n
(vior)-5 b(.)24 b(This)19 b(is)g(normally)e(used)i(to)g(create)f(a)h
(proxy)208 4623 y(to)h(pre)n(v)o(ent)e(modi\002cation)h(of)h(the)g
(dictionary)e(for)i(non-dynamic)d(class)k(types.)50 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.2.)0 4770 y Fj(void)49 b Fg(PyDict_Clear)p
Fj(\()p Fo(PyObject)17 b(*p)p Fj(\))208 4869 y Fr(Empty)i(an)h(e)o
(xisting)f(dictionary)g(of)h(all)g(k)o(e)o(y-v)n(alue)e(pairs.)0
5016 y Fj(int)49 b Fg(PyDict_Contains)p Fj(\()p Fo(PyObject)17
b(*p,)i(PyObject)h(*k)o(e)n(y)p Fj(\))208 5116 y Fr(Determine)j(if)h
(dictionary)f Fo(p)h Fr(contains)g Fo(k)o(e)n(y)p Fr(.)37
b(If)24 b(an)g(item)g(in)h Fo(p)f Fr(is)h(matches)f Fo(k)o(e)n(y)p
Fr(,)h(return)e Fj(1)p Fr(,)j(otherwise)d(return)g Fj(0)p
Fr(.)38 b(On)24 b(error)m(,)208 5216 y(return)19 b Fj(-1)p
Fr(.)25 b(This)20 b(is)h(equi)n(v)n(alent)e(to)h(the)g(Python)f(e)o
(xpression)g(`)p Fo(k)o(e)n(y)49 b Fj(in)g Fo(p)p Fr('.)h(Ne)n(w)21
b(in)f(v)o(ersion)f(2.4.)0 5362 y Fj(PyObject)400 5377
y(*)498 5362 y Fg(PyDict_Copy)p Fj(\()p Fo(PyObject)f(*p)p
Fj(\))p 0 5549 3901 4 v 0 5649 a Fn(7.4.)52 b(Mapping)25
b(Objects)2994 b(67)p eop end
%%Page: 68 74
TeXDict begin 68 73 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(Return)f(a)i(ne)n(w)f
(dictionary)e(that)j(contains)e(the)h(same)h(k)o(e)o(y-v)n(alue)d
(pairs)i(as)h Fo(p)p Fr(.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(1.6.)0
330 y Fj(int)49 b Fg(PyDict_SetItem)p Fj(\()p Fo(PyObject)17
b(*p,)j(PyObject)f(*k)o(e)n(y)-5 b(,)20 b(PyObject)g(*val)p
Fj(\))208 429 y Fr(Insert)e Fo(value)g Fr(into)h(the)g(dictionary)e
Fo(p)i Fr(with)g(a)h(k)o(e)o(y)e(of)h Fo(k)o(e)n(y)p
Fr(.)24 b Fo(k)o(e)n(y)19 b Fr(must)g(be)g(hashable;)f(if)h(it)h(isn')o
(t,)f Fj(TypeError)e Fr(will)j(be)f(raised.)208 529 y(Return)g
Fj(0)i Fr(on)f(success)g(or)g Fj(-1)h Fr(on)e(f)o(ailure.)0
676 y Fj(int)49 b Fg(PyDict_SetItemString)p Fj(\()p Fo(PyObject)16
b(*p,)k(const)g(c)o(har)f(*k)o(e)n(y)-5 b(,)20 b(PyObject)g(*val)p
Fj(\))208 775 y Fr(Insert)k Fo(value)f Fr(into)h(the)h(dictionary)d
Fo(p)j Fr(using)f Fo(k)o(e)n(y)g Fr(as)h(a)g(k)o(e)o(y)-5
b(.)36 b Fo(k)o(e)n(y)24 b Fr(should)g(be)g(a)h Fj(char)2743
790 y(*)2793 775 y Fr(.)37 b(The)24 b(k)o(e)o(y)f(object)h(is)h
(created)f(using)208 875 y Fj(PyString_FromString\()p
Fo(k)o(e)n(y)p Fj(\))p Fr(.)c(Return)g Fj(0)h Fr(on)e(success)i(or)f
Fj(-1)h Fr(on)e(f)o(ailure.)0 1022 y Fj(int)49 b Fg(PyDict_DelItem)p
Fj(\()p Fo(PyObject)17 b(*p,)j(PyObject)f(*k)o(e)n(y)p
Fj(\))208 1121 y Fr(Remo)o(v)o(e)h(the)h(entry)g(in)h(dictionary)e
Fo(p)h Fr(with)h(k)o(e)o(y)f Fo(k)o(e)n(y)p Fr(.)29 b
Fo(k)o(e)n(y)21 b Fr(must)h(be)f(hashable;)h(if)g(it)g(isn')o(t,)f
Fj(TypeError)g Fr(is)h(raised.)29 b(Return)208 1221 y
Fj(0)20 b Fr(on)g(success)h(or)f Fj(-1)g Fr(on)g(f)o(ailure.)0
1368 y Fj(int)49 b Fg(PyDict_DelItemString)p Fj(\()p
Fo(PyObject)16 b(*p,)k(c)o(har)f(*k)o(e)n(y)p Fj(\))208
1468 y Fr(Remo)o(v)o(e)25 b(the)h(entry)f(in)h(dictionary)f
Fo(p)h Fr(which)g(has)g(a)h(k)o(e)o(y)e(speci\002ed)h(by)g(the)g
(string)g Fo(k)o(e)n(y)p Fr(.)43 b(Return)26 b Fj(0)g
Fr(on)g(success)h(or)f Fj(-1)g Fr(on)208 1567 y(f)o(ailure.)0
1714 y Fj(PyObject)400 1729 y(*)498 1714 y Fg(PyDict_GetItem)p
Fj(\()p Fo(PyObject)17 b(*p,)j(PyObject)f(*k)o(e)n(y)p
Fj(\))208 1814 y Fo(Return)g(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 1913 y Fr(Return)g(the)g(object)g(from)g
(dictionary)e Fo(p)j Fr(which)f(has)h(a)g(k)o(e)o(y)e
Fo(k)o(e)n(y)p Fr(.)26 b(Return)20 b Fj(NULL)h Fr(if)f(the)h(k)o(e)o(y)
f Fo(k)o(e)n(y)g Fr(is)h(not)g(present,)e(b)n(ut)i Fo(without)208
2013 y Fr(setting)f(an)g(e)o(xception.)0 2160 y Fj(PyObject)400
2175 y(*)498 2160 y Fg(PyDict_GetItemString)p Fj(\()p
Fo(PyObject)c(*p,)j(const)h(c)o(har)g(*k)o(e)n(y)p Fj(\))208
2259 y Fo(Return)f(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p
Fo(.)208 2359 y Fr(This)g(is)h(the)f(same)h(as)g Fj(PyDict_GetItem\(\))
p Fr(,)c(b)n(ut)j Fo(k)o(e)n(y)g Fr(is)h(speci\002ed)f(as)h(a)g
Fj(char)2687 2374 y(*)2737 2359 y Fr(,)e(rather)h(than)f(a)i
Fj(PyObject)3613 2374 y(*)3663 2359 y Fr(.)0 2506 y Fj(PyObject)400
2521 y(*)498 2506 y Fg(PyDict_Items)p Fj(\()p Fo(PyObject)c(*p)p
Fj(\))208 2606 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2705 y Fr(Return)h(a)h Fj(PyListObject)e Fr(containing)f(all)j
(the)g(items)g(from)f(the)g(dictionary)-5 b(,)20 b(as)i(in)g(the)f
(dictionary)f(method)g Fj(items\(\))208 2805 y Fr(\(see)g(the)g
Fo(Python)f(Libr)o(ary)h(Refer)m(ence)p Fr(\).)0 2952
y Fj(PyObject)400 2967 y(*)498 2952 y Fg(PyDict_Keys)p
Fj(\()p Fo(PyObject)e(*p)p Fj(\))208 3051 y Fo(Return)h(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 3151 y Fr(Return)26
b(a)h Fj(PyListObject)e Fr(containing)g(all)j(the)e(k)o(e)o(ys)h(from)f
(the)g(dictionary)-5 b(,)26 b(as)i(in)f(the)g(dictionary)e(method)g
Fj(keys\(\))208 3251 y Fr(\(see)20 b(the)g Fo(Python)f(Libr)o(ary)h
(Refer)m(ence)p Fr(\).)0 3397 y Fj(PyObject)400 3412
y(*)498 3397 y Fg(PyDict_Values)p Fj(\()p Fo(PyObject)d(*p)p
Fj(\))208 3497 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3597 y Fr(Return)38 b(a)i Fj(PyListObject)e
Fr(containing)f(all)j(the)g(v)n(alues)f(from)f(the)i(dictionary)d
Fo(p)p Fr(,)44 b(as)c(in)g(the)f(dictionary)f(method)208
3696 y Fj(values\(\))19 b Fr(\(see)h(the)g Fo(Python)f(Libr)o(ary)i
(Refer)m(ence)p Fr(\).)0 3843 y Fj(Py_ssize_t)48 b Fg(PyDict_Size)p
Fj(\()p Fo(PyObject)17 b(*p)p Fj(\))208 3943 y Fr(Return)i(the)i
(number)d(of)i(items)g(in)h(the)f(dictionary)-5 b(.)23
b(This)d(is)h(equi)n(v)n(alent)e(to)h(`)p Fj(len\()p
Fo(p)p Fj(\))p Fr(')f(on)g(a)i(dictionary)-5 b(.)0 4090
y Fj(int)49 b Fg(PyDict_Next)p Fj(\()p Fo(PyObject)18
b(*p,)h(Py)p 1344 4090 25 4 v 30 w(ssize)p 1530 4090
V 30 w(t)i(*ppos,)e(PyObject)h(**pk)o(e)n(y)-5 b(,)19
b(PyObject)g(**pvalue)p Fj(\))208 4189 y Fr(Iterate)k(o)o(v)o(er)g(all)
i(k)o(e)o(y-v)n(alue)d(pairs)i(in)h(the)f(dictionary)e
Fo(p)p Fr(.)38 b(The)24 b Fj(int)g Fr(referred)e(to)j(by)f
Fo(ppos)f Fr(must)h(be)h(initialized)f(to)g Fj(0)h Fr(prior)208
4289 y(to)c(the)g(\002rst)g(call)h(to)f(this)h(function)d(to)i(start)h
(the)f(iteration;)f(the)h(function)f(returns)g(true)g(for)h(each)f
(pair)h(in)g(the)g(dictionary)-5 b(,)19 b(and)208 4389
y(f)o(alse)26 b(once)g(all)h(pairs)g(ha)n(v)o(e)f(been)f(reported.)42
b(The)26 b(parameters)g Fo(pk)o(e)n(y)g Fr(and)f Fo(pvalue)h
Fr(should)f(either)h(point)g(to)h Fj(PyObject)3852 4404
y(*)208 4488 y Fr(v)n(ariables)21 b(that)h(will)h(be)f(\002lled)g(in)g
(with)h(each)e(k)o(e)o(y)h(and)f(v)n(alue,)h(respecti)n(v)o(ely)-5
b(,)20 b(or)i(may)g(be)g Fj(NULL)p Fr(.)f(An)o(y)h(references)e
(returned)208 4588 y(through)g(them)j(are)g(borro)n(wed.)31
b Fo(ppos)22 b Fr(should)g(not)g(be)h(altered)g(during)e(iteration.)32
b(Its)24 b(v)n(alue)e(represents)g(of)n(fsets)h(within)g(the)208
4687 y(internal)c(dictionary)f(structure,)h(and)h(since)g(the)h
(structure)e(is)i(sparse,)f(the)g(of)n(fsets)g(are)g(not)g(consecuti)n
(v)o(e.)208 4820 y(F)o(or)f(e)o(xample:)p 0 5549 3901
4 v 0 5649 a Fn(68)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 69 75
TeXDict begin 69 74 bop 444 174 a Fk(PyObject)847 187
y(*)892 174 y(key,)1116 187 y(*)1161 174 y(value;)444
266 y(Py_ssize_t)43 b(pos)h(=)h(0;)444 448 y(while)f
(\(PyDict_Next\(self->dict,)d(&pos,)j(&key,)g(&value\)\))f({)623
540 y(/)668 553 y(*)758 540 y(do)h(something)f(interesting)g(with)i
(the)f(values...)2730 553 y(*)2775 540 y(/)623 631 y(...)444
722 y(})208 912 y Fr(The)19 b(dictionary)e Fo(p)j Fr(should)e(not)i(be)
f(mutated)f(during)g(iteration.)24 b(It)c(is)g(safe)g(\(since)f(Python)
g(2.1\))f(to)i(modify)e(the)h(v)n(alues)g(of)h(the)208
1011 y(k)o(e)o(ys)f(as)i(you)f(iterate)g(o)o(v)o(er)f(the)h(dictionary)
-5 b(,)18 b(b)n(ut)i(only)f(so)i(long)e(as)i(the)f(set)h(of)f(k)o(e)o
(ys)g(does)g(not)g(change.)j(F)o(or)d(e)o(xample:)444
1236 y Fk(PyObject)847 1249 y(*)892 1236 y(key,)1116
1249 y(*)1161 1236 y(value;)444 1327 y(Py_ssize_t)43
b(pos)h(=)h(0;)444 1510 y(while)f(\(PyDict_Next\(self->dict,)d(&pos,)j
(&key,)g(&value\)\))f({)623 1601 y(int)h(i)h(=)g
(PyInt_AS_LONG\(value\))c(+)k(1;)623 1692 y(PyObject)1027
1705 y(*)1072 1692 y(o)f(=)h(PyInt_FromLong\(i\);)623
1783 y(if)g(\(o)f(==)h(NULL\))802 1875 y(return)f(-1;)623
1966 y(if)h(\(PyDict_SetItem\(self->dict,)40 b(key,)k(o\))h(<)f(0\))h
({)802 2057 y(Py_DECREF\(o\);)802 2149 y(return)f(-1;)623
2240 y(})623 2331 y(Py_DECREF\(o\);)444 2423 y(})0 2626
y Fj(int)49 b Fg(PyDict_Merge)p Fj(\()p Fo(PyObject)18
b(*a,)h(PyObject)h(*b,)f(int)i(o)o(verride)p Fj(\))208
2726 y Fr(Iterate)29 b(o)o(v)o(er)g(mapping)g(object)h
Fo(b)g Fr(adding)f(k)o(e)o(y-v)n(alue)f(pairs)i(to)h(dictionary)d
Fo(a)p Fr(.)56 b Fo(b)30 b Fr(may)g(be)g(a)h(dictionary)-5
b(,)31 b(or)f(an)o(y)f(object)208 2826 y(supporting)21
b Fj(PyMapping_Keys\(\))g Fr(and)i Fj(PyObject_GetItem\(\))p
Fr(.)33 b(If)23 b Fo(o)o(verride)h Fr(is)h(true,)f(e)o(xisting)f(pairs)
g(in)h Fo(a)g Fr(will)208 2925 y(be)d(replaced)e(if)j(a)f(matching)f(k)
o(e)o(y)h(is)h(found)d(in)i Fo(b)p Fr(,)g(otherwise)g(pairs)g(will)h
(only)e(be)h(added)f(if)h(there)g(is)h(not)f(a)g(matching)f(k)o(e)o(y)g
(in)208 3025 y Fo(a)p Fr(.)25 b(Return)19 b Fj(0)i Fr(on)f(success)g
(or)g Fj(-1)h Fr(if)f(an)g(e)o(xception)f(w)o(as)i(raised.)50
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 3172 y Fj(int)49
b Fg(PyDict_Update)p Fj(\()p Fo(PyObject)17 b(*a,)j(PyObject)g(*b)p
Fj(\))208 3271 y Fr(This)i(is)i(the)e(same)h(as)g Fj(PyDict_Merge\()p
Fo(a)p Fj(,)47 b Fo(b)p Fj(,)i(1\))23 b Fr(in)g(C,)g(or)f
Fo(a)p Fj(.update\()p Fo(b)p Fj(\))f Fr(in)i(Python.)30
b(Return)23 b Fj(0)g Fr(on)f(success)h(or)208 3371 y
Fj(-1)d Fr(if)g(an)h(e)o(xception)d(w)o(as)j(raised.)50
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 3518 y Fj(int)49
b Fg(PyDict_MergeFromSeq2)p Fj(\()p Fo(PyObject)16 b(*a,)k(PyObject)f
(*seq2,)g(int)i(o)o(verride)p Fj(\))208 3618 y Fr(Update)f(or)i(mer)o
(ge)e(into)h(dictionary)f Fo(a)p Fr(,)h(from)g(the)g(k)o(e)o(y-v)n
(alue)f(pairs)h(in)h Fo(seq2)p Fr(.)29 b Fo(seq2)21 b
Fr(must)g(be)h(an)f(iterable)g(object)g(producing)208
3717 y(iterable)d(objects)g(of)g(length)g(2,)h(vie)n(wed)f(as)h(k)o(e)o
(y-v)n(alue)e(pairs.)24 b(In)18 b(case)i(of)e(duplicate)f(k)o(e)o(ys,)i
(the)f(last)i(wins)f(if)g Fo(o)o(verride)g Fr(is)g(true,)208
3817 y(else)27 b(the)f(\002rst)h(wins.)44 b(Return)26
b Fj(0)h Fr(on)f(success)h(or)g Fj(-1)f Fr(if)h(an)f(e)o(xception)f(w)o
(as)i(raised.)44 b(Equi)n(v)n(alent)24 b(Python)i(\(e)o(xcept)f(for)h
(the)208 3916 y(return)19 b(v)n(alue\):)444 4141 y Fk(def)44
b(PyDict_MergeFromSeq2\(a,)d(seq2,)j(override\):)623
4232 y(for)g(key,)h(value)f(in)g(seq2:)802 4323 y(if)h(override)e(or)i
(key)f(not)h(in)f(a:)982 4415 y(a[key])g(=)g(value)208
4604 y Fr(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)p 0 5549
3901 4 v 0 5649 a Fn(7.4.)52 b(Mapping)25 b(Objects)2994
b(69)p eop end
%%Page: 70 76
TeXDict begin 70 75 bop 0 88 a Fl(7.5)121 b(Other)34
b(Objects)0 338 y Fh(7.5.1)100 b(File)28 b(Objects)0
540 y Fr(Python')-5 b(s)22 b(b)n(uilt-in)h(\002le)h(objects)e(are)h
(implemented)f(entirely)g(on)h(the)g Fj(FILE)2261 555
y(*)2333 540 y Fr(support)f(from)g(the)h(C)h(standard)e(library)-5
b(.)32 b(This)24 b(is)g(an)0 640 y(implementation)18
b(detail)i(and)g(may)g(change)e(in)j(future)e(releases)h(of)g(Python.)0
787 y Fg(PyFileObject)208 887 y Fr(This)g(subtype)f(of)h
Fj(PyObject)f Fr(represents)g(a)i(Python)e(\002le)i(object.)0
1033 y Fj(PyTypeObject)48 b Fg(PyFile_Type)208 1133 y
Fr(This)18 b(instance)g(of)g Fj(PyTypeObject)e Fr(represents)i(the)g
(Python)f(\002le)i(type.)24 b(This)18 b(is)h(e)o(xposed)e(to)h(Python)f
(programs)g(as)i Fj(file)208 1233 y Fr(and)g Fj(types.FileType)p
Fr(.)0 1380 y Fj(int)49 b Fg(PyFile_Check)p Fj(\()p Fo(PyObject)18
b(*p)p Fj(\))208 1479 y Fr(Return)k(true)h(if)g(its)i(ar)o(gument)20
b(is)k(a)g Fj(PyFileObject)d Fr(or)i(a)h(subtype)e(of)h
Fj(PyFileObject)p Fr(.)66 b(Changed)22 b(in)h(v)o(ersion)f(2.2:)208
1579 y(Allo)n(wed)d(subtypes)g(to)i(be)f(accepted.)0
1726 y Fj(int)49 b Fg(PyFile_CheckExact)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 1825 y Fr(Return)i(true)h(if)h(its)g(ar)o(gument)d(is)
j(a)f Fj(PyFileObject)p Fr(,)f(b)n(ut)h(not)g(a)g(subtype)f(of)h
Fj(PyFileObject)p Fr(.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
1972 y Fj(PyObject)400 1987 y(*)498 1972 y Fg(PyFile_FromString)p
Fj(\()p Fo(c)o(har)d(*\002lename)o(,)j(c)o(har)h(*mode)p
Fj(\))208 2072 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2171 y Fr(On)e(success,)i(return)d(a)i(ne)n(w)g(\002le)g
(object)f(that)h(is)h(opened)d(on)h(the)h(\002le)g(gi)n(v)o(en)f(by)g
Fo(\002lename)p Fr(,)g(with)g(a)i(\002le)f(mode)f(gi)n(v)o(en)f(by)h
Fo(mode)p Fr(,)208 2271 y(where)h Fo(mode)h Fr(has)g(the)g(same)h
(semantics)f(as)h(the)f(standard)f(C)i(routine)e Fj(fopen\(\))p
Fr(.)24 b(On)d(f)o(ailure,)e(return)g Fj(NULL)p Fr(.)0
2418 y Fj(PyObject)400 2433 y(*)498 2418 y Fg(PyFile_FromFile)p
Fj(\()p Fo(FILE)e(*fp,)j(c)o(har)f(*name)o(,)g(c)o(har)h(*mode)o(,)f
(int)i(\(*close\)\(FILE*\))p Fj(\))208 2518 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 2617 y Fr(Create)26
b(a)g(ne)n(w)g Fj(PyFileObject)f Fr(from)g(the)h(already-open)d
(standard)i(C)h(\002le)h(pointer)m(,)f Fo(fp)p Fr(.)43
b(The)25 b(function)g Fo(close)h Fr(will)h(be)208 2717
y(called)20 b(when)f(the)h(\002le)h(should)e(be)i(closed.)j(Return)c
Fj(NULL)g Fr(on)g(f)o(ailure.)0 2864 y Fj(FILE)200 2879
y(*)299 2864 y Fg(PyFile_AsFile)p Fj(\()p Fo(PyObject)d(*p)p
Fj(\))208 2963 y Fr(Return)i(the)i(\002le)f(object)g(associated)g(with)
g Fo(p)h Fr(as)g(a)f Fj(FILE)1867 2978 y(*)1917 2963
y Fr(.)0 3110 y Fj(PyObject)400 3125 y(*)498 3110 y Fg(PyFile_GetLine)p
Fj(\()p Fo(PyObject)d(*p,)j(int)g(n)p Fj(\))208 3210
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3309 y Fr(Equi)n(v)n(alent)d(to)j Fo(p)p Fj(.readline\()p
Fc([)p Fo(n)12 b Fc(])p Fj(\))p Fr(,)k(this)21 b(function)c(reads)j
(one)f(line)g(from)g(the)h(object)f Fo(p)p Fr(.)24 b
Fo(p)c Fr(may)f(be)h(a)g(\002le)g(object)f(or)g(an)o(y)208
3409 y(object)h(with)h(a)g Fj(readline\(\))f Fr(method.)26
b(If)21 b Fo(n)g Fr(is)h Fj(0)p Fr(,)f(e)o(xactly)f(one)g(line)h(is)h
(read,)f(re)o(gardless)e(of)i(the)g(length)f(of)g(the)h(line.)28
b(If)20 b Fo(n)208 3509 y Fr(is)k(greater)e(than)h Fj(0)p
Fr(,)h(no)f(more)f(than)h Fo(n)g Fr(bytes)g(will)h(be)f(read)g(from)f
(the)h(\002le;)j(a)d(partial)g(line)g(can)g(be)h(returned.)32
b(In)23 b(both)f(cases,)208 3608 y(an)f(empty)f(string)h(is)h(returned)
d(if)i(the)g(end)g(of)g(the)g(\002le)g(is)h(reached)e(immediately)-5
b(.)26 b(If)21 b Fo(n)g Fr(is)h(less)g(than)f Fj(0)p
Fr(,)g(ho)n(we)n(v)o(er)m(,)e(one)h(line)i(is)208 3708
y(read)d(re)o(gardless)g(of)h(length,)f(b)n(ut)h Fj(EOFError)f
Fr(is)i(raised)f(if)h(the)f(end)g(of)g(the)g(\002le)h(is)g(reached)e
(immediately)-5 b(.)0 3855 y Fj(PyObject)400 3870 y(*)498
3855 y Fg(PyFile_Name)p Fj(\()p Fo(PyObject)18 b(*p)p
Fj(\))208 3954 y Fo(Return)h(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 4054 y Fr(Return)f(the)i(name)e(of)h(the)g
(\002le)h(speci\002ed)f(by)g Fo(p)g Fr(as)h(a)g(string)e(object.)0
4201 y Fj(void)49 b Fg(PyFile_SetBufSize)p Fj(\()p Fo(PyF)l(ileObject)
16 b(*p,)k(int)g(n)p Fj(\))208 4301 y Fr(A)-6 b(v)n(ailable)19
b(on)h(systems)g(with)g Fj(setvbuf\(\))f Fr(only)-5 b(.)24
b(This)c(should)g(only)f(be)h(called)g(immediately)f(after)g(\002le)i
(object)f(creation.)0 4447 y Fj(int)49 b Fg(PyFile_SetEncoding)p
Fj(\()p Fo(PyF)l(ileObject)16 b(*p,)k(const)g(c)o(har)g(*enc)p
Fj(\))208 4547 y Fr(Set)g(the)h(\002le')-5 b(s)21 b(encoding)d(for)i
(Unicode)f(output)g(to)h Fo(enc)p Fr(.)25 b(Return)19
b(1)i(on)e(success)i(and)f(0)g(on)g(f)o(ailure.)50 b(Ne)n(w)20
b(in)h(v)o(ersion)e(2.3.)0 4694 y Fj(int)49 b Fg(PyFile_SoftSpace)p
Fj(\()p Fo(PyObject)17 b(*p,)i(int)i(ne)o(w\003a)o(g)p
Fj(\))208 4794 y Fr(This)g(function)e(e)o(xists)i(for)f(internal)g(use)
h(by)g(the)g(interpreter)-5 b(.)26 b(Set)21 b(the)g Fj(softspace)f
Fr(attrib)n(ute)g(of)h Fo(p)g Fr(to)g Fo(ne)o(w\003a)o(g)e
Fr(and)i(return)208 4893 y(the)e(pre)n(vious)f(v)n(alue.)24
b Fo(p)c Fr(does)f(not)h(ha)n(v)o(e)f(to)g(be)h(a)g(\002le)g(object)g
(for)f(this)h(function)e(to)h(w)o(ork)g(properly;)f(an)o(y)h(object)g
(is)i(supported)208 4993 y(\(thought)g(its)k(only)e(interesting)f(if)i
(the)g Fj(softspace)f Fr(attrib)n(ute)g(can)g(be)h(set\).)36
b(This)24 b(function)e(clears)h(an)o(y)g(errors,)h(and)f(will)208
5092 y(return)18 b Fj(0)h Fr(as)h(the)f(pre)n(vious)f(v)n(alue)g(if)i
(the)f(attrib)n(ute)g(either)g(does)f(not)h(e)o(xist)h(or)f(if)g(there)
g(were)g(errors)f(in)i(retrie)n(ving)d(it.)25 b(There)19
b(is)208 5192 y(no)g(w)o(ay)i(to)f(detect)g(errors)f(from)g(this)i
(function,)d(b)n(ut)j(doing)d(so)j(should)e(not)h(be)g(needed.)0
5339 y Fj(int)49 b Fg(PyFile_WriteObject)p Fj(\()p Fo(PyObject)16
b(*obj,)k(PyObject)f(*p,)h(int)g(\003a)o(gs)p Fj(\))p
0 5549 3901 4 v 0 5649 a Fn(70)2478 b(Chapter)23 b(7.)52
b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 71 77
TeXDict begin 71 76 bop 208 83 a Fr(Write)22 b(object)f
Fo(obj)g Fr(to)h(\002le)g(object)f Fo(p)p Fr(.)29 b(The)21
b(only)g(supported)f(\003ag)h(for)g Fo(\003a)o(gs)g Fr(is)i
Fj(Py_PRINT_RAW)p Fr(;)d(if)i(gi)n(v)o(en,)e(the)i Fj(str\(\))f
Fr(of)208 183 y(the)j(object)h(is)g(written)g(instead)f(of)h(the)g
Fj(repr\(\))p Fr(.)38 b(Return)24 b Fj(0)h Fr(on)g(success)g(or)f
Fj(-1)h Fr(on)g(f)o(ailure;)h(the)f(appropriate)d(e)o(xception)208
282 y(will)e(be)h(set.)0 429 y Fj(int)49 b Fg(PyFile_WriteString)p
Fj(\()p Fo(const)17 b(c)o(har)i(*s,)i(PyObject)e(*p)p
Fj(\))208 529 y Fr(Write)h(string)g Fo(s)h Fr(to)g(\002le)f(object)g
Fo(p)p Fr(.)25 b(Return)20 b Fj(0)g Fr(on)g(success)h(or)f
Fj(-1)g Fr(on)g(f)o(ailure;)g(the)g(appropriate)e(e)o(xception)g(will)j
(be)f(set.)0 814 y Fh(7.5.2)100 b(Instance)28 b(Objects)0
1017 y Fr(There)19 b(are)h(v)o(ery)g(fe)n(w)g(functions)e(speci\002c)j
(to)f(instance)g(objects.)0 1163 y Fj(PyTypeObject)48
b Fg(PyInstance_Type)208 1263 y Fr(T)-7 b(ype)19 b(object)h(for)f
(class)j(instances.)0 1410 y Fj(int)49 b Fg(PyInstance_Check)p
Fj(\()p Fo(PyObject)17 b(*obj)p Fj(\))208 1510 y Fr(Return)i(true)h(if)
h Fo(obj)e Fr(is)j(an)e(instance.)0 1656 y Fj(PyObject)400
1671 y(*)498 1656 y Fg(PyInstance_New)p Fj(\()p Fo(PyObject)d(*class,)j
(PyObject)g(*ar)m(g)o(,)f(PyObject)h(*kw)p Fj(\))208
1756 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1856 y Fr(Create)25 b(a)h(ne)n(w)g(instance)f(of)g(a)h
(speci\002c)g(class.)42 b(The)25 b(parameters)f Fo(ar)m(g)i
Fr(and)f Fo(kw)h Fr(are)g(used)f(as)h(the)g(positional)e(and)h(k)o(e)o
(yw)o(ord)208 1955 y(parameters)19 b(to)h(the)g(object')-5
b(s)20 b(constructor)-5 b(.)0 2102 y Fj(PyObject)400
2117 y(*)498 2102 y Fg(PyInstance_NewRaw)p Fj(\()p Fo(PyObject)16
b(*class,)21 b(PyObject)e(*dict)q Fj(\))208 2202 y Fo(Return)g(value:)
25 b Ff(New)20 b(ref)o(erence)p Fo(.)208 2301 y Fr(Create)e(a)h(ne)n(w)
g(instance)f(of)g(a)h(speci\002c)g(class)g(without)f(calling)g(its)i
(constructor)-5 b(.)23 b Fo(class)c Fr(is)h(the)e(class)i(of)e(ne)n(w)g
(object.)24 b(The)18 b Fo(dict)208 2401 y Fr(parameter)g(will)j(be)f
(used)g(as)h(the)f(object')-5 b(s)20 b Fj(__dict__)p
Fr(;)g(if)g Fj(NULL)p Fr(,)g(a)h(ne)n(w)f(dictionary)e(will)j(be)f
(created)f(for)h(the)g(instance.)0 2686 y Fh(7.5.3)100
b(Function)29 b(Objects)0 2889 y Fr(There)19 b(are)h(a)h(fe)n(w)f
(functions)f(speci\002c)h(to)h(Python)e(functions.)0
3036 y Fg(PyFunctionObject)208 3135 y Fr(The)g(C)j(structure)d(used)h
(for)f(functions.)0 3282 y Fj(PyTypeObject)48 b Fg(PyFunction_Type)208
3382 y Fr(This)32 b(is)i(an)f(instance)f(of)g Fj(PyTypeObject)f
Fr(and)h(represents)g(the)h(Python)e(function)g(type.)62
b(It)33 b(is)h(e)o(xposed)d(to)i(Python)208 3481 y(programmers)17
b(as)k Fj(types.FunctionType)p Fr(.)0 3628 y Fj(int)49
b Fg(PyFunction_Check)p Fj(\()p Fo(PyObject)17 b(*o)p
Fj(\))208 3728 y Fr(Return)i(true)h(if)h Fo(o)f Fr(is)h(a)g(function)d
(object)i(\(has)g(type)g Fj(PyFunction_Type)p Fr(\).)i(The)e(parameter)
e(must)j(not)f(be)g Fj(NULL)p Fr(.)0 3875 y Fj(PyObject)400
3890 y(*)498 3875 y Fg(PyFunction_New)p Fj(\()p Fo(PyObject)d(*code)o
(,)i(PyObject)h(*globals)p Fj(\))208 3974 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4074 y Fr(Return)f(a)h(ne)n(w)g
(function)e(object)h(associated)h(with)g(the)f(code)h(object)f
Fo(code)p Fr(.)24 b Fo(globals)19 b Fr(must)h(be)f(a)i(dictionary)d
(with)i(the)f(global)208 4174 y(v)n(ariables)g(accessible)h(to)h(the)f
(function.)208 4307 y(The)26 b(function')-5 b(s)24 b(docstring,)j(name)
e(and)p 1439 4307 25 4 v 1469 4307 V 86 w Fo(module)p
1745 4307 V 1773 4307 V 85 w Fr(are)h(retrie)n(v)o(ed)f(from)g(the)h
(code)g(object,)h(the)f(ar)o(gument)e(def)o(aults)i(and)208
4406 y(closure)19 b(are)h(set)h(to)g Fj(NULL)p Fr(.)0
4553 y Fj(PyObject)400 4568 y(*)498 4553 y Fg(PyFunction_GetCode)p
Fj(\()p Fo(PyObject)16 b(*op)p Fj(\))208 4653 y Fo(Return)j(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 4752
y Fr(Return)f(the)i(code)e(object)h(associated)g(with)g(the)g(function)
f(object)g Fo(op)p Fr(.)0 4899 y Fj(PyObject)400 4914
y(*)498 4899 y Fg(PyFunction_GetGlobals)p Fj(\()p Fo(PyObject)d(*op)p
Fj(\))208 4999 y Fo(Return)j(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 5098 y Fr(Return)f(the)i(globals)e
(dictionary)g(associated)g(with)i(the)f(function)f(object)g
Fo(op)p Fr(.)0 5245 y Fj(PyObject)400 5260 y(*)498 5245
y Fg(PyFunction_GetModule)p Fj(\()p Fo(PyObject)d(*op)p
Fj(\))208 5345 y Fo(Return)j(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)p 0 5549 3901 4 v 0 5649 a Fn(7.5.)52
b(Other)23 b(Objects)3105 b(71)p eop end
%%Page: 72 78
TeXDict begin 72 77 bop 208 83 a Fr(Return)18 b(the)p
579 83 25 4 v 609 83 V 79 w Fo(module)p 885 83 V 914
83 V 78 w Fr(attrib)n(ute)h(of)g(the)g(function)f(object)g
Fo(op)p Fr(.)25 b(This)19 b(is)h(normally)e(a)h(string)g(containing)e
(the)j(module)d(name,)208 183 y(b)n(ut)j(can)g(be)g(set)h(to)f(an)o(y)g
(other)f(object)h(by)f(Python)g(code.)0 330 y Fj(PyObject)400
345 y(*)498 330 y Fg(PyFunction_GetDefaults)p Fj(\()p
Fo(PyObject)d(*op)p Fj(\))208 429 y Fo(Return)j(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 529
y Fr(Return)f(the)i(ar)o(gument)c(def)o(ault)j(v)n(alues)g(of)g(the)g
(function)e(object)i Fo(op)p Fr(.)k(This)d(can)f(be)g(a)g(tuple)g(of)g
(ar)o(guments)e(or)i Fj(NULL)p Fr(.)0 676 y Fj(int)49
b Fg(PyFunction_SetDefaults)p Fj(\()p Fo(PyObject)16
b(*op,)j(PyObject)g(*defaults)p Fj(\))208 775 y Fr(Set)h(the)h(ar)o
(gument)c(def)o(ault)j(v)n(alues)g(for)f(the)h(function)f(object)h
Fo(op)p Fr(.)k Fo(defaults)c Fr(must)g(be)g Fo(Py)p 2819
775 V 30 w(None)g Fr(or)g(a)g(tuple.)208 908 y(Raises)h
Fj(SystemError)e Fr(and)g(returns)h Fj(-1)g Fr(on)g(f)o(ailure.)0
1055 y Fj(PyObject)400 1070 y(*)498 1055 y Fg(PyFunction_GetClosure)p
Fj(\()p Fo(PyObject)c(*op)p Fj(\))208 1155 y Fo(Return)j(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 1254
y Fr(Return)f(the)i(closure)e(associated)h(with)g(the)h(function)d
(object)i Fo(op)p Fr(.)k(This)d(can)f(be)g Fj(NULL)g
Fr(or)g(a)g(tuple)g(of)g(cell)h(objects.)0 1401 y Fj(int)49
b Fg(PyFunction_SetClosure)p Fj(\()p Fo(PyObject)16 b(*op,)j(PyObject)h
(*closur)m(e)p Fj(\))208 1501 y Fr(Set)g(the)h(closure)e(associated)h
(with)g(the)h(function)d(object)i Fo(op)p Fr(.)k Fo(closur)m(e)c
Fr(must)h(be)f Fo(Py)p 2657 1501 V 29 w(None)g Fr(or)g(a)h(tuple)f(of)g
(cell)g(objects.)208 1634 y(Raises)h Fj(SystemError)e
Fr(and)g(returns)h Fj(-1)g Fr(on)g(f)o(ailure.)0 1918
y Fh(7.5.4)100 b(Method)29 b(Objects)0 2121 y Fr(There)19
b(are)h(some)g(useful)g(functions)f(that)h(are)g(useful)g(for)g(w)o
(orking)e(with)j(method)d(objects.)0 2268 y Fj(PyTypeObject)48
b Fg(PyMethod_Type)208 2368 y Fr(This)23 b(instance)f(of)h
Fj(PyTypeObject)e Fr(represents)h(the)h(Python)f(method)g(type.)32
b(This)24 b(is)f(e)o(xposed)f(to)h(Python)f(programs)f(as)208
2467 y Fj(types.MethodType)p Fr(.)0 2614 y Fj(int)49
b Fg(PyMethod_Check)p Fj(\()p Fo(PyObject)17 b(*o)p Fj(\))208
2714 y Fr(Return)i(true)h(if)h Fo(o)f Fr(is)h(a)g(method)d(object)i
(\(has)g(type)g Fj(PyMethod_Type)p Fr(\).)j(The)c(parameter)g(must)h
(not)g(be)g Fj(NULL)p Fr(.)0 2861 y Fj(PyObject)400 2876
y(*)498 2861 y Fg(PyMethod_New)p Fj(\()p Fo(PyObject)d(*func,)i
(PyObject)h(*self)o(,)h(PyObject)e(*class)p Fj(\))208
2960 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3060 y Fr(Return)k(a)g(ne)n(w)h(method)e(object,)i(with)f
Fo(func)g Fr(being)g(an)o(y)g(callable)g(object;)i(this)f(is)g(the)g
(function)e(that)h(will)h(be)g(called)f(when)208 3160
y(the)18 b(method)g(is)h(called.)25 b(If)18 b(this)h(method)f(should)f
(be)i(bound)e(to)i(an)g(instance,)f Fo(self)32 b Fr(should)17
b(be)i(the)g(instance)f(and)g Fo(class)i Fr(should)208
3259 y(be)j(the)g(class)i(of)e Fo(self)12 b Fr(,)25 b(otherwise)e
Fo(self)36 b Fr(should)22 b(be)i Fj(NULL)f Fr(and)g Fo(class)h
Fr(should)e(be)i(the)f(class)h(which)f(pro)o(vides)f(the)h(unbound)208
3359 y(method..)0 3506 y Fj(PyObject)400 3521 y(*)498
3506 y Fg(PyMethod_Class)p Fj(\()p Fo(PyObject)17 b(*meth)p
Fj(\))208 3605 y Fo(Return)i(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 3705 y Fr(Return)f(the)h(class)h(object)e
(from)g(which)g(the)h(method)e Fo(meth)i Fr(w)o(as)h(created;)e(if)h
(this)h(w)o(as)f(created)g(from)e(an)i(instance,)f(it)i(will)g(be)208
3805 y(the)f(class)h(of)f(the)g(instance.)0 3952 y Fj(PyObject)400
3967 y(*)498 3952 y Fg(PyMethod_GET_CLASS)p Fj(\()p Fo(PyObject)c
(*meth)p Fj(\))208 4051 y Fo(Return)j(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 4151 y Fr(Macro)f(v)o(ersion)g(of)h
Fj(PyMethod_Class\(\))e Fr(which)h(a)n(v)n(oids)h(error)g(checking.)0
4298 y Fj(PyObject)400 4313 y(*)498 4298 y Fg(PyMethod_Function)p
Fj(\()p Fo(PyObject)c(*meth)p Fj(\))208 4397 y Fo(Return)j(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 4497
y Fr(Return)f(the)i(function)d(object)i(associated)g(with)g(the)g
(method)f Fo(meth)p Fr(.)0 4644 y Fj(PyObject)400 4659
y(*)498 4644 y Fg(PyMethod_GET_FUNCTION)p Fj(\()p Fo(PyObject)d(*meth)p
Fj(\))208 4743 y Fo(Return)j(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 4843 y Fr(Macro)f(v)o(ersion)g(of)h
Fj(PyMethod_Function\(\))d Fr(which)j(a)n(v)n(oids)g(error)f(checking.)
0 4990 y Fj(PyObject)400 5005 y(*)498 4990 y Fg(PyMethod_Self)p
Fj(\()p Fo(PyObject)e(*meth)p Fj(\))208 5090 y Fo(Return)i(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 5189
y Fr(Return)f(the)i(instance)e(associated)h(with)h(the)f(method)f
Fo(meth)h Fr(if)g(it)h(is)g(bound,)d(otherwise)i(return)f
Fj(NULL)p Fr(.)p 0 5549 3901 4 v 0 5649 a Fn(72)2478
b(Chapter)23 b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p
eop end
%%Page: 73 79
TeXDict begin 73 78 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyMethod_GET_SELF)p Fj(\()p Fo(PyObject)16 b(*meth)p
Fj(\))208 183 y Fo(Return)j(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 282 y Fr(Macro)f(v)o(ersion)g(of)h
Fj(PyMethod_Self\(\))e Fr(which)h(a)n(v)n(oids)i(error)e(checking.)0
567 y Fh(7.5.5)100 b(Module)30 b(Objects)0 770 y Fr(There)19
b(are)h(only)g(a)g(fe)n(w)h(functions)d(special)j(to)f(module)f
(objects.)0 917 y Fj(PyTypeObject)48 b Fg(PyModule_Type)208
1017 y Fr(This)23 b(instance)f(of)h Fj(PyTypeObject)e
Fr(represents)h(the)h(Python)f(module)g(type.)32 b(This)24
b(is)f(e)o(xposed)f(to)h(Python)f(programs)f(as)208 1116
y Fj(types.ModuleType)p Fr(.)0 1263 y Fj(int)49 b Fg(PyModule_Check)p
Fj(\()p Fo(PyObject)17 b(*p)p Fj(\))208 1363 y Fr(Return)i(true)g(if)h
Fo(p)f Fr(is)i(a)f(module)e(object,)h(or)g(a)h(subtype)e(of)i(a)g
(module)e(object.)49 b(Changed)19 b(in)g(v)o(ersion)g(2.2:)f(Allo)n
(wed)h(subtypes)208 1462 y(to)h(be)g(accepted.)0 1609
y Fj(int)49 b Fg(PyModule_CheckExact)p Fj(\()p Fo(PyObject)16
b(*p)p Fj(\))208 1709 y Fr(Return)j(true)h(if)h Fo(p)f
Fr(is)h(a)g(module)d(object,)i(b)n(ut)g(not)g(a)h(subtype)e(of)g
Fj(PyModule_Type)p Fr(.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
1856 y Fj(PyObject)400 1871 y(*)498 1856 y Fg(PyModule_New)p
Fj(\()p Fo(const)f(c)o(har)h(*name)p Fj(\))208 1955 y
Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p Fo(.)208
2055 y Fr(Return)30 b(a)g(ne)n(w)h(module)e(object)g(with)i(the)f
Fj(__name__)g Fr(attrib)n(ute)g(set)h(to)g Fo(name)p
Fr(.)55 b(Only)30 b(the)g(module')-5 b(s)29 b Fj(__doc__)h
Fr(and)208 2155 y Fj(__name__)19 b Fr(attrib)n(utes)h(are)g(\002lled)g
(in;)h(the)f(caller)g(is)h(responsible)e(for)h(pro)o(viding)d(a)k
Fj(__file__)e Fr(attrib)n(ute.)0 2301 y Fj(PyObject)400
2316 y(*)498 2301 y Fg(PyModule_GetDict)p Fj(\()p Fo(PyObject)e
(*module)p Fj(\))208 2401 y Fo(Return)i(value:)25 b Ff(Borro)n(w)o(ed)
20 b(ref)o(erence)p Fo(.)208 2501 y Fr(Return)i(the)h(dictionary)f
(object)g(that)i(implements)e Fo(module)p Fr(')-5 b(s)22
b(namespace;)i(this)f(object)g(is)h(the)f(same)h(as)g(the)f
Fj(__dict__-)208 2600 y Fr(attrib)n(ute)16 b(of)h(the)g(module)e
(object.)23 b(This)17 b(function)f(ne)n(v)o(er)f(f)o(ails.)49
b(It)17 b(is)h(recommended)c(e)o(xtensions)i(use)h(other)f
Fj(PyModule_-)208 2715 y(*)258 2700 y(\(\))k Fr(and)f
Fj(PyObject_)968 2715 y(*)1018 2700 y(\(\))g Fr(functions)g(rather)g
(than)h(directly)f(manipulate)g(a)h(module')-5 b(s)20
b Fj(__dict__)p Fr(.)0 2847 y Fj(char)200 2862 y(*)299
2847 y Fg(PyModule_GetName)p Fj(\()p Fo(PyObject)c(*module)p
Fj(\))208 2946 y Fr(Return)k Fo(module)p Fr(')-5 b(s)20
b Fj(__name__)g Fr(v)n(alue.)26 b(If)20 b(the)h(module)f(does)g(not)h
(pro)o(vide)d(one,)i(or)h(if)g(it)g(is)h(not)f(a)g(string,)f
Fj(SystemError)208 3046 y Fr(is)h(raised)f(and)f Fj(NULL)h
Fr(is)h(returned.)0 3193 y Fj(char)200 3208 y(*)299 3193
y Fg(PyModule_GetFilename)p Fj(\()p Fo(PyObject)16 b(*module)p
Fj(\))208 3293 y Fr(Return)22 b(the)i(name)e(of)h(the)g(\002le)h(from)f
(which)f Fo(module)g Fr(w)o(as)i(loaded)f(using)f Fo(module)p
Fr(')-5 b(s)23 b Fj(__file__)f Fr(attrib)n(ute.)34 b(If)23
b(this)h(is)g(not)208 3392 y(de\002ned,)18 b(or)i(if)h(it)g(is)g(not)f
(a)g(string,)g(raise)h Fj(SystemError)d Fr(and)i(return)f
Fj(NULL)p Fr(.)0 3539 y Fj(int)49 b Fg(PyModule_AddObject)p
Fj(\()p Fo(PyObject)16 b(*module)o(,)j(const)h(c)o(har)g(*name)o(,)f
(PyObject)g(*value)p Fj(\))208 3639 y Fr(Add)i(an)g(object)g(to)g
Fo(module)g Fr(as)h Fo(name)p Fr(.)28 b(This)21 b(is)i(a)f(con)m(v)o
(enience)c(function)i(which)h(can)g(be)g(used)g(from)g(the)g(module')-5
b(s)21 b(initial-)208 3738 y(ization)e(function.)k(This)e(steals)g(a)g
(reference)d(to)j Fo(value)p Fr(.)j(Return)c Fj(-1)g
Fr(on)g(error)m(,)e Fj(0)j Fr(on)f(success.)51 b(Ne)n(w)20
b(in)h(v)o(ersion)e(2.0.)0 3885 y Fj(int)49 b Fg
(PyModule_AddIntConstant)p Fj(\()p Fo(PyObject)15 b(*module)o(,)k
(const)h(c)o(har)g(*name)o(,)f(long)g(value)p Fj(\))208
3985 y Fr(Add)j(an)i(inte)o(ger)e(constant)g(to)i Fo(module)e
Fr(as)i Fo(name)p Fr(.)34 b(This)23 b(con)m(v)o(enience)e(function)g
(can)i(be)h(used)f(from)f(the)h(module')-5 b(s)23 b(initial-)208
4084 y(ization)c(function.)k(Return)d Fj(-1)h Fr(on)e(error)m(,)g
Fj(0)h Fr(on)g(success.)51 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.0.)0
4231 y Fj(int)49 b Fg(PyModule_AddStringConstant)p Fj(\()p
Fo(PyObject)15 b(*module)o(,)j(const)j(c)o(har)e(*name)o(,)g(const)h(c)
o(har)g(*value)p Fj(\))208 4331 y Fr(Add)c(a)h(string)f(constant)g(to)h
Fo(module)f Fr(as)h Fo(name)p Fr(.)23 b(This)17 b(con)m(v)o(enience)d
(function)h(can)h(be)h(used)f(from)g(the)h(module')-5
b(s)15 b(initialization)208 4431 y(function.)23 b(The)d(string)f
Fo(value)h Fr(must)g(be)g(null-terminated.)j(Return)d
Fj(-1)g Fr(on)g(error)m(,)e Fj(0)j Fr(on)f(success.)51
b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.0.)0 4715 y Fh(7.5.6)100
b(Iter)o(ator)29 b(Objects)0 4918 y Fr(Python)20 b(pro)o(vides)f(tw)o
(o)i(general-purpose)d(iterator)i(objects.)27 b(The)21
b(\002rst,)g(a)h(sequence)e(iterator)m(,)g(w)o(orks)g(with)h(an)g
(arbitrary)f(sequence)0 5018 y(supporting)g(the)j Fj(__getitem__\(\))d
Fr(method.)30 b(The)22 b(second)g(w)o(orks)g(with)h(a)f(callable)h
(object)f(and)f(a)i(sentinel)g(v)n(alue,)f(calling)g(the)0
5118 y(callable)e(for)g(each)f(item)i(in)f(the)g(sequence,)f(and)h
(ending)e(the)j(iteration)e(when)h(the)g(sentinel)g(v)n(alue)f(is)j
(returned.)0 5264 y Fj(PyTypeObject)48 b Fg(PySeqIter_Type)208
5364 y Fr(T)-7 b(ype)22 b(object)h(for)g(iterator)g(objects)g(returned)
e(by)i Fj(PySeqIter_New\(\))f Fr(and)g(the)i(one-ar)o(gument)19
b(form)k(of)g(the)g Fj(iter\(\))p 0 5549 3901 4 v 0 5649
a Fn(7.5.)52 b(Other)23 b(Objects)3105 b(73)p eop end
%%Page: 74 80
TeXDict begin 74 79 bop 208 83 a Fr(b)n(uilt-in)19 b(function)g(for)g
(b)n(uilt-in)h(sequence)f(types.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f
(2.2.)0 230 y Fj(int)49 b Fg(PySeqIter_Check)p Fj(\()p
Fo(op)p Fj(\))208 330 y Fr(Return)19 b(true)h(if)h(the)f(type)g(of)f
Fo(op)h Fr(is)h Fj(PySeqIter_Type)p Fr(.)49 b(Ne)n(w)20
b(in)h(v)o(ersion)e(2.2.)0 476 y Fj(PyObject)400 491
y(*)498 476 y Fg(PySeqIter_New)p Fj(\()p Fo(PyObject)e(*seq)p
Fj(\))208 576 y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 676 y Fr(Return)i(an)g(iterator)g(that)g(w)o(orks)g(with)h(a)g
(general)e(sequence)g(object,)i Fo(seq)p Fr(.)31 b(The)23
b(iteration)e(ends)h(when)g(the)h(sequence)e(raises)208
775 y Fj(IndexError)d Fr(for)i(the)g(subscripting)f(operation.)49
b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)0 922 y Fj(PyTypeObject)48
b Fg(PyCallIter_Type)208 1022 y Fr(T)-7 b(ype)19 b(object)g(for)g
(iterator)f(objects)i(returned)d(by)j Fj(PyCallIter_New\(\))d
Fr(and)i(the)g(tw)o(o-ar)o(gument)e(form)h(of)i(the)f
Fj(iter\(\))208 1121 y Fr(b)n(uilt-in)g(function.)49
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0 1268 y Fj(int)49
b Fg(PyCallIter_Check)p Fj(\()p Fo(op)p Fj(\))208 1368
y Fr(Return)19 b(true)h(if)h(the)f(type)g(of)f Fo(op)h
Fr(is)h Fj(PyCallIter_Type)p Fr(.)49 b(Ne)n(w)20 b(in)h(v)o(ersion)d
(2.2.)0 1515 y Fj(PyObject)400 1530 y(*)498 1515 y Fg(PyCallIter_New)p
Fj(\()p Fo(PyObject)f(*callable)o(,)i(PyObject)g(*sentinel)p
Fj(\))208 1614 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1714 y Fr(Return)f(a)g(ne)n(w)h(iterator)-5
b(.)24 b(The)19 b(\002rst)h(parameter)m(,)e Fo(callable)p
Fr(,)g(can)i(be)f(an)o(y)g(Python)f(callable)h(object)g(that)g(can)h
(be)f(called)g(with)h(no)208 1814 y(parameters;)25 b(each)f(call)h(to)g
(it)g(should)f(return)f(the)i(ne)o(xt)f(item)g(in)h(the)g(iteration.)37
b(When)24 b Fo(callable)g Fr(returns)g(a)h(v)n(alue)e(equal)h(to)208
1913 y Fo(sentinel)p Fr(,)19 b(the)i(iteration)e(will)i(be)f
(terminated.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
2198 y Fh(7.5.7)100 b(Descr)q(iptor)29 b(Objects)0 2401
y Fr(\223Descriptors\224)19 b(are)h(objects)g(that)h(describe)e(some)h
(attrib)n(ute)g(of)g(an)g(object.)k(The)o(y)19 b(are)h(found)f(in)h
(the)g(dictionary)f(of)h(type)f(objects.)0 2548 y Fj(PyTypeObject)48
b Fg(PyProperty_Type)208 2648 y Fr(The)19 b(type)h(object)g(for)f(the)i
(b)n(uilt-in)e(descriptor)g(types.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f
(2.2.)0 2794 y Fj(PyObject)400 2809 y(*)498 2794 y Fg
(PyDescr_NewGetSet)p Fj(\()p Fo(PyT)-6 b(ypeObject)16
b(*type)o(,)j(struct)i(PyGetSetDef)f(*g)o(etset)q Fj(\))208
2894 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 2994 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)0
3141 y Fj(PyObject)400 3156 y(*)498 3141 y Fg(PyDescr_NewMember)p
Fj(\()p Fo(PyT)-6 b(ypeObject)16 b(*type)o(,)j(struct)i(PyMemberDef)f
(*meth)p Fj(\))208 3240 y Fo(Return)f(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 3340 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)0
3487 y Fj(PyObject)400 3502 y(*)498 3487 y Fg(PyDescr_NewMethod)p
Fj(\()p Fo(PyT)-6 b(ypeObject)16 b(*type)o(,)j(struct)i(PyMethodDef)e
(*meth)p Fj(\))208 3586 y Fo(Return)g(value:)25 b Ff(New)20
b(ref)o(erence)p Fo(.)208 3686 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)0
3833 y Fj(PyObject)400 3848 y(*)498 3833 y Fg(PyDescr_NewWrapper)p
Fj(\()p Fo(PyT)-6 b(ypeObject)16 b(*type)o(,)j(struct)i(wr)o(apperbase)
e(*wr)o(apper)-9 b(,)19 b(void)h(*wr)o(apped)r Fj(\))208
3932 y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4032 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)0
4179 y Fj(PyObject)400 4194 y(*)498 4179 y Fg(PyDescr_NewClassMethod)p
Fj(\()p Fo(PyT)-6 b(ypeObject)15 b(*type)o(,)k(PyMethodDef)g(*method)r
Fj(\))208 4279 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4378 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.3.)0
4525 y Fj(int)49 b Fg(PyDescr_IsData)p Fj(\()p Fo(PyObject)17
b(*descr)r Fj(\))208 4625 y Fr(Return)h(true)h(if)g(the)g(descriptor)e
(objects)i Fo(descr)i Fr(describes)d(a)i(data)e(attrib)n(ute,)h(or)f(f)
o(alse)i(if)f(it)h(describes)e(a)h(method.)k Fo(descr)f
Fr(must)208 4724 y(be)e(a)g(descriptor)f(object;)h(there)g(is)h(no)e
(error)g(checking.)49 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
4871 y Fj(PyObject)400 4886 y(*)498 4871 y Fg(PyWrapper_New)p
Fj(\()p Fo(PyObject)e(*,)j(PyObject)g(*)p Fj(\))208 4971
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 5070 y Fr(Ne)n(w)g(in)g(v)o(ersion)f(2.2.)p
0 5549 3901 4 v 0 5649 a Fn(74)2478 b(Chapter)23 b(7.)52
b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 75 81
TeXDict begin 75 80 bop 0 83 a Fh(7.5.8)100 b(Slice)29
b(Objects)0 272 y Fj(PyTypeObject)48 b Fg(PySlice_Type)208
372 y Fr(The)19 b(type)h(object)g(for)f(slice)i(objects.)k(This)20
b(is)h(the)g(same)f(as)h Fj(slice)f Fr(and)f Fj(types.SliceType)p
Fr(.)0 518 y Fj(int)49 b Fg(PySlice_Check)p Fj(\()p Fo(PyObject)17
b(*ob)p Fj(\))208 618 y Fr(Return)i(true)h(if)h Fo(ob)e
Fr(is)j(a)e(slice)h(object;)f Fo(ob)g Fr(must)g(not)g(be)g
Fj(NULL)p Fr(.)0 765 y Fj(PyObject)400 780 y(*)498 765
y Fg(PySlice_New)p Fj(\()p Fo(PyObject)e(*start,)i(PyObject)g(*stop,)f
(PyObject)h(*step)p Fj(\))208 865 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 964 y Fr(Return)j(a)g(ne)n(w)h
(slice)g(object)f(with)g(the)h(gi)n(v)o(en)e(v)n(alues.)34
b(The)23 b Fo(start)q Fr(,)j Fo(stop)p Fr(,)e(and)f Fo(step)g
Fr(parameters)g(are)g(used)g(as)h(the)g(v)n(alues)f(of)208
1064 y(the)e(slice)h(object)f(attrib)n(utes)h(of)f(the)h(same)f(names.)
29 b(An)o(y)21 b(of)g(the)h(v)n(alues)f(may)g(be)h Fj(NULL)p
Fr(,)f(in)g(which)g(case)h(the)g Fj(None)f Fr(will)i(be)208
1163 y(used)c(for)h(the)g(corresponding)d(attrib)n(ute.)25
b(Return)19 b Fj(NULL)h Fr(if)h(the)f(ne)n(w)g(object)g(could)f(not)h
(be)g(allocated.)0 1310 y Fj(int)49 b Fg(PySlice_GetIndices)p
Fj(\()p Fo(PySliceObject)31 b(*slice)o(,)39 b(Py)p 1998
1310 25 4 v 29 w(ssize)p 2183 1310 V 31 w(t)d(length,)h(Py)p
2628 1310 V 30 w(ssize)p 2814 1310 V 30 w(t)f(*start,)j(Py)p
3245 1310 V 29 w(ssize)p 3430 1310 V 31 w(t)d(*stop,)i(Py)p
3848 1310 V 29 w(-)1149 1410 y(ssize)p 1310 1410 V 27
w(t)21 b(*step)p Fj(\))208 1492 y Fr(Retrie)n(v)o(e)e(the)g(start,)h
(stop)f(and)g(step)h(indices)f(from)g(the)g(slice)i(object)e
Fo(slice)p Fr(,)h(assuming)f(a)g(sequence)g(of)g(length)g
Fo(length)p Fr(.)k(T)m(reats)208 1592 y(indices)d(greater)f(than)g
Fo(length)h Fr(as)h(errors.)208 1725 y(Returns)h(0)g(on)g(success)h
(and)f(-1)g(on)f(error)h(with)g(no)g(e)o(xception)e(set)k(\(unless)e
(one)f(of)h(the)h(indices)f(w)o(as)h(not)f Fj(None)g
Fr(and)g(f)o(ailed)208 1824 y(to)e(be)g(con)m(v)o(erted)e(to)i(an)g
(inte)o(ger)m(,)f(in)h(which)g(case)g(-1)g(is)h(returned)e(with)h(an)g
(e)o(xception)e(set\).)208 1957 y(Y)-9 b(ou)24 b(probably)e(do)j(not)f
(w)o(ant)h(to)g(use)g(this)h(function.)37 b(If)24 b(you)g(w)o(ant)h(to)
g(use)g(slice)h(objects)f(in)g(v)o(ersions)e(of)i(Python)f(prior)f(to)
208 2057 y(2.3,)f(you)f(w)o(ould)h(probably)e(do)i(well)h(to)f
(incorporate)e(the)i(source)g(of)g Fj(PySlice_GetIndicesEx)p
Fr(,)e(suitably)h(renamed,)208 2156 y(in)f(the)g(source)g(of)f(your)g
(e)o(xtension.)0 2303 y Fj(int)49 b Fg(PySlice_GetIndicesEx)p
Fj(\()p Fo(PySliceObject)19 b(*slice)o(,)25 b(Py)p 2072
2303 V 30 w(ssize)p 2258 2303 V 31 w(t)f(length,)g(Py)p
2678 2303 V 29 w(ssize)p 2863 2303 V 31 w(t)h(*start,)g(Py)p
3270 2303 V 29 w(ssize)p 3455 2303 V 31 w(t)g(*stop,)f(Py)p
3848 2303 V 29 w(-)1249 2403 y(ssize)p 1410 2403 V 27
w(t)d(*step,)f(Py)p 1786 2403 V 29 w(ssize)p 1971 2403
V 31 w(t)h(*slicelength)p Fj(\))208 2485 y Fr(Usable)30
b(replacement)f(for)h Fj(PySlice_GetIndices)p Fr(.)53
b(Retrie)n(v)o(e)30 b(the)h(start,)j(stop,)e(and)e(step)h(indices)g
(from)e(the)i(slice)208 2585 y(object)18 b Fo(slice)j
Fr(assuming)d(a)i(sequence)e(of)i(length)e Fo(length)p
Fr(,)h(and)g(store)g(the)g(length)g(of)g(the)h(slice)g(in)f
Fo(slicelength)p Fr(.)24 b(Out)c(of)f(bounds)208 2684
y(indices)h(are)g(clipped)f(in)h(a)h(manner)e(consistent)g(with)i(the)f
(handling)e(of)i(normal)f(slices.)208 2817 y(Returns)h(0)g(on)g
(success)g(and)g(-1)g(on)g(error)f(with)h(e)o(xception)e(set.)208
2950 y(Ne)n(w)i(in)g(v)o(ersion)f(2.3.)0 3235 y Fh(7.5.9)100
b(W)m(eak)29 b(Ref)m(erence)g(Objects)0 3438 y Fr(Python)22
b(supports)g Fo(weak)i(r)m(efer)m(ences)f Fr(as)h(\002rst-class)g
(objects.)34 b(There)22 b(are)h(tw)o(o)h(speci\002c)f(object)g(types)g
(which)f(directly)h(implement)0 3537 y(weak)e(references.)27
b(The)21 b(\002rst)g(is)i(a)e(simple)g(reference)f(object,)h(and)f(the)
i(second)e(acts)i(as)g(a)f(proxy)f(for)h(the)g(original)f(object)h(as)h
(much)0 3637 y(as)f(it)g(can.)0 3784 y Fj(int)49 b Fg(PyWeakref_Check)p
Fj(\()p Fo(ob)p Fj(\))208 3883 y Fr(Return)19 b(true)h(if)h
Fo(ob)e Fr(is)j(either)d(a)i(reference)d(or)i(proxy)f(object.)50
b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.2.)0 4030 y Fj(int)49
b Fg(PyWeakref_CheckRef)p Fj(\()p Fo(ob)p Fj(\))208 4130
y Fr(Return)19 b(true)h(if)h Fo(ob)e Fr(is)j(a)e(reference)f(object.)50
b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.2.)0 4277 y Fj(int)49
b Fg(PyWeakref_CheckProxy)p Fj(\()p Fo(ob)p Fj(\))208
4376 y Fr(Return)19 b(true)h(if)h Fo(ob)e Fr(is)j(a)e(proxy)f(object.)
50 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.2.)0 4523 y Fj(PyObject)400
4538 y(*)498 4523 y Fg(PyWeakref_NewRef)p Fj(\()p Fo(PyObject)e(*ob,)i
(PyObject)g(*callbac)n(k)q Fj(\))208 4623 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4722 y Fr(Return)f(a)i(weak)f
(reference)f(object)g(for)h(the)g(object)g Fo(ob)p Fr(.)25
b(This)20 b(will)h(al)o(w)o(ays)g(return)e(a)i(ne)n(w)f(reference,)e(b)
n(ut)j(is)g(not)f(guaranteed)208 4822 y(to)i(create)g(a)g(ne)n(w)g
(object;)h(an)f(e)o(xisting)f(reference)g(object)g(may)h(be)g
(returned.)29 b(The)22 b(second)f(parameter)m(,)f Fo(callbac)n(k)q
Fr(,)i(can)g(be)g(a)208 4922 y(callable)17 b(object)g(that)g(recei)n(v)
o(es)g(noti\002cation)f(when)h Fo(ob)g Fr(is)h(garbage)e(collected;)h
(it)i(should)d(accept)h(a)h(single)f(parameter)m(,)f(which)208
5021 y(will)j(be)g(the)f(weak)h(reference)e(object)h(itself.)25
b Fo(callbac)n(k)19 b Fr(may)f(also)h(be)g Fj(None)f
Fr(or)g Fj(NULL)p Fr(.)h(If)f Fo(ob)g Fr(is)i(not)e(a)h
(weakly-referencable)208 5121 y(object,)24 b(or)h(if)f
Fo(callbac)n(k)h Fr(is)h(not)e(callable,)h Fj(None)p
Fr(,)g(or)g Fj(NULL)p Fr(,)f(this)h(will)g(return)e Fj(NULL)i
Fr(and)e(raise)i Fj(TypeError)p Fr(.)76 b(Ne)n(w)24 b(in)208
5221 y(v)o(ersion)18 b(2.2.)p 0 5549 3901 4 v 0 5649
a Fn(7.5.)52 b(Other)23 b(Objects)3105 b(75)p eop end
%%Page: 76 82
TeXDict begin 76 81 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(PyWeakref_NewProxy)p Fj(\()p Fo(PyObject)16 b(*ob,)j(PyObject)h
(*callbac)n(k)q Fj(\))208 183 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 282 y Fr(Return)27
b(a)i(weak)f(reference)f(proxy)f(object)i(for)g(the)g(object)g
Fo(ob)p Fr(.)49 b(This)28 b(will)h(al)o(w)o(ays)g(return)e(a)i(ne)n(w)f
(reference,)g(b)n(ut)h(is)g(not)208 382 y(guaranteed)13
b(to)j(create)f(a)h(ne)n(w)f(object;)i(an)e(e)o(xisting)g(proxy)f
(object)h(may)g(be)g(returned.)22 b(The)15 b(second)g(parameter)m(,)f
Fo(callbac)n(k)q Fr(,)i(can)208 482 y(be)21 b(a)h(callable)f(object)g
(that)h(recei)n(v)o(es)f(noti\002cation)f(when)h Fo(ob)g
Fr(is)i(garbage)c(collected;)j(it)g(should)f(accept)g(a)h(single)g
(parameter)m(,)208 581 y(which)k(will)j(be)e(the)g(weak)g(reference)f
(object)h(itself.)47 b Fo(callbac)n(k)28 b Fr(may)f(also)h(be)f
Fj(None)g Fr(or)g Fj(NULL)p Fr(.)g(If)g Fo(ob)g Fr(is)i(not)e(a)h
(weakly-)208 681 y(referencable)15 b(object,)j(or)g(if)g
Fo(callbac)n(k)g Fr(is)h(not)f(callable,)g Fj(None)p
Fr(,)g(or)f Fj(NULL)p Fr(,)h(this)g(will)h(return)e Fj(NULL)g
Fr(and)h(raise)g Fj(TypeError)p Fr(.)208 780 y(Ne)n(w)i(in)g(v)o
(ersion)f(2.2.)0 927 y Fj(PyObject)400 942 y(*)498 927
y Fg(PyWeakref_GetObject)p Fj(\()p Fo(PyObject)d(*r)m(ef)c
Fj(\))208 1027 y Fo(Return)19 b(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 1127 y Fr(Return)e(the)h(referenced)e(object)
i(from)f(a)h(weak)g(reference,)e Fo(r)m(ef)12 b Fr(.)26
b(If)18 b(the)h(referent)f(is)i(no)f(longer)e(li)n(v)o(e,)i(returns)f
Fj(None)p Fr(.)50 b(Ne)n(w)19 b(in)208 1226 y(v)o(ersion)f(2.2.)0
1373 y Fj(PyObject)400 1388 y(*)498 1373 y Fg(PyWeakref_GET_OBJECT)p
Fj(\()p Fo(PyObject)e(*r)m(ef)c Fj(\))208 1473 y Fo(Return)19
b(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208
1572 y Fr(Similar)k(to)h Fj(PyWeakref_GetObject\(\))p
Fr(,)d(b)n(ut)i(implemented)f(as)i(a)g(macro)f(that)g(does)g(no)g
(error)g(checking.)75 b(Ne)n(w)24 b(in)208 1672 y(v)o(ersion)18
b(2.2.)0 1957 y Fh(7.5.10)101 b(CObjects)0 2160 y Fr(Refer)16
b(to)g Fo(Extending)f(and)g(Embedding)f(the)i(Python)f(Interpr)m(eter)p
Fr(,)h(section)g(1.12,)g(\223Pro)o(viding)e(a)i(C)h(API)g(for)e(an)h
(Extension)f(Module,)-6 b(\224)0 2259 y(for)20 b(more)f(information)f
(on)h(using)h(these)h(objects.)0 2406 y Fg(PyCObject)208
2506 y Fr(This)j(subtype)g(of)g Fj(PyObject)f Fr(represents)h(an)g
(opaque)f(v)n(alue,)i(useful)f(for)f(C)j(e)o(xtension)d(modules)g(who)h
(need)g(to)h(pass)g(an)208 2605 y(opaque)19 b(v)n(alue)i(\(as)h(a)g
Fj(void)1047 2620 y(*)1118 2605 y Fr(pointer\))e(through)f(Python)h
(code)h(to)h(other)e(C)j(code.)28 b(It)21 b(is)i(often)d(used)h(to)h
(mak)o(e)f(a)h(C)g(function)208 2705 y(pointer)15 b(de\002ned)h(in)h
(one)f(module)g(a)n(v)n(ailable)g(to)h(other)g(modules,)f(so)h(the)g
(re)o(gular)e(import)h(mechanism)g(can)g(be)h(used)g(to)g(access)208
2805 y(C)k(APIs)f(de\002ned)g(in)g(dynamically)e(loaded)h(modules.)0
2952 y Fj(int)49 b Fg(PyCObject_Check)p Fj(\()p Fo(PyObject)17
b(*p)p Fj(\))208 3051 y Fr(Return)i(true)h(if)h(its)g(ar)o(gument)d(is)
j(a)f Fj(PyCObject)p Fr(.)0 3198 y Fj(PyObject)400 3213
y(*)498 3198 y Fg(PyCObject_FromVoidPtr)p Fj(\()p Fo(void*)15
b(cobj,)20 b(void)f(\(*destr\)\(void)g(*\))p Fj(\))208
3298 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3397 y Fr(Create)j(a)h Fj(PyCObject)f Fr(from)f(the)i
Fj(void)1542 3412 y(*)1592 3397 y Fo(cobj)p Fr(.)34 b(The)24
b Fo(destr)i Fr(function)c(will)i(be)f(called)h(when)f(the)g(object)g
(is)i(reclaimed,)208 3497 y(unless)20 b(it)h(is)g Fj(NULL)p
Fr(.)0 3644 y Fj(PyObject)400 3659 y(*)498 3644 y Fg
(PyCObject_FromVoidPtrAndDesc)p Fj(\()p Fo(void*)14 b(cobj,)19
b(void*)h(desc,)g(void)f(\(*destr\)\(void)g(*,)h(void)f(*\))p
Fj(\))208 3743 y Fo(Return)g(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3843 y Fr(Create)j(a)h Fj(PyCObject)f Fr(from)f(the)i
Fj(void)1542 3858 y(*)1592 3843 y Fo(cobj)p Fr(.)34 b(The)24
b Fo(destr)i Fr(function)c(will)i(be)f(called)h(when)f(the)g(object)g
(is)i(reclaimed.)208 3943 y(The)19 b Fo(desc)i Fr(ar)o(gument)d(can)i
(be)g(used)g(to)g(pass)h(e)o(xtra)e(callback)g(data)i(for)e(the)h
(destructor)f(function.)0 4090 y Fj(void)200 4105 y(*)299
4090 y Fg(PyCObject_AsVoidPtr)p Fj(\()p Fo(PyObject*)c(self)d
Fj(\))208 4189 y Fr(Return)19 b(the)i(object)e Fj(void)1049
4204 y(*)1120 4189 y Fr(that)h(the)g Fj(PyCObject)f Fo(self)34
b Fr(w)o(as)21 b(created)e(with.)0 4336 y Fj(void)200
4351 y(*)299 4336 y Fg(PyCObject_GetDesc)p Fj(\()p Fo(PyObject*)d(self)
c Fj(\))208 4436 y Fr(Return)19 b(the)i(description)d
Fj(void)1215 4451 y(*)1286 4436 y Fr(that)i(the)g Fj(PyCObject)f
Fo(self)34 b Fr(w)o(as)21 b(created)e(with.)0 4583 y
Fj(int)49 b Fg(PyCObject_SetVoidPtr)p Fj(\()p Fo(PyObject*)16
b(self)o(,)21 b(void*)e(cobj)p Fj(\))208 4682 y Fr(Set)24
b(the)f(v)n(oid)g(pointer)f(inside)h Fo(self)36 b Fr(to)24
b Fo(cobj)p Fr(.)33 b(The)23 b Fj(PyCObject)g Fr(must)g(not)g(ha)n(v)o
(e)g(an)g(associated)g(destructor)-5 b(.)33 b(Return)23
b(true)208 4782 y(on)c(success,)i(f)o(alse)f(on)g(f)o(ailure.)0
5067 y Fh(7.5.11)101 b(Cell)28 b(Objects)0 5270 y Fr(\223Cell\224)22
b(objects)g(are)g(used)f(to)h(implement)e(v)n(ariables)h(referenced)f
(by)h(multiple)g(scopes.)30 b(F)o(or)21 b(each)h(such)f(v)n(ariable,)g
(a)h(cell)g(object)g(is)0 5369 y(created)f(to)h(store)g(the)h(v)n
(alue;)f(the)g(local)g(v)n(ariables)f(of)h(each)g(stack)g(frame)f(that)
h(references)f(the)h(v)n(alue)f(contains)h(a)g(reference)e(to)j(the)p
0 5549 3901 4 v 0 5649 a Fn(76)2478 b(Chapter)23 b(7.)52
b(Concrete)23 b(Objects)f(La)n(y)n(er)p eop end
%%Page: 77 83
TeXDict begin 77 82 bop 0 83 a Fr(cells)19 b(from)e(outer)g(scopes)h
(which)f(also)i(use)f(that)g(v)n(ariable.)23 b(When)18
b(the)g(v)n(alue)f(is)i(accessed,)f(the)g(v)n(alue)g(contained)e(in)i
(the)g(cell)h(is)g(used)0 183 y(instead)k(of)f(the)h(cell)g(object)f
(itself.)34 b(This)23 b(de-referencing)c(of)k(the)f(cell)i(object)e
(requires)g(support)f(from)h(the)h(generated)e(byte-code;)0
282 y(these)f(are)g(not)g(automatically)f(de-referenced)e(when)j
(accessed.)25 b(Cell)c(objects)f(are)g(not)g(lik)o(ely)g(to)g(be)g
(useful)g(else)n(where.)0 429 y Fg(PyCellObject)208 529
y Fr(The)f(C)j(structure)d(used)h(for)f(cell)i(objects.)0
676 y Fj(PyTypeObject)48 b Fg(PyCell_Type)208 775 y Fr(The)19
b(type)h(object)g(corresponding)d(to)j(cell)g(objects.)0
922 y Fj(int)49 b Fg(PyCell_Check)p Fj(\()p Fo(ob)p Fj(\))208
1022 y Fr(Return)19 b(true)h(if)h Fo(ob)e Fr(is)j(a)e(cell)h(object;)f
Fo(ob)f Fr(must)i(not)e(be)i Fj(NULL)p Fr(.)0 1169 y
Fj(PyObject)400 1184 y(*)498 1169 y Fg(PyCell_New)p Fj(\()p
Fo(PyObject)d(*ob)p Fj(\))208 1268 y Fo(Return)h(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1368 y Fr(Create)g(and)g(return)f
(a)h(ne)n(w)g(cell)h(object)f(containing)e(the)i(v)n(alue)g
Fo(ob)p Fr(.)k(The)c(parameter)f(may)g(be)h Fj(NULL)p
Fr(.)0 1515 y Fj(PyObject)400 1530 y(*)498 1515 y Fg(PyCell_Get)p
Fj(\()p Fo(PyObject)e(*cell)p Fj(\))208 1614 y Fo(Return)h(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 1714 y Fr(Return)f(the)i
(contents)e(of)h(the)g(cell)h Fo(cell)p Fr(.)0 1861 y
Fj(PyObject)400 1876 y(*)498 1861 y Fg(PyCell_GET)p Fj(\()p
Fo(PyObject)d(*cell)p Fj(\))208 1961 y Fo(Return)h(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 2060
y Fr(Return)f(the)i(contents)e(of)h(the)g(cell)h Fo(cell)p
Fr(,)f(b)n(ut)g(without)g(checking)e(that)j Fo(cell)f
Fr(is)h(non-)p Fj(NULL)e Fr(and)g(a)i(cell)g(object.)0
2207 y Fj(int)49 b Fg(PyCell_Set)p Fj(\()p Fo(PyObject)18
b(*cell,)i(PyObject)f(*value)p Fj(\))208 2307 y Fr(Set)26
b(the)f(contents)g(of)g(the)g(cell)h(object)f Fo(cell)h
Fr(to)g Fo(value)p Fr(.)40 b(This)25 b(releases)h(the)f(reference)f(to)
i(an)o(y)e(current)g(content)h(of)g(the)g(cell.)208 2406
y Fo(value)18 b Fr(may)h(be)h Fj(NULL)p Fr(.)f Fo(cell)h
Fr(must)f(be)g(non-)p Fj(NULL)p Fr(;)f(if)h(it)i(is)f(not)f(a)h(cell)g
(object,)e Fj(-1)i Fr(will)g(be)g(returned.)i(On)e(success,)g
Fj(0)f Fr(will)i(be)208 2506 y(returned.)0 2653 y Fj(void)49
b Fg(PyCell_SET)p Fj(\()p Fo(PyObject)18 b(*cell,)i(PyObject)f(*value)p
Fj(\))208 2752 y Fr(Sets)27 b(the)g(v)n(alue)f(of)g(the)h(cell)g
(object)f Fo(cell)h Fr(to)g Fo(value)p Fr(.)44 b(No)26
b(reference)f(counts)h(are)h(adjusted,)g(and)f(no)g(checks)h(are)f
(made)g(for)208 2852 y(safety;)20 b Fo(cell)g Fr(must)h(be)f(non-)p
Fj(NULL)e Fr(and)i(must)g(be)g(a)h(cell)f(object.)0 3137
y Fh(7.5.12)101 b(Gener)o(ator)29 b(Objects)0 3340 y
Fr(Generator)19 b(objects)i(are)g(what)g(Python)f(uses)h(to)g
(implement)f(generator)f(iterators.)27 b(The)o(y)20 b(are)h(normally)e
(created)h(by)h(iterating)f(o)o(v)o(er)0 3439 y(a)h(function)d(that)i
(yields)g(v)n(alues,)g(rather)f(than)h(e)o(xplicitly)f(calling)h
Fj(PyGen_New)p Fr(.)0 3586 y Fg(PyGenObject)208 3686
y Fr(The)f(C)j(structure)d(used)h(for)f(generator)g(objects.)0
3833 y Fj(PyTypeObject)48 b Fg(PyGen_Type)208 3932 y
Fr(The)19 b(type)h(object)g(corresponding)d(to)j(generator)e(objects)0
4079 y Fj(int)49 b Fg(PyGen_Check)p Fj(\()p Fo(ob)p Fj(\))208
4179 y Fr(Return)19 b(true)h(if)h Fo(ob)e Fr(is)j(a)e(generator)e
(object;)i Fo(ob)g Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)0
4326 y Fj(int)49 b Fg(PyGen_CheckExact)p Fj(\()p Fo(ob)p
Fj(\))208 4425 y Fr(Return)19 b(true)h(if)h Fo(ob)p Fr(')-5
b(s)20 b(type)f(is)j Fo(PyGen)p 1307 4425 25 4 v 28 w(T)-6
b(ype)20 b Fr(is)i(a)e(generator)e(object;)i Fo(ob)g
Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)0 4572 y Fj(PyObject)400
4587 y(*)498 4572 y Fg(PyGen_New)p Fj(\()p Fo(PyF)-5
b(r)o(ameObject)17 b(*fr)o(ame)p Fj(\))208 4672 y Fo(Return)i(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4772 y Fr(Create)29
b(and)g(return)g(a)h(ne)n(w)f(generator)f(object)h(based)g(on)g(the)h
Fo(fr)o(ame)f Fr(object.)53 b(A)30 b(reference)e(to)h
Fo(fr)o(ame)h Fr(is)g(stolen)g(by)f(this)208 4871 y(function.)23
b(The)d(parameter)e(must)j(not)e(be)h Fj(NULL)p Fr(.)p
0 5549 3901 4 v 0 5649 a Fn(7.5.)52 b(Other)23 b(Objects)3105
b(77)p eop end
%%Page: 78 84
TeXDict begin 78 83 bop 0 83 a Fh(7.5.13)101 b(DateTime)28
b(Objects)0 286 y Fr(V)-9 b(arious)31 b(date)g(and)g(time)g(objects)h
(are)f(supplied)f(by)h(the)h Fj(datetime)e Fr(module.)58
b(Before)31 b(using)g(an)o(y)f(of)h(these)h(functions,)h(the)0
386 y(header)h(\002le)i(`)p Fs(datetime)o(.h)p Fr(')31
b(must)k(be)g(included)f(in)h(your)f(source)g(\(note)g(that)i(this)f
(is)h(not)f(included)e(by)i(`)p Fs(Python.h)p Fr('\),)h(and)f(the)0
485 y(macro)27 b Fj(PyDateTime_IMPORT)e Fr(must)j(be)f(in)m(v)n(ok)o
(ed.)46 b(The)28 b(macro)f(puts)g(a)h(pointer)f(to)h(a)g(C)h(structure)
e(into)g(a)h(static)h(v)n(ariable,)0 585 y Fj(PyDateTimeAPI)p
Fr(,)18 b(that)i(is)h(used)f(by)g(the)g(follo)n(wing)f(macros.)0
732 y(T)-7 b(ype-check)18 b(macros:)0 879 y Fj(int)49
b Fg(PyDate_Check)p Fj(\()p Fo(PyObject)18 b(*ob)p Fj(\))208
978 y Fr(Return)k(true)h(if)h Fo(ob)f Fr(is)h(of)f(type)g
Fj(PyDateTime_DateType)d Fr(or)j(a)g(subtype)g(of)g Fj
(PyDateTime_DateType)p Fr(.)31 b Fo(ob)23 b Fr(must)208
1078 y(not)c(be)i Fj(NULL)p Fr(.)40 b(Ne)n(w)20 b(in)h(v)o(ersion)e
(2.4.)0 1225 y Fj(int)49 b Fg(PyDate_CheckExact)p Fj(\()p
Fo(PyObject)17 b(*ob)p Fj(\))208 1324 y Fr(Return)i(true)h(if)h
Fo(ob)e Fr(is)j(of)d(type)h Fj(PyDateTime_DateType)p
Fr(.)i Fo(ob)e Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)41
b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0 1471 y Fj(int)49
b Fg(PyDateTime_Check)p Fj(\()p Fo(PyObject)17 b(*ob)p
Fj(\))208 1571 y Fr(Return)d(true)h(if)h Fo(ob)f Fr(is)h(of)f(type)g
Fj(PyDateTime_DateTimeType)d Fr(or)j(a)g(subtype)g(of)g
Fj(PyDateTime_DateTimeType)p Fr(.)208 1670 y Fo(ob)k
Fr(must)i(not)e(be)i Fj(NULL)p Fr(.)40 b(Ne)n(w)20 b(in)h(v)o(ersion)e
(2.4.)0 1817 y Fj(int)49 b Fg(PyDateTime_CheckExact)p
Fj(\()p Fo(PyObject)16 b(*ob)p Fj(\))208 1917 y Fr(Return)j(true)h(if)h
Fo(ob)e Fr(is)j(of)d(type)h Fj(PyDateTime_DateTimeType)p
Fr(.)h Fo(ob)f Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)41
b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0 2064 y Fj(int)49
b Fg(PyTime_Check)p Fj(\()p Fo(PyObject)18 b(*ob)p Fj(\))208
2163 y Fr(Return)k(true)h(if)h Fo(ob)f Fr(is)h(of)f(type)g
Fj(PyDateTime_TimeType)d Fr(or)j(a)g(subtype)g(of)g Fj
(PyDateTime_TimeType)p Fr(.)31 b Fo(ob)23 b Fr(must)208
2263 y(not)c(be)i Fj(NULL)p Fr(.)40 b(Ne)n(w)20 b(in)h(v)o(ersion)e
(2.4.)0 2410 y Fj(int)49 b Fg(PyTime_CheckExact)p Fj(\()p
Fo(PyObject)17 b(*ob)p Fj(\))208 2510 y Fr(Return)i(true)h(if)h
Fo(ob)e Fr(is)j(of)d(type)h Fj(PyDateTime_TimeType)p
Fr(.)i Fo(ob)e Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)41
b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0 2656 y Fj(int)49
b Fg(PyDelta_Check)p Fj(\()p Fo(PyObject)17 b(*ob)p Fj(\))208
2756 y Fr(Return)28 b(true)h(if)g Fo(ob)f Fr(is)i(of)f(type)g
Fj(PyDateTime_DeltaType)c Fr(or)k(a)g(subtype)f(of)h
Fj(PyDateTime_DeltaType)p Fr(.)48 b Fo(ob)208 2856 y
Fr(must)20 b(not)g(be)g Fj(NULL)p Fr(.)40 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.4.)0 3003 y Fj(int)49 b Fg(PyDelta_CheckExact)p
Fj(\()p Fo(PyObject)16 b(*ob)p Fj(\))208 3102 y Fr(Return)j(true)h(if)h
Fo(ob)e Fr(is)j(of)d(type)h Fj(PyDateTime_DeltaType)p
Fr(.)i Fo(ob)e Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)40
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0 3249 y Fj(int)49
b Fg(PyTZInfo_Check)p Fj(\()p Fo(PyObject)17 b(*ob)p
Fj(\))208 3349 y Fr(Return)k(true)h(if)h Fo(ob)f Fr(is)h(of)f(type)g
Fj(PyDateTime_TZInfoType)d Fr(or)j(a)h(subtype)e(of)h
Fj(PyDateTime_TZInfoType)p Fr(.)28 b Fo(ob)208 3448 y
Fr(must)20 b(not)g(be)g Fj(NULL)p Fr(.)40 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.4.)0 3595 y Fj(int)49 b Fg(PyTZInfo_CheckExact)p
Fj(\()p Fo(PyObject)16 b(*ob)p Fj(\))208 3695 y Fr(Return)j(true)h(if)h
Fo(ob)e Fr(is)j(of)d(type)h Fj(PyDateTime_TZInfoType)p
Fr(.)i Fo(ob)e Fr(must)g(not)g(be)g Fj(NULL)p Fr(.)40
b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0 3842 y(Macros)h(to)g(create)g
(objects:)0 3989 y Fj(PyObject)400 4004 y(*)498 3989
y Fg(PyDate_FromDate)p Fj(\()p Fo(int)e(year)-9 b(,)19
b(int)i(month,)e(int)h(day)p Fj(\))208 4088 y Fo(Return)f(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4188 y Fr(Return)f(a)i
Fj(datetime.date)d Fr(object)i(with)g(the)g(speci\002ed)g(year)m(,)f
(month)g(and)h(day)-5 b(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.4.)0
4335 y Fj(PyObject)400 4350 y(*)498 4335 y Fg
(PyDateTime_FromDateAndTime)p Fj(\()p Fo(int)e(year)-9
b(,)20 b(int)h(month,)f(int)g(day)-5 b(,)21 b(int)f(hour)-9
b(,)20 b(int)h(minute)o(,)f(int)h(second,)e(int)1848
4434 y(usecond)q Fj(\))208 4510 y Fo(Return)g(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4609 y Fr(Return)28
b(a)h Fj(datetime.datetime)d Fr(object)i(with)h(the)g(speci\002ed)f
(year)m(,)i(month,)f(day)-5 b(,)30 b(hour)m(,)f(minute,)h(second)e(and)
g(mi-)208 4709 y(crosecond.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0
4856 y Fj(PyObject)400 4871 y(*)498 4856 y Fg(PyTime_FromTime)p
Fj(\()p Fo(int)f(hour)-9 b(,)19 b(int)h(minute)o(,)g(int)g(second,)f
(int)i(usecond)r Fj(\))208 4955 y Fo(Return)e(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 5055 y Fr(Return)h(a)h
Fj(datetime.time)f Fr(object)g(with)h(the)g(speci\002ed)g(hour)m(,)e
(minute,)i(second)f(and)g(microsecond.)59 b(Ne)n(w)23
b(in)f(v)o(ersion)208 5155 y(2.4.)0 5301 y Fj(PyObject)400
5316 y(*)498 5301 y Fg(PyDelta_FromDSU)p Fj(\()p Fo(int)c(days,)h(int)i
(seconds,)e(int)h(useconds)p Fj(\))p 0 5549 3901 4 v
0 5649 a Fn(78)2478 b(Chapter)23 b(7.)52 b(Concrete)23
b(Objects)f(La)n(y)n(er)p eop end
%%Page: 79 85
TeXDict begin 79 84 bop 208 83 a Fo(Return)19 b(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 183 y Fr(Return)i(a)h
Fj(datetime.timedelta)d Fr(object)j(representing)d(the)j(gi)n(v)o(en)f
(number)f(of)h(days,)h(seconds)f(and)h(microseconds.)208
282 y(Normalization)f(is)k(performed)c(so)j(that)g(the)g(resulting)f
(number)f(of)h(microseconds)f(and)h(seconds)g(lie)h(in)g(the)g(ranges)f
(docu-)208 382 y(mented)19 b(for)g Fj(datetime.timedelta)f
Fr(objects.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0
529 y(Macros)27 b(to)h(e)o(xtract)f(\002elds)h(from)e(date)i(objects.)
47 b(The)27 b(ar)o(gument)e(must)j(be)f(an)h(instance)f(of)g
Fj(PyDateTime_Date)p Fr(,)g(including)0 628 y(subclasses)21
b(\(such)e(as)i Fj(PyDateTime_DateTime)p Fr(\).)h(The)e(ar)o(gument)d
(must)k(not)e(be)i Fj(NULL)p Fr(,)e(and)h(the)g(type)g(is)h(not)f
(check)o(ed:)0 775 y Fj(int)49 b Fg(PyDateTime_GET_YEAR)p
Fj(\()p Fo(PyDateT)-5 b(ime)p 1615 775 25 4 v 26 w(Date)20
b(*o)p Fj(\))208 875 y Fr(Return)f(the)i(year)m(,)e(as)h(a)h(positi)n
(v)o(e)e(int.)51 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0
1022 y Fj(int)49 b Fg(PyDateTime_GET_MONTH)p Fj(\()p
Fo(PyDateT)-5 b(ime)p 1665 1022 V 26 w(Date)20 b(*o)p
Fj(\))208 1121 y Fr(Return)f(the)i(month,)d(as)j(an)f(int)h(from)e(1)h
(through)e(12.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)0
1268 y Fj(int)49 b Fg(PyDateTime_GET_DAY)p Fj(\()p Fo(PyDateT)-5
b(ime)p 1565 1268 V 26 w(Date)20 b(*o)p Fj(\))208 1368
y Fr(Return)f(the)i(day)-5 b(,)18 b(as)j(an)g(int)f(from)f(1)h(through)
e(31.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0 1515
y(Macros)27 b(to)g(e)o(xtract)g(\002elds)h(from)e(datetime)h(objects.)
46 b(The)28 b(ar)o(gument)d(must)i(be)g(an)h(instance)f(of)g
Fj(PyDateTime_DateTime)p Fr(,)0 1614 y(including)18 b(subclasses.)26
b(The)20 b(ar)o(gument)d(must)k(not)f(be)g Fj(NULL)p
Fr(,)f(and)h(the)g(type)g(is)h(not)f(check)o(ed:)0 1761
y Fj(int)49 b Fg(PyDateTime_DATE_GET_HOUR)p Fj(\()p Fo(PyDateT)-5
b(ime)p 1865 1761 V 25 w(DateT)g(ime)21 b(*o)p Fj(\))208
1861 y Fr(Return)e(the)i(hour)m(,)d(as)j(an)f(int)g(from)f(0)i(through)
d(23.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0 2008
y Fj(int)49 b Fg(PyDateTime_DATE_GET_MINUTE)p Fj(\()p
Fo(PyDateT)-5 b(ime)p 1965 2008 V 25 w(DateT)g(ime)20
b(*o)p Fj(\))208 2107 y Fr(Return)f(the)i(minute,)e(as)i(an)f(int)g
(from)f(0)i(through)d(59.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0
2254 y Fj(int)49 b Fg(PyDateTime_DATE_GET_SECOND)p Fj(\()p
Fo(PyDateT)-5 b(ime)p 1965 2254 V 25 w(DateT)g(ime)20
b(*o)p Fj(\))208 2354 y Fr(Return)f(the)i(second,)e(as)h(an)h(int)f
(from)f(0)h(through)e(59.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0
2501 y Fj(int)49 b Fg(PyDateTime_DATE_GET_MICROSECOND)p
Fj(\()p Fo(PyDa)o(teT)-5 b(ime)p 2214 2501 V 25 w(DateT)g(ime)20
b(*o)p Fj(\))208 2600 y Fr(Return)f(the)i(microsecond,)c(as)k(an)f(int)
h(from)e(0)h(through)e(999999.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)
0 2747 y(Macros)27 b(to)g(e)o(xtract)f(\002elds)i(from)e(time)h
(objects.)45 b(The)27 b(ar)o(gument)e(must)i(be)g(an)g(instance)f(of)h
Fj(PyDateTime_Time)p Fr(,)f(including)0 2847 y(subclasses.)f(The)20
b(ar)o(gument)e(must)i(not)g(be)g Fj(NULL)p Fr(,)g(and)g(the)g(type)g
(is)h(not)f(check)o(ed:)0 2994 y Fj(int)49 b Fg
(PyDateTime_TIME_GET_HOUR)p Fj(\()p Fo(PyDateT)-5 b(ime)p
1865 2994 V 25 w(T)g(ime)21 b(*o)p Fj(\))208 3093 y Fr(Return)e(the)i
(hour)m(,)d(as)j(an)f(int)g(from)f(0)i(through)d(23.)50
b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0 3240 y Fj(int)49
b Fg(PyDateTime_TIME_GET_MINUTE)p Fj(\()p Fo(PyDateT)-5
b(ime)p 1965 3240 V 25 w(T)g(ime)21 b(*o)p Fj(\))208
3340 y Fr(Return)e(the)i(minute,)e(as)i(an)f(int)g(from)f(0)i(through)d
(59.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.4.)0 3487 y
Fj(int)49 b Fg(PyDateTime_TIME_GET_SECOND)p Fj(\()p Fo(PyDateT)-5
b(ime)p 1965 3487 V 25 w(T)g(ime)21 b(*o)p Fj(\))208
3586 y Fr(Return)e(the)i(second,)e(as)h(an)h(int)f(from)f(0)h(through)e
(59.)51 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0 3733 y
Fj(int)49 b Fg(PyDateTime_TIME_GET_MICROSECOND)p Fj(\()p
Fo(PyDa)o(teT)-5 b(ime)p 2214 3733 V 25 w(T)g(ime)21
b(*o)p Fj(\))208 3833 y Fr(Return)e(the)i(microsecond,)c(as)k(an)f(int)
h(from)e(0)h(through)e(999999.)48 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.4.)
0 3980 y(Macros)h(for)f(the)i(con)m(v)o(enience)c(of)j(modules)f
(implementing)f(the)i(DB)h(API:)0 4127 y Fj(PyObject)400
4142 y(*)498 4127 y Fg(PyDateTime_FromTimestamp)p Fj(\()p
Fo(PyObject)15 b(*ar)m(gs)p Fj(\))208 4226 y Fo(Return)k(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4326 y Fr(Create)37
b(and)g(return)f(a)h(ne)n(w)g Fj(datetime.datetime)e
Fr(object)h(gi)n(v)o(en)g(an)h(ar)o(gument)e(tuple)i(suitable)g(for)g
(passing)f(to)208 4425 y Fj(datetime.datetime.fromtimestamp\(\))o
Fr(.)46 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0 4572 y
Fj(PyObject)400 4587 y(*)498 4572 y Fg(PyDate_FromTimestamp)p
Fj(\()p Fo(PyObject)d(*ar)m(gs)p Fj(\))208 4672 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)208 4772 y Fr(Create)51
b(and)g(return)f(a)i(ne)n(w)f Fj(datetime.date)f Fr(object)h(gi)n(v)o
(en)f(an)h(ar)o(gument)e(tuple)i(suitable)h(for)e(passing)h(to)208
4871 y Fj(datetime.date.fromtimestamp\(\))p Fr(.)45 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.4.)0 5156 y Fh(7.5.14)101 b(Set)28
b(Objects)0 5359 y Fr(Ne)n(w)20 b(in)h(v)o(ersion)e(2.5.)p
0 5549 3901 4 v 0 5649 a Fn(7.5.)52 b(Other)23 b(Objects)3105
b(79)p eop end
%%Page: 80 86
TeXDict begin 80 85 bop 0 83 a Fr(This)51 b(section)f(details)g(the)h
(public)e(API)i(for)f Fj(set)g Fr(and)g Fj(frozenset)f
Fr(objects.)115 b(An)o(y)50 b(functionality)e(not)i(listed)h(be-)0
183 y(lo)n(w)d(is)h(best)f(accessed)f(using)h(the)f(either)h(the)g
(abstract)f(object)g(protocol)g(\(including)e Fj
(PyObject_CallMethod\(\))p Fr(,)0 282 y Fj
(PyObject_RichCompareBool\(\))p Fr(,)55 b Fj(PyObject_Hash\(\))p
Fr(,)i Fj(PyObject_Repr\(\))p Fr(,)g Fj(PyObject_IsTrue\(\))p
Fr(,)0 382 y Fj(PyObject_Print\(\))p Fr(,)25 b(and)g
Fj(PyObject_GetIter\(\))p Fr(\))e(or)i(the)h(abstract)g(number)e
(protocol)g(\(including)g Fj(PyNumber_-)0 482 y(Add\(\))p
Fr(,)51 b Fj(PyNumber_Subtract\(\))p Fr(,)e Fj(PyNumber_Or\(\))p
Fr(,)h Fj(PyNumber_Xor\(\))p Fr(,)f Fj(PyNumber_InPlaceAdd\(\))p
Fr(,)0 581 y Fj(PyNumber_InPlaceSubtract\(\))p Fr(,)16
b Fj(PyNumber_InPlaceOr\(\))p Fr(,)g(and)k Fj(PyNumber_InPlaceXor\(\))p
Fr(\).)0 728 y Fg(PySetObject)208 828 y Fr(This)j(subtype)f(of)g
Fj(PyObject)g Fr(is)i(used)f(to)g(hold)f(the)h(internal)f(data)h(for)g
(both)f Fj(set)h Fr(and)f Fj(frozenset)g Fr(objects.)33
b(It)23 b(is)h(lik)o(e)208 927 y(a)d Fj(PyDictObject)e
Fr(in)i(that)g(it)h(is)g(a)f(\002x)o(ed)g(size)g(for)g(small)g(sets)h
(\(much)e(lik)o(e)h(tuple)g(storage\))e(and)i(will)h(point)e(to)h(a)g
(separate,)208 1027 y(v)n(ariable)26 b(sized)h(block)g(of)g(memory)e
(for)i(medium)f(and)h(lar)o(ge)f(sized)i(sets)g(\(much)e(lik)o(e)i
(list)h(storage\).)45 b(None)27 b(of)g(the)g(\002elds)208
1127 y(of)22 b(this)h(structure)f(should)g(be)h(considered)e(public)g
(and)i(are)f(subject)h(to)g(change.)31 b(All)23 b(access)h(should)e(be)
g(done)g(through)f(the)208 1226 y(documented)c(API)k(rather)e(than)h
(by)f(manipulating)f(the)j(v)n(alues)e(in)i(the)f(structure.)0
1373 y Fj(PyTypeObject)48 b Fg(PySet_Type)208 1473 y
Fr(This)20 b(is)h(an)f(instance)g(of)g Fj(PyTypeObject)e
Fr(representing)h(the)h(Python)f Fj(set)h Fr(type.)0
1620 y Fj(PyTypeObject)48 b Fg(PyFrozenSet_Type)208 1719
y Fr(This)20 b(is)h(an)f(instance)g(of)g Fj(PyTypeObject)e
Fr(representing)h(the)h(Python)f Fj(frozenset)g Fr(type.)0
1866 y(The)25 b(follo)n(wing)f(type)h(check)g(macros)g(w)o(ork)g(on)g
(pointers)g(to)g(an)o(y)g(Python)g(object.)40 b(Lik)o(e)n(wise,)27
b(the)e(constructor)f(functions)g(w)o(ork)0 1966 y(with)c(an)o(y)g
(iterable)f(Python)h(object.)0 2113 y Fj(int)49 b Fg(PyAnySet_Check)p
Fj(\()p Fo(PyObject)17 b(*p)p Fj(\))208 2212 y Fr(Return)i(true)h(if)h
Fo(p)f Fr(is)h(a)g Fj(set)f Fr(object,)f(a)i Fj(frozenset)e
Fr(object,)g(or)h(an)g(instance)g(of)g(a)h(subtype.)0
2359 y Fj(int)49 b Fg(PyAnySet_CheckExact)p Fj(\()p Fo(PyObject)16
b(*p)p Fj(\))208 2459 y Fr(Return)j(true)h(if)h Fo(p)f
Fr(is)h(a)g Fj(set)f Fr(object)f(or)h(a)h Fj(frozenset)e
Fr(object)h(b)n(ut)g(not)g(an)g(instance)g(of)g(a)g(subtype.)0
2606 y Fj(int)49 b Fg(PyFrozenSet_CheckExact)p Fj(\()p
Fo(PyObject)16 b(*p)p Fj(\))208 2705 y Fr(Return)j(true)h(if)h
Fo(p)f Fr(is)h(a)g Fj(frozenset)e Fr(object)g(b)n(ut)i(not)e(an)i
(instance)e(of)h(a)h(subtype.)0 2852 y Fj(PyObject)400
2867 y(*)498 2852 y Fg(PySet_New)p Fj(\()p Fo(PyObject)d(*iter)o(able)p
Fj(\))208 2952 y Fo(Return)h(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3051 y Fr(Return)e(a)h(ne)n(w)f Fj(set)h Fr(containing)d
(objects)i(returned)f(by)h(the)h Fo(iter)o(able)p Fr(.)24
b(The)18 b Fo(iter)o(able)g Fr(may)g(be)h Fj(NULL)f Fr(to)h(create)f(a)
h(ne)n(w)f(empty)208 3151 y(set.)37 b(Return)24 b(the)g(ne)n(w)f(set)i
(on)f(success)h(or)e Fj(NULL)h Fr(on)g(f)o(ailure.)36
b(Raise)25 b Fj(TypeError)e Fr(if)h Fo(iter)o(able)g
Fr(is)h(not)f(actually)f(iterable.)208 3251 y(The)c(constructor)g(is)i
(also)f(useful)g(for)g(cop)o(ying)e(a)j(set)g(\()p Fj(c=set\(s\))p
Fr(\).)0 3397 y Fj(PyObject)400 3412 y(*)498 3397 y Fg(PyFrozenSet_New)
p Fj(\()p Fo(PyObject)c(*iter)o(able)p Fj(\))208 3497
y Fo(Return)i(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 3597 y Fr(Return)i(a)i(ne)n(w)f Fj(frozenset)f
Fr(containing)f(objects)i(returned)e(by)i(the)g Fo(iter)o(able)p
Fr(.)34 b(The)22 b Fo(iter)o(able)h Fr(may)g(be)g Fj(NULL)g
Fr(to)g(create)g(a)208 3696 y(ne)n(w)f(empty)h(frozenset.)32
b(Return)22 b(the)h(ne)n(w)g(set)h(on)f(success)g(or)g
Fj(NULL)g Fr(on)f(f)o(ailure.)33 b(Raise)24 b Fj(TypeError)e
Fr(if)h Fo(iter)o(able)g Fr(is)h(not)208 3796 y(actually)19
b(iterable.)0 3943 y(The)g(follo)n(wing)f(functions)g(and)h(macros)g
(are)g(a)n(v)n(ailable)g(for)g(instances)g(of)h Fj(set)f
Fr(or)g Fj(frozenset)g Fr(or)g(instances)g(of)g(their)h(subtypes.)0
4090 y Fj(Py_ssize_t)48 b Fg(PySet_Size)p Fj(\()p Fo(PyObject)18
b(*anyset)q Fj(\))208 4189 y Fr(Return)36 b(the)h(length)f(of)g(a)h
Fj(set)g Fr(or)g Fj(frozenset)e Fr(object.)75 b(Equi)n(v)n(alent)35
b(to)i(`)p Fj(len\()p Fo(anyset)q Fj(\))p Fr('.)73 b(Raises)38
b(a)f Fj(PyExc_-)208 4289 y(SystemError)18 b Fr(if)j
Fo(anyset)g Fr(is)g(not)f(a)h Fj(set)p Fr(,)f Fj(frozenset)p
Fr(,)e(or)i(an)h(instance)e(of)h(a)h(subtype.)0 4436
y Fj(Py_ssize_t)48 b Fg(PySet_GET_SIZE)p Fj(\()p Fo(PyObject)17
b(*anyset)q Fj(\))208 4535 y Fr(Macro)i(form)g(of)h Fj(PySet_Size\(\))f
Fr(without)g(error)g(checking.)0 4682 y Fj(int)49 b Fg(PySet_Contains)p
Fj(\()p Fo(PyObject)17 b(*anyset,)i(PyObject)h(*k)o(e)n(y)p
Fj(\))208 4782 y Fr(Return)29 b(1)h(if)g(found,)g(0)g(if)g(not)g
(found,)g(and)f(-1)h(if)g(an)g(error)e(is)j(encountered.)51
b(Unlik)o(e)30 b(the)g(Python)e Fj(__contains__-)208
4882 y(\(\))g Fr(method,)g(this)h(function)d(does)i(not)g
(automatically)f(con)m(v)o(ert)f(unhashable)g(sets)j(into)f(temporary)e
(frozensets.)48 b(Raise)29 b(a)208 4981 y Fj(TypeError)20
b Fr(if)h(the)g Fo(k)o(e)n(y)g Fr(is)h(unhashable.)k(Raise)c
Fj(PyExc_SystemError)d Fr(if)i Fo(anyset)h Fr(is)g(not)f(a)h
Fj(set)p Fr(,)f Fj(frozenset)p Fr(,)f(or)208 5081 y(an)g(instance)f(of)
h(a)h(subtype.)0 5228 y(The)g(follo)n(wing)e(functions)g(are)i(a)n(v)n
(ailable)g(for)f(instances)h(of)g Fj(set)g Fr(or)f(its)i(subtypes)f(b)n
(ut)f(not)h(for)f(instances)h(of)g Fj(frozenset)f Fr(or)h(its)0
5327 y(subtypes.)p 0 5549 3901 4 v 0 5649 a Fn(80)2478
b(Chapter)23 b(7.)52 b(Concrete)23 b(Objects)f(La)n(y)n(er)p
eop end
%%Page: 81 87
TeXDict begin 81 86 bop 0 83 a Fj(int)49 b Fg(PySet_Add)p
Fj(\()p Fo(PyObject)18 b(*set,)i(PyObject)g(*k)o(e)n(y)p
Fj(\))208 183 y Fr(Add)25 b Fo(k)o(e)n(y)h Fr(to)h(a)f
Fj(set)g Fr(instance.)43 b(Does)26 b(not)g(apply)f(to)i
Fj(frozenset)e Fr(instances.)42 b(Return)26 b(0)g(on)g(success)h(or)f
(-1)g(on)f(f)o(ailure.)208 282 y(Raise)i(a)g Fj(TypeError)e
Fr(if)h(the)h Fo(k)o(e)n(y)f Fr(is)h(unhashable.)41 b(Raise)27
b(a)g Fj(MemoryError)e Fr(if)i(there)e(is)j(no)d(room)h(to)g(gro)n(w)-5
b(.)42 b(Raise)27 b(a)208 382 y Fj(SystemError)18 b Fr(if)j
Fo(set)h Fr(is)f(an)f(not)g(an)g(instance)g(of)g Fj(set)g
Fr(or)g(its)i(subtype.)0 529 y Fj(int)49 b Fg(PySet_Discard)p
Fj(\()p Fo(PyObject)17 b(*set,)k(PyObject)e(*k)o(e)n(y)p
Fj(\))208 628 y Fr(Return)31 b(1)h(if)h(found)d(and)h(remo)o(v)o(ed,)i
(0)f(if)g(not)g(found)e(\(no)i(action)f(tak)o(en\),)j(and)e(-1)f(if)i
(an)f(error)f(is)i(encountered.)57 b(Does)208 728 y(not)31
b(raise)g Fj(KeyError)g Fr(for)f(missing)h(k)o(e)o(ys.)58
b(Raise)33 b(a)e Fj(TypeError)g Fr(if)g(the)h Fo(k)o(e)n(y)f
Fr(is)h(unhashable.)56 b(Unlik)o(e)31 b(the)h(Python)208
828 y Fj(discard\(\))23 b Fr(method,)g(this)i(function)d(does)i(not)g
(automatically)e(con)m(v)o(ert)g(unhashable)h(sets)i(into)f(temporary)e
(frozensets.)208 927 y(Raise)f Fj(PyExc_SystemError)c
Fr(if)k Fo(set)h Fr(is)f(an)g(not)e(an)i(instance)e(of)h
Fj(set)g Fr(or)g(its)i(subtype.)0 1074 y Fj(PyObject)400
1089 y(*)498 1074 y Fg(PySet_Pop)p Fj(\()p Fo(PyObject)c(*set)q
Fj(\))208 1174 y Fo(Return)h(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 1273 y Fr(Return)i(a)i(ne)n(w)e(reference)g(to)h(an)g
(arbitrary)f(object)g(in)h(the)g Fo(set)q Fr(,)i(and)e(remo)o(v)o(es)e
(the)i(object)g(from)f(the)h Fo(set)q Fr(.)35 b(Return)22
b Fj(NULL)h Fr(on)208 1373 y(f)o(ailure.)28 b(Raise)23
b Fj(KeyError)d Fr(if)i(the)g(set)g(is)g(empty)-5 b(.)28
b(Raise)23 b(a)f Fj(SystemError)e Fr(if)i Fo(set)i Fr(is)e(an)g(not)f
(an)g(instance)g(of)h Fj(set)f Fr(or)h(its)208 1473 y(subtype.)0
1620 y Fj(int)49 b Fg(PySet_Clear)p Fj(\()p Fo(PyObject)18
b(*set)q Fj(\))208 1719 y Fr(Empty)h(an)h(e)o(xisting)f(set)i(of)f(all)
h(elements.)p 0 5549 3901 4 v 0 5649 a Fn(7.5.)52 b(Other)23
b(Objects)3105 b(81)p eop end
%%Page: 82 88
TeXDict begin 82 87 bop 0 5549 3901 4 v 0 5649 a Fn(82)p
eop end
%%Page: 83 89
TeXDict begin 83 88 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3535
427 y Fm(EIGHT)p 0 515 V 330 978 a Fx(Initialization,)58
b(Finalization,)f(and)g(Threads)0 1443 y Fj(void)49 b
Fg(Py_Initialize)p Fj(\(\))208 1542 y Fr(Initialize)40
b(the)g(Python)g(interpreter)-5 b(.)84 b(In)41 b(an)f(application)f
(embedding)f(Python,)44 b(this)d(should)f(be)g(called)g(before)g(us-)
208 1642 y(ing)k(an)o(y)f(other)h(Python/C)f(API)i(functions;)55
b(with)44 b(the)h(e)o(xception)d(of)i Fj(Py_SetProgramName\(\))p
Fr(,)j Fj(PyEval_-)208 1741 y(InitThreads\(\))p Fr(,)26
b Fj(PyEval_ReleaseLock\(\))p Fr(,)e(and)i Fj(PyEval_AcquireLock\(\))p
Fr(.)41 b(This)27 b(initializes)g(the)f(ta-)208 1841
y(ble)e(of)h(loaded)e(modules)h(\()p Fj(sys.modules)p
Fr(\),)f(and)h(creates)h(the)g(fundamental)d(modules)h
Fj(__builtin__)p Fr(,)h Fj(__main__)208 1941 y Fr(and)g
Fj(sys)p Fr(.)38 b(It)25 b(also)g(initializes)g(the)f(module)g(search)g
(path)g(\()p Fj(sys.path)p Fr(\).)37 b(It)24 b(does)h(not)f(set)h
Fj(sys.argv)p Fr(;)h(use)f Fj(PySys_-)208 2040 y(SetArgv\(\))19
b Fr(for)h(that.)27 b(This)21 b(is)g(a)g(no-op)e(when)h(called)h(for)f
(a)h(second)f(time)h(\(without)e(calling)i Fj(Py_Finalize\(\))d
Fr(\002rst\).)208 2140 y(There)h(is)i(no)f(return)f(v)n(alue;)g(it)i
(is)g(a)g(f)o(atal)g(error)e(if)h(the)g(initialization)g(f)o(ails.)0
2287 y Fj(void)49 b Fg(Py_InitializeEx)p Fj(\()p Fo(int)18
b(initsigs)p Fj(\))208 2386 y Fr(This)j(function)f(w)o(orks)h(lik)o(e)h
Fj(Py_Initialize\(\))d Fr(if)j Fo(initsigs)g Fr(is)g(1.)29
b(If)21 b Fo(initsigs)h Fr(is)h(0,)e(it)i(skips)e(initialization)g(re)o
(gistration)208 2486 y(of)e(signal)i(handlers,)d(which)i(might)g(be)g
(useful)f(when)h(Python)f(is)i(embedded.)49 b(Ne)n(w)20
b(in)g(v)o(ersion)f(2.4.)0 2633 y Fj(int)49 b Fg(Py_IsInitialized)p
Fj(\(\))208 2733 y Fr(Return)37 b(true)h(\(nonzero\))d(when)j(the)g
(Python)f(interpreter)g(has)h(been)f(initialized,)42
b(f)o(alse)d(\(zero\))e(if)h(not.)79 b(After)38 b Fj(Py_-)208
2832 y(Finalize\(\))18 b Fr(is)k(called,)d(this)i(returns)e(f)o(alse)i
(until)f Fj(Py_Initialize\(\))e Fr(is)j(called)f(again.)0
2979 y Fj(void)49 b Fg(Py_Finalize)p Fj(\(\))208 3079
y Fr(Undo)28 b(all)j(initializations)e(made)g(by)h Fj
(Py_Initialize\(\))d Fr(and)j(subsequent)e(use)i(of)f(Python/C)g(API)i
(functions,)f(and)208 3178 y(destro)o(y)e(all)i(sub-interpreters)e
(\(see)h Fj(Py_NewInterpreter\(\))e Fr(belo)n(w\))h(that)i(were)f
(created)g(and)g(not)g(yet)h(destro)o(yed)208 3278 y(since)24
b(the)g(last)h(call)g(to)f Fj(Py_Initialize\(\))p Fr(.)34
b(Ideally)-5 b(,)24 b(this)h(frees)f(all)g(memory)f(allocated)g(by)h
(the)g(Python)f(interpreter)-5 b(.)208 3378 y(This)23
b(is)i(a)f(no-op)e(when)h(called)h(for)f(a)h(second)f(time)h(\(without)
f(calling)g Fj(Py_Initialize\(\))f Fr(again)g(\002rst\).)36
b(There)23 b(is)i(no)208 3477 y(return)19 b(v)n(alue;)g(errors)h
(during)e(\002nalization)h(are)i(ignored.)208 3610 y(This)29
b(function)e(is)i(pro)o(vided)e(for)h(a)h(number)e(of)h(reasons.)51
b(An)28 b(embedding)f(application)g(might)h(w)o(ant)h(to)g(restart)g
(Python)208 3710 y(without)e(ha)n(ving)g(to)h(restart)g(the)g
(application)e(itself.)49 b(An)28 b(application)f(that)h(has)g(loaded)f
(the)h(Python)f(interpreter)f(from)h(a)208 3809 y(dynamically)17
b(loadable)i(library)f(\(or)h(DLL\))g(might)g(w)o(ant)h(to)g(free)f
(all)h(memory)e(allocated)h(by)g(Python)f(before)g(unloading)g(the)208
3909 y(DLL.)h(During)f(a)i(hunt)f(for)g(memory)f(leaks)i(in)f(an)h
(application)e(a)i(de)n(v)o(eloper)d(might)i(w)o(ant)h(to)g(free)f(all)
h(memory)e(allocated)h(by)208 4009 y(Python)g(before)f(e)o(xiting)i
(from)f(the)h(application.)208 4141 y Fp(Bugs)g(and)g(ca)n(v)o(eats:)k
Fr(The)19 b(destruction)f(of)i(modules)e(and)h(objects)h(in)g(modules)e
(is)j(done)e(in)h(random)d(order;)i(this)h(may)g(cause)208
4241 y(destructors)29 b(\()p Fj(__del__\(\))f Fr(methods\))h(to)h(f)o
(ail)h(when)e(the)o(y)h(depend)e(on)i(other)f(objects)h(\(e)n(v)o(en)f
(functions\))f(or)i(modules.)208 4341 y(Dynamically)15
b(loaded)h(e)o(xtension)f(modules)h(loaded)g(by)g(Python)g(are)g(not)h
(unloaded.)22 b(Small)17 b(amounts)f(of)g(memory)f(allocated)208
4440 y(by)27 b(the)h(Python)e(interpreter)g(may)i(not)f(be)h(freed)f
(\(if)h(you)e(\002nd)i(a)g(leak,)h(please)f(report)f(it\).)48
b(Memory)26 b(tied)i(up)g(in)f(circular)208 4540 y(references)18
b(between)g(objects)i(is)g(not)f(freed.)24 b(Some)19
b(memory)f(allocated)h(by)g(e)o(xtension)f(modules)g(may)h(not)h(be)f
(freed.)24 b(Some)208 4640 y(e)o(xtensions)e(may)h(not)g(w)o(ork)g
(properly)e(if)j(their)f(initialization)g(routine)f(is)i(called)g(more)
e(than)h(once;)i(this)f(can)f(happen)f(if)i(an)208 4739
y(application)18 b(calls)j Fj(Py_Initialize\(\))d Fr(and)i
Fj(Py_Finalize\(\))e Fr(more)h(than)h(once.)0 4886 y
Fj(PyThreadState)650 4901 y(*)747 4886 y Fg(Py_NewInterpreter)p
Fj(\(\))208 4986 y Fr(Create)g(a)h(ne)n(w)f(sub-interpreter)-5
b(.)23 b(This)d(is)h(an)g(\(almost\))e(totally)h(separate)g(en)m
(vironment)d(for)j(the)g(e)o(x)o(ecution)e(of)i(Python)f(code.)208
5085 y(In)30 b(particular)m(,)i(the)f(ne)n(w)g(interpreter)e(has)j
(separate,)h(independent)28 b(v)o(ersions)i(of)h(all)h(imported)d
(modules,)j(including)e(the)208 5185 y(fundamental)20
b(modules)i Fj(__builtin__)p Fr(,)h Fj(__main__)f Fr(and)h
Fj(sys)p Fr(.)34 b(The)22 b(table)i(of)f(loaded)f(modules)g(\()p
Fj(sys.modules)p Fr(\))208 5285 y(and)e(the)g(module)g(search)g(path)g
(\()p Fj(sys.path)p Fr(\))g(are)g(also)h(separate.)26
b(The)21 b(ne)n(w)f(en)m(vironment)e(has)j(no)f Fj(sys.argv)g
Fr(v)n(ariable.)208 5384 y(It)28 b(has)h(ne)n(w)f(standard)f(I/O)h
(stream)g(\002le)h(objects)f Fj(sys.stdin)p Fr(,)h Fj(sys.stdout)e
Fr(and)h Fj(sys.stderr)f Fr(\(ho)n(we)n(v)o(er)e(these)p
0 5549 3901 4 v 3808 5649 a Fn(83)p eop end
%%Page: 84 90
TeXDict begin 84 89 bop 208 83 a Fr(refer)19 b(to)h(the)h(same)f
(underlying)d Fj(FILE)j Fr(structures)g(in)g(the)g(C)i(library\).)208
216 y(The)17 b(return)g(v)n(alue)g(points)g(to)h(the)g(\002rst)h
(thread)d(state)j(created)e(in)h(the)g(ne)n(w)f(sub-interpreter)-5
b(.)22 b(This)c(thread)f(state)i(is)f(made)g(in)g(the)208
315 y(current)j(thread)g(state.)32 b(Note)22 b(that)g(no)g(actual)g
(thread)g(is)h(created;)g(see)f(the)h(discussion)f(of)g(thread)f
(states)i(belo)n(w)-5 b(.)30 b(If)23 b(creation)208 415
y(of)18 b(the)g(ne)n(w)h(interpreter)e(is)i(unsuccessful,)f
Fj(NULL)g Fr(is)i(returned;)d(no)h(e)o(xception)f(is)i(set)h(since)e
(the)h(e)o(xception)e(state)i(is)g(stored)f(in)208 515
y(the)j(current)f(thread)g(state)i(and)e(there)h(may)f(not)h(be)g(a)h
(current)e(thread)g(state.)28 b(\(Lik)o(e)21 b(all)h(other)e(Python/C)g
(API)i(functions,)e(the)208 614 y(global)e(interpreter)f(lock)h(must)h
(be)g(held)g(before)e(calling)i(this)g(function)e(and)i(is)h(still)g
(held)e(when)g(it)i(returns;)f(ho)n(we)n(v)o(er)m(,)d(unlik)o(e)208
714 y(most)k(other)f(Python/C)h(API)g(functions,)f(there)g(needn')o(t)g
(be)h(a)g(current)f(thread)g(state)i(on)f(entry)-5 b(.\))208
847 y(Extension)30 b(modules)g(are)h(shared)g(between)f
(\(sub-\)interpreters)f(as)j(follo)n(ws:)47 b(the)31
b(\002rst)h(time)g(a)g(particular)e(e)o(xtension)g(is)208
946 y(imported,)16 b(it)k(is)f(initialized)f(normally)-5
b(,)17 b(and)h(a)g(\(shallo)n(w\))g(cop)o(y)f(of)i(its)g(module')-5
b(s)18 b(dictionary)e(is)k(squirreled)d(a)o(w)o(ay)-5
b(.)23 b(When)c(the)208 1046 y(same)h(e)o(xtension)e(is)j(imported)e
(by)h(another)e(\(sub-\)interpreter)m(,)e(a)21 b(ne)n(w)f(module)e(is)j
(initialized)f(and)g(\002lled)g(with)g(the)g(contents)208
1146 y(of)f(this)h(cop)o(y;)f(the)h(e)o(xtension')-5
b(s)19 b Fj(init)g Fr(function)f(is)j(not)f(called.)k(Note)c(that)g
(this)g(is)h(dif)n(ferent)d(from)g(what)i(happens)e(when)i(an)208
1245 y(e)o(xtension)f(is)k(imported)c(after)i(the)g(interpreter)f(has)i
(been)e(completely)g(re-initialized)g(by)h(calling)g
Fj(Py_Finalize\(\))e Fr(and)208 1345 y Fj(Py_Initialize\(\))p
Fr(;)f(in)i(that)g(case,)h(the)f(e)o(xtension')-5 b(s)19
b Fj(init)p Fo(module)f Fr(function)h Fo(is)i Fr(called)f(again.)208
1478 y Fp(Bugs)25 b(and)f(ca)n(v)o(eats:)32 b Fr(Because)24
b(sub-interpreters)e(\(and)h(the)h(main)g(interpreter\))e(are)i(part)g
(of)g(the)g(same)g(process,)h(the)f(insu-)208 1577 y(lation)f(between)f
(them)h(isn')o(t)g(perfect)g(\227)h(for)f(e)o(xample,)f(using)h(lo)n
(w-le)n(v)o(el)f(\002le)i(operations)e(lik)o(e)48 b Fj(os.close\(\))22
b Fr(the)o(y)h(can)208 1677 y(\(accidentally)e(or)i(maliciously\))f(af)
n(fect)g(each)h(other')-5 b(s)22 b(open)g(\002les.)35
b(Because)23 b(of)g(the)g(w)o(ay)g(e)o(xtensions)f(are)h(shared)f
(between)208 1777 y(\(sub-\)interpreters,)f(some)i(e)o(xtensions)g(may)
g(not)g(w)o(ork)h(properly;)f(this)h(is)h(especially)e(lik)o(ely)h
(when)f(the)g(e)o(xtension)g(mak)o(es)208 1876 y(use)c(of)g(\(static\))
g(global)g(v)n(ariables,)f(or)h(when)f(the)i(e)o(xtension)d
(manipulates)i(its)h(module')-5 b(s)18 b(dictionary)f(after)i(its)h
(initialization.)208 1976 y(It)26 b(is)i(possible)e(to)h(insert)f
(objects)h(created)e(in)i(one)f(sub-interpreter)e(into)i(a)h(namespace)
f(of)g(another)f(sub-interpreter;)i(this)208 2076 y(should)22
b(be)i(done)f(with)h(great)f(care)h(to)g(a)n(v)n(oid)g(sharing)e(user)n
(-de\002ned)h(functions,)g(methods,)g(instances)h(or)f(classes)i
(between)208 2175 y(sub-interpreters,)18 b(since)j(import)f(operations)
f(e)o(x)o(ecuted)g(by)h(such)h(objects)f(may)h(af)n(fect)f(the)h(wrong)
e(\(sub-\)interpreter')-5 b(s)18 b(dic-)208 2275 y(tionary)h(of)g
(loaded)h(modules.)j(\(XXX)e(This)f(is)h(a)g(hard-to-\002x)d(b)n(ug)h
(that)h(will)h(be)g(addressed)e(in)h(a)h(future)e(release.\))208
2408 y(Also)j(note)g(that)g(the)g(use)h(of)f(this)g(functionality)e(is)
k(incompatible)c(with)i(e)o(xtension)f(modules)g(such)h(as)h(PyObjC)f
(and)g(ctypes)208 2507 y(that)30 b(use)h(the)g Fj(PyGILState_)1188
2522 y(*)1267 2507 y Fr(APIs)g(\(and)e(this)j(is)f(inherent)e(in)i(the)
g(w)o(ay)f(the)h Fj(PyGILState_)3263 2522 y(*)3342 2507
y Fr(functions)e(w)o(ork\).)208 2607 y(Simple)20 b(things)f(may)h(w)o
(ork,)f(b)n(ut)i(confusing)d(beha)n(vior)g(will)j(al)o(w)o(ays)g(be)f
(near)-5 b(.)0 2754 y Fj(void)49 b Fg(Py_EndInterpreter)p
Fj(\()p Fo(PyThr)m(eadState)15 b(*tstate)p Fj(\))208
2853 y Fr(Destro)o(y)23 b(the)i(\(sub-\)interpreter)20
b(represented)j(by)h(the)g(gi)n(v)o(en)f(thread)g(state.)38
b(The)24 b(gi)n(v)o(en)f(thread)g(state)i(must)f(be)h(the)f(current)208
2953 y(thread)d(state.)31 b(See)22 b(the)g(discussion)g(of)g(thread)f
(states)i(belo)n(w)-5 b(.)29 b(When)22 b(the)g(call)h(returns,)e(the)h
(current)f(thread)g(state)i(is)g Fj(NULL)p Fr(.)208 3053
y(All)e(thread)f(states)i(associated)e(with)h(this)h(interpreter)d(are)
h(destro)o(yed.)26 b(\(The)20 b(global)g(interpreter)f(lock)h(must)h
(be)g(held)f(before)208 3152 y(calling)j(this)h(function)d(and)i(is)i
(still)g(held)e(when)g(it)h(returns.\))34 b Fj(Py_Finalize\(\))21
b Fr(will)k(destro)o(y)d(all)i(sub-interpreters)d(that)208
3252 y(ha)n(v)o(en')o(t)d(been)h(e)o(xplicitly)h(destro)o(yed)e(at)j
(that)f(point.)0 3399 y Fj(void)49 b Fg(Py_SetProgramName)p
Fj(\()p Fo(c)o(har)16 b(*name)p Fj(\))208 3498 y Fr(This)24
b(function)g(should)f(be)i(called)g(before)e Fj(Py_Initialize\(\))f
Fr(is)k(called)f(for)f(the)h(\002rst)g(time,)h(if)f(it)h(is)f(called)g
(at)g(all.)39 b(It)208 3598 y(tells)18 b(the)f(interpreter)e(the)j(v)n
(alue)e(of)h(the)g Fj(argv[0])f Fr(ar)o(gument)f(to)j(the)f
Fj(main\(\))f Fr(function)g(of)h(the)g(program.)22 b(This)17
b(is)h(used)f(by)208 3698 y Fj(Py_GetPath\(\))f Fr(and)h(some)g(other)g
(functions)f(belo)n(w)h(to)h(\002nd)f(the)h(Python)e(run-time)h
(libraries)g(relati)n(v)o(e)g(to)h(the)f(interpreter)208
3797 y(e)o(x)o(ecutable.)32 b(The)22 b(def)o(ault)h(v)n(alue)f(is)i
Fj('python')p Fr(.)33 b(The)23 b(ar)o(gument)e(should)h(point)h(to)g(a)
h(zero-terminated)c(character)i(string)208 3897 y(in)k(static)i
(storage)e(whose)g(contents)g(will)h(not)f(change)f(for)h(the)h
(duration)e(of)h(the)h(program')-5 b(s)24 b(e)o(x)o(ecution.)42
b(No)27 b(code)f(in)h(the)208 3997 y(Python)19 b(interpreter)f(will)j
(change)e(the)h(contents)g(of)g(this)g(storage.)0 4143
y Fj(char)200 4158 y(*)299 4143 y Fg(Py_GetProgramName)p
Fj(\(\))208 4243 y Fr(Return)j(the)g(program)e(name)i(set)h(with)g
Fj(Py_SetProgramName\(\))p Fr(,)d(or)i(the)h(def)o(ault.)34
b(The)23 b(returned)f(string)h(points)g(into)208 4343
y(static)e(storage;)e(the)h(caller)h(should)e(not)h(modify)e(its)j(v)n
(alue.)0 4490 y Fj(char)200 4505 y(*)299 4490 y Fg(Py_GetPrefix)p
Fj(\(\))208 4589 y Fr(Return)c(the)i Fo(pr)m(e\002x)e
Fr(for)h(installed)g(platform-independent)13 b(\002les.)26
b(This)18 b(is)h(deri)n(v)o(ed)e(through)f(a)j(number)d(of)i
(complicated)f(rules)208 4689 y(from)27 b(the)h(program)f(name)h(set)h
(with)f Fj(Py_SetProgramName\(\))e Fr(and)i(some)g(en)m(vironment)e(v)n
(ariables;)31 b(for)d(e)o(xample,)208 4788 y(if)23 b(the)g(program)e
(name)h(is)i Fj('/usr/local/bin/python')p Fr(,)19 b(the)k(pre\002x)g
(is)h Fj('/usr/local')p Fr(.)31 b(The)23 b(returned)e(string)208
4888 y(points)i(into)g(static)i(storage;)g(the)f(caller)g(should)e(not)
i(modify)e(its)j(v)n(alue.)35 b(This)24 b(corresponds)d(to)j(the)g
(pre\002x)f(v)n(ariable)g(in)h(the)208 4988 y(top-le)n(v)o(el)g(`)p
Fs(Mak)o(e\002le)p Fr(')h(and)h(the)g Fp(--pr)o(e\002x)f
Fr(ar)o(gument)f(to)i(the)h Fp(con\002gur)o(e)e Fr(script)h(at)h(b)n
(uild)f(time.)43 b(The)26 b(v)n(alue)f(is)j(a)n(v)n(ailable)d(to)208
5087 y(Python)19 b(code)g(as)i Fj(sys.prefix)p Fr(.)j(It)c(is)h(only)f
(useful)f(on)j(U)t Fi(N)t(I)t(X)r Fr(.)k(See)21 b(also)f(the)g(ne)o(xt)
g(function.)0 5234 y Fj(char)200 5249 y(*)299 5234 y
Fg(Py_GetExecPrefix)p Fj(\(\))208 5334 y Fr(Return)i(the)h
Fo(e)n(xec-pr)m(e\002x)f Fr(for)h(installed)g(platform-)p
Fo(de)p Fr(pendent)18 b(\002les.)34 b(This)24 b(is)g(deri)n(v)o(ed)d
(through)g(a)i(number)e(of)i(complicated)p 0 5549 3901
4 v 0 5649 a Fn(84)1934 b(Chapter)23 b(8.)52 b(Initialization,)26
b(Finalization,)f(and)e(Threads)p eop end
%%Page: 85 91
TeXDict begin 85 90 bop 208 83 a Fr(rules)28 b(from)g(the)h(program)e
(name)h(set)i(with)f Fj(Py_SetProgramName\(\))d Fr(and)i(some)h(en)m
(vironment)c(v)n(ariables;)33 b(for)28 b(e)o(x-)208 183
y(ample,)j(if)e(the)h(program)d(name)i(is)h Fj('/usr/local/bin/python')
p Fr(,)e(the)i(e)o(x)o(ec-pre\002x)c(is)31 b Fj('/usr/local')p
Fr(.)51 b(The)208 282 y(returned)20 b(string)j(points)f(into)g(static)h
(storage;)h(the)e(caller)h(should)e(not)i(modify)e(its)i(v)n(alue.)31
b(This)23 b(corresponds)e(to)h(the)h(e)o(x)o(ec)p 3849
282 25 4 v 28 w(-)208 382 y(pre\002x)g(v)n(ariable)f(in)i(the)g(top-le)
n(v)o(el)f(`)p Fs(Mak)o(e\002le)p Fr(')f(and)h(the)h
Fp(--exec-pr)o(e\002x)e Fr(ar)o(gument)f(to)j(the)g Fp(con\002gur)o(e)f
Fr(script)h(at)g(b)n(uild)g(time.)208 482 y(The)19 b(v)n(alue)h(is)h(a)
n(v)n(ailable)f(to)g(Python)f(code)h(as)h Fj(sys.exec_prefix)p
Fr(.)h(It)f(is)g(only)e(useful)h(on)i(U)t Fi(N)t(I)t(X)r
Fr(.)208 614 y(Background:)35 b(The)27 b(e)o(x)o(ec-pre\002x)d(dif)n
(fers)i(from)f(the)i(pre\002x)f(when)g(platform)f(dependent)g(\002les)j
(\(such)e(as)h(e)o(x)o(ecutables)e(and)208 714 y(shared)19
b(libraries\))g(are)h(installed)g(in)g(a)g(dif)n(ferent)e(directory)g
(tree.)25 b(In)20 b(a)g(typical)g(installation,)f(platform)f(dependent)
g(\002les)j(may)208 814 y(be)f(installed)g(in)g(the)g(`)p
Fs(/usr/local/plat)p Fr(')d(subtree)i(while)h(platform)f(independent)f
(may)h(be)h(installed)h(in)f(`)p Fs(/usr/local)p Fr('.)208
946 y(Generally)j(speaking,)h(a)g(platform)f(is)i(a)g(combination)d(of)
i(hardw)o(are)f(and)h(softw)o(are)g(f)o(amilies,)h(e.g.)37
b(Sparc)24 b(machines)g(run-)208 1046 y(ning)d(the)h(Solaris)g(2.x)f
(operating)g(system)h(are)g(considered)e(the)i(same)g(platform,)f(b)n
(ut)h(Intel)g(machines)f(running)f(Solaris)i(2.x)208
1146 y(are)h(another)f(platform,)g(and)h(Intel)g(machines)g(running)e
(Linux)h(are)i(yet)f(another)f(platform.)33 b(Dif)n(ferent)22
b(major)h(re)n(visions)g(of)208 1245 y(the)c(same)h(operating)d(system)
j(generally)e(also)i(form)e(dif)n(ferent)g(platforms.)23
b(Non-)r(U)t Fi(N)t(I)t(X)e Fr(operating)d(systems)i(are)f(a)h(dif)n
(ferent)208 1345 y(story;)27 b(the)e(installation)g(strate)o(gies)g(on)
g(those)g(systems)h(are)f(so)g(dif)n(ferent)f(that)h(the)g(pre\002x)g
(and)g(e)o(x)o(ec-pre\002x)d(are)j(meaning-)208 1445
y(less,)i(and)d(set)i(to)f(the)g(empty)g(string.)39 b(Note)25
b(that)g(compiled)f(Python)g(bytecode)f(\002les)j(are)f(platform)f
(independent)e(\(b)n(ut)j(not)208 1544 y(independent)17
b(from)i(the)h(Python)g(v)o(ersion)e(by)i(which)g(the)o(y)f(were)h
(compiled!\).)208 1677 y(System)31 b(administrators)f(will)i(kno)n(w)e
(ho)n(w)h(to)g(con\002gure)f(the)h Fp(mount)h Fr(or)f
Fp(automount)f Fr(programs)f(to)j(share)f(`)p Fs(/usr/local)p
Fr(')208 1777 y(between)19 b(platforms)g(while)h(ha)n(ving)f(`)p
Fs(/usr/local/plat)p Fr(')d(be)21 b(a)f(dif)n(ferent)f(\002lesystem)h
(for)g(each)g(platform.)0 1924 y Fj(char)200 1939 y(*)299
1924 y Fg(Py_GetProgramFullPath)p Fj(\(\))208 2023 y
Fr(Return)f(the)i(full)f(program)e(name)i(of)g(the)g(Python)f(e)o(x)o
(ecutable;)f(this)j(is)g(computed)e(as)i(a)f(side-ef)n(fect)g(of)g
(deri)n(ving)e(the)i(def)o(ault)208 2123 y(module)25
b(search)i(path)f(from)g(the)h(program)e(name)h(\(set)h(by)g
Fj(Py_SetProgramName\(\))d Fr(abo)o(v)o(e\).)43 b(The)27
b(returned)e(string)208 2222 y(points)30 b(into)i(static)g(storage;)k
(the)c(caller)f(should)f(not)h(modify)f(its)j(v)n(alue.)57
b(The)31 b(v)n(alue)g(is)h(a)n(v)n(ailable)f(to)h(Python)e(code)h(as)
208 2322 y Fj(sys.executable)p Fr(.)0 2469 y Fj(char)200
2484 y(*)299 2469 y Fg(Py_GetPath)p Fj(\(\))208 2569
y Fr(Return)56 b(the)h(def)o(ault)f(module)f(search)i(path;)75
b(this)57 b(is)h(computed)d(from)g(the)i(program)e(name)h(\(set)h(by)g
Fj(Py_-)208 2668 y(SetProgramName\(\))27 b Fr(abo)o(v)o(e\))h(and)h
(some)h(en)m(vironment)d(v)n(ariables.)53 b(The)29 b(returned)g(string)
g(consists)h(of)g(a)g(series)h(of)208 2768 y(directory)18
b(names)j(separated)e(by)i(a)g(platform)e(dependent)f(delimiter)i
(character)-5 b(.)26 b(The)20 b(delimiter)g(character)f(is)j(`)p
Fj(:)p Fr(')j(on)e(U)t Fi(N)t(I)t(X)208 2867 y Fr(and)d(Mac)h(OS)h(X,)f
(`)p Fj(;)p Fr(')h(on)e(W)m(indo)n(ws.)28 b(The)20 b(returned)g(string)
g(points)h(into)g(static)h(storage;)f(the)g(caller)g(should)f(not)h
(modify)f(its)208 2967 y(v)n(alue.)j(The)18 b(v)n(alue)g(is)i(a)n(v)n
(ailable)e(to)g(Python)g(code)g(as)h(the)f(list)i Fj(sys.path)p
Fr(,)e(which)g(may)g(be)g(modi\002ed)f(to)i(change)e(the)i(future)208
3067 y(search)g(path)h(for)g(loaded)f(modules.)0 3214
y Fj(const)49 b(char)499 3229 y(*)598 3214 y Fg(Py_GetVersion)p
Fj(\(\))208 3313 y Fr(Return)19 b(the)i(v)o(ersion)d(of)i(this)h
(Python)e(interpreter)-5 b(.)24 b(This)c(is)h(a)g(string)f(that)g
(looks)g(something)e(lik)o(e)444 3537 y Fk("1.5)44 b(\(#67,)g(Dec)g(31)
h(1997,)f(22:34:28\))f([GCC)h(2.7.2.2]")208 3727 y Fr(The)25
b(\002rst)j(w)o(ord)d(\(up)h(to)g(the)g(\002rst)h(space)g(character\))d
(is)j(the)g(current)e(Python)g(v)o(ersion;)j(the)e(\002rst)h(three)f
(characters)f(are)i(the)208 3826 y(major)21 b(and)h(minor)f(v)o(ersion)
g(separated)g(by)h(a)h(period.)30 b(The)22 b(returned)e(string)i
(points)g(into)g(static)h(storage;)g(the)f(caller)h(should)208
3926 y(not)c(modify)g(its)i(v)n(alue.)j(The)c(v)n(alue)g(is)h(a)n(v)n
(ailable)f(to)g(Python)f(code)h(as)g Fj(sys.version)p
Fr(.)0 4073 y Fj(const)49 b(char)499 4088 y(*)598 4073
y Fg(Py_GetBuildNumber)p Fj(\(\))208 4173 y Fr(Return)20
b(a)g(string)h(representing)d(the)j(Sub)o(v)o(ersion)d(re)n(vision)h
(that)i(this)g(Python)e(e)o(x)o(ecutable)g(w)o(as)i(b)n(uilt)g(from.)j
(This)d(number)e(is)208 4272 y(a)24 b(string)g(because)g(it)h(may)f
(contain)f(a)i(trailing)e('M')h(if)h(Python)e(w)o(as)i(b)n(uilt)g(from)
e(a)i(mix)o(ed)e(re)n(vision)g(source)h(tree.)75 b(Ne)n(w)24
b(in)208 4372 y(v)o(ersion)18 b(2.5.)0 4519 y Fj(const)49
b(char)499 4534 y(*)598 4519 y Fg(Py_GetPlatform)p Fj(\(\))208
4618 y Fr(Return)20 b(the)g(platform)f(identi\002er)h(for)g(the)h
(current)e(platform.)25 b(On)e(U)t Fi(N)t(I)t(X)r Fr(,)e(this)g(is)h
(formed)d(from)h(the)g(\223of)n(\002cial\224)g(name)g(of)h(the)208
4718 y(operating)16 b(system,)j(con)m(v)o(erted)d(to)i(lo)n(wer)g
(case,)h(follo)n(wed)e(by)h(the)h(major)f(re)n(vision)f(number;)g
(e.g.,)h(for)g(Solaris)h(2.x,)f(which)g(is)208 4818 y(also)g(kno)n(wn)f
(as)i(SunOS)f(5.x,)f(the)i(v)n(alue)e(is)i Fj('sunos5')p
Fr(.)24 b(On)18 b(Mac)g(OS)h(X,)g(it)g(is)g Fj('darwin')p
Fr(.)k(On)18 b(W)m(indo)n(ws,)g(it)h(is)g Fj('win')p
Fr(.)208 4917 y(The)24 b(returned)f(string)i(points)f(into)h(static)g
(storage;)i(the)e(caller)g(should)f(not)g(modify)f(its)j(v)n(alue.)39
b(The)24 b(v)n(alue)g(is)i(a)n(v)n(ailable)e(to)208 5017
y(Python)19 b(code)g(as)i Fj(sys.platform)p Fr(.)0 5164
y Fj(const)49 b(char)499 5179 y(*)598 5164 y Fg(Py_GetCopyright)p
Fj(\(\))208 5263 y Fr(Return)19 b(the)i(of)n(\002cial)e(cop)o(yright)g
(string)g(for)h(the)g(current)f(Python)g(v)o(ersion,)g(for)g(e)o
(xample)208 5396 y Fj('Copyright)48 b(1991-1995)g(Stichting)g
(Mathematisch)f(Centrum,)i(Amsterdam')p 0 5549 3901 4
v 3808 5649 a Fn(85)p eop end
%%Page: 86 92
TeXDict begin 86 91 bop 208 83 a Fr(The)24 b(returned)f(string)i
(points)f(into)h(static)g(storage;)i(the)e(caller)g(should)f(not)g
(modify)f(its)j(v)n(alue.)39 b(The)24 b(v)n(alue)g(is)i(a)n(v)n
(ailable)e(to)208 183 y(Python)19 b(code)g(as)i Fj(sys.copyright)p
Fr(.)0 330 y Fj(const)49 b(char)499 345 y(*)598 330 y
Fg(Py_GetCompiler)p Fj(\(\))208 429 y Fr(Return)19 b(an)h(indication)f
(of)h(the)g(compiler)f(used)h(to)h(b)n(uild)e(the)i(current)d(Python)h
(v)o(ersion,)g(in)h(square)g(brack)o(ets,)f(for)h(e)o(xample:)444
653 y Fk("[GCC)44 b(2.7.2.2]")208 843 y Fr(The)24 b(returned)f(string)i
(points)f(into)h(static)g(storage;)i(the)e(caller)g(should)f(not)g
(modify)f(its)j(v)n(alue.)39 b(The)24 b(v)n(alue)g(is)i(a)n(v)n
(ailable)e(to)208 942 y(Python)19 b(code)g(as)i(part)f(of)g(the)g(v)n
(ariable)f Fj(sys.version)p Fr(.)0 1089 y Fj(const)49
b(char)499 1104 y(*)598 1089 y Fg(Py_GetBuildInfo)p Fj(\(\))208
1189 y Fr(Return)15 b(information)e(about)h(the)i(sequence)e(number)f
(and)i(b)n(uild)g(date)h(and)f(time)g(of)g(the)h(current)e(Python)g
(interpreter)g(instance,)208 1289 y(for)19 b(e)o(xample)444
1513 y Fk("#67,)44 b(Aug)89 b(1)45 b(1997,)f(22:34:28")208
1702 y Fr(The)24 b(returned)f(string)i(points)f(into)h(static)g
(storage;)i(the)e(caller)g(should)f(not)g(modify)f(its)j(v)n(alue.)39
b(The)24 b(v)n(alue)g(is)i(a)n(v)n(ailable)e(to)208 1802
y(Python)19 b(code)g(as)i(part)f(of)g(the)g(v)n(ariable)f
Fj(sys.version)p Fr(.)0 1949 y Fj(void)49 b Fg(PySys_SetArgv)p
Fj(\()p Fo(int)18 b(ar)m(gc,)h(c)o(har)h(**ar)m(gv)p
Fj(\))208 2048 y Fr(Set)e Fj(sys.argv)f Fr(based)g(on)h
Fo(ar)m(gc)f Fr(and)h Fo(ar)m(gv)p Fr(.)24 b(These)17
b(parameters)g(are)h(similar)g(to)g(those)f(passed)h(to)g(the)g
(program')-5 b(s)16 b Fj(main\(\))208 2148 y Fr(function)29
b(with)i(the)g(dif)n(ference)e(that)i(the)g(\002rst)g(entry)f(should)g
(refer)g(to)i(the)e(script)h(\002le)h(to)f(be)g(e)o(x)o(ecuted)e
(rather)h(than)h(the)208 2248 y(e)o(x)o(ecutable)d(hosting)h(the)i
(Python)e(interpreter)-5 b(.)54 b(If)30 b(there)g(isn')o(t)g(a)h
(script)f(that)g(will)h(be)g(run,)g(the)g(\002rst)g(entry)e(in)i
Fo(ar)m(gv)f Fr(can)208 2347 y(be)e(an)g(empty)g(string.)50
b(If)28 b(this)h(function)e(f)o(ails)i(to)g(initialize)g
Fj(sys.argv)p Fr(,)g(a)g(f)o(atal)g(condition)d(is)k(signalled)e(using)
g Fj(Py_-)208 2447 y(FatalError\(\))p Fr(.)0 2774 y Fl(8.1)121
b(Thread)35 b(State)f(and)h(the)f(Global)g(Inter)t(preter)h(Loc)n(k)0
3007 y Fr(The)23 b(Python)g(interpreter)f(is)j(not)f(fully)f(thread)g
(safe.)36 b(In)23 b(order)g(to)h(support)e(multi-threaded)f(Python)i
(programs,)g(there')-5 b(s)23 b(a)h(global)0 3107 y(lock)i(that)g(must)
h(be)f(held)g(by)g(the)h(current)e(thread)g(before)g(it)i(can)g(safely)
f(access)h(Python)e(objects.)44 b(W)m(ithout)25 b(the)i(lock,)g(e)n(v)o
(en)f(the)0 3206 y(simplest)18 b(operations)e(could)h(cause)g(problems)
f(in)i(a)g(multi-threaded)d(program:)22 b(for)17 b(e)o(xample,)f(when)h
(tw)o(o)h(threads)f(simultaneously)0 3306 y(increment)d(the)i
(reference)e(count)g(of)i(the)f(same)h(object,)g(the)f(reference)f
(count)h(could)g(end)g(up)g(being)g(incremented)e(only)i(once)g
(instead)0 3405 y(of)20 b(twice.)0 3552 y(Therefore,)28
b(the)h(rule)f(e)o(xists)h(that)g(only)f(the)h(thread)e(that)i(has)g
(acquired)e(the)i(global)f(interpreter)f(lock)h(may)g(operate)f(on)i
(Python)0 3652 y(objects)i(or)f(call)i(Python/C)e(API)h(functions.)56
b(In)31 b(order)f(to)h(support)e(multi-threaded)g(Python)h(programs,)h
(the)g(interpreter)f(re)o(g-)0 3752 y(ularly)g(releases)h(and)f
(reacquires)f(the)i(lock)f(\227)h(by)f(def)o(ault,)i(e)n(v)o(ery)e(100)
f(bytecode)g(instructions)h(\(this)h(can)f(be)g(changed)f(with)0
3851 y Fj(sys.setcheckinterval\(\))p Fr(\).)42 b(The)27
b(lock)g(is)h(also)g(released)f(and)f(reacquired)g(around)f
(potentially)h(blocking)f(I/O)j(opera-)0 3951 y(tions)19
b(lik)o(e)h(reading)d(or)i(writing)g(a)h(\002le,)f(so)h(that)f(other)g
(threads)f(can)h(run)f(while)i(the)f(thread)f(that)h(requests)g(the)g
(I/O)h(is)g(w)o(aiting)f(for)g(the)0 4051 y(I/O)h(operation)f(to)h
(complete.)0 4197 y(The)d(Python)g(interpreter)f(needs)h(to)h(k)o(eep)f
(some)h(bookk)o(eeping)c(information)h(separate)i(per)h(thread)e(\227)j
(for)e(this)h(it)g(uses)g(a)g(data)g(struc-)0 4297 y(ture)24
b(called)h Fj(PyThreadState)p Fr(.)36 b(There')-5 b(s)25
b(one)f(global)g(v)n(ariable,)g(ho)n(we)n(v)o(er:)32
b(the)25 b(pointer)f(to)g(the)h(current)e Fj(PyThreadState)0
4397 y Fr(structure.)32 b(While)23 b(most)g(thread)e(packages)h(ha)n(v)
o(e)g(a)h(w)o(ay)g(to)g(store)g(\223per)n(-thread)d(global)i(data,)-6
b(\224)23 b(Python')-5 b(s)22 b(internal)g(platform)f(inde-)0
4496 y(pendent)d(thread)h(abstraction)f(doesn')o(t)g(support)h(this)h
(yet.)25 b(Therefore,)17 b(the)j(current)e(thread)h(state)h(must)g(be)g
(manipulated)d(e)o(xplicitly)-5 b(.)0 4643 y(This)31
b(is)h(easy)g(enough)d(in)i(most)g(cases.)59 b(Most)31
b(code)f(manipulating)f(the)i(global)g(interpreter)e(lock)i(has)g(the)g
(follo)n(wing)f(simple)0 4743 y(structure:)p 0 5549 3901
4 v 0 5649 a Fn(86)1934 b(Chapter)23 b(8.)52 b(Initialization,)26
b(Finalization,)f(and)e(Threads)p eop end
%%Page: 87 93
TeXDict begin 87 92 bop 236 174 a Fk(Save)44 b(the)h(thread)f(state)g
(in)g(a)h(local)f(variable.)236 266 y(Release)g(the)g(interpreter)f
(lock.)236 357 y(...Do)h(some)g(blocking)g(I/O)g(operation...)236
448 y(Reacquire)g(the)g(interpreter)f(lock.)236 540 y(Restore)h(the)g
(thread)g(state)g(from)g(the)h(local)e(variable.)0 826
y Fr(This)20 b(is)h(so)g(common)d(that)j(a)f(pair)g(of)g(macros)g(e)o
(xists)g(to)h(simplify)e(it:)236 1064 y Fk(Py_BEGIN_ALLOW_THREADS)236
1156 y(...Do)44 b(some)g(blocking)g(I/O)g(operation...)236
1247 y(Py_END_ALLOW_THREADS)0 1534 y Fr(The)21 b Fj
(Py_BEGIN_ALLOW_THREADS)d Fr(macro)j(opens)g(a)h(ne)n(w)g(block)e(and)h
(declares)h(a)g(hidden)e(local)h(v)n(ariable;)h(the)f
Fj(Py_END_-)0 1633 y(ALLOW_THREADS)27 b Fr(macro)h(closes)i(the)f
(block.)50 b(Another)28 b(adv)n(antage)f(of)h(using)h(these)g(tw)o(o)g
(macros)f(is)i(that)f(when)g(Python)f(is)0 1733 y(compiled)19
b(without)g(thread)g(support,)g(the)o(y)h(are)g(de\002ned)f(empty)-5
b(,)18 b(thus)j(sa)n(ving)e(the)i(thread)e(state)i(and)e(lock)h
(manipulations.)0 1880 y(When)g(thread)f(support)g(is)i(enabled,)e(the)
h(block)f(abo)o(v)o(e)g(e)o(xpands)f(to)j(the)f(follo)n(wing)f(code:)
416 2118 y Fk(PyThreadState)1043 2131 y(*)1088 2118 y(_save;)416
2300 y(_save)44 b(=)g(PyEval_SaveThread\(\);)416 2392
y(...Do)g(some)g(blocking)f(I/O)i(operation...)416 2483
y(PyEval_RestoreThread\(_save\);)0 2770 y Fr(Using)20
b(e)n(v)o(en)f(lo)n(wer)h(le)n(v)o(el)g(primiti)n(v)o(es,)f(we)h(can)g
(get)g(roughly)f(the)h(same)g(ef)n(fect)g(as)h(follo)n(ws:)416
3008 y Fk(PyThreadState)1043 3021 y(*)1088 3008 y(_save;)416
3190 y(_save)44 b(=)g(PyThreadState_Swap\(NULL\);)416
3282 y(PyEval_ReleaseLock\(\);)416 3373 y(...Do)g(some)g(blocking)f
(I/O)i(operation...)416 3464 y(PyEval_AcquireLock\(\);)416
3556 y(PyThreadState_Swap\(_save\);)0 3842 y Fr(There)23
b(are)g(some)h(subtle)f(dif)n(ferences;)h(in)g(particular)m(,)e
Fj(PyEval_RestoreThread\(\))e Fr(sa)n(v)o(es)k(and)f(restores)h(the)f
(v)n(alue)g(of)h(the)0 3942 y(global)e(v)n(ariable)h
Fj(errno)p Fr(,)g(since)g(the)h(lock)f(manipulation)e(does)i(not)g
(guarantee)e(that)i Fj(errno)g Fr(is)i(left)e(alone.)34
b(Also,)24 b(when)f(thread)0 4042 y(support)h(is)i(disabled,)f
Fj(PyEval_SaveThread\(\))e Fr(and)h Fj(PyEval_RestoreThread\(\))e
Fr(don')o(t)h(manipulate)h(the)h(lock;)i(in)0 4141 y(this)32
b(case,)j Fj(PyEval_ReleaseLock\(\))28 b Fr(and)j Fj
(PyEval_AcquireLock\(\))e Fr(are)i(not)h(a)n(v)n(ailable.)58
b(This)32 b(is)h(done)d(so)i(that)0 4241 y(dynamically)14
b(loaded)h(e)o(xtensions)f(compiled)h(with)h(thread)f(support)g
(enabled)f(can)i(be)g(loaded)f(by)g(an)h(interpreter)e(that)i(w)o(as)h
(compiled)0 4340 y(with)j(disabled)g(thread)f(support.)0
4487 y(The)f(global)f(interpreter)f(lock)h(is)i(used)f(to)g(protect)f
(the)h(pointer)f(to)h(the)g(current)e(thread)h(state.)25
b(When)18 b(releasing)f(the)h(lock)g(and)f(sa)n(ving)0
4587 y(the)28 b(thread)f(state,)k(the)d(current)e(thread)h(state)i
(pointer)e(must)h(be)g(retrie)n(v)o(ed)e(before)h(the)h(lock)g(is)h
(released)e(\(since)h(another)f(thread)0 4687 y(could)20
b(immediately)h(acquire)f(the)h(lock)g(and)g(store)h(its)g(o)n(wn)f
(thread)f(state)j(in)e(the)h(global)e(v)n(ariable\).)27
b(Con)m(v)o(ersely)-5 b(,)20 b(when)g(acquiring)0 4786
y(the)g(lock)g(and)g(restoring)e(the)j(thread)e(state,)i(the)f(lock)g
(must)g(be)g(acquired)e(before)h(storing)h(the)g(thread)f(state)i
(pointer)-5 b(.)0 4933 y(Why)25 b(am)g(I)h(going)e(on)h(with)h(so)f
(much)g(detail)g(about)g(this?)41 b(Because)25 b(when)g(threads)g(are)g
(created)g(from)f(C,)i(the)o(y)f(don')o(t)f(ha)n(v)o(e)h(the)0
5033 y(global)19 b(interpreter)f(lock,)h(nor)g(is)h(there)f(a)h(thread)
f(state)h(data)g(structure)f(for)g(them.)24 b(Such)19
b(threads)g(must)h(bootstrap)e(themselv)o(es)h(into)0
5132 y(e)o(xistence,)24 b(by)g(\002rst)h(creating)e(a)i(thread)e(state)
i(data)f(structure,)g(then)g(acquiring)f(the)h(lock,)g(and)g(\002nally)
g(storing)g(their)g(thread)f(state)0 5232 y(pointer)m(,)e(before)f(the)
o(y)h(can)h(start)h(using)e(the)h(Python/C)f(API.)h(When)g(the)o(y)f
(are)h(done,)f(the)o(y)h(should)e(reset)j(the)f(thread)f(state)h
(pointer)m(,)0 5332 y(release)e(the)g(lock,)g(and)g(\002nally)f(free)h
(their)g(thread)f(state)i(data)f(structure.)p 0 5549
3901 4 v 0 5649 a Fn(8.1.)52 b(Thread)23 b(State)h(and)g(the)f(Global)h
(Inter)r(preter)g(Loc)n(k)1969 b(87)p eop end
%%Page: 88 94
TeXDict begin 88 93 bop 0 83 a Fr(Be)o(ginning)27 b(with)h(v)o(ersion)f
(2.3,)j(threads)d(can)i(no)n(w)e(tak)o(e)i(adv)n(antage)d(of)i(the)h
Fj(PyGILState_)2869 98 y(*)2919 83 y(\(\))d Fr(functions)h(to)i(do)f
(all)g(of)h(the)0 183 y(abo)o(v)o(e)19 b(automatically)-5
b(.)23 b(The)c(typical)h(idiom)g(for)f(calling)h(into)g(Python)f(from)g
(a)i(C)g(thread)e(is)i(no)n(w:)416 421 y Fk(PyGILState_STATE)42
b(gstate;)416 512 y(gstate)h(=)i(PyGILState_Ensure\(\);)416
695 y(/)461 708 y(*)550 695 y(Perform)f(Python)g(actions)f(here.)1895
708 y(*)1940 695 y(/)416 786 y(result)g(=)i(CallSomeFunction\(\);)416
877 y(/)461 890 y(*)550 877 y(evaluate)f(result)1267
890 y(*)1312 877 y(/)416 1060 y(/)461 1073 y(*)550 1060
y(Release)g(the)g(thread.)g(No)g(Python)g(API)g(allowed)g(beyond)g
(this)g(point.)3285 1073 y(*)3330 1060 y(/)416 1151 y
(PyGILState_Release\(gstate\);)0 1438 y Fr(Note)k(that)g(the)h
Fj(PyGILState_)1084 1453 y(*)1134 1438 y(\(\))d Fr(functions)h(assume)h
(there)g(is)h(only)e(one)h(global)f(interpreter)g(\(created)g
(automati-)0 1538 y(cally)i(by)g Fj(Py_Initialize\(\))p
Fr(\).)111 b(Python)48 b(still)j(supports)d(the)h(creation)g(of)g
(additional)f(interpreters)g(\(using)h Fj(Py_-)0 1637
y(NewInterpreter\(\))p Fr(\),)17 b(b)n(ut)j(mixing)f(multiple)h
(interpreters)f(and)g(the)i Fj(PyGILState_)2757 1652
y(*)2807 1637 y(\(\))d Fr(API)i(is)h(unsupported.)0 1784
y Fg(PyInterpreterState)208 1884 y Fr(This)26 b(data)g(structure)g
(represents)f(the)i(state)g(shared)e(by)h(a)h(number)e(of)h
(cooperating)e(threads.)43 b(Threads)25 b(belonging)f(to)j(the)208
1983 y(same)19 b(interpreter)f(share)h(their)g(module)g(administration)
e(and)i(a)h(fe)n(w)f(other)g(internal)g(items.)25 b(There)19
b(are)g(no)g(public)g(members)208 2083 y(in)h(this)h(structure.)208
2216 y(Threads)i(belonging)g(to)i(dif)n(ferent)e(interpreters)g
(initially)i(share)f(nothing,)g(e)o(xcept)g(process)g(state)i(lik)o(e)f
(a)n(v)n(ailable)f(memory)-5 b(,)208 2315 y(open)22 b(\002le)h
(descriptors)f(and)h(such.)34 b(The)22 b(global)h(interpreter)e(lock)i
(is)h(also)f(shared)g(by)g(all)g(threads,)g(re)o(gardless)f(of)h(to)g
(which)208 2415 y(interpreter)18 b(the)o(y)i(belong.)0
2562 y Fg(PyThreadState)208 2662 y Fr(This)63 b(data)g(structure)f
(represents)g(the)h(state)g(of)g(a)g(single)g(thread.)152
b(The)63 b(only)f(public)g(data)h(member)f(is)208 2761
y Fj(PyInterpreterState)1154 2776 y(*)1204 2761 y(interp)p
Fr(,)19 b(which)h(points)g(to)g(this)h(thread')-5 b(s)19
b(interpreter)g(state.)0 2908 y Fj(void)49 b Fg(PyEval_InitThreads)p
Fj(\(\))208 3008 y Fr(Initialize)24 b(and)h(acquire)f(the)h(global)f
(interpreter)g(lock.)39 b(It)25 b(should)f(be)h(called)g(in)g(the)g
(main)g(thread)f(before)g(creating)g(a)h(sec-)208 3107
y(ond)j(thread)h(or)h(engaging)d(in)j(an)o(y)f(other)g(thread)g
(operations)f(such)i(as)g Fj(PyEval_ReleaseLock\(\))d
Fr(or)i Fj(PyEval_-)208 3207 y(ReleaseThread\()p Fo(tstate)p
Fj(\))p Fr(.)91 b(It)44 b(is)g(not)f(needed)f(before)g(calling)g
Fj(PyEval_SaveThread\(\))f Fr(or)h Fj(PyEval_-)208 3307
y(RestoreThread\(\))p Fr(.)208 3439 y(This)16 b(is)h(a)f(no-op)e(when)h
(called)h(for)f(a)i(second)e(time.)24 b(It)16 b(is)h(safe)f(to)g(call)g
(this)h(function)d(before)h(calling)g Fj(Py_Initialize\(\))p
Fr(.)208 3572 y(When)27 b(only)f(the)h(main)g(thread)f(e)o(xists,)j(no)
e(lock)g(operations)f(are)h(needed.)44 b(This)28 b(is)g(a)g(common)d
(situation)i(\(most)g(Python)208 3672 y(programs)18 b(do)h(not)h(use)g
(threads\),)f(and)h(the)g(lock)f(operations)g(slo)n(w)h(the)g
(interpreter)f(do)n(wn)g(a)h(bit.)26 b(Therefore,)17
b(the)j(lock)g(is)h(not)208 3771 y(created)f(initially)-5
b(.)29 b(This)21 b(situation)g(is)i(equi)n(v)n(alent)c(to)j(ha)n(ving)e
(acquired)g(the)i(lock:)27 b(when)21 b(there)g(is)h(only)f(a)h(single)f
(thread,)g(all)208 3871 y(object)e(accesses)h(are)g(safe.)25
b(Therefore,)17 b(when)i(this)h(function)e(initializes)i(the)g(lock,)f
(it)h(also)g(acquires)f(it.)25 b(Before)19 b(the)h(Python)208
3971 y Fj(thread)g Fr(module)f(creates)i(a)h(ne)n(w)e(thread,)g(kno)n
(wing)f(that)i(either)g(it)g(has)g(the)g(lock)g(or)f(the)h(lock)g
(hasn')o(t)f(been)g(created)g(yet,)h(it)208 4070 y(calls)j
Fj(PyEval_InitThreads\(\))p Fr(.)31 b(When)23 b(this)h(call)g(returns,)
f(it)i(is)f(guaranteed)d(that)j(the)f(lock)g(has)h(been)e(created)h
(and)208 4170 y(that)d(the)g(calling)g(thread)f(has)h(acquired)f(it.)
208 4303 y(It)k(is)g Fp(not)g Fr(safe)g(to)g(call)g(this)h(function)d
(when)h(it)i(is)f(unkno)n(wn)e(which)h(thread)g(\(if)h(an)o(y\))e
(currently)g(has)i(the)g(global)f(interpreter)208 4402
y(lock.)208 4535 y(This)e(function)e(is)k(not)d(a)n(v)n(ailable)h(when)
g(thread)f(support)g(is)i(disabled)e(at)i(compile)e(time.)0
4682 y Fj(int)49 b Fg(PyEval_ThreadsInitialized)p Fj(\(\))208
4782 y Fr(Returns)21 b(a)h(non-zero)e(v)n(alue)h(if)h
Fj(PyEval_InitThreads\(\))d Fr(has)j(been)f(called.)29
b(This)22 b(function)e(can)i(be)g(called)f(without)208
4881 y(holding)16 b(the)i(lock,)g(and)f(therefore)g(can)h(be)g(used)g
(to)g(a)n(v)n(oid)g(calls)h(to)f(the)g(locking)f(API)h(when)g(running)e
(single-threaded.)21 b(This)208 4981 y(function)d(is)j(not)f(a)n(v)n
(ailable)g(when)f(thread)h(support)e(is)j(disabled)f(at)h(compile)e
(time.)51 b(Ne)n(w)20 b(in)h(v)o(ersion)d(2.4.)0 5128
y Fj(void)49 b Fg(PyEval_AcquireLock)p Fj(\(\))208 5228
y Fr(Acquire)19 b(the)i(global)e(interpreter)g(lock.)26
b(The)20 b(lock)g(must)h(ha)n(v)o(e)f(been)g(created)f(earlier)-5
b(.)26 b(If)21 b(this)g(thread)e(already)h(has)h(the)f(lock,)208
5327 y(a)g(deadlock)f(ensues.)24 b(This)d(function)d(is)j(not)f(a)n(v)n
(ailable)g(when)g(thread)f(support)g(is)i(disabled)e(at)i(compile)e
(time.)p 0 5549 3901 4 v 0 5649 a Fn(88)1934 b(Chapter)23
b(8.)52 b(Initialization,)26 b(Finalization,)f(and)e(Threads)p
eop end
%%Page: 89 95
TeXDict begin 89 94 bop 0 83 a Fj(void)49 b Fg(PyEval_ReleaseLock)p
Fj(\(\))208 183 y Fr(Release)19 b(the)g(global)f(interpreter)f(lock.)24
b(The)19 b(lock)f(must)h(ha)n(v)o(e)f(been)h(created)f(earlier)-5
b(.)24 b(This)19 b(function)e(is)j(not)f(a)n(v)n(ailable)f(when)208
282 y(thread)h(support)g(is)i(disabled)e(at)i(compile)e(time.)0
429 y Fj(void)49 b Fg(PyEval_AcquireThread)p Fj(\()p
Fo(PyThr)m(eadState)14 b(*tstate)p Fj(\))208 529 y Fr(Acquire)25
b(the)i(global)f(interpreter)g(lock)g(and)g(set)i(the)f(current)e
(thread)h(state)i(to)f Fo(tstate)p Fr(,)i(which)d(should)g(not)h(be)f
Fj(NULL)p Fr(.)h(The)208 628 y(lock)d(must)g(ha)n(v)o(e)g(been)g
(created)f(earlier)-5 b(.)38 b(If)25 b(this)g(thread)e(already)h(has)g
(the)h(lock,)g(deadlock)d(ensues.)38 b(This)25 b(function)d(is)k(not)
208 728 y(a)n(v)n(ailable)19 b(when)h(thread)f(support)g(is)i(disabled)
e(at)i(compile)e(time.)0 875 y Fj(void)49 b Fg(PyEval_ReleaseThread)p
Fj(\()p Fo(PyThr)m(eadState)14 b(*tstate)p Fj(\))208
975 y Fr(Reset)22 b(the)f(current)e(thread)h(state)i(to)f
Fj(NULL)g Fr(and)g(release)g(the)g(global)f(interpreter)f(lock.)27
b(The)21 b(lock)f(must)i(ha)n(v)o(e)e(been)g(created)208
1074 y(earlier)27 b(and)g(must)h(be)g(held)g(by)f(the)h(current)f
(thread.)47 b(The)28 b Fo(tstate)g Fr(ar)o(gument,)f(which)h(must)g
(not)f(be)h Fj(NULL)p Fr(,)g(is)h(only)e(used)208 1174
y(to)g(check)f(that)h(it)h(represents)e(the)h(current)f(thread)g(state)
i(\227)g(if)f(it)h(isn')o(t,)g(a)f(f)o(atal)h(error)e(is)i(reported.)43
b(This)28 b(function)d(is)j(not)208 1273 y(a)n(v)n(ailable)19
b(when)h(thread)f(support)g(is)i(disabled)e(at)i(compile)e(time.)0
1420 y Fj(PyThreadState)650 1435 y(*)747 1420 y Fg(PyEval_SaveThread)p
Fj(\(\))208 1520 y Fr(Release)26 b(the)f(interpreter)f(lock)h(\(if)g
(it)h(has)g(been)e(created)h(and)g(thread)f(support)g(is)i(enabled\))e
(and)h(reset)h(the)f(thread)f(state)i(to)208 1620 y Fj(NULL)p
Fr(,)21 b(returning)g(the)h(pre)n(vious)f(thread)g(state)i(\(which)e
(is)j(not)e Fj(NULL)p Fr(\).)f(If)h(the)h(lock)e(has)i(been)e(created,)
h(the)h(current)e(thread)208 1719 y(must)f(ha)n(v)o(e)f(acquired)g(it.)
26 b(\(This)20 b(function)e(is)j(a)n(v)n(ailable)f(e)n(v)o(en)f(when)h
(thread)f(support)g(is)i(disabled)e(at)i(compile)e(time.\))0
1866 y Fj(void)49 b Fg(PyEval_RestoreThread)p Fj(\()p
Fo(PyThr)m(eadState)14 b(*tstate)p Fj(\))208 1966 y Fr(Acquire)h(the)i
(interpreter)e(lock)i(\(if)f(it)i(has)f(been)f(created)g(and)g(thread)g
(support)f(is)j(enabled\))d(and)i(set)g(the)g(thread)f(state)h(to)g
Fo(tstate)p Fr(,)208 2065 y(which)22 b(must)i(not)f(be)g
Fj(NULL)p Fr(.)g(If)g(the)g(lock)g(has)h(been)e(created,)h(the)h
(current)e(thread)g(must)h(not)g(ha)n(v)o(e)g(acquired)f(it,)i
(otherwise)208 2165 y(deadlock)18 b(ensues.)25 b(\(This)20
b(function)e(is)j(a)n(v)n(ailable)f(e)n(v)o(en)f(when)h(thread)f
(support)g(is)i(disabled)f(at)g(compile)g(time.\))0 2312
y(The)k(follo)n(wing)f(macros)h(are)h(normally)e(used)h(without)g(a)h
(trailing)f(semicolon;)i(look)e(for)g(e)o(xample)f(usage)h(in)h(the)g
(Python)e(source)0 2411 y(distrib)n(ution.)0 2558 y Fg
(Py_BEGIN_ALLOW_THREADS)208 2658 y Fr(This)36 b(macro)g(e)o(xpands)f
(to)i(`)p Fj({PyThreadState)1822 2673 y(*)1872 2658 y(_save;)48
b(_save)h(=)h(PyEval_SaveThread\(\);)p Fr('.)71 b(Note)208
2758 y(that)27 b(it)i(contains)e(an)g(opening)f(brace;)31
b(it)d(must)g(be)g(matched)e(with)i(a)g(follo)n(wing)e
Fj(Py_END_ALLOW_THREADS)f Fr(macro.)208 2857 y(See)20
b(abo)o(v)o(e)f(for)g(further)g(discussion)h(of)g(this)g(macro.)k(It)d
(is)g(a)f(no-op)f(when)g(thread)h(support)f(is)i(disabled)e(at)i
(compile)e(time.)0 3004 y Fg(Py_END_ALLOW_THREADS)208
3104 y Fr(This)k(macro)f(e)o(xpands)g(to)h(`)p Fj
(PyEval_RestoreThread\(_save\);)44 b(})p Fr('.)34 b(Note)23
b(that)g(it)h(contains)f(a)g(closing)g(brace;)h(it)208
3203 y(must)h(be)h(matched)e(with)i(an)f(earlier)h Fj
(Py_BEGIN_ALLOW_THREADS)c Fr(macro.)40 b(See)26 b(abo)o(v)o(e)e(for)h
(further)f(discussion)h(of)208 3303 y(this)20 b(macro.)k(It)d(is)g(a)f
(no-op)f(when)g(thread)h(support)f(is)i(disabled)e(at)i(compile)e
(time.)0 3450 y Fg(Py_BLOCK_THREADS)208 3549 y Fr(This)33
b(macro)g(e)o(xpands)e(to)j(`)p Fj(PyEval_RestoreThread\(_save\);)p
Fr(':)46 b(it)34 b(is)g(equi)n(v)n(alent)e(to)i Fj(Py_END_ALLOW_-)208
3649 y(THREADS)19 b Fr(without)g(the)i(closing)e(brace.)25
b(It)20 b(is)h(a)g(no-op)d(when)i(thread)f(support)g(is)i(disabled)e
(at)i(compile)e(time.)0 3796 y Fg(Py_UNBLOCK_THREADS)208
3896 y Fr(This)k(macro)g(e)o(xpands)e(to)j(`)p Fj(_save)48
b(=)i(PyEval_SaveThread\(\);)p Fr(':)28 b(it)c(is)h(equi)n(v)n(alent)c
(to)j Fj(Py_BEGIN_ALLOW_-)208 3995 y(THREADS)d Fr(without)h(the)h
(opening)d(brace)i(and)g(v)n(ariable)f(declaration.)30
b(It)23 b(is)h(a)f(no-op)d(when)i(thread)g(support)f(is)i(disabled)f
(at)208 4095 y(compile)d(time.)0 4242 y(All)k(of)g(the)g(follo)n(wing)e
(functions)g(are)i(only)f(a)n(v)n(ailable)g(when)h(thread)f(support)f
(is)j(enabled)d(at)j(compile)d(time,)j(and)e(must)h(be)g(called)0
4341 y(only)c(when)h(the)g(interpreter)f(lock)g(has)i(been)e(created.)0
4488 y Fj(PyInterpreterState)900 4503 y(*)996 4488 y
Fg(PyInterpreterState_New)p Fj(\(\))208 4588 y Fr(Create)h(a)h(ne)n(w)g
(interpreter)e(state)i(object.)26 b(The)20 b(interpreter)f(lock)h(need)
g(not)g(be)h(held,)f(b)n(ut)g(may)g(be)h(held)f(if)h(it)g(is)h
(necessary)d(to)208 4687 y(serialize)h(calls)h(to)f(this)h(function.)0
4834 y Fj(void)49 b Fg(PyInterpreterState_Clear)p Fj(\()p
Fo(PyInterpr)m(eterSta)o(te)15 b(*interp)p Fj(\))208
4934 y Fr(Reset)21 b(all)g(information)c(in)k(an)f(interpreter)e(state)
j(object.)k(The)20 b(interpreter)e(lock)i(must)g(be)g(held.)0
5081 y Fj(void)49 b Fg(PyInterpreterState_Delete)p Fj(\()p
Fo(PyInterpr)m(eterSta)o(te)15 b(*interp)p Fj(\))208
5180 y Fr(Destro)o(y)22 b(an)g(interpreter)f(state)i(object.)31
b(The)22 b(interpreter)e(lock)i(need)g(not)g(be)g(held.)31
b(The)22 b(interpreter)f(state)i(must)f(ha)n(v)o(e)g(been)208
5280 y(reset)e(with)g(a)h(pre)n(vious)e(call)h(to)h Fj
(PyInterpreterState_Clear\(\))p Fr(.)p 0 5549 3901 4
v 0 5649 a Fn(8.1.)52 b(Thread)23 b(State)h(and)g(the)f(Global)h(Inter)
r(preter)g(Loc)n(k)1969 b(89)p eop end
%%Page: 90 96
TeXDict begin 90 95 bop 0 83 a Fj(PyThreadState)650 98
y(*)747 83 y Fg(PyThreadState_New)p Fj(\()p Fo(PyInterpr)m(eterState)15
b(*interp)p Fj(\))208 183 y Fr(Create)k(a)h(ne)n(w)g(thread)f(state)h
(object)f(belonging)e(to)j(the)g(gi)n(v)o(en)e(interpreter)g(object.)24
b(The)19 b(interpreter)f(lock)i(need)e(not)i(be)f(held,)208
282 y(b)n(ut)h(may)f(be)i(held)e(if)i(it)g(is)g(necessary)e(to)i
(serialize)f(calls)h(to)f(this)h(function.)0 429 y Fj(void)49
b Fg(PyThreadState_Clear)p Fj(\()p Fo(PyThr)m(eadState)14
b(*tstate)p Fj(\))208 529 y Fr(Reset)21 b(all)g(information)c(in)k(a)f
(thread)g(state)g(object.)25 b(The)20 b(interpreter)e(lock)i(must)g(be)
g(held.)0 676 y Fj(void)49 b Fg(PyThreadState_Delete)p
Fj(\()p Fo(PyThr)m(eadState)14 b(*tstate)p Fj(\))208
775 y Fr(Destro)o(y)20 b(a)i(thread)e(state)h(object.)27
b(The)21 b(interpreter)e(lock)h(need)h(not)f(be)h(held.)27
b(The)21 b(thread)f(state)h(must)g(ha)n(v)o(e)g(been)f(reset)h(with)208
875 y(a)f(pre)n(vious)f(call)h(to)h Fj(PyThreadState_Clear\(\))p
Fr(.)0 1022 y Fj(PyThreadState)650 1037 y(*)747 1022
y Fg(PyThreadState_Get)p Fj(\(\))208 1121 y Fr(Return)h(the)g(current)g
(thread)g(state.)33 b(The)22 b(interpreter)f(lock)h(must)h(be)g(held.)
31 b(When)23 b(the)g(current)e(thread)h(state)h(is)h
Fj(NULL)p Fr(,)e(this)208 1221 y(issues)f(a)f(f)o(atal)h(error)e(\(so)h
(that)g(the)g(caller)h(needn')o(t)d(check)h(for)h Fj(NULL)p
Fr(\).)0 1368 y Fj(PyThreadState)650 1383 y(*)747 1368
y Fg(PyThreadState_Swap)p Fj(\()p Fo(PyThr)m(eadState)15
b(*tstate)p Fj(\))208 1468 y Fr(Sw)o(ap)30 b(the)g(current)e(thread)h
(state)i(with)f(the)g(thread)f(state)i(gi)n(v)o(en)e(by)g(the)h(ar)o
(gument)e Fo(tstate)p Fr(,)k(which)e(may)f(be)h Fj(NULL)p
Fr(.)g(The)208 1567 y(interpreter)18 b(lock)i(must)g(be)g(held.)0
1714 y Fj(PyObject)400 1729 y(*)498 1714 y Fg(PyThreadState_GetDict)p
Fj(\(\))208 1814 y Fo(Return)f(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 1913 y Fr(Return)h(a)i(dictionary)e(in)h
(which)g(e)o(xtensions)g(can)g(store)g(thread-speci\002c)f(state)i
(information.)29 b(Each)22 b(e)o(xtension)f(should)g(use)208
2013 y(a)f(unique)f(k)o(e)o(y)g(to)h(use)g(to)h(store)f(state)g(in)h
(the)f(dictionary)-5 b(.)22 b(It)f(is)g(okay)e(to)h(call)g(this)h
(function)d(when)h(no)h(current)f(thread)g(state)i(is)208
2113 y(a)n(v)n(ailable.)33 b(If)23 b(this)g(function)f(returns)g
Fj(NULL)p Fr(,)h(no)f(e)o(xception)g(has)h(been)f(raised)h(and)g(the)g
(caller)g(should)f(assume)h(no)g(current)208 2212 y(thread)d(state)i
(is)h(a)n(v)n(ailable.)58 b(Changed)20 b(in)i(v)o(ersion)e(2.3:)h(Pre)n
(viously)f(this)i(could)f(only)f(be)i(called)f(when)g(a)h(current)e
(thread)h(is)208 2312 y(acti)n(v)o(e,)e(and)h Fj(NULL)g
Fr(meant)f(that)i(an)f(e)o(xception)e(w)o(as)j(raised.)0
2459 y Fj(int)49 b Fg(PyThreadState_SetAsyncExc)p Fj(\()p
Fo(long)15 b(id,)20 b(PyObject)g(*e)n(xc)p Fj(\))208
2558 y Fr(Asynchronously)f(raise)k(an)f(e)o(xception)e(in)j(a)g
(thread.)31 b(The)22 b Fo(id)i Fr(ar)o(gument)d(is)i(the)f(thread)g(id)
g(of)h(the)f(tar)o(get)g(thread;)g Fo(e)n(xc)h Fr(is)h(the)208
2658 y(e)o(xception)c(object)i(to)h(be)f(raised.)31 b(This)23
b(function)e(does)h(not)g(steal)h(an)o(y)f(references)f(to)i
Fo(e)n(xc)p Fr(.)32 b(T)-7 b(o)22 b(pre)n(v)o(ent)f(nai)n(v)o(e)h
(misuse,)g(you)208 2758 y(must)g(write)h(your)e(o)n(wn)h(C)i(e)o
(xtension)d(to)h(call)h(this.)33 b(Must)23 b(be)f(called)g(with)h(the)g
(GIL)f(held.)32 b(Returns)22 b(the)h(number)d(of)j(thread)208
2857 y(states)h(modi\002ed;)h(this)f(is)h(normally)d(one,)i(b)n(ut)g
(will)g(be)g(zero)f(if)h(the)g(thread)f(id)g(isn')o(t)h(found.)34
b(If)23 b Fo(e)n(xc)i Fr(is)f Fj(NULL)p Fr(,)g(the)g(pending)208
2957 y(e)o(xception)18 b(\(if)i(an)o(y\))f(for)h(the)g(thread)f(is)i
(cleared.)j(This)d(raises)f(no)g(e)o(xceptions.)49 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.3.)0 3104 y Fj(PyGILState_STATE)47
b Fg(PyGILState_Ensure)p Fj(\(\))208 3203 y Fr(Ensure)17
b(that)h(the)g(current)e(thread)h(is)i(ready)e(to)h(call)h(the)f
(Python)f(C)i(API)f(re)o(gardless)e(of)i(the)g(current)f(state)h(of)g
(Python,)f(or)h(of)g(its)208 3303 y(thread)h(lock.)25
b(This)20 b(may)g(be)h(called)f(as)h(man)o(y)e(times)i(as)g(desired)f
(by)g(a)g(thread)g(as)h(long)e(as)i(each)f(call)h(is)h(matched)d(with)h
(a)h(call)208 3403 y(to)f Fj(PyGILState_Release\(\))p
Fr(.)h(In)f(general,)f(other)g(thread-related)e(APIs)k(may)e(be)h(used)
g(between)f Fj(PyGILState_-)208 3502 y(Ensure\(\))c Fr(and)h
Fj(PyGILState_Release\(\))d Fr(calls)k(as)g(long)f(as)h(the)f(thread)g
(state)h(is)g(restored)e(to)i(its)g(pre)n(vious)e(state)i(be-)208
3602 y(fore)f(the)h(Release\(\).)24 b(F)o(or)16 b(e)o(xample,)g(normal)
g(usage)g(of)h(the)g Fj(Py_BEGIN_ALLOW_THREADS)c Fr(and)k
Fj(Py_END_ALLOW_-)208 3701 y(THREADS)i Fr(macros)h(is)h(acceptable.)208
3834 y(The)h(return)f(v)n(alue)h(is)i(an)f(opaque)e(\224handle\224)g
(to)i(the)g(thread)f(state)h(when)f Fj(PyGILState_Acquire\(\))e
Fr(w)o(as)j(called,)g(and)208 3934 y(must)16 b(be)g(passed)g(to)h
Fj(PyGILState_Release\(\))c Fr(to)j(ensure)g(Python)f(is)i(left)g(in)f
(the)h(same)f(state.)24 b(Ev)o(en)16 b(though)e(recursi)n(v)o(e)208
4033 y(calls)23 b(are)f(allo)n(wed,)g(these)h(handles)e
Fo(cannot)g Fr(be)h(shared)g(-)h(each)f(unique)e(call)j(to)g
Fj(PyGILState_Ensure)d Fr(must)i(sa)n(v)o(e)h(the)208
4133 y(handle)c(for)g(its)i(call)g(to)f Fj(PyGILState_Release)p
Fr(.)208 4266 y(When)g(the)g(function)e(returns,)h(the)i(current)d
(thread)i(will)h(hold)e(the)h(GIL.)g(F)o(ailure)g(is)h(a)f(f)o(atal)h
(error)-5 b(.)50 b(Ne)n(w)20 b(in)h(v)o(ersion)e(2.3.)0
4413 y Fj(void)49 b Fg(PyGILState_Release)p Fj(\()p Fo(PyGILState)p
1593 4413 25 4 v 25 w(ST)l(A)m(TE)r Fj(\))208 4512 y
Fr(Release)21 b(an)o(y)g(resources)f(pre)n(viously)f(acquired.)26
b(After)21 b(this)g(call,)h(Python')-5 b(s)20 b(state)i(will)g(be)f
(the)g(same)g(as)h(it)f(w)o(as)h(prior)e(to)i(the)208
4612 y(corresponding)f Fj(PyGILState_Ensure)i Fr(call)i(\(b)n(ut)g
(generally)e(this)j(state)g(will)g(be)f(unkno)n(wn)d(to)k(the)f(caller)
m(,)g(hence)g(the)208 4712 y(use)20 b(of)g(the)g(GILState)g(API.\))208
4845 y(Ev)o(ery)25 b(call)j(to)f Fj(PyGILState_Ensure\(\))d
Fr(must)j(be)g(matched)f(by)g(a)i(call)f(to)g Fj
(PyGILState_Release\(\))d Fr(on)j(the)208 4944 y(same)20
b(thread.)50 b(Ne)n(w)20 b(in)g(v)o(ersion)f(2.3.)p 0
5549 3901 4 v 0 5649 a Fn(90)1934 b(Chapter)23 b(8.)52
b(Initialization,)26 b(Finalization,)f(and)e(Threads)p
eop end
%%Page: 91 97
TeXDict begin 91 96 bop 0 87 a Fl(8.2)121 b(Pro\002ling)33
b(and)h(T)-14 b(r)o(acing)0 320 y Fr(The)21 b(Python)f(interpreter)f
(pro)o(vides)h(some)h(lo)n(w-le)n(v)o(el)e(support)h(for)h(attaching)f
(pro\002ling)g(and)g(e)o(x)o(ecution)f(tracing)h(f)o(acilities.)29
b(These)0 420 y(are)20 b(used)g(for)g(pro\002ling,)e(deb)n(ugging,)g
(and)h(co)o(v)o(erage)f(analysis)i(tools.)0 567 y(Starting)25
b(with)g(Python)g(2.2,)h(the)f(implementation)e(of)i(this)h(f)o
(acility)g(w)o(as)g(substantially)f(re)n(vised,)g(and)g(an)g(interf)o
(ace)g(from)f(C)j(w)o(as)0 666 y(added.)47 b(This)28
b(C)h(interf)o(ace)e(allo)n(ws)i(the)f(pro\002ling)e(or)i(tracing)f
(code)h(to)g(a)n(v)n(oid)f(the)h(o)o(v)o(erhead)e(of)i(calling)f
(through)f(Python-le)n(v)o(el)0 766 y(callable)c(objects,)g(making)e(a)
i(direct)g(C)h(function)d(call)i(instead.)30 b(The)22
b(essential)g(attrib)n(utes)g(of)g(the)g(f)o(acility)g(ha)n(v)o(e)f
(not)g(changed;)h(the)0 866 y(interf)o(ace)i(allo)n(ws)h(trace)f
(functions)g(to)h(be)f(installed)h(per)n(-thread,)f(and)g(the)h(basic)g
(e)n(v)o(ents)f(reported)f(to)h(the)h(trace)g(function)e(are)i(the)0
965 y(same)20 b(as)h(had)f(been)f(reported)g(to)h(the)g(Python-le)n(v)o
(el)e(trace)i(functions)f(in)h(pre)n(vious)f(v)o(ersions.)0
1112 y Fg(int)49 b(\()249 1125 y(*)299 1112 y(Py_tracefunc\)\(PyObject)
1445 1125 y(*)1495 1112 y(obj,)f(PyFrameObject)2441 1125
y(*)2491 1112 y(frame,)g(int)i(what,)e(PyObject)3786
1125 y(*)3836 1112 y(arg\))208 1212 y Fr(The)20 b(type)h(of)f(the)h
(trace)g(function)e(re)o(gistered)h(using)g Fj(PyEval_SetProfile\(\))e
Fr(and)i Fj(PyEval_SetTrace\(\))p Fr(.)25 b(The)208 1311
y(\002rst)i(parameter)e(is)j(the)f(object)f(passed)g(to)h(the)g(re)o
(gistration)e(function)g(as)j Fo(obj)p Fr(,)f Fo(fr)o(ame)g
Fr(is)h(the)e(frame)g(object)h(to)f(which)h(the)208 1411
y(e)n(v)o(ent)i(pertains,)j Fo(what)f Fr(is)g(one)f(of)g(the)g
(constants)g Fj(PyTrace_CALL)p Fr(,)e Fj(PyTrace_EXCEPTION)p
Fr(,)f Fj(PyTrace_LINE)p Fr(,)208 1511 y Fj(PyTrace_RETURN)p
Fr(,)e Fj(PyTrace_C_CALL)p Fr(,)g Fj(PyTrace_C_EXCEPTION)p
Fr(,)g(or)i Fj(PyTrace_C_RETURN)p Fr(,)f(and)h Fo(ar)m(g)208
1610 y Fr(depends)18 b(on)i(the)g(v)n(alue)g(of)g Fo(what)q
Fr(:)541 1737 y Fp(V)-8 b(alue)21 b(of)f Ff(what)p 1536
1767 4 100 v 569 w Fp(Meaning)h(of)e Ff(arg)p 491 1771
3126 4 v 541 1840 a Fj(PyTrace_CALL)p 1536 1870 4 100
v 446 w Fr(Al)o(w)o(ays)i Fj(NULL)p Fr(.)541 1940 y Fj
(PyTrace_EXCEPTION)p 1536 1970 V 196 w Fr(Exception)e(information)e(as)
k(returned)e(by)g Fj(sys.exc_info\(\))p Fr(.)541 2040
y Fj(PyTrace_LINE)p 1536 2070 V 446 w Fr(Al)o(w)o(ays)i
Fj(NULL)p Fr(.)541 2139 y Fj(PyTrace_RETURN)p 1536 2169
V 346 w Fr(V)-9 b(alue)20 b(being)f(returned)g(to)h(the)g(caller)-5
b(.)541 2239 y Fj(PyTrace_C_CALL)p 1536 2269 V 346 w
Fr(Name)20 b(of)g(function)f(being)g(called.)541 2339
y Fj(PyTrace_C_EXCEPTION)p 1536 2368 V 96 w Fr(Al)o(w)o(ays)i
Fj(NULL)p Fr(.)541 2438 y Fj(PyTrace_C_RETURN)p 1536
2468 V 246 w Fr(Al)o(w)o(ays)g Fj(NULL)p Fr(.)0 2579
y Fj(int)49 b Fg(PyTrace_CALL)208 2678 y Fr(The)26 b(v)n(alue)g(of)h
(the)f Fo(what)j Fr(parameter)c(to)i(a)g Fj(Py_tracefunc)e
Fr(function)g(when)h(a)i(ne)n(w)e(call)i(to)e(a)i(function)d(or)h
(method)g(is)208 2778 y(being)20 b(reported,)h(or)g(a)i(ne)n(w)e(entry)
g(into)h(a)g(generator)-5 b(.)29 b(Note)22 b(that)g(the)f(creation)g
(of)h(the)g(iterator)f(for)g(a)i(generator)c(function)i(is)208
2878 y(not)e(reported)g(as)i(there)e(is)j(no)d(control)g(transfer)h(to)
g(the)g(Python)f(bytecode)g(in)h(the)g(corresponding)d(frame.)0
3024 y Fj(int)49 b Fg(PyTrace_EXCEPTION)208 3124 y Fr(The)22
b(v)n(alue)f(of)i(the)f Fo(what)i Fr(parameter)d(to)i(a)g
Fj(Py_tracefunc)e Fr(function)f(when)i(an)h(e)o(xception)d(has)j(been)f
(raised.)31 b(The)22 b(call-)208 3224 y(back)e(function)f(is)j(called)f
(with)g(this)h(v)n(alue)e(for)h Fo(what)h Fr(when)f(after)g(an)o(y)f
(bytecode)f(is)j(processed)e(after)h(which)f(the)h(e)o(xception)208
3323 y(becomes)27 b(set)i(within)g(the)f(frame)g(being)f(e)o(x)o
(ecuted.)48 b(The)28 b(ef)n(fect)g(of)g(this)h(is)g(that)g(as)g(e)o
(xception)e(propagation)e(causes)k(the)208 3423 y(Python)17
b(stack)h(to)h(unwind,)e(the)h(callback)g(is)h(called)f(upon)f(return)g
(to)h(each)g(frame)g(as)h(the)f(e)o(xception)f(propagates.)22
b(Only)c(trace)208 3523 y(functions)g(recei)n(v)o(es)i(these)g(e)n(v)o
(ents;)g(the)o(y)f(are)h(not)g(needed)f(by)h(the)g(pro\002ler)-5
b(.)0 3669 y Fj(int)49 b Fg(PyTrace_LINE)208 3769 y Fr(The)25
b(v)n(alue)g(passed)g(as)i(the)e Fo(what)i Fr(parameter)e(to)g(a)h
(trace)g(function)e(\(b)n(ut)h(not)g(a)h(pro\002ling)f(function\))e
(when)i(a)h(line-number)208 3869 y(e)n(v)o(ent)19 b(is)i(being)e
(reported.)0 4016 y Fj(int)49 b Fg(PyTrace_RETURN)208
4115 y Fr(The)24 b(v)n(alue)f(for)h(the)h Fo(what)h Fr(parameter)d(to)h
Fj(Py_tracefunc)f Fr(functions)g(when)h(a)h(call)f(is)i(returning)c
(without)i(propagating)208 4215 y(an)c(e)o(xception.)0
4362 y Fj(int)49 b Fg(PyTrace_C_CALL)208 4461 y Fr(The)19
b(v)n(alue)h(for)f(the)i Fo(what)g Fr(parameter)e(to)h
Fj(Py_tracefunc)f Fr(functions)g(when)g(a)i(C)g(function)d(is)k(about)d
(to)h(be)g(called.)0 4608 y Fj(int)49 b Fg(PyTrace_C_EXCEPTION)208
4708 y Fr(The)19 b(v)n(alue)h(for)f(the)i Fo(what)g Fr(parameter)e(to)h
Fj(Py_tracefunc)f Fr(functions)g(when)g(a)i(C)g(function)d(has)j(thro)n
(wn)e(an)h(e)o(xception.)0 4855 y Fj(int)49 b Fg(PyTrace_C_RETURN)208
4954 y Fr(The)19 b(v)n(alue)h(for)f(the)i Fo(what)g Fr(parameter)e(to)h
Fj(Py_tracefunc)f Fr(functions)g(when)g(a)i(C)g(function)d(has)j
(returned.)0 5101 y Fj(void)49 b Fg(PyEval_SetProfile)p
Fj(\()p Fo(Py)p 1242 5101 25 4 v 26 w(tr)o(acefunc)19
b(func,)h(PyObject)f(*obj)p Fj(\))208 5201 y Fr(Set)28
b(the)g(pro\002ler)e(function)g(to)i Fo(func)p Fr(.)47
b(The)28 b Fo(obj)f Fr(parameter)g(is)h(passed)g(to)g(the)g(function)e
(as)i(its)h(\002rst)f(parameter)m(,)g(and)f(may)208 5300
y(be)e(an)o(y)g(Python)f(object,)i(or)g Fj(NULL)p Fr(.)f(If)g(the)h
(pro\002le)f(function)e(needs)i(to)h(maintain)f(state,)i(using)e(a)h
(dif)n(ferent)e(v)n(alue)h(for)g Fo(obj)208 5400 y Fr(for)i(each)h
(thread)g(pro)o(vides)e(a)j(con)m(v)o(enient)d(and)i(thread-safe)e
(place)i(to)h(store)f(it.)50 b(The)28 b(pro\002le)g(function)f(is)i
(called)f(for)g(all)p 0 5549 3901 4 v 0 5649 a Fn(8.2.)52
b(Pro\002ling)24 b(and)g(T)-10 b(r)o(acing)2867 b(91)p
eop end
%%Page: 92 98
TeXDict begin 92 97 bop 208 83 a Fr(monitored)18 b(e)n(v)o(ents)h(e)o
(xcept)g(the)i(line-number)c(e)n(v)o(ents.)0 230 y Fj(void)49
b Fg(PyEval_SetTrace)p Fj(\()p Fo(Py)p 1142 230 25 4
v 27 w(tr)o(acefunc)19 b(func,)g(PyObject)h(*obj)p Fj(\))208
330 y Fr(Set)g(the)f(tracing)g(function)f(to)i Fo(func)p
Fr(.)k(This)c(is)g(similar)g(to)g Fj(PyEval_SetProfile\(\))p
Fr(,)c(e)o(xcept)j(the)g(tracing)g(function)f(does)208
429 y(recei)n(v)o(e)h(line-number)e(e)n(v)o(ents.)0 757
y Fl(8.3)121 b(Adv)m(anced)35 b(Deb)n(ugger)g(Suppor)5
b(t)0 989 y Fr(These)20 b(functions)f(are)h(only)f(intended)g(to)h(be)g
(used)g(by)g(adv)n(anced)e(deb)n(ugging)g(tools.)0 1136
y Fj(PyInterpreterState)900 1151 y(*)996 1136 y Fg
(PyInterpreterState_Head)p Fj(\(\))208 1236 y Fr(Return)h(the)i
(interpreter)d(state)j(object)f(at)g(the)h(head)e(of)h(the)g(list)h(of)
f(all)h(such)f(objects.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
1383 y Fj(PyInterpreterState)900 1398 y(*)996 1383 y
Fg(PyInterpreterState_Next)p Fj(\()p Fo(PyInterpr)m(eterState)14
b(*interp)p Fj(\))208 1482 y Fr(Return)19 b(the)i(ne)o(xt)e
(interpreter)g(state)h(object)g(after)g Fo(interp)g Fr(from)f(the)h
(list)i(of)e(all)g(such)g(objects.)51 b(Ne)n(w)20 b(in)h(v)o(ersion)d
(2.2.)0 1629 y Fj(PyThreadState)697 1644 y(*)797 1629
y Fg(PyInterpreterState_ThreadHead)p Fj(\()p Fo(PyIn)o(terpr)m(eterSta)
o(te)d(*interp)p Fj(\))208 1729 y Fr(Return)24 b(the)h(a)h(pointer)d
(to)i(the)h(\002rst)f Fj(PyThreadState)e Fr(object)i(in)g(the)g(list)h
(of)f(threads)f(associated)h(with)g(the)g(interpreter)208
1829 y Fo(interp)p Fr(.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)0
1975 y Fj(PyThreadState)650 1990 y(*)747 1975 y Fg(PyThreadState_Next)p
Fj(\()p Fo(PyThr)m(eadState)c(*tstate)p Fj(\))208 2075
y Fr(Return)41 b(the)g(ne)o(xt)g(thread)f(state)i(object)f(after)g
Fo(tstate)h Fr(from)f(the)g(list)i(of)e(all)h(such)f(objects)g
(belonging)e(to)j(the)f(same)208 2175 y Fj(PyInterpreterState)17
b Fr(object.)50 b(Ne)n(w)21 b(in)f(v)o(ersion)f(2.2.)p
0 5549 3901 4 v 0 5649 a Fn(92)1934 b(Chapter)23 b(8.)52
b(Initialization,)26 b(Finalization,)f(and)e(Threads)p
eop end
%%Page: 93 99
TeXDict begin 93 98 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3614
427 y Fm(NINE)p 0 515 V 1828 978 a Fx(Memor)6 b(y)57
b(Management)0 1506 y Fl(9.1)121 b(Ov)m(er)t(vie)n(w)0
1739 y Fr(Memory)22 b(management)e(in)k(Python)e(in)m(v)n(olv)o(es)f(a)
j(pri)n(v)n(ate)e(heap)g(containing)g(all)h(Python)f(objects)h(and)g
(data)g(structures.)33 b(The)22 b(man-)0 1839 y(agement)27
b(of)i(this)g(pri)n(v)n(ate)e(heap)h(is)h(ensured)e(internally)h(by)g
(the)g Fo(Python)g(memory)g(mana)o(g)o(er)p Fr(.)49 b(The)28
b(Python)f(memory)g(manager)0 1939 y(has)d(dif)n(ferent)d(components)g
(which)i(deal)g(with)h(v)n(arious)e(dynamic)g(storage)g(management)f
(aspects,)j(lik)o(e)g(sharing,)f(se)o(gmentation,)0 2038
y(preallocation)18 b(or)i(caching.)0 2185 y(At)31 b(the)f(lo)n(west)h
(le)n(v)o(el,)h(a)f(ra)o(w)f(memory)f(allocator)g(ensures)h(that)g
(there)g(is)h(enough)e(room)g(in)h(the)h(pri)n(v)n(ate)e(heap)h(for)f
(storing)h(all)0 2285 y(Python-related)c(data)i(by)f(interacting)g
(with)i(the)f(memory)e(manager)h(of)h(the)g(operating)e(system.)49
b(On)28 b(top)g(of)g(the)g(ra)o(w)g(memory)0 2384 y(allocator)m(,)h(se)
n(v)o(eral)e(object-speci\002c)g(allocators)h(operate)f(on)h(the)g
(same)h(heap)e(and)h(implement)f(distinct)h(memory)f(management)0
2484 y(policies)21 b(adapted)f(to)h(the)g(peculiarities)g(of)g(e)n(v)o
(ery)e(object)i(type.)27 b(F)o(or)21 b(e)o(xample,)e(inte)o(ger)h
(objects)h(are)g(managed)f(dif)n(ferently)f(within)0
2584 y(the)29 b(heap)f(than)g(strings,)i(tuples)f(or)f(dictionaries)f
(because)h(inte)o(gers)g(imply)g(dif)n(ferent)f(storage)h(requirements)
e(and)i(speed/space)0 2683 y(tradeof)n(fs.)e(The)20 b(Python)g(memory)f
(manager)h(thus)h(dele)o(gates)e(some)i(of)g(the)g(w)o(ork)f(to)h(the)g
(object-speci\002c)f(allocators,)g(b)n(ut)h(ensures)0
2783 y(that)f(the)g(latter)h(operate)e(within)h(the)g(bounds)f(of)h
(the)g(pri)n(v)n(ate)f(heap.)0 2930 y(It)g(is)h(important)d(to)i
(understand)d(that)j(the)g(management)d(of)j(the)g(Python)e(heap)h(is)i
(performed)c(by)i(the)h(interpreter)e(itself)j(and)e(that)h(the)0
3029 y(user)j(has)h(no)f(control)f(o)o(v)o(er)h(it,)h(e)n(v)o(en)f(if)g
(she)h(re)o(gularly)e(manipulates)g(object)h(pointers)f(to)i(memory)e
(blocks)h(inside)g(that)h(heap.)31 b(The)0 3129 y(allocation)19
b(of)h(heap)g(space)g(for)g(Python)f(objects)h(and)g(other)g(internal)f
(b)n(uf)n(fers)g(is)j(performed)17 b(on)j(demand)f(by)h(the)g(Python)f
(memory)0 3229 y(manager)g(through)f(the)i(Python/C)f(API)i(functions)e
(listed)h(in)h(this)f(document.)0 3375 y(T)-7 b(o)32
b(a)n(v)n(oid)g(memory)f(corruption,)h(e)o(xtension)f(writers)h(should)
f(ne)n(v)o(er)g(try)h(to)h(operate)e(on)g(Python)g(objects)h(with)h
(the)f(functions)0 3475 y(e)o(xported)d(by)h(the)h(C)g(library:)45
b Fj(malloc\(\))p Fr(,)33 b Fj(calloc\(\))p Fr(,)f Fj(realloc\(\))d
Fr(and)h Fj(free\(\))p Fr(.)56 b(This)31 b(will)h(result)e(in)h(mix)o
(ed)f(calls)0 3575 y(between)21 b(the)i(C)g(allocator)e(and)h(the)g
(Python)f(memory)f(manager)h(with)h(f)o(atal)h(consequences,)d(because)
i(the)o(y)f(implement)g(dif)n(ferent)0 3674 y(algorithms)h(and)h
(operate)f(on)h(dif)n(ferent)f(heaps.)34 b(Ho)n(we)n(v)o(er)m(,)23
b(one)f(may)h(safely)h(allocate)f(and)g(release)g(memory)f(blocks)h
(with)g(the)h(C)0 3774 y(library)19 b(allocator)g(for)h(indi)n(vidual)e
(purposes,)h(as)i(sho)n(wn)e(in)i(the)f(follo)n(wing)e(e)o(xample:)416
4012 y Fk(PyObject)819 4025 y(*)864 4012 y(res;)416 4103
y(char)640 4116 y(*)685 4103 y(buf)44 b(=)h(\(char)1223
4116 y(*)1268 4103 y(\))f(malloc\(BUFSIZ\);)e(/)2119
4116 y(*)2209 4103 y(for)i(I/O)2567 4116 y(*)2612 4103
y(/)416 4286 y(if)g(\(buf)g(==)h(NULL\))595 4377 y(return)f
(PyErr_NoMemory\(\);)416 4469 y(...Do)g(some)g(I/O)g(operation)f
(involving)h(buf...)416 4560 y(res)g(=)h(PyString_FromString\(buf\);)
416 4651 y(free\(buf\);)e(/)954 4664 y(*)1043 4651 y(malloc'ed)1492
4664 y(*)1537 4651 y(/)416 4743 y(return)g(res;)0 5029
y Fr(In)27 b(this)h(e)o(xample,)g(the)g(memory)e(request)h(for)g(the)g
(I/O)h(b)n(uf)n(fer)e(is)j(handled)d(by)h(the)h(C)g(library)f
(allocator)-5 b(.)47 b(The)27 b(Python)f(memory)0 5129
y(manager)19 b(is)i(in)m(v)n(olv)o(ed)d(only)h(in)i(the)f(allocation)f
(of)h(the)g(string)g(object)g(returned)e(as)j(a)g(result.)0
5276 y(In)16 b(most)h(situations,)g(ho)n(we)n(v)o(er)m(,)e(it)i(is)h
(recommended)13 b(to)k(allocate)f(memory)f(from)h(the)g(Python)g(heap)g
(speci\002cally)g(because)g(the)g(latter)0 5375 y(is)24
b(under)e(control)g(of)h(the)g(Python)f(memory)g(manager)-5
b(.)33 b(F)o(or)23 b(e)o(xample,)f(this)i(is)g(required)d(when)i(the)g
(interpreter)f(is)i(e)o(xtended)d(with)p 0 5549 3901
4 v 3808 5649 a Fn(93)p eop end
%%Page: 94 100
TeXDict begin 94 99 bop 0 83 a Fr(ne)n(w)24 b(object)g(types)g(written)
g(in)g(C.)h(Another)e(reason)h(for)f(using)h(the)g(Python)f(heap)h(is)h
(the)f(desire)g(to)h Fo(inform)f Fr(the)g(Python)f(memory)0
183 y(manager)d(about)g(the)i(memory)e(needs)h(of)g(the)g(e)o(xtension)
f(module.)27 b(Ev)o(en)21 b(when)g(the)g(requested)f(memory)g(is)i
(used)g(e)o(xclusi)n(v)o(ely)d(for)0 282 y(internal,)27
b(highly-speci\002c)d(purposes,)j(dele)o(gating)d(all)j(memory)d
(requests)i(to)h(the)f(Python)f(memory)g(manager)g(causes)h(the)h
(inter)n(-)0 382 y(preter)20 b(to)i(ha)n(v)o(e)f(a)g(more)g(accurate)f
(image)h(of)g(its)h(memory)e(footprint)f(as)j(a)g(whole.)27
b(Consequently)-5 b(,)19 b(under)h(certain)h(circumstances,)0
482 y(the)d(Python)g(memory)e(manager)h(may)h(or)g(may)g(not)h(trigger)
e(appropriate)f(actions,)i(lik)o(e)h(garbage)d(collection,)i(memory)f
(compaction)0 581 y(or)30 b(other)f(pre)n(v)o(enti)n(v)o(e)e
(procedures.)53 b(Note)30 b(that)g(by)f(using)h(the)g(C)h(library)e
(allocator)g(as)i(sho)n(wn)e(in)h(the)g(pre)n(vious)f(e)o(xample,)i
(the)0 681 y(allocated)19 b(memory)g(for)g(the)i(I/O)f(b)n(uf)n(fer)f
(escapes)h(completely)f(the)h(Python)f(memory)g(manager)-5
b(.)0 1008 y Fl(9.2)121 b(Memor)t(y)32 b(Interf)l(ace)0
1241 y Fr(The)20 b(follo)n(wing)f(function)f(sets,)j(modeled)e(after)h
(the)g(ANSI)h(C)g(standard,)e(b)n(ut)h(specifying)f(beha)n(vior)g(when)
h(requesting)e(zero)i(bytes,)0 1341 y(are)g(a)n(v)n(ailable)g(for)f
(allocating)h(and)f(releasing)h(memory)e(from)h(the)i(Python)e(heap:)0
1488 y Fj(void)200 1503 y(*)299 1488 y Fg(PyMem_Malloc)p
Fj(\()p Fo(size)p 1078 1488 25 4 v 28 w(t)i(n)p Fj(\))208
1587 y Fr(Allocates)k Fo(n)h Fr(bytes)f(and)g(returns)g(a)h(pointer)e
(of)h(type)g Fj(void)2007 1602 y(*)2083 1587 y Fr(to)g(the)h(allocated)
f(memory)-5 b(,)24 b(or)h Fj(NULL)h Fr(if)g(the)f(request)g(f)o(ails.)
208 1687 y(Requesting)j(zero)g(bytes)h(returns)f(a)h(distinct)g(non-)p
Fj(NULL)e Fr(pointer)h(if)h(possible,)h(as)g(if)f Fj(PyMem_Malloc\(1\))
e Fr(had)h(been)208 1786 y(called)20 b(instead.)k(The)c(memory)f(will)i
(not)e(ha)n(v)o(e)h(been)f(initialized)h(in)h(an)o(y)e(w)o(ay)-5
b(.)0 1933 y Fj(void)200 1948 y(*)299 1933 y Fg(PyMem_Realloc)p
Fj(\()p Fo(void)17 b(*p,)j(size)p 1414 1933 V 30 w(t)h(n)p
Fj(\))208 2033 y Fr(Resizes)k(the)f(memory)e(block)h(pointed)g(to)h(by)
f Fo(p)h Fr(to)g Fo(n)g Fr(bytes.)37 b(The)23 b(contents)g(will)i(be)f
(unchanged)d(to)j(the)g(minimum)f(of)h(the)208 2133 y(old)g(and)g(the)h
(ne)n(w)f(sizes.)39 b(If)25 b Fo(p)f Fr(is)i Fj(NULL)p
Fr(,)e(the)h(call)g(is)g(equi)n(v)n(alent)e(to)i Fj(PyMem_Malloc\()p
Fo(n)p Fj(\))p Fr(;)f(else)h(if)g Fo(n)g Fr(is)h(equal)e(to)g(zero,)208
2232 y(the)f(memory)e(block)h(is)i(resized)e(b)n(ut)h(is)h(not)f
(freed,)f(and)h(the)g(returned)e(pointer)g(is)j(non-)p
Fj(NULL)p Fr(.)d(Unless)i Fo(p)g Fr(is)h Fj(NULL)p Fr(,)f(it)h(must)208
2332 y(ha)n(v)o(e)j(been)h(returned)e(by)i(a)g(pre)n(vious)f(call)h(to)
h Fj(PyMem_Malloc\(\))d Fr(or)i Fj(PyMem_Realloc\(\))p
Fr(.)46 b(If)28 b(the)h(request)e(f)o(ails,)208 2431
y Fj(PyMem_Realloc\(\))18 b Fr(returns)h Fj(NULL)h Fr(and)f
Fo(p)i Fr(remains)e(a)i(v)n(alid)f(pointer)f(to)h(the)g(pre)n(vious)f
(memory)f(area.)0 2578 y Fj(void)49 b Fg(PyMem_Free)p
Fj(\()p Fo(void)18 b(*p)p Fj(\))208 2678 y Fr(Frees)33
b(the)f(memory)f(block)h(pointed)g(to)g(by)h Fo(p)p Fr(,)j(which)c
(must)g(ha)n(v)o(e)h(been)f(returned)f(by)h(a)h(pre)n(vious)e(call)i
(to)g Fj(PyMem_-)208 2778 y(Malloc\(\))24 b Fr(or)h Fj
(PyMem_Realloc\(\))p Fr(.)38 b(Otherwise,)26 b(or)f(if)g
Fj(PyMem_Free\(p\))f Fr(has)h(been)g(called)g(before,)g(unde\002ned)208
2877 y(beha)n(vior)18 b(occurs.)24 b(If)c Fo(p)h Fr(is)g
Fj(NULL)p Fr(,)f(no)f(operation)g(is)i(performed.)0 3024
y(The)f(follo)n(wing)e(type-oriented)g(macros)h(are)h(pro)o(vided)e
(for)i(con)m(v)o(enience.)i(Note)e(that)g Fo(TYPE)i Fr(refers)e(to)g
(an)o(y)g(C)h(type.)0 3171 y Fo(TYPE)196 3186 y Fj(*)295
3171 y Fg(PyMem_New)p Fj(\()p Fo(TYPE,)e(size)p 1158
3171 V 30 w(t)i(n)p Fj(\))208 3271 y Fr(Same)e(as)h Fj
(PyMem_Malloc\(\))p Fr(,)d(b)n(ut)j(allocates)f Fj(\()p
Fo(n)1815 3286 y Fj(*)1915 3271 y(sizeof\()p Fo(TYPE)r
Fj(\)\))f Fr(bytes)h(of)g(memory)-5 b(.)23 b(Returns)c(a)h(pointer)e
(cast)208 3370 y(to)i Fo(TYPE)489 3385 y Fj(*)539 3370
y Fr(.)25 b(The)20 b(memory)e(will)j(not)f(ha)n(v)o(e)g(been)f
(initialized)h(in)g(an)o(y)g(w)o(ay)-5 b(.)0 3517 y Fo(TYPE)196
3532 y Fj(*)295 3517 y Fg(PyMem_Resize)p Fj(\()p Fo(void)18
b(*p,)h(TYPE,)h(size)p 1595 3517 V 31 w(t)h(n)p Fj(\))208
3617 y Fr(Same)f(as)g Fj(PyMem_Realloc\(\))p Fr(,)e(b)n(ut)i(the)g
(memory)e(block)h(is)i(resized)f(to)g Fj(\()p Fo(n)2598
3632 y Fj(*)2698 3617 y(sizeof\()p Fo(TYPE)r Fj(\)\))f
Fr(bytes.)24 b(Returns)c(a)208 3716 y(pointer)f(cast)h(to)h
Fo(TYPE)895 3731 y Fj(*)945 3716 y Fr(.)k(On)20 b(return,)f
Fo(p)h Fr(will)h(be)f(a)h(pointer)e(to)h(the)g(ne)n(w)g(memory)f(area,)
g(or)h Fj(NULL)g Fr(in)h(the)f(e)n(v)o(ent)f(of)h(f)o(ailure.)0
3863 y Fj(void)49 b Fg(PyMem_Del)p Fj(\()p Fo(void)18
b(*p)p Fj(\))208 3963 y Fr(Same)i(as)h Fj(PyMem_Free\(\))p
Fr(.)0 4110 y(In)f(addition,)e(the)i(follo)n(wing)e(macro)h(sets)h(are)
g(pro)o(vided)d(for)j(calling)f(the)h(Python)e(memory)g(allocator)h
(directly)-5 b(,)19 b(without)g(in)m(v)n(olving)0 4209
y(the)24 b(C)g(API)g(functions)e(listed)i(abo)o(v)o(e.)33
b(Ho)n(we)n(v)o(er)m(,)22 b(note)h(that)h(their)f(use)h(does)f(not)g
(preserv)o(e)f(binary)g(compatibility)g(across)i(Python)0
4309 y(v)o(ersions)19 b(and)h(is)h(therefore)d(deprecated)h(in)h(e)o
(xtension)f(modules.)0 4456 y Fj(PyMem_MALLOC\(\))p Fr(,)f
Fj(PyMem_REALLOC\(\))p Fr(,)g Fj(PyMem_FREE\(\))p Fr(.)0
4603 y Fj(PyMem_NEW\(\))p Fr(,)g Fj(PyMem_RESIZE\(\))p
Fr(,)g Fj(PyMem_DEL\(\))p Fr(.)0 4930 y Fl(9.3)121 b(Examples)0
5163 y Fr(Here)23 b(is)h(the)f(e)o(xample)f(from)g(section)h(9.1,)g(re)
n(written)g(so)g(that)g(the)h(I/O)f(b)n(uf)n(fer)f(is)i(allocated)e
(from)g(the)i(Python)e(heap)g(by)h(using)g(the)0 5262
y(\002rst)e(function)d(set:)p 0 5549 3901 4 v 0 5649
a Fn(94)2536 b(Chapter)23 b(9.)52 b(Memor)r(y)23 b(Management)p
eop end
%%Page: 95 101
TeXDict begin 95 100 bop 416 83 a Fk(PyObject)819 96
y(*)864 83 y(res;)416 174 y(char)640 187 y(*)685 174
y(buf)44 b(=)h(\(char)1223 187 y(*)1268 174 y(\))f
(PyMem_Malloc\(BUFSIZ\);)d(/)2388 187 y(*)2478 174 y(for)j(I/O)2836
187 y(*)2881 174 y(/)416 357 y(if)g(\(buf)g(==)h(NULL\))595
448 y(return)f(PyErr_NoMemory\(\);)416 540 y(/)461 553
y(*)550 540 y(...Do)g(some)g(I/O)h(operation)e(involving)g(buf...)2433
553 y(*)2478 540 y(/)416 631 y(res)h(=)h(PyString_FromString\(buf\);)
416 722 y(PyMem_Free\(buf\);)d(/)1223 735 y(*)1312 722
y(allocated)i(with)g(PyMem_Malloc)2567 735 y(*)2612 722
y(/)416 814 y(return)f(res;)0 1100 y Fr(The)20 b(same)g(code)g(using)f
(the)i(type-oriented)c(function)h(set:)416 1247 y Fk(PyObject)819
1260 y(*)864 1247 y(res;)416 1338 y(char)640 1351 y(*)685
1338 y(buf)44 b(=)h(PyMem_New\(char,)d(BUFSIZ\);)h(/)2119
1351 y(*)2209 1338 y(for)h(I/O)2567 1351 y(*)2612 1338
y(/)416 1521 y(if)g(\(buf)g(==)h(NULL\))595 1612 y(return)f
(PyErr_NoMemory\(\);)416 1704 y(/)461 1717 y(*)550 1704
y(...Do)g(some)g(I/O)h(operation)e(involving)g(buf...)2433
1717 y(*)2478 1704 y(/)416 1795 y(res)h(=)h
(PyString_FromString\(buf\);)416 1886 y(PyMem_Del\(buf\);)d(/)1178
1899 y(*)1267 1886 y(allocated)i(with)g(PyMem_New)2388
1899 y(*)2433 1886 y(/)416 1978 y(return)f(res;)0 2264
y Fr(Note)18 b(that)g(in)h(the)f(tw)o(o)g(e)o(xamples)f(abo)o(v)o(e,)g
(the)h(b)n(uf)n(fer)e(is)j(al)o(w)o(ays)g(manipulated)d(via)i
(functions)f(belonging)f(to)i(the)g(same)g(set.)25 b(Indeed,)0
2364 y(it)30 b(is)h(required)d(to)i(use)g(the)g(same)g(memory)e(API)i
(f)o(amily)f(for)g(a)h(gi)n(v)o(en)f(memory)f(block,)j(so)f(that)g(the)
f(risk)h(of)g(mixing)e(dif)n(ferent)0 2463 y(allocators)18
b(is)j(reduced)c(to)i(a)h(minimum.)j(The)c(follo)n(wing)e(code)h
(sequence)g(contains)h(tw)o(o)g(errors,)f(one)h(of)g(which)f(is)i
(labeled)f(as)h Fo(fatal)0 2563 y Fr(because)g(it)g(mix)o(es)g(tw)o(o)h
(dif)n(ferent)d(allocators)i(operating)e(on)i(dif)n(ferent)e(heaps.)236
2710 y Fk(char)460 2723 y(*)505 2710 y(buf1)44 b(=)h(PyMem_New\(char,)d
(BUFSIZ\);)236 2801 y(char)460 2814 y(*)505 2801 y(buf2)i(=)h(\(char)
1088 2814 y(*)1133 2801 y(\))g(malloc\(BUFSIZ\);)236
2893 y(char)460 2906 y(*)505 2893 y(buf3)f(=)h(\(char)1088
2906 y(*)1133 2893 y(\))g(PyMem_Malloc\(BUFSIZ\);)236
2984 y(...)236 3075 y(PyMem_Del\(buf3\);)87 b(/)1088
3088 y(*)1178 3075 y(Wrong)44 b(--)g(should)g(be)g(PyMem_Free\(\))2612
3088 y(*)2657 3075 y(/)236 3166 y(free\(buf2\);)312 b(/)1088
3179 y(*)1178 3166 y(Right)44 b(--)g(allocated)f(via)i(malloc\(\))2612
3179 y(*)2657 3166 y(/)236 3258 y(free\(buf1\);)312 b(/)1088
3271 y(*)1178 3258 y(Fatal)44 b(--)g(should)g(be)g(PyMem_Del\(\))2612
3271 y(*)2657 3258 y(/)0 3544 y Fr(In)15 b(addition)f(to)h(the)h
(functions)e(aimed)g(at)i(handling)d(ra)o(w)i(memory)f(blocks)h(from)f
(the)h(Python)f(heap,)i(objects)f(in)g(Python)f(are)h(allocated)0
3644 y(and)20 b(released)f(with)i Fj(PyObject_New\(\))p
Fr(,)d Fj(PyObject_NewVar\(\))f Fr(and)j Fj(PyObject_Del\(\))p
Fr(.)0 3791 y(These)g(will)h(be)f(e)o(xplained)e(in)j(the)f(ne)o(xt)f
(chapter)g(on)h(de\002ning)f(and)h(implementing)e(ne)n(w)i(object)f
(types)h(in)h(C.)p 0 5549 3901 4 v 0 5649 a Fn(9.3.)52
b(Examples)3254 b(95)p eop end
%%Page: 96 102
TeXDict begin 96 101 bop 0 5549 3901 4 v 0 5649 a Fn(96)p
eop end
%%Page: 97 103
TeXDict begin 97 102 bop 0 83 3901 9 v 3503 230 a Fn(CHAPTER)3661
427 y Fm(TEN)p 0 515 V 987 978 a Fx(Object)58 b(Implementation)f
(Suppor)8 b(t)0 1465 y Fr(This)20 b(chapter)f(describes)h(the)g
(functions,)f(types,)h(and)f(macros)h(used)g(when)f(de\002ning)g(ne)n
(w)h(object)g(types.)0 1792 y Fl(10.1)121 b(Allocating)34
b(Objects)f(on)h(the)h(Heap)0 2011 y Fj(PyObject)400
2026 y(*)498 2011 y Fg(_PyObject_New)p Fj(\()p Fo(PyT)-6
b(ypeObject)16 b(*type)p Fj(\))208 2111 y Fo(Return)j(value:)25
b Ff(New)20 b(ref)o(erence)p Fo(.)0 2357 y Fj(PyObject)400
2372 y(*)498 2357 y Fg(_PyObject_NewVar)p Fj(\()p Fo(PyT)-6
b(ypeObject)16 b(*type)o(,)j(Py)p 2143 2357 25 4 v 30
w(ssize)p 2329 2357 V 31 w(t)h(size)p Fj(\))208 2457
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)0 2703 y Fj(void)49 b Fg(_PyObject_Del)p Fj(\()p
Fo(PyObject)17 b(*op)p Fj(\))0 2850 y(PyObject)400 2865
y(*)498 2850 y Fg(PyObject_Init)p Fj(\()p Fo(PyObject)g(*op,)i(PyT)-6
b(ypeObject)19 b(*type)p Fj(\))208 2950 y Fo(Return)g(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 3050
y Fr(Initialize)k(a)g(ne)n(wly-allocated)e(object)i Fo(op)g
Fr(with)h(its)g(type)f(and)g(initial)g(reference.)36
b(Returns)24 b(the)h(initialized)f(object.)36 b(If)25
b Fo(type)208 3149 y Fr(indicates)d(that)i(the)f(object)f(participates)
h(in)g(the)g(c)o(yclic)g(garbage)e(detector)m(,)h(it)i(is)g(added)e(to)
h(the)g(detector')-5 b(s)23 b(set)h(of)f(observ)o(ed)208
3249 y(objects.)h(Other)c(\002elds)h(of)f(the)g(object)f(are)i(not)e
(af)n(fected.)0 3396 y Fj(PyVarObject)550 3411 y(*)648
3396 y Fg(PyObject_InitVar)p Fj(\()p Fo(PyV)-9 b(arObject)15
b(*op,)k(PyT)-6 b(ypeObject)19 b(*type)o(,)h(Py)p 2904
3396 V 29 w(ssize)p 3089 3396 V 31 w(t)h(size)p Fj(\))208
3495 y Fo(Return)e(value:)25 b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p
Fo(.)208 3595 y Fr(This)h(does)h(e)n(v)o(erything)c Fj
(PyObject_Init\(\))i Fr(does,)h(and)g(also)h(initializes)g(the)f
(length)g(information)e(for)i(a)h(v)n(ariable-size)208
3695 y(object.)0 3841 y Fo(TYPE)196 3856 y Fj(*)295 3841
y Fg(PyObject_New)p Fj(\()p Fo(TYPE,)c(PyT)-6 b(ypeObject)19
b(*type)p Fj(\))208 3941 y Fr(Allocate)29 b(a)h(ne)n(w)f(Python)f
(object)h(using)g(the)g(C)i(structure)d(type)h Fo(TYPE)j
Fr(and)d(the)g(Python)g(type)f(object)h Fo(type)p Fr(.)53
b(Fields)30 b(not)208 4041 y(de\002ned)19 b(by)i(the)f(Python)g(object)
g(header)g(are)h(not)f(initialized;)h(the)f(object')-5
b(s)21 b(reference)e(count)h(will)h(be)g(one.)26 b(The)21
b(size)g(of)g(the)208 4140 y(memory)d(allocation)h(is)i(determined)e
(from)g(the)h Fj(tp_basicsize)e Fr(\002eld)j(of)f(the)g(type)g(object.)
0 4287 y Fo(TYPE)196 4302 y Fj(*)295 4287 y Fg(PyObject_NewVar)p
Fj(\()p Fo(TYPE,)e(PyT)-6 b(ypeObject)19 b(*type)o(,)g(Py)p
2126 4287 V 30 w(ssize)p 2312 4287 V 30 w(t)i(size)p
Fj(\))208 4387 y Fr(Allocate)29 b(a)h(ne)n(w)f(Python)f(object)h(using)
g(the)g(C)i(structure)d(type)h Fo(TYPE)j Fr(and)d(the)g(Python)g(type)f
(object)h Fo(type)p Fr(.)53 b(Fields)30 b(not)208 4486
y(de\002ned)24 b(by)i(the)g(Python)e(object)i(header)e(are)i(not)g
(initialized.)41 b(The)26 b(allocated)f(memory)f(allo)n(ws)i(for)g(the)
f Fo(TYPE)k Fr(structure)208 4586 y(plus)24 b Fo(size)h
Fr(\002elds)g(of)f(the)g(size)h(gi)n(v)o(en)f(by)f(the)i
Fj(tp_itemsize)e Fr(\002eld)h(of)g Fo(type)p Fr(.)37
b(This)25 b(is)g(useful)f(for)g(implementing)e(objects)208
4686 y(lik)o(e)i(tuples,)g(which)g(are)g(able)g(to)g(determine)f(their)
g(size)i(at)f(construction)e(time.)37 b(Embedding)21
b(the)j(array)g(of)f(\002elds)i(into)f(the)208 4785 y(same)c
(allocation)f(decreases)h(the)g(number)f(of)g(allocations,)h(impro)o
(ving)d(the)j(memory)f(management)f(ef)n(\002cienc)o(y)-5
b(.)0 4932 y Fj(void)49 b Fg(PyObject_Del)p Fj(\()p Fo(PyObject)17
b(*op)p Fj(\))208 5032 y Fr(Releases)26 b(memory)e(allocated)g(to)i(an)
f(object)g(using)g Fj(PyObject_New\(\))e Fr(or)i Fj
(PyObject_NewVar\(\))p Fr(.)38 b(This)25 b(is)h(nor)n(-)208
5131 y(mally)c(called)g(from)g(the)g Fj(tp_dealloc)f
Fr(handler)g(speci\002ed)i(in)f(the)h(object')-5 b(s)22
b(type.)32 b(The)22 b(\002elds)h(of)f(the)g(object)g(should)g(not)208
5231 y(be)e(accessed)g(after)g(this)g(call)h(as)g(the)f(memory)f(is)i
(no)f(longer)e(a)j(v)n(alid)f(Python)f(object.)p 0 5549
3901 4 v 3808 5649 a Fn(97)p eop end
%%Page: 98 104
TeXDict begin 98 103 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(Py_InitModule)p Fj(\()p Fo(c)o(har)17 b(*name)o(,)i
(PyMethodDef)g(*methods)p Fj(\))208 183 y Fo(Return)g(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 282
y Fr(Create)g(a)h(ne)n(w)f(module)e(object)i(based)g(on)g(a)g(name)g
(and)f(table)i(of)f(functions,)e(returning)g(the)i(ne)n(w)g(module)f
(object.)208 415 y(Changed)f(in)j(v)o(ersion)e(2.3:)g(Older)h(v)o
(ersions)f(of)h(Python)f(did)h(not)g(support)f Fj(NULL)h
Fr(as)h(the)f(v)n(alue)f(for)h(the)g Fo(methods)g Fr(ar)o(gument.)0
562 y Fj(PyObject)400 577 y(*)498 562 y Fg(Py_InitModule3)p
Fj(\()p Fo(c)o(har)d(*name)o(,)i(PyMethodDef)g(*methods,)g(c)o(har)g
(*doc)p Fj(\))208 662 y Fo(Return)g(value:)25 b Ff(Borro)n(w)o(ed)20
b(ref)o(erence)p Fo(.)208 761 y Fr(Create)h(a)g(ne)n(w)g(module)e
(object)i(based)f(on)h(a)g(name)f(and)h(table)g(of)f(functions,)g
(returning)f(the)i(ne)n(w)f(module)g(object.)26 b(If)21
b Fo(doc)g Fr(is)208 861 y(non-)p Fj(NULL)p Fr(,)c(it)k(will)g(be)f
(used)g(to)h(de\002ne)e(the)i(docstring)d(for)i(the)g(module.)208
994 y(Changed)e(in)j(v)o(ersion)e(2.3:)g(Older)h(v)o(ersions)f(of)h
(Python)f(did)h(not)g(support)f Fj(NULL)h Fr(as)h(the)f(v)n(alue)f(for)
h(the)g Fo(methods)g Fr(ar)o(gument.)0 1141 y Fj(PyObject)400
1156 y(*)498 1141 y Fg(Py_InitModule4)p Fj(\()p Fo(c)o(har)d(*name)o(,)
i(PyMethodDef)g(*methods,)g(c)o(har)g(*doc,)g(PyObject)h(*self)o(,)g
(int)h(apiver)r Fj(\))208 1240 y Fo(Return)e(value:)25
b Ff(Borro)n(w)o(ed)20 b(ref)o(erence)p Fo(.)208 1340
y Fr(Create)k(a)h(ne)n(w)g(module)e(object)h(based)g(on)g(a)h(name)f
(and)g(table)h(of)f(functions,)g(returning)e(the)j(ne)n(w)f(module)f
(object.)38 b(If)24 b Fo(doc)208 1439 y Fr(is)h(non-)p
Fj(NULL)p Fr(,)d(it)j(will)h(be)e(used)g(to)h(de\002ne)f(the)h
(docstring)e(for)g(the)i(module.)36 b(If)25 b Fo(self)37
b Fr(is)26 b(non-)p Fj(NULL)p Fr(,)c(it)j(will)g(passed)g(to)g(the)208
1539 y(functions)19 b(of)i(the)g(module)f(as)i(their)f(\(otherwise)f
Fj(NULL)p Fr(\))h(\002rst)h(parameter)-5 b(.)27 b(\(This)21
b(w)o(as)h(added)e(as)i(an)f(e)o(xperimental)e(feature,)208
1639 y(and)d(there)g(are)h(no)g(kno)n(wn)e(uses)j(in)f(the)g(current)f
(v)o(ersion)f(of)i(Python.\))22 b(F)o(or)17 b Fo(apiver)r
Fr(,)g(the)g(only)f(v)n(alue)g(which)h(should)f(be)h(passed)208
1738 y(is)k(de\002ned)e(by)h(the)g(constant)f Fj(PYTHON_API_VERSION)p
Fr(.)208 1871 y Fp(Note:)26 b Fr(Most)c(uses)g(of)f(this)h(function)e
(should)g(probably)f(be)j(using)f(the)g Fj(Py_InitModule3\(\))e
Fr(instead;)j(only)f(use)g(this)h(if)208 1971 y(you)d(are)h(sure)g(you)
f(need)h(it.)208 2104 y(Changed)e(in)j(v)o(ersion)e(2.3:)g(Older)h(v)o
(ersions)f(of)h(Python)f(did)h(not)g(support)f Fj(NULL)h
Fr(as)h(the)f(v)n(alue)f(for)h(the)g Fo(methods)g Fr(ar)o(gument.)0
2250 y Fj(PyObject)48 b Fg(_Py_NoneStruct)208 2350 y
Fr(Object)25 b(which)f(is)j(visible)e(in)g(Python)g(as)h
Fj(None)p Fr(.)40 b(This)25 b(should)f(only)h(be)g(accessed)g(using)g
(the)g Fj(Py_None)g Fr(macro,)g(which)208 2450 y(e)n(v)n(aluates)19
b(to)h(a)h(pointer)e(to)h(this)h(object.)0 2777 y Fl(10.2)121
b(Common)34 b(Object)g(Str)r(uctures)0 3010 y Fr(There)d(are)g(a)h(lar)
o(ge)e(number)g(of)h(structures)g(which)f(are)i(used)f(in)g(the)h
(de\002nition)e(of)h(object)g(types)g(for)g(Python.)57
b(This)32 b(section)0 3110 y(describes)20 b(these)g(structures)g(and)f
(ho)n(w)h(the)o(y)f(are)h(used.)0 3256 y(All)f(Python)f(objects)g
(ultimately)g(share)g(a)h(small)g(number)e(of)h(\002elds)h(at)g(the)g
(be)o(ginning)d(of)i(the)g(object')-5 b(s)19 b(representation)d(in)j
(memory)-5 b(.)0 3356 y(These)20 b(are)h(represented)e(by)h(the)h
Fj(PyObject)f Fr(and)g Fj(PyVarObject)f Fr(types,)h(which)g(are)h
(de\002ned,)e(in)i(turn,)f(by)g(the)h(e)o(xpansions)e(of)0
3456 y(some)h(macros)g(also)g(used,)g(whether)f(directly)g(or)h
(indirectly)-5 b(,)19 b(in)h(the)g(de\002nition)f(of)h(all)h(other)e
(Python)g(objects.)0 3603 y Fg(PyObject)208 3702 y Fr(All)i(object)f
(types)h(are)g(e)o(xtensions)e(of)i(this)g(type.)27 b(This)21
b(is)g(a)g(type)g(which)f(contains)g(the)h(information)d(Python)i
(needs)h(to)f(treat)208 3802 y(a)28 b(pointer)f(to)h(an)g(object)g(as)h
(an)f(object.)48 b(In)28 b(a)g(normal)f(\223release\224)h(b)n(uild,)i
(it)e(contains)g(only)f(the)h(objects)g(reference)f(count)208
3901 y(and)h(a)i(pointer)e(to)h(the)h(corresponding)c(type)i(object.)52
b(It)29 b(corresponds)e(to)j(the)f(\002elds)h(de\002ned)e(by)h(the)g(e)
o(xpansion)f(of)h(the)208 4001 y Fj(PyObject_HEAD)18
b Fr(macro.)0 4148 y Fg(PyVarObject)208 4248 y Fr(This)k(is)h(an)f(e)o
(xtension)f(of)h Fj(PyObject)g Fr(that)g(adds)g(the)g
Fj(ob_size)g Fr(\002eld.)31 b(This)22 b(is)i(only)d(used)h(for)g
(objects)g(that)g(ha)n(v)o(e)g(some)208 4347 y(notion)g(of)i
Fo(length)p Fr(.)36 b(This)25 b(type)e(does)h(not)g(often)f(appear)g
(in)i(the)f(Python/C)f(API.)h(It)h(corresponds)d(to)i(the)g(\002elds)h
(de\002ned)e(by)208 4447 y(the)d(e)o(xpansion)e(of)i(the)g
Fj(PyObject_VAR_HEAD)e Fr(macro.)0 4594 y(These)i(macros)g(are)g(used)g
(in)g(the)g(de\002nition)f(of)h Fj(PyObject)f Fr(and)h
Fj(PyVarObject)p Fr(:)0 4741 y Fg(PyObject_HEAD)208 4840
y Fr(This)e(is)h(a)g(macro)e(which)h(e)o(xpands)e(to)j(the)f
(declarations)f(of)h(the)g(\002elds)h(of)e(the)i Fj(PyObject)e
Fr(type;)h(it)h(is)h(used)d(when)h(declaring)208 4940
y(ne)n(w)27 b(types)g(which)h(represent)e(objects)i(without)e(a)j(v)n
(arying)c(length.)47 b(The)27 b(speci\002c)h(\002elds)g(it)g(e)o
(xpands)f(to)g(depend)f(on)i(the)208 5039 y(de\002nition)19
b(of)h Fj(Py_TRACE_REFS)p Fr(.)e(By)i(def)o(ault,)f(that)i(macro)e(is)i
(not)f(de\002ned,)f(and)h Fj(PyObject_HEAD)e Fr(e)o(xpands)g(to:)p
0 5549 3901 4 v 0 5649 a Fn(98)2152 b(Chapter)23 b(10.)52
b(Object)23 b(Implementation)j(Suppor)s(t)p eop end
%%Page: 99 105
TeXDict begin 99 104 bop 623 174 a Fk(Py_ssize_t)43 b(ob_refcnt;)623
266 y(PyTypeObject)1206 279 y(*)1251 266 y(ob_type;)208
513 y Fr(When)20 b Fj(Py_TRACE_REFS)e Fr(is)j(de\002ned,)e(it)i(e)o
(xpands)d(to:)623 730 y Fk(PyObject)1027 743 y(*)1072
730 y(_ob_next,)1520 743 y(*)1565 730 y(_ob_prev;)623
821 y(Py_ssize_t)43 b(ob_refcnt;)623 913 y(PyTypeObject)1206
926 y(*)1251 913 y(ob_type;)0 1205 y Fg(PyObject_VAR_HEAD)208
1305 y Fr(This)27 b(is)i(a)e(macro)g(which)g(e)o(xpands)f(to)h(the)h
(declarations)e(of)h(the)g(\002elds)h(of)f(the)h Fj(PyVarObject)e
Fr(type;)k(it)f(is)f(used)f(when)208 1405 y(declaring)f(ne)n(w)h(types)
h(which)f(represent)f(objects)i(with)f(a)h(length)f(that)h(v)n(aries)f
(from)g(instance)g(to)h(instance.)47 b(This)28 b(macro)208
1504 y(al)o(w)o(ays)20 b(e)o(xpands)f(to:)623 1721 y
Fk(PyObject_HEAD)623 1812 y(Py_ssize_t)43 b(ob_size;)208
2060 y Fr(Note)31 b(that)h Fj(PyObject_HEAD)e Fr(is)j(part)f(of)f(the)h
(e)o(xpansion,)h(and)e(that)h(its)h(o)n(wn)e(e)o(xpansion)f(v)n(aries)i
(depending)d(on)j(the)208 2160 y(de\002nition)19 b(of)h
Fj(Py_TRACE_REFS)p Fr(.)0 2306 y(PyObject)p 315 2306
25 4 v 29 w(HEAD)p 575 2306 V 29 w(INIT)0 2453 y Fg(PyCFunction)208
2553 y Fr(T)-7 b(ype)41 b(of)h(the)h(functions)d(used)i(to)h(implement)
e(most)h(Python)f(callables)i(in)f(C.)h(Functions)e(of)h(this)h(type)f
(tak)o(e)g(tw)o(o)208 2653 y Fj(PyObject)608 2668 y(*)680
2653 y Fr(parameters)22 b(and)g(return)g(one)h(such)g(v)n(alue.)34
b(If)23 b(the)g(return)f(v)n(alue)g(is)j Fj(NULL)p Fr(,)d(an)i(e)o
(xception)d(shall)j(ha)n(v)o(e)e(been)208 2752 y(set.)37
b(If)24 b(not)g Fj(NULL)p Fr(,)g(the)g(return)f(v)n(alue)h(is)h
(interpreted)e(as)i(the)f(return)f(v)n(alue)g(of)h(the)h(function)d(as)
j(e)o(xposed)e(in)h(Python.)36 b(The)208 2852 y(function)18
b(must)i(return)f(a)i(ne)n(w)f(reference.)0 2999 y Fg(PyMethodDef)208
3098 y Fr(Structure)f(used)h(to)g(describe)f(a)i(method)e(of)h(an)g(e)o
(xtension)f(type.)24 b(This)c(structure)g(has)g(four)f(\002elds:)642
3220 y Fp(Field)p 1089 3250 4 100 v 318 w(C)i(T)-6 b(ype)p
1627 3250 V 283 w(Meaning)p 592 3253 2924 4 v 642 3323
a Fj(ml_name)p 1089 3353 4 100 v 148 w Fr(char)20 b(*)p
1627 3353 V 332 w(name)g(of)g(the)g(method)642 3423 y
Fj(ml_meth)p 1089 3452 V 148 w Fr(PyCFunction)p 1627
3452 V 98 w(pointer)f(to)h(the)h(C)g(implementation)642
3522 y Fj(ml_flags)p 1089 3552 V 98 w Fr(int)p 1627 3552
V 450 w(\003ag)f(bits)h(indicating)e(ho)n(w)h(the)g(call)g(should)g(be)
g(constructed)642 3622 y Fj(ml_doc)p 1089 3652 V 198
w Fr(char)g(*)p 1627 3652 V 332 w(points)g(to)g(the)g(contents)g(of)g
(the)g(docstring)0 3764 y(The)h Fj(ml_meth)f Fr(is)i(a)f(C)h(function)e
(pointer)-5 b(.)26 b(The)21 b(functions)f(may)g(be)h(of)g(dif)n(ferent)
e(types,)i(b)n(ut)g(the)o(y)g(al)o(w)o(ays)g(return)f
Fj(PyObject)3831 3779 y(*)3881 3764 y Fr(.)0 3863 y(If)31
b(the)h(function)e(is)i(not)g(of)f(the)h Fj(PyCFunction)p
Fr(,)g(the)g(compiler)e(will)j(require)d(a)i(cast)g(in)g(the)g(method)e
(table.)59 b(Ev)o(en)30 b(though)0 3963 y Fj(PyCFunction)20
b Fr(de\002nes)g(the)i(\002rst)f(parameter)f(as)i Fj(PyObject)1945
3978 y(*)1995 3963 y Fr(,)e(it)h(is)h(common)e(that)h(the)g(method)f
(implementation)e(uses)k(a)g(the)0 4063 y(speci\002c)e(C)i(type)d(of)h
(the)g Fo(self)34 b Fr(object.)0 4210 y(The)21 b Fj(ml_flags)f
Fr(\002eld)i(is)g(a)f(bit\002eld)h(which)e(can)h(include)g(the)g(follo)
n(wing)e(\003ags.)29 b(The)21 b(indi)n(vidual)e(\003ags)j(indicate)f
(either)f(a)i(calling)0 4309 y(con)m(v)o(ention)e(or)j(a)h(binding)d
(con)m(v)o(ention.)31 b(Of)24 b(the)f(calling)g(con)m(v)o(ention)d
(\003ags,)k(only)e Fj(METH_VARARGS)g Fr(and)g Fj(METH_KEYWORDS)0
4409 y Fr(can)g(be)g(combined)d(\(b)n(ut)j(note)f(that)h
Fj(METH_KEYWORDS)e Fr(alone)i(is)h(equi)n(v)n(alent)d(to)i
Fj(METH_VARARGS)47 b(|)j(METH_KEYWORDS)p Fr(\).)0 4509
y(An)o(y)19 b(of)h(the)h(calling)e(con)m(v)o(ention)e(\003ags)k(can)f
(be)g(combined)e(with)j(a)f(binding)f(\003ag.)0 4655
y Fg(METH_VARARGS)208 4755 y Fr(This)j(is)g(the)g(typical)g(calling)f
(con)m(v)o(ention,)e(where)i(the)h(methods)f(ha)n(v)o(e)g(the)h(type)f
Fj(PyCFunction)p Fr(.)29 b(The)21 b(function)f(e)o(xpects)208
4855 y(tw)o(o)26 b Fj(PyObject)758 4870 y(*)834 4855
y Fr(v)n(alues.)44 b(The)26 b(\002rst)h(one)f(is)i(the)e
Fo(self)40 b Fr(object)26 b(for)g(methods;)j(for)d(module)f(functions,)
i(it)g(has)g(the)f(v)n(alue)208 4954 y(gi)n(v)o(en)e(to)j
Fj(Py_InitModule4\(\))c Fr(\(or)j Fj(NULL)g Fr(if)g Fj
(Py_InitModule\(\))e Fr(w)o(as)j(used\).)42 b(The)26
b(second)f(parameter)g(\(often)208 5054 y(called)20 b
Fo(ar)m(gs)p Fr(\))g(is)h(a)g(tuple)f(object)g(representing)f(all)i(ar)
o(guments.)i(This)e(parameter)e(is)i(typically)f(processed)f(using)h
Fj(PyArg_-)208 5154 y(ParseTuple\(\))e Fr(or)i Fj(PyArg_UnpackTuple)p
Fr(.)0 5300 y Fg(METH_KEYWORDS)208 5400 y Fr(Methods)d(with)i(these)g
(\003ags)f(must)h(be)f(of)h(type)f Fj(PyCFunctionWithKeywords)p
Fr(.)i(The)e(function)f(e)o(xpects)h(three)g(param-)p
0 5549 3901 4 v 0 5649 a Fn(10.2.)52 b(Common)24 b(Object)f(Str)q
(uctures)2569 b(99)p eop end
%%Page: 100 106
TeXDict begin 100 105 bop 208 83 a Fr(eters:)31 b Fo(self)12
b Fr(,)25 b Fo(ar)m(gs)p Fr(,)f(and)f(a)g(dictionary)f(of)h(all)h(the)f
(k)o(e)o(yw)o(ord)e(ar)o(guments.)32 b(The)23 b(\003ag)h(is)g
(typically)e(combined)g(with)h Fj(METH_-)208 183 y(VARARGS)p
Fr(,)c(and)g(the)i(parameters)e(are)h(typically)f(processed)g(using)h
Fj(PyArg_ParseTupleAndKeywords\(\))p Fr(.)0 330 y Fg(METH_NOARGS)208
429 y Fr(Methods)15 b(without)g(parameters)f(don')o(t)h(need)g(to)h
(check)f(whether)g(ar)o(guments)e(are)j(gi)n(v)o(en)f(if)h(the)o(y)f
(are)h(listed)g(with)g(the)g Fj(METH_-)208 529 y(NOARGS)k
Fr(\003ag.)27 b(The)o(y)20 b(need)g(to)h(be)g(of)f(type)h
Fj(PyCFunction)p Fr(.)k(When)c(used)g(with)g(object)f(methods,)g(the)h
(\002rst)g(parameter)f(is)208 628 y(typically)e(named)g
Fj(self)h Fr(and)f(will)i(hold)e(a)i(reference)d(to)i(the)g(object)g
(instance.)24 b(In)19 b(all)g(cases)h(the)f(second)f(parameter)g(will)i
(be)208 728 y Fj(NULL)p Fr(.)0 875 y Fg(METH_O)208 975
y Fr(Methods)29 b(with)h(a)h(single)f(object)f(ar)o(gument)f(can)i(be)g
(listed)h(with)f(the)g Fj(METH_O)g Fr(\003ag,)j(instead)c(of)h(in)m(v)n
(oking)e Fj(PyArg_-)208 1074 y(ParseTuple\(\))23 b Fr(with)j(a)g
Fj("O")f Fr(ar)o(gument.)39 b(The)o(y)24 b(ha)n(v)o(e)h(the)h(type)f
Fj(PyCFunction)p Fr(,)g(with)g(the)h Fo(self)38 b Fr(parameter)m(,)25
b(and)g(a)208 1174 y Fj(PyObject)608 1189 y(*)677 1174
y Fr(parameter)18 b(representing)g(the)j(single)f(ar)o(gument.)0
1321 y Fg(METH_OLDARGS)208 1420 y Fr(This)k(calling)f(con)m(v)o(ention)
e(is)k(deprecated.)34 b(The)24 b(method)f(must)h(be)f(of)h(type)g
Fj(PyCFunction)p Fr(.)34 b(The)24 b(second)f(ar)o(gument)f(is)208
1520 y Fj(NULL)e Fr(if)h(no)f(ar)o(guments)f(are)i(gi)n(v)o(en,)e(a)i
(single)g(object)f(if)h(e)o(xactly)f(one)g(ar)o(gument)e(is)k(gi)n(v)o
(en,)d(and)h(a)h(tuple)g(of)f(objects)g(if)h(more)208
1620 y(than)h(one)g(ar)o(gument)f(is)i(gi)n(v)o(en.)32
b(There)22 b(is)h(no)g(w)o(ay)g(for)f(a)h(function)e(using)h(this)h
(con)m(v)o(ention)d(to)j(distinguish)f(between)g(a)h(call)208
1719 y(with)d(multiple)f(ar)o(guments)g(and)g(a)i(call)f(with)h(a)f
(tuple)g(as)h(the)f(only)g(ar)o(gument.)0 1866 y(These)g(tw)o(o)g
(constants)g(are)g(not)f(used)h(to)g(indicate)g(the)g(calling)f(con)m
(v)o(ention)e(b)n(ut)j(the)g(binding)e(when)i(use)g(with)g(methods)f
(of)h(classes.)0 1966 y(These)f(may)f(not)g(be)h(used)g(for)f
(functions)f(de\002ned)h(for)g(modules.)24 b(At)19 b(most)g(one)f(of)h
(these)g(\003ags)g(may)f(be)h(set)g(for)g(an)o(y)f(gi)n(v)o(en)f
(method.)0 2113 y Fg(METH_CLASS)208 2212 y Fr(The)i(method)f(will)j(be)
e(passed)h(the)f(type)h(object)f(as)h(the)g(\002rst)g(parameter)e
(rather)h(than)g(an)h(instance)f(of)g(the)h(type.)k(This)c(is)h(used)
208 2312 y(to)e(create)g Fo(class)g(methods)p Fr(,)g(similar)g(to)g
(what)g(is)h(created)f(when)f(using)h(the)g Fj(classmethod\(\))e
Fr(b)n(uilt-in)i(function.)48 b(Ne)n(w)19 b(in)208 2411
y(v)o(ersion)f(2.3.)0 2558 y Fg(METH_STATIC)208 2658
y Fr(The)g(method)g(will)h(be)g(passed)g Fj(NULL)g Fr(as)g(the)g
(\002rst)h(parameter)d(rather)i(than)f(an)h(instance)f(of)h(the)g
(type.)24 b(This)19 b(is)h(used)f(to)g(create)208 2758
y Fo(static)e(methods)p Fr(,)g(similar)h(to)g(what)f(is)h(created)f
(when)g(using)g(the)g Fj(staticmethod\(\))f Fr(b)n(uilt-in)g(function.)
48 b(Ne)n(w)17 b(in)h(v)o(ersion)208 2857 y(2.3.)0 3004
y(One)i(other)f(constant)h(controls)f(whether)g(a)i(method)e(is)i
(loaded)e(in)h(place)g(of)g(another)f(de\002nition)g(with)h(the)h(same)
f(method)f(name.)0 3151 y Fg(METH_COEXIST)208 3251 y
Fr(The)27 b(method)f(will)i(be)g(loaded)e(in)i(place)f(of)h(e)o
(xisting)e(de\002nitions.)47 b(W)m(ithout)27 b Fo(METH)p
2786 3251 25 4 v 30 w(COEXIST)6 b Fr(,)27 b(the)h(def)o(ault)e(is)j(to)
f(skip)208 3350 y(repeated)f(de\002nitions.)50 b(Since)29
b(slot)g(wrappers)e(are)i(loaded)f(before)f(the)i(method)e(table,)k
(the)d(e)o(xistence)g(of)h(a)g Fo(sq)p 3594 3350 V 30
w(contains)208 3450 y Fr(slot,)c(for)f(e)o(xample,)g(w)o(ould)f
(generate)g(a)i(wrapped)e(method)g(named)g Fj(__contains__\(\))f
Fr(and)i(preclude)f(the)h(loading)f(of)208 3549 y(a)j(corresponding)c
(PyCFunction)i(with)i(the)f(same)h(name.)40 b(W)m(ith)26
b(the)g(\003ag)g(de\002ned,)f(the)h(PyCFunction)e(will)i(be)g(loaded)e
(in)208 3649 y(place)h(of)g(the)g(wrapper)f(object)h(and)g(will)h(co-e)
o(xist)e(with)i(the)f(slot.)41 b(This)26 b(is)g(helpful)e(because)h
(calls)h(to)f(PyCFunctions)g(are)208 3749 y(optimized)18
b(more)i(than)f(wrapper)g(object)h(calls.)51 b(Ne)n(w)21
b(in)f(v)o(ersion)f(2.4.)0 3896 y Fj(PyObject)400 3911
y(*)498 3896 y Fg(Py_FindMethod)p Fj(\()p Fo(PyMethodDef)d(table[],)21
b(PyObject)e(*ob,)g(c)o(har)h(*name)p Fj(\))208 3995
y Fo(Return)f(value:)25 b Ff(New)20 b(ref)o(erence)p
Fo(.)208 4095 y Fr(Return)i(a)i(bound)e(method)g(object)h(for)f(an)i(e)
o(xtension)e(type)g(implemented)g(in)h(C.)i(This)e(can)g(be)h(useful)e
(in)i(the)f(implementa-)208 4194 y(tion)d(of)g(a)h Fj(tp_getattro)e
Fr(or)h Fj(tp_getattr)f Fr(handler)g(that)i(does)f(not)g(use)h(the)g
Fj(PyObject_GenericGetAttr\(\))208 4294 y Fr(function.)0
4621 y Fl(10.3)121 b(T)-14 b(ype)34 b(Objects)0 4854
y Fr(Perhaps)28 b(one)g(of)g(the)h(most)g(important)e(structures)h(of)g
(the)g(Python)g(object)g(system)h(is)g(the)g(structure)f(that)g
(de\002nes)h(a)g(ne)n(w)f(type:)0 4954 y(the)f Fj(PyTypeObject)e
Fr(structure.)43 b(T)-7 b(ype)26 b(objects)h(can)f(be)h(handled)e
(using)h(an)o(y)g(of)h(the)f Fj(PyObject_)3130 4969 y(*)3180
4954 y(\(\))f Fr(or)i Fj(PyType_)3752 4969 y(*)3802 4954
y(\(\))0 5054 y Fr(functions,)19 b(b)n(ut)h(do)h(not)f(of)n(fer)f(much)
h(that')-5 b(s)21 b(interesting)e(to)i(most)f(Python)g(applications.)k
(These)d(objects)f(are)g(fundamental)e(to)j(ho)n(w)0
5153 y(objects)i(beha)n(v)o(e,)g(so)g(the)o(y)g(are)g(v)o(ery)f
(important)g(to)i(the)f(interpreter)f(itself)h(and)g(to)h(an)o(y)e(e)o
(xtension)g(module)g(that)h(implements)g(ne)n(w)0 5253
y(types.)0 5400 y(T)-7 b(ype)22 b(objects)h(are)g(f)o(airly)f(lar)o(ge)
g(compared)f(to)i(most)g(of)g(the)g(standard)f(types.)33
b(The)22 b(reason)g(for)h(the)g(size)g(is)h(that)f(each)g(type)f
(object)p 0 5549 3901 4 v 0 5649 a Fn(100)2106 b(Chapter)23
b(10.)52 b(Object)23 b(Implementation)j(Suppor)s(t)p
eop end
%%Page: 101 107
TeXDict begin 101 106 bop 0 83 a Fr(stores)30 b(a)g(lar)o(ge)f(number)e
(of)j(v)n(alues,)h(mostly)e(C)i(function)d(pointers,)j(each)e(of)g
(which)h(implements)e(a)i(small)g(part)g(of)f(the)h(type')-5
b(s)0 183 y(functionality)g(.)34 b(The)24 b(\002elds)h(of)f(the)g(type)
g(object)g(are)g(e)o(xamined)e(in)i(detail)h(in)f(this)h(section.)37
b(The)23 b(\002elds)i(will)g(be)f(described)f(in)i(the)0
282 y(order)19 b(in)h(which)g(the)o(y)f(occur)h(in)g(the)g(structure.)0
429 y(T)-7 b(ypedefs:)44 b(unaryfunc,)29 b(binaryfunc,)h(ternaryfunc,)f
(inquiry)-5 b(,)31 b(coercion,)f(intar)o(gfunc,)g(intintar)o(gfunc,)f
(intobjar)o(gproc,)g(intintob-)0 529 y(jar)o(gproc,)c(objobjar)o
(gproc,)d(destructor)m(,)k(freefunc,)f(printfunc,)g(getattrfunc,)g
(getattrofunc,)f(setattrfunc,)i(setattrofunc,)g(cmpfunc,)0
628 y(reprfunc,)18 b(hashfunc)0 775 y(The)25 b(structure)f
(de\002nition)f(for)i Fj(PyTypeObject)e Fr(can)i(be)g(found)e(in)i(`)p
Fs(Include/object.h)p Fr('.)35 b(F)o(or)24 b(con)m(v)o(enience)e(of)j
(reference,)f(this)0 875 y(repeats)c(the)g(de\002nition)f(found)g
(there:)236 1063 y Fk(typedef)44 b(struct)g(_typeobject)f({)416
1155 y(PyObject_VAR_HEAD)416 1246 y(char)640 1259 y(*)685
1246 y(tp_name;)g(/)1133 1259 y(*)1223 1246 y(For)h(printing,)f(in)i
(format)e("<module>.<name>")3105 1259 y(*)3150 1246 y(/)416
1337 y(int)h(tp_basicsize,)f(tp_itemsize;)f(/)1850 1350
y(*)1940 1337 y(For)i(allocation)2612 1350 y(*)2657 1337
y(/)416 1520 y(/)461 1533 y(*)550 1520 y(Methods)g(to)g(implement)g
(standard)f(operations)2388 1533 y(*)2433 1520 y(/)416
1703 y(destructor)g(tp_dealloc;)416 1794 y(printfunc)g(tp_print;)416
1885 y(getattrfunc)g(tp_getattr;)416 1977 y(setattrfunc)g(tp_setattr;)
416 2068 y(cmpfunc)g(tp_compare;)416 2159 y(reprfunc)g(tp_repr;)416
2342 y(/)461 2355 y(*)550 2342 y(Method)h(suites)g(for)g(standard)g
(classes)2119 2355 y(*)2164 2342 y(/)416 2524 y(PyNumberMethods)1133
2537 y(*)1178 2524 y(tp_as_number;)416 2616 y(PySequenceMethods)1223
2629 y(*)1268 2616 y(tp_as_sequence;)416 2707 y(PyMappingMethods)1178
2720 y(*)1223 2707 y(tp_as_mapping;)416 2890 y(/)461
2903 y(*)550 2890 y(More)g(standard)g(operations)f(\(here)h(for)g
(binary)g(compatibility\))3105 2903 y(*)3150 2890 y(/)416
3072 y(hashfunc)f(tp_hash;)416 3164 y(ternaryfunc)g(tp_call;)416
3255 y(reprfunc)g(tp_str;)416 3346 y(getattrofunc)f(tp_getattro;)416
3438 y(setattrofunc)g(tp_setattro;)416 3620 y(/)461 3633
y(*)550 3620 y(Functions)h(to)i(access)f(object)g(as)g(input/output)f
(buffer)2792 3633 y(*)2837 3620 y(/)416 3712 y(PyBufferProcs)1043
3725 y(*)1088 3712 y(tp_as_buffer;)416 3894 y(/)461 3907
y(*)550 3894 y(Flags)h(to)h(define)e(presence)h(of)g(optional/expanded)
e(features)3016 3907 y(*)3061 3894 y(/)416 3986 y(long)i(tp_flags;)416
4168 y(char)640 4181 y(*)685 4168 y(tp_doc;)f(/)1088
4181 y(*)1178 4168 y(Documentation)f(string)2119 4181
y(*)2164 4168 y(/)416 4351 y(/)461 4364 y(*)550 4351
y(Assigned)i(meaning)f(in)i(release)e(2.0)1985 4364 y(*)2030
4351 y(/)416 4442 y(/)461 4455 y(*)550 4442 y(call)h(function)g(for)g
(all)g(accessible)f(objects)2388 4455 y(*)2433 4442 y(/)416
4534 y(traverseproc)f(tp_traverse;)416 4716 y(/)461 4729
y(*)550 4716 y(delete)i(references)f(to)i(contained)e(objects)2298
4729 y(*)2343 4716 y(/)416 4808 y(inquiry)g(tp_clear;)416
4990 y(/)461 5003 y(*)550 4990 y(Assigned)h(meaning)f(in)i(release)e
(2.1)1985 5003 y(*)2030 4990 y(/)416 5082 y(/)461 5095
y(*)550 5082 y(rich)h(comparisons)1312 5095 y(*)1357
5082 y(/)416 5173 y(richcmpfunc)f(tp_richcompare;)416
5356 y(/)461 5369 y(*)550 5356 y(weak)h(reference)g(enabler)1581
5369 y(*)1626 5356 y(/)p 0 5549 3901 4 v 0 5649 a Fn(10.3.)52
b(T)-10 b(ype)23 b(Objects)3046 b(101)p eop end
%%Page: 102 108
TeXDict begin 102 107 bop 416 83 a Fk(long)44 b(tp_weaklistoffset;)416
266 y(/)461 279 y(*)550 266 y(Added)g(in)h(release)e(2.2)1492
279 y(*)1537 266 y(/)416 357 y(/)461 370 y(*)550 357
y(Iterators)998 370 y(*)1043 357 y(/)416 448 y(getiterfunc)g(tp_iter;)
416 540 y(iternextfunc)f(tp_iternext;)416 722 y(/)461
735 y(*)550 722 y(Attribute)h(descriptor)h(and)g(subclassing)f(stuff)
2478 735 y(*)2523 722 y(/)416 814 y(struct)g(PyMethodDef)1267
827 y(*)1312 814 y(tp_methods;)416 905 y(struct)g(PyMemberDef)1267
918 y(*)1312 905 y(tp_members;)416 996 y(struct)g(PyGetSetDef)1267
1009 y(*)1312 996 y(tp_getset;)416 1088 y(struct)g(_typeobject)1267
1101 y(*)1312 1088 y(tp_base;)416 1179 y(PyObject)819
1192 y(*)864 1179 y(tp_dict;)416 1270 y(descrgetfunc)f(tp_descr_get;)
416 1362 y(descrsetfunc)g(tp_descr_set;)416 1453 y(long)i
(tp_dictoffset;)416 1544 y(initproc)f(tp_init;)416 1636
y(allocfunc)g(tp_alloc;)416 1727 y(newfunc)g(tp_new;)416
1818 y(freefunc)g(tp_free;)h(/)1268 1831 y(*)1357 1818
y(Low-level)f(free-memory)g(routine)2702 1831 y(*)2747
1818 y(/)416 1910 y(inquiry)g(tp_is_gc;)h(/)1268 1923
y(*)1357 1910 y(For)g(PyObject_IS_GC)2209 1923 y(*)2254
1910 y(/)416 2001 y(PyObject)819 2014 y(*)864 2001 y(tp_bases;)416
2092 y(PyObject)819 2105 y(*)864 2092 y(tp_mro;)g(/)1268
2105 y(*)1357 2092 y(method)g(resolution)f(order)2433
2105 y(*)2478 2092 y(/)416 2183 y(PyObject)819 2196 y(*)864
2183 y(tp_cache;)416 2275 y(PyObject)819 2288 y(*)864
2275 y(tp_subclasses;)416 2366 y(PyObject)819 2379 y(*)864
2366 y(tp_weaklist;)236 2549 y(})i(PyTypeObject;)0 2736
y Fr(The)15 b(type)g(object)g(structure)f(e)o(xtends)h(the)g
Fj(PyVarObject)f Fr(structure.)22 b(The)15 b Fj(ob_size)g
Fr(\002eld)g(is)i(used)e(for)g(dynamic)e(types)j(\(created)0
2835 y(by)21 b Fj(type_new\(\))p Fr(,)f(usually)h(called)h(from)e(a)i
(class)g(statement\).)29 b(Note)21 b(that)h Fj(PyType_Type)e
Fr(\(the)h(metatype\))f(initializes)i Fj(tp_-)0 2935
y(itemsize)p Fr(,)d(which)h(means)g(that)g(its)h(instances)f(\(i.e.)25
b(type)20 b(objects\))f Fo(must)i Fr(ha)n(v)o(e)e(the)i
Fj(ob_size)e Fr(\002eld.)0 3082 y Fj(PyObject)400 3097
y(*)498 3082 y Fg(_ob_next)0 3182 y Fj(PyObject)400 3197
y(*)498 3182 y Fg(_ob_prev)208 3281 y Fr(These)c(\002elds)i(are)e(only)
g(present)h(when)f(the)h(macro)f Fj(Py_TRACE_REFS)f Fr(is)j(de\002ned.)
22 b(Their)15 b(initialization)g(to)i Fj(NULL)e Fr(is)i(tak)o(en)208
3381 y(care)28 b(of)f(by)h(the)g Fj(PyObject_HEAD_INIT)e
Fr(macro.)48 b(F)o(or)27 b(statically)i(allocated)e(objects,)j(these)e
(\002elds)h(al)o(w)o(ays)f(remain)208 3480 y Fj(NULL)p
Fr(.)19 b(F)o(or)g(dynamically)f(allocated)h(objects,)g(these)h(tw)o(o)
g(\002elds)g(are)g(used)f(to)h(link)f(the)h(object)f(into)h(a)g
(doubly-link)o(ed)c(list)21 b(of)208 3580 y Fo(all)d
Fr(li)n(v)o(e)g(objects)g(on)g(the)g(heap.)23 b(This)c(could)e(be)h
(used)g(for)f(v)n(arious)g(deb)n(ugging)f(purposes;)h(currently)g(the)h
(only)f(use)i(is)g(to)f(print)208 3680 y(the)i(objects)g(that)g(are)g
(still)h(ali)n(v)o(e)f(at)h(the)f(end)g(of)g(a)g(run)g(when)f(the)i(en)
m(vironment)c(v)n(ariable)i(PYTHONDUMPREFS)h(is)i(set.)208
3809 y(These)e(\002elds)g(are)g(not)g(inherited)f(by)h(subtypes.)0
3956 y Fj(Py_ssize_t)48 b Fg(ob_refcnt)208 4056 y Fr(This)20
b(is)h(the)f(type)f(object')-5 b(s)20 b(reference)e(count,)h
(initialized)h(to)g Fj(1)g Fr(by)g(the)g Fj(PyObject_HEAD_INIT)d
Fr(macro.)24 b(Note)c(that)g(for)208 4155 y(statically)j(allocated)g
(type)f(objects,)i(the)f(type')-5 b(s)23 b(instances)g(\(objects)g
(whose)g Fj(ob_type)f Fr(points)h(back)f(to)i(the)f(type\))f(do)h
Fo(not)208 4255 y Fr(count)c(as)i(references.)i(But)e(for)f
(dynamically)e(allocated)h(type)h(objects,)g(the)g(instances)g
Fo(do)g Fr(count)f(as)i(references.)208 4385 y(This)f(\002eld)g(is)h
(not)f(inherited)f(by)h(subtypes.)0 4531 y Fj(PyTypeObject)600
4546 y(*)697 4531 y Fg(ob_type)208 4631 y Fr(This)e(is)g(the)g(type')-5
b(s)18 b(type,)f(in)h(other)f(w)o(ords)h(its)g(metatype.)23
b(It)18 b(is)h(initialized)f(by)f(the)h(ar)o(gument)d(to)j(the)g
Fj(PyObject_HEAD_-)208 4731 y(INIT)f Fr(macro,)h(and)f(its)i(v)n(alue)f
(should)f(normally)f(be)i Fj(&PyType_Type)p Fr(.)k(Ho)n(we)n(v)o(er)m
(,)17 b(for)g(dynamically)f(loadable)h(e)o(xtension)208
4830 y(modules)24 b(that)i(must)f(be)h(usable)f(on)g(W)m(indo)n(ws)g
(\(at)h(least\),)h(the)e(compiler)g(complains)f(that)i(this)g(is)g(not)
g(a)g(v)n(alid)f(initializer)-5 b(.)208 4930 y(Therefore,)25
b(the)h(con)m(v)o(ention)d(is)28 b(to)e(pass)h Fj(NULL)f
Fr(to)g(the)g Fj(PyObject_HEAD_INIT)e Fr(macro)h(and)h(to)g(initialize)
h(this)f(\002eld)208 5030 y(e)o(xplicitly)c(at)h(the)g(start)h(of)e
(the)h(module')-5 b(s)22 b(initialization)h(function,)e(before)h(doing)
g(an)o(ything)e(else.)34 b(This)24 b(is)f(typically)g(done)208
5129 y(lik)o(e)d(this:)444 5350 y Fk(Foo_Type.ob_type)42
b(=)j(&PyType_Type;)p 0 5549 3901 4 v 0 5649 a Fn(102)2106
b(Chapter)23 b(10.)52 b(Object)23 b(Implementation)j(Suppor)s(t)p
eop end
%%Page: 103 109
TeXDict begin 103 108 bop 208 83 a Fr(This)28 b(should)f(be)h(done)f
(before)g(an)o(y)g(instances)h(of)g(the)g(type)f(are)h(created.)48
b Fj(PyType_Ready\(\))26 b Fr(checks)i(if)g Fj(ob_type)208
183 y Fr(is)h Fj(NULL)p Fr(,)e(and)h(if)g(so,)i(initializes)f(it:)41
b(in)28 b(Python)f(2.2,)i(it)g(is)g(set)g(to)f Fj(&PyType_Type)p
Fr(;)j(in)d(Python)f(2.2.1)f(and)i(later)g(it)h(is)208
282 y(initialized)23 b(to)i(the)f Fj(ob_type)f Fr(\002eld)i(of)e(the)i
(base)f(class.)38 b Fj(PyType_Ready\(\))22 b Fr(will)j(not)f(change)e
(this)j(\002eld)f(if)h(it)g(is)g(non-)208 382 y(zero.)208
515 y(In)19 b(Python)f(2.2,)h(this)h(\002eld)f(is)i(not)e(inherited)f
(by)h(subtypes.)24 b(In)19 b(2.2.1,)f(and)h(in)g(2.3)g(and)g(be)o
(yond,)e(it)j(is)h(inherited)d(by)h(subtypes.)0 662 y
Fj(Py_ssize_t)48 b Fg(ob_size)208 761 y Fr(F)o(or)23
b(statically)h(allocated)f(type)g(objects,)h(this)g(should)f(be)h
(initialized)f(to)h(zero.)35 b(F)o(or)23 b(dynamically)f(allocated)h
(type)g(objects,)208 861 y(this)d(\002eld)h(has)f(a)h(special)f
(internal)f(meaning.)208 994 y(This)h(\002eld)g(is)h(not)f(inherited)f
(by)h(subtypes.)0 1141 y Fj(char)200 1156 y(*)299 1141
y Fg(tp_name)208 1240 y Fr(Pointer)25 b(to)i(a)f(NUL-terminated)e
(string)i(containing)f(the)h(name)f(of)h(the)h(type.)42
b(F)o(or)26 b(types)g(that)g(are)h(accessible)f(as)h(module)208
1340 y(globals,)d(the)g(string)f(should)h(be)f(the)i(full)e(module)g
(name,)h(follo)n(wed)f(by)h(a)g(dot,)g(follo)n(wed)f(by)h(the)g(type)f
(name;)j(for)d(b)n(uilt-in)208 1439 y(types,)28 b(it)g(should)d(be)i
(just)h(the)f(type)f(name.)45 b(If)27 b(the)g(module)f(is)h(a)h
(submodule)d(of)h(a)i(package,)f(the)g(full)g(package)e(name)i(is)208
1539 y(part)20 b(of)h(the)h(full)f(module)f(name.)27
b(F)o(or)21 b(e)o(xample,)f(a)i(type)f(named)f Fj(T)i
Fr(de\002ned)e(in)h(module)f Fj(M)i Fr(in)f(subpackage)e
Fj(Q)j Fr(in)f(package)f Fj(P)208 1639 y Fr(should)f(ha)n(v)o(e)g(the)i
Fj(tp_name)e Fr(initializer)h Fj("P.Q.M.T")p Fr(.)208
1772 y(F)o(or)d(dynamically)g(allocated)g(type)h(objects,)g(this)g
(should)g(just)g(be)g(the)g(type)g(name,)g(and)f(the)i(module)d(name)i
(e)o(xplicitly)f(stored)208 1871 y(in)j(the)g(type)g(dict)g(as)h(the)f
(v)n(alue)g(for)f(k)o(e)o(y)h Fj('__module__')p Fr(.)208
2004 y(F)o(or)30 b(statically)g(allocated)g(type)g(objects,)j(the)d(tp)
p 1680 2004 25 4 v 30 w(name)g(\002eld)g(should)g(contain)f(a)i(dot.)55
b(Ev)o(erything)28 b(before)h(the)i(last)g(dot)208 2104
y(is)c(made)g(accessible)f(as)i(the)f Fj(__module__)e
Fr(attrib)n(ute,)j(and)e(e)n(v)o(erything)f(after)h(the)h(last)h(dot)e
(is)i(made)e(accessible)h(as)h(the)208 2203 y Fj(__name__)19
b Fr(attrib)n(ute.)208 2336 y(If)28 b(no)h(dot)g(is)h(present,)g(the)f
(entire)g Fj(tp_name)f Fr(\002eld)i(is)g(made)e(accessible)h(as)h(the)f
Fj(__name__)f Fr(attrib)n(ute,)j(and)d(the)i Fj(__-)208
2436 y(module__)20 b Fr(attrib)n(ute)g(is)i(unde\002ned)d(\(unless)i(e)
o(xplicitly)f(set)i(in)f(the)g(dictionary)-5 b(,)19 b(as)j(e)o
(xplained)d(abo)o(v)o(e\).)26 b(This)21 b(means)g(your)208
2535 y(type)e(will)i(be)f(impossible)g(to)g(pickle.)208
2668 y(This)g(\002eld)g(is)h(not)f(inherited)f(by)h(subtypes.)0
2815 y Fj(Py_ssize_t)48 b Fg(tp_basicsize)0 2915 y Fj(Py_ssize_t)g
Fg(tp_itemsize)208 3014 y Fr(These)20 b(\002elds)g(allo)n(w)g
(calculating)f(the)i(size)f(in)h(bytes)f(of)g(instances)g(of)g(the)g
(type.)208 3147 y(There)k(are)h(tw)o(o)h(kinds)f(of)g(types:)35
b(types)26 b(with)f(\002x)o(ed-length)e(instances)i(ha)n(v)o(e)g(a)h
(zero)f Fj(tp_itemsize)f Fr(\002eld,)i(types)f(with)208
3247 y(v)n(ariable-length)i(instances)k(ha)n(v)o(e)f(a)h(non-zero)e
Fj(tp_itemsize)g Fr(\002eld.)57 b(F)o(or)30 b(a)h(type)g(with)g(\002x)o
(ed-length)d(instances,)33 b(all)208 3346 y(instances)20
b(ha)n(v)o(e)f(the)h(same)h(size,)f(gi)n(v)o(en)f(in)i
Fj(tp_basicsize)p Fr(.)208 3479 y(F)o(or)29 b(a)h(type)f(with)g(v)n
(ariable-length)e(instances,)32 b(the)d(instances)h(must)f(ha)n(v)o(e)g
(an)h Fj(ob_size)e Fr(\002eld,)k(and)d(the)h(instance)f(size)208
3579 y(is)e Fj(tp_basicsize)e Fr(plus)h(N)h(times)g Fj(tp_itemsize)p
Fr(,)f(where)g(N)h(is)h(the)e(\223length\224)g(of)g(the)g(object.)44
b(The)26 b(v)n(alue)f(of)i(N)g(is)208 3678 y(typically)c(stored)h(in)h
(the)g(instance')-5 b(s)24 b Fj(ob_size)g Fr(\002eld.)39
b(There)24 b(are)g(e)o(xceptions:)33 b(for)24 b(e)o(xample,)g(long)g
(ints)h(use)g(a)g(ne)o(gati)n(v)o(e)208 3778 y Fj(ob_size)20
b Fr(to)g(indicate)h(a)g(ne)o(gati)n(v)o(e)d(number)m(,)h(and)h(N)h(is)
h Fj(abs\(ob_size\))d Fr(there.)26 b(Also,)21 b(the)g(presence)e(of)i
(an)f Fj(ob_size)208 3878 y Fr(\002eld)f(in)g(the)g(instance)g(layout)f
(doesn')o(t)g(mean)g(that)h(the)h(instance)e(structure)g(is)i(v)n
(ariable-length)d(\(for)h(e)o(xample,)f(the)j(structure)208
3977 y(for)f(the)h(list)i(type)d(has)i(\002x)o(ed-length)d(instances,)h
(yet)i(those)f(instances)g(ha)n(v)o(e)f(a)i(meaningful)d
Fj(ob_size)h Fr(\002eld\).)208 4110 y(The)24 b(basic)h(size)g(includes)
f(the)h(\002elds)g(in)g(the)g(instance)f(declared)g(by)g(the)h(macro)f
Fj(PyObject_HEAD)e Fr(or)j Fj(PyObject_-)208 4210 y(VAR_HEAD)k
Fr(\(whiche)n(v)o(er)f(is)j(used)f(to)g(declare)f(the)i(instance)e
(struct\))h(and)g(this)g(in)h(turn)e(includes)h(the)g
Fj(_ob_prev)f Fr(and)208 4309 y Fj(_ob_next)24 b Fr(\002elds)h(if)g
(the)o(y)f(are)h(present.)39 b(This)25 b(means)f(that)h(the)g(only)f
(correct)g(w)o(ay)h(to)g(get)g(an)g(initializer)g(for)f(the)h
Fj(tp_-)208 4409 y(basicsize)f Fr(is)i(to)f(use)h(the)f
Fj(sizeof)g Fr(operator)e(on)i(the)h(struct)f(used)g(to)g(declare)g
(the)g(instance)g(layout.)39 b(The)25 b(basic)h(size)208
4509 y(does)20 b(not)g(include)f(the)i(GC)g(header)e(size)i(\(this)g
(is)h(ne)n(w)e(in)g(Python)g(2.2;)g(in)g(2.1)g(and)g(2.0,)g(the)g(GC)h
(header)f(size)h(w)o(as)g(included)208 4608 y(in)f Fj(tp_basicsize)p
Fr(\).)208 4741 y(These)26 b(\002elds)h(are)f(inherited)f(separately)h
(by)g(subtypes.)43 b(If)27 b(the)f(base)h(type)f(has)g(a)h(non-zero)d
Fj(tp_itemsize)p Fr(,)j(it)g(is)g(gen-)208 4841 y(erally)g(not)g(safe)h
(to)f(set)i Fj(tp_itemsize)d Fr(to)i(a)g(dif)n(ferent)e(non-zero)f(v)n
(alue)i(in)g(a)h(subtype)f(\(though)e(this)j(depends)e(on)i(the)208
4940 y(implementation)18 b(of)h(the)i(base)f(type\).)208
5073 y(A)34 b(note)f(about)g(alignment:)50 b(if)34 b(the)g(v)n(ariable)
f(items)h(require)e(a)i(particular)e(alignment,)k(this)e(should)f(be)g
(tak)o(en)g(care)h(of)208 5173 y(by)k(the)g(v)n(alue)g(of)g
Fj(tp_basicsize)p Fr(.)78 b(Example:)61 b(suppose)37
b(a)i(type)f(implements)f(an)i(array)e(of)i Fj(double)p
Fr(.)79 b Fj(tp_-)208 5272 y(itemsize)22 b Fr(is)j Fj(sizeof\(double\))
p Fr(.)34 b(It)24 b(is)g(the)g(programmer')-5 b(s)21
b(responsibility)h(that)i Fj(tp_basicsize)e Fr(is)j(a)f(multiple)208
5372 y(of)19 b Fj(sizeof\(double\))g Fr(\(assuming)g(this)h(is)i(the)e
(alignment)f(requirement)e(for)j Fj(double)p Fr(\).)p
0 5549 3901 4 v 0 5649 a Fn(10.3.)52 b(T)-10 b(ype)23
b(Objects)3046 b(103)p eop end
%%Page: 104 110
TeXDict begin 104 109 bop 0 83 a Fj(destructor)48 b Fg(tp_dealloc)208
183 y Fr(A)23 b(pointer)f(to)h(the)g(instance)g(destructor)e(function.)
32 b(This)23 b(function)e(must)i(be)g(de\002ned)f(unless)h(the)g(type)g
(guarantees)e(that)j(its)208 282 y(instances)c(will)h(ne)n(v)o(er)d(be)
j(deallocated)d(\(as)j(is)g(the)f(case)h(for)e(the)i(singletons)e
Fj(None)h Fr(and)g Fj(Ellipsis)p Fr(\).)208 415 y(The)f(destructor)f
(function)g(is)j(called)f(by)f(the)h Fj(Py_DECREF\(\))e
Fr(and)h Fj(Py_XDECREF\(\))g Fr(macros)g(when)g(the)h(ne)n(w)f
(reference)208 515 y(count)24 b(is)j(zero.)41 b(At)26
b(this)g(point,)g(the)g(instance)f(is)i(still)g(in)f(e)o(xistence,)g(b)
n(ut)f(there)h(are)f(no)g(references)g(to)h(it.)42 b(The)25
b(destructor)208 614 y(function)i(should)h(free)g(all)i(references)e
(which)g(the)h(instance)g(o)n(wns,)h(free)f(all)g(memory)f(b)n(uf)n
(fers)g(o)n(wned)f(by)i(the)g(instance)208 714 y(\(using)15
b(the)i(freeing)f(function)f(corresponding)e(to)k(the)g(allocation)e
(function)g(used)i(to)g(allocate)f(the)h(b)n(uf)n(fer\),)f(and)g
(\002nally)g(\(as)i(its)208 814 y(last)j(action\))e(call)h(the)h(type')
-5 b(s)20 b Fj(tp_free)f Fr(function.)k(If)d(the)g(type)g(is)h(not)f
(subtypable)e(\(doesn')o(t)h(ha)n(v)o(e)g(the)h Fj(Py_TPFLAGS_-)208
913 y(BASETYPE)j Fr(\003ag)i(bit)g(set\),)g(it)h(is)f(permissible)f(to)
h(call)g(the)f(object)g(deallocator)f(directly)h(instead)g(of)g(via)h
Fj(tp_free)p Fr(.)37 b(The)208 1013 y(object)24 b(deallocator)e(should)
i(be)g(the)h(one)f(used)g(to)h(allocate)f(the)h(instance;)h(this)f(is)g
(normally)e Fj(PyObject_Del\(\))g Fr(if)i(the)208 1112
y(instance)d(w)o(as)i(allocated)e(using)g Fj(PyObject_New\(\))f
Fr(or)i Fj(PyObject_VarNew\(\))p Fr(,)d(or)j Fj(PyObject_GC_Del\(\))d
Fr(if)208 1212 y(the)g(instance)g(w)o(as)h(allocated)e(using)h
Fj(PyObject_GC_New\(\))d Fr(or)j Fj(PyObject_GC_VarNew\(\))p
Fr(.)208 1345 y(This)g(\002eld)g(is)h(inherited)e(by)h(subtypes.)0
1492 y Fj(printfunc)48 b Fg(tp_print)208 1591 y Fr(An)20
b(optional)f(pointer)g(to)h(the)g(instance)g(print)g(function.)208
1724 y(The)k(print)g(function)f(is)j(only)e(called)h(when)f(the)h
(instance)g(is)g(printed)f(to)h(a)g Fo(r)m(eal)h Fr(\002le;)h(when)e
(it)g(is)h(printed)e(to)h(a)g(pseudo-\002le)208 1824
y(\(lik)o(e)g(a)h Fj(StringIO)e Fr(instance\),)i(the)f(instance')-5
b(s)26 b Fj(tp_repr)e Fr(or)i Fj(tp_str)e Fr(function)g(is)i(called)g
(to)f(con)m(v)o(ert)f(it)i(to)f(a)h(string.)208 1924
y(These)19 b(are)g(also)g(called)g(when)g(the)g(type')-5
b(s)19 b Fj(tp_print)f Fr(\002eld)i(is)g Fj(NULL)p Fr(.)f(A)g(type)g
(should)f(ne)n(v)o(er)g(implement)g Fj(tp_print)g Fr(in)208
2023 y(a)i(w)o(ay)g(that)h(produces)d(dif)n(ferent)h(output)g(than)g
Fj(tp_repr)h Fr(or)g Fj(tp_str)f Fr(w)o(ould.)208 2156
y(The)f(print)g(function)f(is)i(called)g(with)g(the)f(same)h(signature)
f(as)h Fj(PyObject_Print\(\))p Fr(:)j Fj(int)49 b(tp_print\(PyObject)
208 2271 y(*)258 2256 y(self,)f(FILE)805 2271 y(*)855
2256 y(file,)h(int)g(flags\))p Fr(.)30 b(The)22 b Fo(self)35
b Fr(ar)o(gument)19 b(is)k(the)f(instance)g(to)g(be)g(printed.)29
b(The)22 b Fo(\002le)g Fr(ar)o(gument)208 2355 y(is)29
b(the)g(stdio)g(\002le)g(to)g(which)f(it)h(is)h(to)f(be)f(printed.)50
b(The)28 b Fo(\003a)o(gs)g Fr(ar)o(gument)f(is)i(composed)e(of)i
(\003ag)f(bits.)51 b(The)29 b(only)f(\003ag)g(bit)208
2455 y(currently)16 b(de\002ned)i(is)i Fj(Py_PRINT_RAW)p
Fr(.)c(When)j(the)f Fj(Py_PRINT_RAW)f Fr(\003ag)i(bit)g(is)g(set,)h
(the)e(instance)h(should)e(be)i(printed)208 2555 y(the)j(same)h(w)o(ay)
g(as)g Fj(tp_str)f Fr(w)o(ould)g(format)f(it;)k(when)d(the)h
Fj(Py_PRINT_RAW)e Fr(\003ag)h(bit)h(is)h(clear)m(,)e(the)h(instance)f
(should)g(be)208 2654 y(printed)c(the)i(same)g(w)o(as)g(as)h
Fj(tp_repr)d Fr(w)o(ould)h(format)g(it.)26 b(It)20 b(should)e(return)h
Fj(-1)h Fr(and)f(set)h(an)g(e)o(xception)e(condition)g(when)h(an)208
2754 y(error)g(occurred)f(during)g(the)j(comparison.)208
2887 y(It)i(is)h(possible)e(that)h(the)g Fj(tp_print)f
Fr(\002eld)i(will)f(be)g(deprecated.)31 b(In)23 b(an)o(y)f(case,)i(it)g
(is)g(recommended)c(not)i(to)h(de\002ne)g Fj(tp_-)208
2986 y(print)p Fr(,)c(b)n(ut)h(instead)g(to)h(rely)e(on)h
Fj(tp_repr)g Fr(and)f Fj(tp_str)h Fr(for)g(printing.)208
3119 y(This)g(\002eld)g(is)h(inherited)e(by)h(subtypes.)0
3266 y Fj(getattrfunc)48 b Fg(tp_getattr)208 3366 y Fr(An)20
b(optional)f(pointer)g(to)h(the)g(get-attrib)n(ute-string)e(function.)
208 3498 y(This)e(\002eld)f(is)i(deprecated.)22 b(When)15
b(it)i(is)g(de\002ned,)e(it)i(should)d(point)h(to)h(a)h(function)d
(that)i(acts)g(the)g(same)g(as)g(the)g Fj(tp_getattro)208
3598 y Fr(function,)k(b)n(ut)i(taking)f(a)i(C)g(string)f(instead)f(of)h
(a)h(Python)e(string)g(object)h(to)g(gi)n(v)o(e)f(the)h(attrib)n(ute)g
(name.)30 b(The)22 b(signature)f(is)i(the)208 3698 y(same)d(as)h(for)e
Fj(PyObject_GetAttrString\(\))p Fr(.)208 3830 y(This)25
b(\002eld)h(is)g(inherited)e(by)h(subtypes)f(together)g(with)i
Fj(tp_getattro)p Fr(:)34 b(a)25 b(subtype)g(inherits)g(both)f
Fj(tp_getattr)g Fr(and)208 3930 y Fj(tp_getattro)18 b
Fr(from)h(its)j(base)e(type)g(when)f(the)h(subtype')-5
b(s)20 b Fj(tp_getattr)f Fr(and)g Fj(tp_getattro)g Fr(are)h(both)g
Fj(NULL)p Fr(.)0 4077 y Fj(setattrfunc)48 b Fg(tp_setattr)208
4177 y Fr(An)20 b(optional)f(pointer)g(to)h(the)g(set-attrib)n
(ute-string)f(function.)208 4309 y(This)d(\002eld)f(is)i(deprecated.)22
b(When)15 b(it)i(is)g(de\002ned,)e(it)i(should)d(point)h(to)h(a)h
(function)d(that)i(acts)g(the)g(same)g(as)g(the)g Fj(tp_setattro)208
4409 y Fr(function,)k(b)n(ut)i(taking)f(a)i(C)g(string)f(instead)f(of)h
(a)h(Python)e(string)g(object)h(to)g(gi)n(v)o(e)f(the)h(attrib)n(ute)g
(name.)30 b(The)22 b(signature)f(is)i(the)208 4509 y(same)d(as)h(for)e
Fj(PyObject_SetAttrString\(\))p Fr(.)208 4642 y(This)25
b(\002eld)h(is)g(inherited)e(by)h(subtypes)f(together)g(with)i
Fj(tp_setattro)p Fr(:)34 b(a)25 b(subtype)g(inherits)g(both)f
Fj(tp_setattr)g Fr(and)208 4741 y Fj(tp_setattro)18 b
Fr(from)h(its)j(base)e(type)g(when)f(the)h(subtype')-5
b(s)20 b Fj(tp_setattr)f Fr(and)g Fj(tp_setattro)g Fr(are)h(both)g
Fj(NULL)p Fr(.)0 4888 y Fj(cmpfunc)49 b Fg(tp_compare)208
4988 y Fr(An)20 b(optional)f(pointer)g(to)h(the)g(three-w)o(ay)f
(comparison)f(function.)208 5120 y(The)24 b(signature)g(is)i(the)f
(same)g(as)g(for)f Fj(PyObject_Compare\(\))p Fr(.)37
b(The)24 b(function)f(should)h(return)g Fj(1)h Fr(if)g
Fo(self)38 b Fr(greater)24 b(than)208 5220 y Fo(other)r
Fr(,)17 b Fj(0)g Fr(if)g Fo(self)30 b Fr(is)18 b(equal)e(to)h
Fo(other)r Fr(,)g(and)f Fj(-1)i Fr(if)f Fo(self)30 b
Fr(less)18 b(than)e Fo(other)r Fr(.)24 b(It)17 b(should)f(return)f
Fj(-1)i Fr(and)g(set)h(an)e(e)o(xception)f(condition)208
5320 y(when)k(an)h(error)f(occurred)f(during)h(the)h(comparison.)p
0 5549 3901 4 v 0 5649 a Fn(104)2106 b(Chapter)23 b(10.)52
b(Object)23 b(Implementation)j(Suppor)s(t)p eop end
%%Page: 105 111
TeXDict begin 105 110 bop 208 83 a Fr(This)35 b(\002eld)h(is)g
(inherited)e(by)h(subtypes)g(together)f(with)h Fj(tp_richcompare)f
Fr(and)h Fj(tp_hash)p Fr(:)55 b(a)35 b(subtypes)g(inherits)208
183 y(all)c(three)g(of)f Fj(tp_compare)p Fr(,)j Fj(tp_richcompare)p
Fr(,)e(and)g Fj(tp_hash)f Fr(when)g(the)h(subtype')-5
b(s)31 b Fj(tp_compare)p Fr(,)h Fj(tp_-)208 282 y(richcompare)p
Fr(,)18 b(and)i Fj(tp_hash)f Fr(are)h(all)h Fj(NULL)p
Fr(.)0 429 y Fj(reprfunc)48 b Fg(tp_repr)208 529 y Fr(An)20
b(optional)f(pointer)g(to)h(a)h(function)d(that)i(implements)g(the)g(b)
n(uilt-in)f(function)g Fj(repr\(\))p Fr(.)208 662 y(The)h(signature)f
(is)j(the)e(same)h(as)g(for)f Fj(PyObject_Repr\(\))p
Fr(;)f(it)i(must)g(return)e(a)i(string)g(or)f(a)h(Unicode)e(object.)26
b(Ideally)-5 b(,)19 b(this)208 761 y(function)k(should)h(return)g(a)h
(string)g(that,)h(when)f(passed)g(to)g Fj(eval\(\))p
Fr(,)h(gi)n(v)o(en)d(a)j(suitable)f(en)m(vironment,)e(returns)h(an)h
(object)208 861 y(with)c(the)h(same)g(v)n(alue.)29 b(If)21
b(this)h(is)h(not)e(feasible,)h(it)g(should)f(return)g(a)h(string)f
(starting)g(with)h(`)p Fb(<)p Fr(')f(and)g(ending)g(with)g(`)p
Fb(>)p Fr(')h(from)208 960 y(which)d(both)h(the)g(type)g(and)f(the)h(v)
n(alue)g(of)g(the)g(object)g(can)g(be)g(deduced.)208
1093 y(When)i(this)h(\002eld)g(is)g(not)f(set,)i(a)f(string)f(of)h(the)
f(form)g(`)p Fj(<\045s)49 b(object)f(at)i(\045p>)p Fr(')22
b(is)h(returned,)f(where)f Fj(\045s)i Fr(is)h(replaced)d(by)208
1193 y(the)f(type)f(name,)h(and)f Fj(\045p)i Fr(by)f(the)g(object')-5
b(s)20 b(memory)e(address.)208 1326 y(This)i(\002eld)g(is)h(inherited)e
(by)h(subtypes.)0 1473 y(PyNumberMethods)d(*tp)p 783
1473 25 4 v 29 w(as)p 881 1473 V 30 w(number;)0 1620
y(XXX)0 1766 y(PySequenceMethods)g(*tp)p 829 1766 V 29
w(as)p 927 1766 V 30 w(sequence;)0 1913 y(XXX)0 2060
y(PyMappingMethods)g(*tp)p 811 2060 V 29 w(as)p 909 2060
V 30 w(mapping;)0 2207 y(XXX)0 2354 y Fj(hashfunc)48
b Fg(tp_hash)208 2454 y Fr(An)20 b(optional)f(pointer)g(to)h(a)h
(function)d(that)i(implements)g(the)g(b)n(uilt-in)f(function)g
Fj(hash\(\))p Fr(.)208 2586 y(The)25 b(signature)f(is)j(the)f(same)f
(as)i(for)e Fj(PyObject_Hash\(\))p Fr(;)h(it)g(must)g(return)f(a)h(C)g
(long.)41 b(The)25 b(v)n(alue)g Fj(-1)h Fr(should)e(not)i(be)208
2686 y(returned)20 b(as)i(a)h(normal)d(return)h(v)n(alue;)h(when)g(an)g
(error)e(occurs)i(during)e(the)i(computation)e(of)h(the)h(hash)g(v)n
(alue,)f(the)h(function)208 2786 y(should)d(set)i(an)f(e)o(xception)e
(and)i(return)f Fj(-1)p Fr(.)208 2918 y(When)i(this)h(\002eld)f(is)h
(not)f(set,)h(tw)o(o)g(possibilities)g(e)o(xist:)27 b(if)22
b(the)f Fj(tp_compare)f Fr(and)h Fj(tp_richcompare)e
Fr(\002elds)j(are)f(both)208 3018 y Fj(NULL)p Fr(,)e(a)i(def)o(ault)e
(hash)h(v)n(alue)g(based)g(on)f(the)i(object')-5 b(s)20
b(address)f(is)j(returned;)c(otherwise,)h(a)i Fj(TypeError)e
Fr(is)i(raised.)208 3151 y(This)j(\002eld)h(is)h(inherited)e(by)g
(subtypes)g(together)f(with)i Fj(tp_richcompare)e Fr(and)h
Fj(tp_compare)p Fr(:)33 b(a)25 b(subtypes)f(inherits)208
3251 y(all)29 b(three)g(of)g Fj(tp_compare)p Fr(,)g Fj(tp_richcompare)p
Fr(,)g(and)g Fj(tp_hash)p Fr(,)h(when)f(the)g(subtype')-5
b(s)28 b Fj(tp_compare)p Fr(,)i Fj(tp_-)208 3350 y(richcompare)18
b Fr(and)i Fj(tp_hash)f Fr(are)h(all)h Fj(NULL)p Fr(.)0
3497 y Fj(ternaryfunc)48 b Fg(tp_call)208 3597 y Fr(An)24
b(optional)e(pointer)h(to)h(a)h(function)d(that)i(implements)f(calling)
h(the)g(object.)35 b(This)24 b(should)f(be)h Fj(NULL)g
Fr(if)g(the)h(object)e(is)i(not)208 3696 y(callable.)f(The)c(signature)
f(is)i(the)g(same)f(as)h(for)e Fj(PyObject_Call\(\))p
Fr(.)208 3829 y(This)h(\002eld)g(is)h(inherited)e(by)h(subtypes.)0
3976 y Fj(reprfunc)48 b Fg(tp_str)208 4076 y Fr(An)21
b(optional)g(pointer)g(to)h(a)g(function)e(that)i(implements)f(the)h(b)
n(uilt-in)f(operation)f Fj(str\(\))p Fr(.)29 b(\(Note)22
b(that)g Fj(str)f Fr(is)i(a)f(type)g(no)n(w)-5 b(,)208
4175 y(and)17 b Fj(str\(\))h Fr(calls)g(the)g(constructor)e(for)i(that)
g(type.)23 b(This)18 b(constructor)e(calls)j Fj(PyObject_Str\(\))d
Fr(to)i(do)g(the)g(actual)f(w)o(ork,)208 4275 y(and)i
Fj(PyObject_Str\(\))f Fr(will)j(call)g(this)g(handler)-5
b(.\))208 4408 y(The)19 b(signature)g(is)j(the)e(same)g(as)h(for)e
Fj(PyObject_Str\(\))p Fr(;)g(it)i(must)f(return)f(a)h(string)g(or)g(a)h
(Unicode)e(object.)24 b(This)c(function)208 4507 y(should)d(return)g(a)
i(\223friendly\224)e(string)h(representation)e(of)i(the)g(object,)g(as)
h(this)g(is)h(the)e(representation)e(that)j(will)g(be)f(used)h(by)f
(the)208 4607 y(print)h(statement.)208 4740 y(When)h(this)g(\002eld)h
(is)g(not)f(set,)g Fj(PyObject_Repr\(\))e Fr(is)j(called)f(to)h(return)
e(a)h(string)g(representation.)208 4873 y(This)g(\002eld)g(is)h
(inherited)e(by)h(subtypes.)0 5019 y Fj(getattrofunc)48
b Fg(tp_getattro)208 5119 y Fr(An)20 b(optional)f(pointer)g(to)h(the)g
(get-attrib)n(ute)f(function.)208 5252 y(The)37 b(signature)g(is)h(the)
g(same)g(as)h(for)e Fj(PyObject_GetAttr\(\))p Fr(.)75
b(It)38 b(is)g(usually)g(con)m(v)o(enient)d(to)j(set)g(this)g(\002eld)g
(to)208 5352 y Fj(PyObject_GenericGetAttr\(\))p Fr(,)15
b(which)20 b(implements)f(the)h(normal)f(w)o(ay)i(of)f(looking)e(for)i
(object)f(attrib)n(utes.)p 0 5549 3901 4 v 0 5649 a Fn(10.3.)52
b(T)-10 b(ype)23 b(Objects)3046 b(105)p eop end
%%Page: 106 112
TeXDict begin 106 111 bop 208 83 a Fr(This)28 b(\002eld)h(is)h
(inherited)d(by)h(subtypes)g(together)f(with)i Fj(tp_getattr)p
Fr(:)41 b(a)29 b(subtype)f(inherits)g(both)g Fj(tp_getattr)f
Fr(and)208 183 y Fj(tp_getattro)18 b Fr(from)h(its)j(base)e(type)g
(when)f(the)h(subtype')-5 b(s)20 b Fj(tp_getattr)f Fr(and)g
Fj(tp_getattro)g Fr(are)h(both)g Fj(NULL)p Fr(.)0 330
y Fj(setattrofunc)48 b Fg(tp_setattro)208 429 y Fr(An)20
b(optional)f(pointer)g(to)h(the)g(set-attrib)n(ute)g(function.)208
562 y(The)37 b(signature)g(is)h(the)g(same)g(as)h(for)e
Fj(PyObject_SetAttr\(\))p Fr(.)75 b(It)38 b(is)g(usually)g(con)m(v)o
(enient)d(to)j(set)g(this)g(\002eld)g(to)208 662 y Fj
(PyObject_GenericSetAttr\(\))p Fr(,)15 b(which)20 b(implements)f(the)h
(normal)f(w)o(ay)i(of)f(setting)g(object)f(attrib)n(utes.)208
794 y(This)28 b(\002eld)h(is)h(inherited)d(by)h(subtypes)g(together)f
(with)i Fj(tp_setattr)p Fr(:)41 b(a)29 b(subtype)f(inherits)g(both)g
Fj(tp_setattr)f Fr(and)208 894 y Fj(tp_setattro)18 b
Fr(from)h(its)j(base)e(type)g(when)f(the)h(subtype')-5
b(s)20 b Fj(tp_setattr)f Fr(and)g Fj(tp_setattro)g Fr(are)h(both)g
Fj(NULL)p Fr(.)0 1041 y Fj(PyBufferProcs)650 1056 y(*)747
1041 y Fg(tp_as_buffer)208 1141 y Fr(Pointer)h(to)h(an)g(additional)e
(structure)h(that)h(contains)f(\002elds)h(rele)n(v)n(ant)f(only)g(to)h
(objects)g(which)f(implement)f(the)i(b)n(uf)n(fer)f(inter)n(-)208
1240 y(f)o(ace.)j(These)c(\002elds)h(are)f(documented)e(in)i(\223Buf)n
(fer)f(Object)h(Structures\224)g(\(section)f(10.7\).)208
1373 y(The)g Fj(tp_as_buffer)g Fr(\002eld)h(is)h(not)f(inherited,)f(b)n
(ut)h(the)g(contained)f(\002elds)i(are)f(inherited)f(indi)n(vidually)-5
b(.)0 1520 y Fj(long)49 b Fg(tp_flags)208 1620 y Fr(This)22
b(\002eld)g(is)h(a)g(bit)g(mask)f(of)g(v)n(arious)f(\003ags.)31
b(Some)22 b(\003ags)g(indicate)g(v)n(ariant)f(semantics)i(for)e
(certain)h(situations;)h(others)f(are)208 1719 y(used)k(to)h(indicate)g
(that)g(certain)f(\002elds)i(in)f(the)g(type)f(object)g(\(or)h(in)g
(the)g(e)o(xtension)e(structures)i(referenced)d(via)j
Fj(tp_as_-)208 1819 y(number)p Fr(,)g Fj(tp_as_sequence)p
Fr(,)e Fj(tp_as_mapping)p Fr(,)h(and)g Fj(tp_as_buffer)p
Fr(\))e(that)i(were)h(historically)e(not)h(al)o(w)o(ays)208
1918 y(present)18 b(are)h(v)n(alid;)g(if)g(such)g(a)g(\003ag)g(bit)g
(is)h(clear)m(,)f(the)g(type)f(\002elds)i(it)g(guards)d(must)i(not)g
(be)g(accessed)g(and)f(must)h(be)g(considered)208 2018
y(to)h(ha)n(v)o(e)f(a)i(zero)f(or)g Fj(NULL)g Fr(v)n(alue)f(instead.)
208 2151 y(Inheritance)h(of)i(this)h(\002eld)g(is)g(complicated.)31
b(Most)22 b(\003ag)h(bits)g(are)f(inherited)g(indi)n(vidually)-5
b(,)20 b(i.e.)32 b(if)23 b(the)f(base)h(type)f(has)h(a)f(\003ag)208
2250 y(bit)f(set,)h(the)f(subtype)f(inherits)h(this)g(\003ag)h(bit.)28
b(The)20 b(\003ag)i(bits)f(that)g(pertain)g(to)g(e)o(xtension)f
(structures)g(are)h(strictly)g(inherited)f(if)208 2350
y(the)j(e)o(xtension)f(structure)g(is)i(inherited,)f(i.e.)34
b(the)24 b(base)f(type')-5 b(s)23 b(v)n(alue)g(of)g(the)g(\003ag)h(bit)
f(is)h(copied)e(into)h(the)h(subtype)e(together)208 2450
y(with)h(a)h(pointer)e(to)h(the)h(e)o(xtension)d(structure.)34
b(The)23 b Fj(Py_TPFLAGS_HAVE_GC)d Fr(\003ag)j(bit)h(is)g(inherited)e
(together)g(with)i(the)208 2549 y Fj(tp_traverse)17 b
Fr(and)i Fj(tp_clear)f Fr(\002elds,)i(i.e.)25 b(if)19
b(the)g Fj(Py_TPFLAGS_HAVE_GC)e Fr(\003ag)i(bit)g(is)h(clear)g(in)f
(the)g(subtype)f(and)208 2649 y(the)25 b Fj(tp_traverse)e
Fr(and)i Fj(tp_clear)f Fr(\002elds)h(in)g(the)g(subtype)f(e)o(xist)h
(\(as)h(indicated)e(by)g(the)h Fj(Py_TPFLAGS_HAVE_-)208
2749 y(RICHCOMPARE)18 b Fr(\003ag)j(bit\))f(and)f(ha)n(v)o(e)h
Fj(NULL)g Fr(v)n(alues.)208 2881 y(The)d(follo)n(wing)g(bit)h(masks)g
(are)h(currently)d(de\002ned;)i(these)g(can)g(be)g(or)n(-ed)f(together)
g(using)h(the)g Fj(|)g Fr(operator)f(to)h(form)f(the)h(v)n(alue)208
2981 y(of)24 b(the)h Fj(tp_flags)f Fr(\002eld.)39 b(The)25
b(macro)f Fj(PyType_HasFeature\(\))e Fr(tak)o(es)j(a)g(type)g(and)f(a)i
(\003ags)f(v)n(alue,)g Fo(tp)g Fr(and)f Fo(f)12 b Fr(,)27
b(and)208 3081 y(checks)19 b(whether)g Fo(tp)p Fj(->tp_flags)48
b(&)p Fo(f)33 b Fr(is)21 b(non-zero.)208 3214 y Fg
(Py_TPFLAGS_HAVE_GETCHARBUFFER)390 3313 y Fr(If)53 b(this)g(bit)g(is)h
(set,)62 b(the)53 b Fj(PyBufferProcs)e Fr(struct)h(referenced)f(by)i
Fj(tp_as_buffer)e Fr(has)i(the)g Fj(bf_-)390 3413 y(getcharbuffer)19
b Fr(\002eld.)208 3546 y Fg(Py_TPFLAGS_HAVE_SEQUENCE_IN)390
3645 y Fr(If)30 b(this)h(bit)g(is)g(set,)i(the)e Fj(PySequenceMethods)c
Fr(struct)k(referenced)d(by)i Fj(tp_as_sequence)e Fr(has)i(the)h
Fj(sq_-)390 3745 y(contains)19 b Fr(\002eld.)208 3878
y Fg(Py_TPFLAGS_GC)390 3977 y Fr(This)i(bit)f(is)h(obsolete.)j(The)c
(bit)h(it)g(used)e(to)i(name)e(is)j(no)d(longer)g(in)i(use.)k(The)20
b(symbol)f(is)i(no)n(w)f(de\002ned)f(as)i(zero.)208 4110
y Fg(Py_TPFLAGS_HAVE_INPLACEOPS)390 4210 y Fr(If)48 b(this)h(bit)g(is)g
(set,)56 b(the)48 b Fj(PySequenceMethods)e Fr(struct)i(referenced)f(by)
g Fj(tp_as_sequence)g Fr(and)h(the)390 4309 y Fj(PyNumberMethods)31
b Fr(structure)i(referenced)e(by)i Fj(tp_as_number)e
Fr(contain)i(the)g(\002elds)h(for)f(in-place)f(opera-)390
4409 y(tors.)25 b(In)20 b(particular)m(,)e(this)j(means)f(that)g(the)g
Fj(PyNumberMethods)e Fr(structure)i(has)g(the)g(\002elds)h
Fj(nb_inplace_add)p Fr(,)390 4509 y Fj(nb_inplace_subtract)p
Fr(,)33 b Fj(nb_inplace_multiply)p Fr(,)g Fj(nb_inplace_divide)p
Fr(,)g Fj(nb_inplace_-)390 4608 y(remainder)p Fr(,)70
b Fj(nb_inplace_power)p Fr(,)f Fj(nb_inplace_lshift)p
Fr(,)g Fj(nb_inplace_rshift)p Fr(,)g Fj(nb_-)390 4708
y(inplace_and)p Fr(,)24 b Fj(nb_inplace_xor)p Fr(,)f(and)h
Fj(nb_inplace_or)p Fr(;)h(and)f(the)h Fj(PySequenceMethods)d
Fr(struct)390 4808 y(has)f(the)f(\002elds)g Fj(sq_inplace_concat)e
Fr(and)i Fj(sq_inplace_repeat)p Fr(.)208 4940 y Fg
(Py_TPFLAGS_CHECKTYPES)390 5040 y Fr(If)28 b(this)g(bit)g(is)h(set,)h
(the)e(binary)e(and)i(ternary)e(operations)g(in)i(the)g
Fj(PyNumberMethods)e Fr(structure)g(referenced)g(by)390
5140 y Fj(tp_as_number)17 b Fr(accept)h(ar)o(guments)e(of)i(arbitrary)f
(object)g(types,)i(and)e(do)h(their)g(o)n(wn)g(type)g(con)m(v)o
(ersions)e(if)i(needed.)390 5239 y(If)24 b(this)g(bit)g(is)h(clear)m(,)
f(those)g(operations)e(require)g(that)i(all)h(ar)o(guments)c(ha)n(v)o
(e)j(the)f(current)g(type)g(as)i(their)e(type,)h(and)g(the)p
0 5549 3901 4 v 0 5649 a Fn(106)2106 b(Chapter)23 b(10.)52
b(Object)23 b(Implementation)j(Suppor)s(t)p eop end
%%Page: 107 113
TeXDict begin 107 112 bop 390 83 a Fr(caller)21 b(is)h(supposed)d(to)j
(perform)c(a)k(coercion)d(operation)g(\002rst.)28 b(This)21
b(applies)g(to)g Fj(nb_add)p Fr(,)f Fj(nb_subtract)p
Fr(,)g Fj(nb_-)390 183 y(multiply)p Fr(,)28 b Fj(nb_divide)p
Fr(,)f Fj(nb_remainder)p Fr(,)g Fj(nb_divmod)p Fr(,)h
Fj(nb_power)p Fr(,)f Fj(nb_lshift)p Fr(,)h Fj(nb_rshift)p
Fr(,)390 282 y Fj(nb_and)p Fr(,)20 b Fj(nb_xor)p Fr(,)f(and)h
Fj(nb_or)p Fr(.)208 415 y Fg(Py_TPFLAGS_HAVE_RICHCOMPARE)390
515 y Fr(If)i(this)g(bit)g(is)h(set,)f(the)g(type)f(object)g(has)h(the)
g Fj(tp_richcompare)d Fr(\002eld,)j(as)h(well)f(as)h(the)e
Fj(tp_traverse)f Fr(and)i(the)390 614 y Fj(tp_clear)d
Fr(\002elds.)208 747 y Fg(Py_TPFLAGS_HAVE_WEAKREFS)390
847 y Fr(If)g(this)g(bit)g(is)h(set,)g(the)e Fj(tp_weaklistoffset)f
Fr(\002eld)i(is)g(de\002ned.)24 b(Instances)18 b(of)h(a)g(type)f(are)h
(weakly)f(referenceable)390 946 y(if)j(the)f(type')-5
b(s)20 b Fj(tp_weaklistoffset)e Fr(\002eld)i(has)g(a)h(v)n(alue)e
(greater)h(than)f(zero.)208 1079 y Fg(Py_TPFLAGS_HAVE_ITER)390
1179 y Fr(If)h(this)h(bit)f(is)i(set,)e(the)g(type)g(object)g(has)g
(the)g Fj(tp_iter)g Fr(and)g Fj(tp_iternext)e Fr(\002elds.)208
1312 y Fg(Py_TPFLAGS_HAVE_CLASS)390 1411 y Fr(If)47 b(this)h(bit)g(is)g
(set,)55 b(the)47 b(type)g(object)g(has)g(se)n(v)o(eral)g(ne)n(w)g
(\002elds)h(de\002ned)e(starting)h(in)h(Python)e(2.2:)79
b Fj(tp_-)390 1511 y(methods)p Fr(,)28 b Fj(tp_members)p
Fr(,)f Fj(tp_getset)p Fr(,)h Fj(tp_base)p Fr(,)g Fj(tp_dict)p
Fr(,)g Fj(tp_descr_get)p Fr(,)e Fj(tp_descr_set)p Fr(,)390
1611 y Fj(tp_dictoffset)p Fr(,)h Fj(tp_init)p Fr(,)h
Fj(tp_alloc)p Fr(,)f Fj(tp_new)p Fr(,)h Fj(tp_free)p
Fr(,)g Fj(tp_is_gc)p Fr(,)g Fj(tp_bases)p Fr(,)f Fj(tp_mro)p
Fr(,)390 1710 y Fj(tp_cache)p Fr(,)19 b Fj(tp_subclasses)p
Fr(,)f(and)i Fj(tp_weaklist)p Fr(.)208 1843 y Fg(Py_TPFLAGS_HEAPTYPE)
390 1943 y Fr(This)k(bit)g(is)g(set)g(when)f(the)h(type)f(object)g
(itself)h(is)h(allocated)d(on)i(the)f(heap.)34 b(In)24
b(this)g(case,)g(the)g Fj(ob_type)f Fr(\002eld)g(of)h(its)390
2042 y(instances)e(is)i(considered)c(a)j(reference)d(to)j(the)f(type,)g
(and)g(the)g(type)g(object)f(is)i(INCREF'ed)f(when)g(a)h(ne)n(w)f
(instance)g(is)390 2142 y(created,)c(and)g(DECREF'ed)h(when)f(an)g
(instance)h(is)g(destro)o(yed)e(\(this)i(does)f(not)h(apply)e(to)i
(instances)g(of)f(subtypes;)g(only)390 2242 y(the)i(type)g(referenced)e
(by)i(the)g(instance')-5 b(s)20 b(ob)p 1710 2242 25 4
v 29 w(type)g(gets)g(INCREF'ed)g(or)g(DECREF'ed\).)208
2374 y Fg(Py_TPFLAGS_BASETYPE)390 2474 y Fr(This)e(bit)h(is)f(set)h
(when)e(the)h(type)g(can)g(be)g(used)f(as)i(the)f(base)g(type)f(of)h
(another)e(type.)24 b(If)18 b(this)g(bit)h(is)g(clear)m(,)e(the)h(type)
g(cannot)390 2574 y(be)i(subtyped)f(\(similar)h(to)g(a)h
(\224\002nal\224)f(class)h(in)f(Ja)n(v)n(a\).)208 2707
y Fg(Py_TPFLAGS_READY)390 2806 y Fr(This)h(bit)f(is)h(set)g(when)f(the)
g(type)g(object)f(has)i(been)e(fully)h(initialized)g(by)f
Fj(PyType_Ready\(\))p Fr(.)208 2939 y Fg(Py_TPFLAGS_READYING)390
3039 y Fr(This)i(bit)f(is)h(set)g(while)f Fj(PyType_Ready\(\))e
Fr(is)k(in)e(the)g(process)g(of)g(initializing)f(the)i(type)e(object.)
208 3171 y Fg(Py_TPFLAGS_HAVE_GC)390 3271 y Fr(This)28
b(bit)h(is)f(set)h(when)e(the)h(object)g(supports)f(garbage)f
(collection.)47 b(If)28 b(this)g(bit)g(is)h(set,)i(instances)c(must)h
(be)g(created)390 3371 y(using)23 b Fj(PyObject_GC_New\(\))d
Fr(and)j(destro)o(yed)e(using)i Fj(PyObject_GC_Del\(\))p
Fr(.)31 b(More)22 b(information)f(in)i(sec-)390 3470
y(tion)h(XXX)f(about)g(garbage)f(collection.)34 b(This)23
b(bit)h(also)g(implies)g(that)f(the)h(GC-related)f(\002elds)h
Fj(tp_traverse)e Fr(and)390 3570 y Fj(tp_clear)i Fr(are)g(present)g(in)
h(the)g(type)f(object;)i(b)n(ut)f(those)f(\002elds)h(also)g(e)o(xist)g
(when)f Fj(Py_TPFLAGS_HAVE_GC)e Fr(is)390 3670 y(clear)e(b)n(ut)g
Fj(Py_TPFLAGS_HAVE_RICHCOMPARE)c Fr(is)21 b(set.)208
3802 y Fg(Py_TPFLAGS_DEFAULT)390 3902 y Fr(This)29 b(is)h(a)g(bitmask)e
(of)h(all)g(the)g(bits)h(that)f(pertain)f(to)h(the)g(e)o(xistence)f(of)
g(certain)h(\002elds)g(in)g(the)g(type)g(object)f(and)h(its)390
4002 y(e)o(xtension)17 b(structures.)23 b(Currently)-5
b(,)17 b(it)i(includes)e(the)h(follo)n(wing)f(bits:)25
b Fj(Py_TPFLAGS_HAVE_GETCHARBUFFER)p Fr(,)390 4101 y
Fj(Py_TPFLAGS_HAVE_SEQUENCE_IN)p Fr(,)110 b Fj
(Py_TPFLAGS_HAVE_INPLACEOPS)p Fr(,)g Fj(Py_TPFLAGS_-)390
4201 y(HAVE_RICHCOMPARE)p Fr(,)g Fj(Py_TPFLAGS_HAVE_WEAKREFS)p
Fr(,)e Fj(Py_TPFLAGS_HAVE_ITER)p Fr(,)h(and)390 4301
y Fj(Py_TPFLAGS_HAVE_CLASS)p Fr(.)0 4447 y Fj(char)200
4462 y(*)299 4447 y Fg(tp_doc)208 4547 y Fr(An)23 b(optional)f(pointer)
f(to)j(a)f(NUL-terminated)e(C)j(string)f(gi)n(ving)f(the)h(docstring)f
(for)g(this)i(type)f(object.)33 b(This)23 b(is)h(e)o(xposed)e(as)208
4647 y(the)e Fj(__doc__)f Fr(attrib)n(ute)h(on)g(the)g(type)g(and)f
(instances)h(of)g(the)h(type.)208 4779 y(This)f(\002eld)g(is)h
Fo(not)f Fr(inherited)f(by)h(subtypes.)0 4926 y(The)g(follo)n(wing)e
(three)i(\002elds)h(only)e(e)o(xist)h(if)h(the)f Fj
(Py_TPFLAGS_HAVE_RICHCOMPARE)c Fr(\003ag)k(bit)h(is)g(set.)0
5073 y Fj(traverseproc)48 b Fg(tp_traverse)208 5173 y
Fr(An)22 b(optional)f(pointer)h(to)g(a)h(tra)n(v)o(ersal)f(function)f
(for)h(the)h(garbage)d(collector)-5 b(.)32 b(This)22
b(is)i(only)e(used)g(if)h(the)f Fj(Py_TPFLAGS_-)208 5272
y(HAVE_GC)g Fr(\003ag)h(bit)h(is)g(set.)34 b(More)23
b(information)e(about)h(Python')-5 b(s)22 b(garbage)f(collection)h
(scheme)h(can)g(be)g(found)e(in)j(section)208 5372 y(10.9.)p
0 5549 3901 4 v 0 5649 a Fn(10.3.)52 b(T)-10 b(ype)23
b(Objects)3046 b(107)p eop end
%%Page: 108 114
TeXDict begin 108 113 bop 208 83 a Fr(The)24 b Fj(tp_traverse)f
Fr(pointer)g(is)j(used)e(by)g(the)h(garbage)d(collector)i(to)h(detect)f
(reference)f(c)o(ycles.)38 b(A)25 b(typical)f(implemen-)208
183 y(tation)k(of)g(a)g Fj(tp_traverse)f Fr(function)g(simply)h(calls)h
Fj(Py_VISIT\(\))e Fr(on)g(each)h(of)g(the)h(instance')-5
b(s)28 b(members)f(that)i(are)208 282 y(Python)19 b(objects.)24
b(F)o(or)c(e)o(xampe,)f(this)h(is)h(function)e Fj(local_traverse)f
Fr(from)h(the)h Fj(thread)g Fr(e)o(xtension)f(module:)533
499 y Fk(static)44 b(int)533 590 y(local_traverse\(localobject)1744
603 y(*)1789 590 y(self,)g(visitproc)f(visit,)h(void)3044
603 y(*)3089 590 y(arg\))533 682 y({)713 773 y(Py_VISIT\(self->args\);)
713 864 y(Py_VISIT\(self->kw\);)713 956 y(Py_VISIT\(self->dict\);)713
1047 y(return)g(0;)533 1138 y(})208 1412 y Fr(Note)27
b(that)h Fj(Py_VISIT\(\))e Fr(is)i(called)f(only)g(on)g(those)h
(members)e(that)i(can)f(participate)f(in)i(reference)e(c)o(ycles.)46
b(Although)208 1512 y(there)19 b(is)i(also)g(a)g(`)p
Fj(self->key)p Fr(')d(member)m(,)g(it)j(can)f(only)f(be)i
Fj(NULL)f Fr(or)g(a)g(Python)f(string)h(and)g(therefore)e(cannot)h(be)h
(part)g(of)g(a)208 1611 y(reference)e(c)o(ycle.)208 1737
y(On)k(the)g(other)g(hand,)f(e)n(v)o(en)h(if)g(you)g(kno)n(w)f(a)i
(member)e(can)h(ne)n(v)o(er)f(be)h(part)g(of)g(a)h(c)o(ycle,)f(as)h(a)g
(deb)n(ugging)d(aid)i(you)g(may)f(w)o(ant)208 1836 y(to)f(visit)h(it)g
(an)o(yw)o(ay)d(just)j(so)g(the)f Fj(gc)g Fr(module')-5
b(s)20 b Fj(get_referents\(\))e Fr(function)g(will)j(include)e(it.)208
1962 y(Note)27 b(that)h Fj(Py_VISIT\(\))f Fr(requires)g(the)h
Fo(visit)i Fr(and)e Fo(ar)m(g)f Fr(parameters)g(to)h
Fj(local_traverse)e Fr(to)i(ha)n(v)o(e)f(these)h(speci\002c)208
2062 y(names;)20 b(don')o(t)e(name)i(them)f(just)i(an)o(ything.)208
2187 y(This)c(\002eld)h(is)g(inherited)e(by)h(subtypes)g(together)f
(with)h Fj(tp_clear)g Fr(and)f(the)i Fj(Py_TPFLAGS_HAVE_GC)c
Fr(\003ag)k(bit:)24 b(the)17 b(\003ag)208 2287 y(bit,)j
Fj(tp_traverse)p Fr(,)e(and)i Fj(tp_clear)f Fr(are)i(all)f(inherited)f
(from)h(the)g(base)g(type)g(if)g(the)o(y)g(are)g(all)h(zero)f(in)g(the)
g(subtype)f Fo(and)208 2386 y Fr(the)h(subtype)f(has)h(the)g
Fj(Py_TPFLAGS_HAVE_RICHCOMPARE)c Fr(\003ag)k(bit)h(set.)0
2533 y Fj(inquiry)49 b Fg(tp_clear)208 2633 y Fr(An)29
b(optional)e(pointer)h(to)h(a)g(clear)g(function)e(for)i(the)g(garbage)
e(collector)-5 b(.)50 b(This)29 b(is)h(only)e(used)h(if)g(the)g
Fj(Py_TPFLAGS_-)208 2732 y(HAVE_GC)19 b Fr(\003ag)h(bit)h(is)g(set.)208
2858 y(The)i Fj(tp_clear)h Fr(member)f(function)f(is)j(used)f(to)h
(break)e(reference)g(c)o(ycles)h(in)g(c)o(yclic)g(garbage)e(detected)i
(by)f(the)i(garbage)208 2958 y(collector)-5 b(.)37 b(T)-7
b(ak)o(en)25 b(together)m(,)f(all)h Fj(tp_clear)f Fr(functions)f(in)i
(the)f(system)h(must)g(combine)e(to)i(break)f(all)h(reference)e(c)o
(ycles.)208 3057 y(This)16 b(is)i(subtle,)f(and)f(if)h(in)f(an)o(y)g
(doubt)f(supply)h(a)h Fj(tp_clear)f Fr(function.)22 b(F)o(or)16
b(e)o(xample,)f(the)i(tuple)f(type)g(does)h(not)f(implement)208
3157 y(a)i Fj(tp_clear)e Fr(function,)g(because)h(it')-5
b(s)19 b(possible)e(to)h(pro)o(v)o(e)e(that)i(no)f(reference)f(c)o
(ycle)h(can)g(be)h(composed)e(entirely)h(of)g(tuples.)208
3256 y(Therefore)f(the)j Fj(tp_clear)e Fr(functions)g(of)i(other)e
(types)i(must)f(be)h(suf)n(\002cient)f(to)g(break)g(an)o(y)g(c)o(ycle)g
(containing)e(a)j(tuple.)24 b(This)208 3356 y(isn')o(t)19
b(immediately)g(ob)o(vious,)f(and)i(there')-5 b(s)20
b(rarely)g(a)g(good)f(reason)g(to)i(a)n(v)n(oid)f(implementing)e
Fj(tp_clear)p Fr(.)208 3482 y(Implementations)29 b(of)j
Fj(tp_clear)e Fr(should)h(drop)g(the)h(instance')-5 b(s)31
b(references)g(to)h(those)f(of)h(its)h(members)d(that)i(may)g(be)208
3581 y(Python)19 b(objects,)g(and)h(set)h(its)g(pointers)e(to)i(those)f
(members)f(to)h Fj(NULL)p Fr(,)g(as)h(in)f(the)g(follo)n(wing)f(e)o
(xample:)533 3798 y Fk(static)44 b(int)533 3889 y
(local_clear\(localobject)1609 3902 y(*)1654 3889 y(self\))533
3981 y({)713 4072 y(Py_CLEAR\(self->key\);)713 4163 y
(Py_CLEAR\(self->args\);)713 4255 y(Py_CLEAR\(self->kw\);)713
4346 y(Py_CLEAR\(self->dict\);)713 4437 y(return)g(0;)533
4529 y(})208 4802 y Fr(The)17 b Fj(Py_CLEAR\(\))f Fr(macro)h(should)f
(be)h(used,)h(because)f(clearing)f(references)g(is)j(delicate:)24
b(the)17 b(reference)f(to)i(the)f(contained)208 4902
y(object)24 b(must)h(not)g(be)g(decremented)e(until)i(after)g(the)g
(pointer)f(to)h(the)h(contained)d(object)i(is)h(set)g(to)f
Fj(NULL)p Fr(.)g(This)g(is)h(because)208 5001 y(decrementing)14
b(the)j(reference)f(count)g(may)g(cause)h(the)g(contained)f(object)g
(to)i(become)d(trash,)j(triggering)d(a)i(chain)g(of)g(reclama-)208
5101 y(tion)h(acti)n(vity)h(that)f(may)h(include)f(in)m(v)n(oking)e
(arbitrary)i(Python)f(code)h(\(due)g(to)h(\002nalizers,)g(or)g(weakref)
e(callbacks,)i(associated)208 5201 y(with)g(the)g(contained)f
(object\).)24 b(If)19 b(it')-5 b(s)20 b(possible)f(for)g(such)g(code)g
(to)g(reference)f Fo(self)32 b Fr(again,)18 b(it')-5
b(s)21 b(important)d(that)h(the)g(pointer)f(to)208 5300
y(the)k(contained)f(object)i(be)f Fj(NULL)h Fr(at)g(that)g(time,)g(so)g
(that)g Fo(self)36 b Fr(kno)n(ws)22 b(the)g(contained)g(object)g(can)g
(no)h(longer)e(be)i(used.)32 b(The)208 5400 y Fj(Py_CLEAR\(\))18
b Fr(macro)i(performs)e(the)i(operations)f(in)h(a)h(safe)f(order)-5
b(.)p 0 5549 3901 4 v 0 5649 a Fn(108)2106 b(Chapter)23
b(10.)52 b(Object)23 b(Implementation)j(Suppor)s(t)p
eop end
%%Page: 109 115
TeXDict begin 109 114 bop 208 83 a Fr(Because)29 b(the)g(goal)f(of)h
Fj(tp_clear)f Fr(functions)g(is)i(to)f(break)f(reference)f(c)o(ycles,)k
(it')-5 b(s)30 b(not)f(necessary)f(to)h(clear)g(contained)208
183 y(objects)20 b(lik)o(e)h(Python)f(strings)h(or)f(Python)g(inte)o
(gers,)g(which)g(can')o(t)g(participate)g(in)h(reference)e(c)o(ycles.)
26 b(On)21 b(the)g(other)f(hand,)g(it)208 282 y(may)g(be)g(con)m(v)o
(enient)e(to)j(clear)f(all)h(contained)e(Python)h(objects,)g(and)g
(write)h(the)f(type')-5 b(s)21 b Fj(tp_dealloc)e Fr(function)g(to)i(in)
m(v)n(ok)o(e)208 382 y Fj(tp_clear)p Fr(.)208 515 y(More)e(information)
f(about)h(Python')-5 b(s)20 b(garbage)e(collection)h(scheme)h(can)g(be)
g(found)e(in)i(section)g(10.9.)208 648 y(This)d(\002eld)g(is)g
(inherited)f(by)h(subtypes)f(together)f(with)i Fj(tp_traverse)e
Fr(and)i(the)g Fj(Py_TPFLAGS_HAVE_GC)d Fr(\003ag)j(bit:)24
b(the)208 747 y(\003ag)c(bit,)g Fj(tp_traverse)p Fr(,)f(and)g
Fj(tp_clear)h Fr(are)g(all)h(inherited)e(from)g(the)h(base)g(type)g(if)
h(the)o(y)e(are)i(all)f(zero)g(in)g(the)h(subtype)208
847 y Fo(and)e Fr(the)h(subtype)f(has)i(the)f Fj
(Py_TPFLAGS_HAVE_RICHCOMPARE)15 b Fr(\003ag)21 b(bit)f(set.)0
994 y Fj(richcmpfunc)48 b Fg(tp_richcompare)208 1093
y Fr(An)20 b(optional)f(pointer)g(to)h(the)g(rich)g(comparison)e
(function.)208 1226 y(The)30 b(signature)g(is)i(the)f(same)g(as)h(for)e
Fj(PyObject_RichCompare\(\))p Fr(.)54 b(The)31 b(function)e(should)h
(return)g(the)h(result)g(of)208 1326 y(the)i(comparison)f(\(usually)h
Fj(Py_True)g Fr(or)h Fj(Py_False)p Fr(\).)65 b(If)34
b(the)g(comparison)d(is)k(unde\002ned,)g(it)g(must)f(return)f
Fj(Py_-)208 1425 y(NotImplemented)p Fr(,)17 b(if)k(another)e(error)g
(occurred)f(it)j(must)f(return)f Fj(NULL)h Fr(and)g(set)h(an)f(e)o
(xception)e(condition.)208 1558 y(This)24 b(\002eld)g(is)h(inherited)d
(by)i(subtypes)f(together)g(with)h Fj(tp_compare)f Fr(and)g
Fj(tp_hash)p Fr(:)32 b(a)24 b(subtype)f(inherits)h(all)g(three)g(of)208
1658 y Fj(tp_compare)p Fr(,)15 b Fj(tp_richcompare)p
Fr(,)f(and)h Fj(tp_hash)p Fr(,)h(when)f(the)h(subtype')-5
b(s)15 b Fj(tp_compare)p Fr(,)g Fj(tp_richcompare)p Fr(,)208
1757 y(and)k Fj(tp_hash)h Fr(are)g(all)h Fj(NULL)p Fr(.)208
1890 y(The)41 b(follo)n(wing)g(constants)h(are)g(de\002ned)f(to)i(be)f
(used)g(as)h(the)f(third)g(ar)o(gument)e(for)h Fj(tp_richcompare)f
Fr(and)i(for)208 1990 y Fj(PyObject_RichCompare\(\))p
Fr(:)1623 2114 y Fp(Constant)p 1994 2144 4 100 v 99 w(Comparison)p
1574 2147 961 4 v 1623 2217 a Fj(Py_LT)p 1994 2247 4
100 v 367 w(<)1623 2317 y(Py_LE)p 1994 2347 V 342 w(<=)1623
2416 y(Py_EQ)p 1994 2446 V 342 w(==)1623 2516 y(Py_NE)p
1994 2546 V 342 w(!=)1623 2616 y(Py_GT)p 1994 2646 V
367 w(>)1623 2715 y(Py_GE)p 1994 2745 V 342 w(>=)0 2857
y Fr(The)20 b(ne)o(xt)f(\002eld)i(only)e(e)o(xists)i(if)f(the)g
Fj(Py_TPFLAGS_HAVE_WEAKREFS)d Fr(\003ag)j(bit)g(is)h(set.)0
3004 y Fj(long)49 b Fg(tp_weaklistoffset)208 3104 y Fr(If)25
b(the)h(instances)g(of)f(this)h(type)g(are)f(weakly)g(referenceable,)g
(this)h(\002eld)g(is)h(greater)e(than)g(zero)g(and)g(contains)g(the)h
(of)n(fset)f(in)208 3203 y(the)h(instance)h(structure)e(of)i(the)f
(weak)h(reference)e(list)j(head)e(\(ignoring)e(the)j(GC)g(header)m(,)g
(if)g(present\);)i(this)e(of)n(fset)f(is)i(used)208 3303
y(by)c Fj(PyObject_ClearWeakRefs\(\))d Fr(and)k(the)g
Fj(PyWeakref_)2310 3318 y(*)2360 3303 y(\(\))e Fr(functions.)38
b(The)24 b(instance)h(structure)f(needs)g(to)208 3403
y(include)19 b(a)h(\002eld)h(of)f(type)f Fj(PyObject)1352
3418 y(*)1421 3403 y Fr(which)h(is)h(initialized)f(to)g
Fj(NULL)p Fr(.)208 3536 y(Do)f(not)h(confuse)f(this)h(\002eld)g(with)g
Fj(tp_weaklist)p Fr(;)f(that)h(is)h(the)f(list)h(head)e(for)g(weak)h
(references)e(to)i(the)g(type)g(object)f(itself.)208
3668 y(This)g(\002eld)h(is)g(inherited)e(by)h(subtypes,)g(b)n(ut)g(see)
h(the)g(rules)f(listed)h(belo)n(w)-5 b(.)23 b(A)d(subtype)f(may)g(o)o
(v)o(erride)e(this)j(of)n(fset;)f(this)h(means)208 3768
y(that)g(the)g(subtype)g(uses)h(a)f(dif)n(ferent)f(weak)h(reference)f
(list)j(head)d(than)h(the)h(base)f(type.)25 b(Since)c(the)f(list)h
(head)f(is)h(al)o(w)o(ays)g(found)208 3868 y(via)f Fj
(tp_weaklistoffset)p Fr(,)d(this)k(should)e(not)h(be)g(a)h(problem.)208
4001 y(When)c(a)h(type)f(de\002ned)g(by)g(a)h(class)h(statement)e(has)h
(no)f Fj(__slots__)g Fr(declaration,)f(and)h(none)g(of)g(its)i(base)e
(types)h(are)f(weakly)208 4100 y(referenceable,)k(the)j(type)f(is)i
(made)e(weakly)g(referenceable)e(by)i(adding)f(a)i(weak)g(reference)e
(list)i(head)f(slot)i(to)e(the)h(instance)208 4200 y(layout)19
b(and)h(setting)g(the)g Fj(tp_weaklistoffset)d Fr(of)j(that)h(slot')-5
b(s)21 b(of)n(fset.)208 4333 y(When)28 b(a)g(type')-5
b(s)29 b Fj(__slots__)e Fr(declaration)g(contains)g(a)i(slot)g(named)e
Fj(__weakref__)p Fr(,)i(that)f(slot)h(becomes)e(the)i(weak)208
4432 y(reference)16 b(list)j(head)e(for)h(instances)g(of)f(the)h(type,)
g(and)f(the)i(slot')-5 b(s)18 b(of)n(fset)g(is)h(stored)e(in)h(the)h
(type')-5 b(s)17 b Fj(tp_weaklistoffset)p Fr(.)208 4565
y(When)27 b(a)g(type')-5 b(s)28 b Fj(__slots__)e Fr(declaration)g(does)
h(not)g(contain)f(a)i(slot)g(named)e Fj(__weakref__)p
Fr(,)h(the)h(type)f(inherits)g(its)208 4665 y Fj(tp_weaklistoffset)17
b Fr(from)i(its)i(base)g(type.)0 4812 y(The)f(ne)o(xt)f(tw)o(o)i
(\002elds)f(only)g(e)o(xist)g(if)h(the)f Fj(Py_TPFLAGS_HAVE_CLASS)d
Fr(\003ag)j(bit)g(is)i(set.)0 4958 y Fj(getiterfunc)48
b Fg(tp_iter)208 5058 y Fr(An)25 b(optional)f(pointer)g(to)h(a)h
(function)e(that)h(returns)f(an)i(iterator)e(for)h(the)g(object.)40
b(Its)26 b(presence)e(normally)g(signals)h(that)h(the)208
5158 y(instances)15 b(of)h(this)g(type)g(are)g(iterable)f(\(although)f
(sequences)h(may)g(be)h(iterable)f(without)g(this)i(function,)e(and)g
(classic)i(instances)208 5257 y(al)o(w)o(ays)j(ha)n(v)o(e)g(this)h
(function,)d(e)n(v)o(en)h(if)h(the)o(y)g(don')o(t)e(de\002ne)i(an)g
Fj(__iter__\(\))f Fr(method\).)208 5390 y(This)h(function)e(has)j(the)f
(same)g(signature)f(as)i Fj(PyObject_GetIter\(\))p Fr(.)p
0 5549 3901 4 v 0 5649 a Fn(10.3.)52 b(T)-10 b(ype)23
b(Objects)3046 b(109)p eop end
%%Page: 110 116
TeXDict begin 110 115 bop 208 83 a Fr(This)20 b(\002eld)g(is)h
(inherited)e(by)h(subtypes.)0 230 y Fj(iternextfunc)48
b Fg(tp_iternext)208 330 y Fr(An)20 b(optional)f(pointer)f(to)j(a)f
(function)f(that)h(returns)f(the)h(ne)o(xt)g(item)g(in)g(an)g(iterator)
m(,)f(or)h(raises)h Fj(StopIteration)d Fr(when)i(the)208
429 y(iterator)h(is)h(e)o(xhausted.)29 b(Its)22 b(presence)f(normally)f
(signals)i(that)g(the)g(instances)g(of)f(this)h(type)g(are)g(iterators)
f(\(although)f(classic)208 529 y(instances)g(al)o(w)o(ays)g(ha)n(v)o(e)
g(this)h(function,)d(e)n(v)o(en)h(if)i(the)o(y)e(don')o(t)f(de\002ne)i
(a)h Fj(next\(\))e Fr(method\).)208 662 y(Iterator)25
b(types)i(should)f(also)h(de\002ne)f(the)h Fj(tp_iter)f
Fr(function,)h(and)f(that)h(function)e(should)h(return)g(the)h
(iterator)f(instance)208 761 y(itself)20 b(\(not)g(a)g(ne)n(w)g
(iterator)g(instance\).)208 894 y(This)g(function)e(has)j(the)f(same)g
(signature)f(as)i Fj(PyIter_Next\(\))p Fr(.)208 1027
y(This)f(\002eld)g(is)h(inherited)e(by)h(subtypes.)0
1174 y(The)g(ne)o(xt)f(\002elds,)i(up)f(to)g(and)g(including)e
Fj(tp_weaklist)p Fr(,)g(only)i(e)o(xist)g(if)h(the)f
Fj(Py_TPFLAGS_HAVE_CLASS)d Fr(\003ag)j(bit)g(is)h(set.)0
1321 y Fj(struct)49 b(PyMethodDef)899 1336 y(*)996 1321
y Fg(tp_methods)208 1420 y Fr(An)20 b(optional)f(pointer)g(to)h(a)h
(static)g Fj(NULL)p Fr(-terminated)c(array)i(of)h Fj(PyMethodDef)f
Fr(structures,)g(declaring)g(re)o(gular)g(methods)208
1520 y(of)g(this)i(type.)208 1653 y(F)o(or)c(each)h(entry)f(in)h(the)g
(array)-5 b(,)17 b(an)h(entry)f(is)i(added)e(to)h(the)g(type')-5
b(s)18 b(dictionary)e(\(see)i Fj(tp_dict)f Fr(belo)n(w\))g(containing)g
(a)h(method)208 1752 y(descriptor)-5 b(.)208 1885 y(This)20
b(\002eld)g(is)h(not)f(inherited)f(by)h(subtypes)f(\(methods)g(are)h
(inherited)f(through)f(a)j(dif)n(ferent)d(mechanism\).)0
2032 y Fj(struct)49 b(PyMemberDef)899 2047 y(*)996 2032
y Fg(tp_members)208 2132 y Fr(An)31 b(optional)e(pointer)h(to)h(a)g
(static)h Fj(NULL)p Fr(-terminated)d(array)h(of)h Fj(PyMemberDef)e
Fr(structures,)k(declaring)c(re)o(gular)h(data)208 2231
y(members)19 b(\(\002elds)h(or)g(slots\))h(of)e(instances)i(of)e(this)i
(type.)208 2364 y(F)o(or)16 b(each)g(entry)g(in)h(the)g(array)-5
b(,)16 b(an)h(entry)f(is)h(added)f(to)h(the)f(type')-5
b(s)17 b(dictionary)e(\(see)i Fj(tp_dict)f Fr(belo)n(w\))g(containing)f
(a)i(member)208 2464 y(descriptor)-5 b(.)208 2597 y(This)20
b(\002eld)g(is)h(not)f(inherited)f(by)h(subtypes)f(\(members)g(are)h
(inherited)f(through)f(a)j(dif)n(ferent)d(mechanism\).)0
2743 y Fj(struct)49 b(PyGetSetDef)899 2758 y(*)996 2743
y Fg(tp_getset)208 2843 y Fr(An)27 b(optional)g(pointer)f(to)i(a)g
(static)h Fj(NULL)p Fr(-terminated)c(array)i(of)g Fj(PyGetSetDef)g
Fr(structures,)h(declaring)f(computed)e(at-)208 2943
y(trib)n(utes)20 b(of)g(instances)g(of)g(this)g(type.)208
3076 y(F)o(or)g(each)h(entry)f(in)h(the)g(array)-5 b(,)19
b(an)i(entry)f(is)i(added)e(to)h(the)g(type')-5 b(s)21
b(dictionary)e(\(see)i Fj(tp_dict)f Fr(belo)n(w\))g(containing)f(a)i
(getset)208 3175 y(descriptor)-5 b(.)208 3308 y(This)20
b(\002eld)g(is)h(not)f(inherited)f(by)h(subtypes)f(\(computed)f(attrib)
n(utes)i(are)g(inherited)f(through)f(a)j(dif)n(ferent)d(mechanism\).)
208 3441 y(Docs)i(for)f(PyGetSetDef)h(\(XXX)h(belong)d(else)n(where\):)
444 3665 y Fk(typedef)43 b(PyObject)1206 3678 y(*)1251
3665 y(\()1296 3678 y(*)1341 3665 y(getter\)\(PyObject)2103
3678 y(*)2148 3665 y(,)h(void)2461 3678 y(*)2506 3665
y(\);)444 3756 y(typedef)f(int)i(\()1027 3769 y(*)1072
3756 y(setter\)\(PyObject)1834 3769 y(*)1879 3756 y(,)f(PyObject)2372
3769 y(*)2417 3756 y(,)g(void)2730 3769 y(*)2775 3756
y(\);)444 3939 y(typedef)f(struct)h(PyGetSetDef)f({)623
4030 y(char)847 4043 y(*)892 4030 y(name;)179 b(/)1341
4043 y(*)1430 4030 y(attribute)43 b(name)2103 4043 y(*)2148
4030 y(/)623 4122 y(getter)h(get;)179 b(/)1341 4135 y(*)1430
4122 y(C)45 b(function)e(to)i(get)f(the)g(attribute)2865
4135 y(*)2910 4122 y(/)623 4213 y(setter)g(set;)179 b(/)1341
4226 y(*)1430 4213 y(C)45 b(function)e(to)i(set)f(the)g(attribute)2865
4226 y(*)2910 4213 y(/)623 4304 y(char)847 4317 y(*)892
4304 y(doc;)224 b(/)1341 4317 y(*)1430 4304 y(optional)44
b(doc)g(string)2327 4317 y(*)2372 4304 y(/)623 4396 y(void)847
4409 y(*)892 4396 y(closure;)g(/)1341 4409 y(*)1430 4396
y(optional)g(additional)f(data)h(for)g(getter)g(and)g(setter)3537
4409 y(*)3582 4396 y(/)444 4487 y(})g(PyGetSetDef;)0
4689 y Fj(PyTypeObject)600 4704 y(*)697 4689 y Fg(tp_base)208
4788 y Fr(An)17 b(optional)g(pointer)g(to)h(a)g(base)g(type)f(from)g
(which)g(type)h(properties)e(are)i(inherited.)23 b(At)18
b(this)h(le)n(v)o(el,)e(only)g(single)h(inheritance)208
4888 y(is)j(supported;)d(multiple)i(inheritance)e(require)h
(dynamically)f(creating)h(a)i(type)f(object)f(by)h(calling)g(the)g
(metatype.)208 5021 y(This)c(\002eld)h(is)h(not)f(inherited)e(by)h
(subtypes)g(\(ob)o(viously\),)f(b)n(ut)h(it)i(def)o(aults)e(to)h
Fj(&PyBaseObject_Type)d Fr(\(which)i(to)h(Python)208
5121 y(programmers)g(is)k(kno)n(wn)e(as)i(the)f(type)g
Fj(object)p Fr(\).)0 5267 y Fj(PyObject)400 5282 y(*)498
5267 y Fg(tp_dict)208 5367 y Fr(The)f(type')-5 b(s)21
b(dictionary)d(is)j(stored)f(here)f(by)h Fj(PyType_Ready\(\))p
Fr(.)p 0 5549 3901 4 v 0 5649 a Fn(110)2106 b(Chapter)23
b(10.)52 b(Object)23 b(Implementation)j(Suppor)s(t)p
eop end
%%Page: 111 117
TeXDict begin 111 116 bop 208 83 a Fr(This)24 b(\002eld)g(should)f
(normally)g(be)h(initialized)f(to)i Fj(NULL)f Fr(before)e(PyT)-7
b(ype)p 2390 83 25 4 v 29 w(Ready)24 b(is)h(called;)h(it)f(may)e(also)i
(be)f(initialized)f(to)208 183 y(a)h(dictionary)f(containing)f(initial)
i(attrib)n(utes)g(for)g(the)g(type.)36 b(Once)24 b Fj(PyType_Ready\(\))
e Fr(has)j(initialized)f(the)g(type,)g(e)o(xtra)208 282
y(attrib)n(utes)h(for)g(the)g(type)g(may)h(be)f(added)f(to)i(this)g
(dictionary)e(only)h(if)g(the)o(y)g(don')o(t)f(correspond)f(to)j(o)o(v)
o(erloaded)c(operations)208 382 y(\(lik)o(e)e Fj(__add__\(\))p
Fr(\).)208 511 y(This)27 b(\002eld)g(is)i(not)d(inherited)g(by)h
(subtypes)g(\(though)e(the)i(attrib)n(utes)g(de\002ned)f(in)i(here)e
(are)i(inherited)d(through)h(a)h(dif)n(ferent)208 610
y(mechanism\).)0 757 y Fj(descrgetfunc)48 b Fg(tp_descr_get)208
857 y Fr(An)20 b(optional)f(pointer)g(to)h(a)h(\224descriptor)d
(get\224)i(function.)208 985 y(The)f(function)g(signature)g(is)444
1205 y Fk(PyObject)847 1218 y(*)937 1205 y(tp_descr_get\(PyObject)1923
1218 y(*)1968 1205 y(self,)44 b(PyObject)2641 1218 y(*)2686
1205 y(obj,)g(PyObject)3313 1218 y(*)3358 1205 y(type\);)208
1390 y Fr(XXX)20 b(blah,)g(blah.)208 1519 y(This)g(\002eld)g(is)h
(inherited)e(by)h(subtypes.)0 1666 y Fj(descrsetfunc)48
b Fg(tp_descr_set)208 1766 y Fr(An)20 b(optional)f(pointer)g(to)h(a)h
(\224descriptor)d(set\224)j(function.)208 1894 y(The)e(function)g
(signature)g(is)444 2114 y Fk(int)44 b(tp_descr_set\(PyObject)1609
2127 y(*)1654 2114 y(self,)g(PyObject)2327 2127 y(*)2372
2114 y(obj,)g(PyObject)2999 2127 y(*)3044 2114 y(value\);)208
2299 y Fr(This)20 b(\002eld)g(is)h(inherited)e(by)h(subtypes.)208
2428 y(XXX)g(blah,)g(blah.)0 2575 y Fj(long)49 b Fg(tp_dictoffset)208
2675 y Fr(If)23 b(the)h(instances)g(of)g(this)g(type)f(ha)n(v)o(e)h(a)g
(dictionary)e(containing)g(instance)h(v)n(ariables,)h(this)h(\002eld)f
(is)g(non-zero)e(and)h(contains)208 2774 y(the)h(of)n(fset)g(in)h(the)g
(instances)g(of)f(the)h(type)f(of)g(the)h(instance)f(v)n(ariable)g
(dictionary;)h(this)g(of)n(fset)g(is)g(used)g(by)f Fj(PyObject_-)208
2874 y(GenericGetAttr\(\))p Fr(.)208 3002 y(Do)c(not)g(confuse)f(this)h
(\002eld)h(with)f Fj(tp_dict)p Fr(;)g(that)g(is)h(the)f(dictionary)f
(for)g(attrib)n(utes)h(of)g(the)g(type)g(object)g(itself.)208
3131 y(If)h(the)g(v)n(alue)g(of)g(this)h(\002eld)g(is)g(greater)f(than)
g(zero,)g(it)h(speci\002es)g(the)f(of)n(fset)g(from)f(the)i(start)g(of)
f(the)g(instance)h(structure.)27 b(If)22 b(the)208 3231
y(v)n(alue)i(is)h(less)h(than)e(zero,)i(it)f(speci\002es)g(the)g(of)n
(fset)f(from)g(the)h Fo(end)f Fr(of)h(the)f(instance)h(structure.)38
b(A)25 b(ne)o(gati)n(v)o(e)d(of)n(fset)j(is)g(more)208
3330 y(e)o(xpensi)n(v)o(e)d(to)j(use,)g(and)f(should)f(only)h(be)g
(used)g(when)g(the)g(instance)g(structure)g(contains)g(a)g(v)n
(ariable-length)e(part.)37 b(This)25 b(is)208 3430 y(used)i(for)g(e)o
(xample)f(to)i(add)f(an)h(instance)f(v)n(ariable)f(dictionary)g(to)i
(subtypes)f(of)g Fj(str)h Fr(or)f Fj(tuple)p Fr(.)47
b(Note)27 b(that)h(the)g Fj(tp_-)208 3530 y(basicsize)18
b Fr(\002eld)i(should)f(account)g(for)g(the)h(dictionary)e(added)h(to)h
(the)f(end)h(in)g(that)g(case,)g(e)n(v)o(en)f(though)f(the)i
(dictionary)e(is)208 3629 y(not)k(included)g(in)h(the)h(basic)f(object)
g(layout.)33 b(On)23 b(a)g(system)h(with)f(a)h(pointer)e(size)i(of)e(4)
i(bytes,)f Fj(tp_dictoffset)f Fr(should)208 3729 y(be)e(set)h(to)f
Fj(-4)g Fr(to)h(indicate)e(that)i(the)f(dictionary)e(is)j(at)g(the)f(v)
o(ery)f(end)h(of)g(the)g(structure.)208 3857 y(The)f(real)i(dictionary)
d(of)n(fset)i(in)g(an)g(instance)g(can)g(be)g(computed)e(from)h(a)i(ne)
o(gati)n(v)o(e)d Fj(tp_dictoffset)g Fr(as)j(follo)n(ws:)444
4077 y Fk(dictoffset)43 b(=)i(tp_basicsize)d(+)j(abs\(ob_size\))2239
4090 y(*)2284 4077 y(tp_itemsize)c(+)k(tp_dictoffset)444
4169 y(if)f(dictoffset)f(is)i(not)f(aligned)g(on)g(sizeof\(void)2373
4182 y(*)2418 4169 y(\):)623 4260 y(round)g(up)h(to)f(sizeof\(void)1656
4273 y(*)1701 4260 y(\))208 4445 y Fr(where)25 b Fj(tp_basicsize)p
Fr(,)h Fj(tp_itemsize)f Fr(and)h Fj(tp_dictoffset)f Fr(are)h(tak)o(en)g
(from)f(the)i(type)f(object,)h(and)f Fj(ob_-)208 4545
y(size)k Fr(is)h(tak)o(en)g(from)e(the)i(instance.)56
b(The)30 b(absolute)g(v)n(alue)g(is)h(tak)o(en)f(because)g(long)g(ints)
h(use)g(the)f(sign)h(of)f Fj(ob_size)208 4645 y Fr(to)e(store)h(the)g
(sign)f(of)h(the)g(number)-5 b(.)49 b(\(There')-5 b(s)27
b(ne)n(v)o(er)h(a)h(need)f(to)h(do)f(this)h(calculation)f(yourself;)j
(it)f(is)f(done)f(for)g(you)g(by)208 4744 y Fj
(_PyObject_GetDictPtr\(\))p Fr(.\))208 4873 y(This)19
b(\002eld)h(is)g(inherited)e(by)h(subtypes,)g(b)n(ut)g(see)h(the)g
(rules)f(listed)h(belo)n(w)-5 b(.)23 b(A)d(subtype)f(may)g(o)o(v)o
(erride)e(this)j(of)n(fset;)f(this)h(means)208 4972 y(that)k(the)f
(subtype)g(instances)h(store)g(the)g(dictionary)e(at)i(a)h(dif)n
(ference)c(of)n(fset)j(than)f(the)h(base)g(type.)36 b(Since)24
b(the)g(dictionary)e(is)208 5072 y(al)o(w)o(ays)e(found)f(via)h
Fj(tp_dictoffset)p Fr(,)e(this)j(should)e(not)h(be)g(a)g(problem.)208
5201 y(When)25 b(a)h(type)f(de\002ned)g(by)g(a)h(class)g(statement)g
(has)g(no)f Fj(__slots__)f Fr(declaration,)h(and)g(none)g(of)g(its)i
(base)e(types)h(has)g(an)208 5300 y(instance)18 b(v)n(ariable)g
(dictionary)-5 b(,)16 b(a)j(dictionary)e(slot)j(is)g(added)d(to)i(the)g
(instance)f(layout)g(and)g(the)h Fj(tp_dictoffset)e Fr(is)j(set)f(to)
208 5400 y(that)h(slot')-5 b(s)21 b(of)n(fset.)p 0 5549
3901 4 v 0 5649 a Fn(10.3.)52 b(T)-10 b(ype)23 b(Objects)3046
b(111)p eop end
%%Page: 112 118
TeXDict begin 112 117 bop 208 83 a Fr(When)15 b(a)i(type)e(de\002ned)g
(by)h(a)g(class)h(statement)f(has)g(a)g Fj(__slots__)f
Fr(declaration,)g(the)h(type)g(inherits)f(its)i Fj(tp_dictoffset)208
183 y Fr(from)i(its)i(base)f(type.)208 310 y(\(Adding)27
b(a)i(slot)h(named)e Fj(__dict__)g Fr(to)h(the)g Fj(__slots__)f
Fr(declaration)f(does)i(not)f(ha)n(v)o(e)h(the)g(e)o(xpected)e(ef)n
(fect,)j(it)g(just)208 410 y(causes)20 b(confusion.)j(Maybe)c(this)i
(should)e(be)h(added)f(as)i(a)g(feature)e(just)i(lik)o(e)f
Fj(__weakref__)f Fr(though.\))0 557 y Fj(initproc)48
b Fg(tp_init)208 656 y Fr(An)20 b(optional)f(pointer)g(to)h(an)g
(instance)g(initialization)f(function.)208 784 y(This)i(function)e
(corresponds)f(to)j(the)g Fj(__init__\(\))e Fr(method)h(of)g(classes.)
28 b(Lik)o(e)21 b Fj(__init__\(\))p Fr(,)e(it)j(is)f(possible)g(to)g
(create)208 884 y(an)c(instance)h(without)f(calling)g
Fj(__init__\(\))p Fr(,)g(and)g(it)h(is)h(possible)f(to)g(reinitialize)f
(an)h(instance)f(by)g(calling)h(its)g Fj(__init_-)208
983 y(_\(\))i Fr(method)f(again.)208 1111 y(The)g(function)g(signature)
g(is)444 1330 y Fk(int)44 b(tp_init\(PyObject)1385 1343
y(*)1430 1330 y(self,)g(PyObject)2103 1343 y(*)2148 1330
y(args,)f(PyObject)2820 1343 y(*)2865 1330 y(kwds\))208
1514 y Fr(The)16 b(self)g(ar)o(gument)e(is)k(the)e(instance)g(to)g(be)h
(initialized;)g(the)f Fo(ar)m(gs)h Fr(and)f Fo(kwds)h
Fr(ar)o(guments)d(represent)h(positional)h(and)f(k)o(e)o(yw)o(ord)208
1614 y(ar)o(guments)j(of)i(the)g(call)g(to)h Fj(__init__\(\))p
Fr(.)208 1741 y(The)j Fj(tp_init)g Fr(function,)g(if)h(not)f
Fj(NULL)p Fr(,)h(is)h(called)e(when)g(an)h(instance)f(is)i(created)e
(normally)f(by)i(calling)f(its)i(type,)f(after)208 1841
y(the)19 b(type')-5 b(s)19 b Fj(tp_new)g Fr(function)e(has)j(returned)d
(an)i(instance)g(of)g(the)h(type.)k(If)19 b(the)g Fj(tp_new)g
Fr(function)e(returns)i(an)g(instance)g(of)208 1940 y(some)f(other)g
(type)g(that)h(is)h(not)e(a)h(subtype)f(of)g(the)h(original)e(type,)i
(no)f Fj(tp_init)g Fr(function)f(is)j(called;)f(if)g
Fj(tp_new)f Fr(returns)g(an)208 2040 y(instance)h(of)h(a)h(subtype)e
(of)g(the)i(original)e(type,)g(the)h(subtype')-5 b(s)19
b Fj(tp_init)h Fr(is)h(called.)j(\(VERSION)d(NO)m(TE:)e(described)g
(here)208 2140 y(is)g(what)g(is)h(implemented)d(in)i(Python)f(2.2.1)f
(and)h(later)-5 b(.)25 b(In)19 b(Python)f(2.2,)g(the)h
Fj(tp_init)f Fr(of)g(the)h(type)g(of)f(the)h(object)f(returned)208
2239 y(by)h Fj(tp_new)h Fr(w)o(as)h(al)o(w)o(ays)g(called,)e(if)i(not)f
Fj(NULL)p Fr(.\))208 2367 y(This)g(\002eld)g(is)h(inherited)e(by)h
(subtypes.)0 2514 y Fj(allocfunc)48 b Fg(tp_alloc)208
2613 y Fr(An)20 b(optional)f(pointer)g(to)h(an)g(instance)g(allocation)
f(function.)208 2741 y(The)g(function)g(signature)g(is)444
2960 y Fk(PyObject)847 2973 y(*)892 2960 y(tp_alloc\(PyTypeObject)1878
2973 y(*)1923 2960 y(self,)44 b(Py_ssize_t)f(nitems\))208
3144 y Fr(The)26 b(purpose)f(of)h(this)h(function)e(is)j(to)f(separate)
f(memory)f(allocation)g(from)h(memory)f(initialization.)43
b(It)27 b(should)f(return)f(a)208 3244 y(pointer)c(to)i(a)g(block)e(of)
h(memory)f(of)h(adequate)g(length)f(for)h(the)h(instance,)f(suitably)g
(aligned,)g(and)g(initialized)g(to)h(zeros,)g(b)n(ut)208
3343 y(with)g Fj(ob_refcnt)f Fr(set)i(to)f Fj(1)g Fr(and)g
Fj(ob_type)f Fr(set)i(to)f(the)h(type)e(ar)o(gument.)31
b(If)23 b(the)h(type')-5 b(s)23 b Fj(tp_itemsize)e Fr(is)j(non-zero,)
208 3443 y(the)19 b(object')-5 b(s)19 b Fj(ob_size)g
Fr(\002eld)h(should)e(be)i(initialized)f(to)h Fo(nitems)g
Fr(and)f(the)g(length)g(of)g(the)g(allocated)g(memory)f(block)h(should)
208 3543 y(be)k Fj(tp_basicsize)47 b(+)j Fo(nitems)1274
3558 y Fj(*)1324 3543 y(tp_itemsize)p Fr(,)21 b(rounded)g(up)i(to)g(a)h
(multiple)e(of)h Fj(sizeof\(void)3411 3558 y(*)3461 3543
y(\))p Fr(;)f(otherwise,)208 3642 y Fo(nitems)e Fr(is)h(not)f(used)g
(and)g(the)g(length)f(of)h(the)g(block)f(should)h(be)g
Fj(tp_basicsize)p Fr(.)208 3770 y(Do)27 b(not)h(use)g(this)h(function)d
(to)i(do)f(an)o(y)g(other)g(instance)h(initialization,)h(not)e(e)n(v)o
(en)g(to)h(allocate)g(additional)e(memory;)k(that)208
3869 y(should)19 b(be)h(done)f(by)h Fj(tp_new)p Fr(.)208
3997 y(This)e(\002eld)g(is)h(inherited)d(by)i(static)h(subtypes,)e(b)n
(ut)h(not)f(by)h(dynamic)e(subtypes)h(\(subtypes)g(created)g(by)h(a)g
(class)h(statement\);)f(in)208 4097 y(the)i(latter)m(,)g(this)h
(\002eld)f(is)h(al)o(w)o(ays)g(set)g(to)g Fj(PyType_GenericAlloc\(\))p
Fr(,)16 b(to)21 b(force)e(a)i(standard)e(heap)h(allocation)f(strate)o
(gy)-5 b(.)208 4196 y(That)19 b(is)j(also)e(the)g(recommended)d(v)n
(alue)j(for)f(statically)i(de\002ned)e(types.)0 4343
y Fj(newfunc)49 b Fg(tp_new)208 4443 y Fr(An)20 b(optional)f(pointer)g
(to)h(an)g(instance)g(creation)f(function.)208 4570 y(If)26
b(this)h(function)e(is)i Fj(NULL)f Fr(for)g(a)h(particular)e(type,)i
(that)g(type)f(cannot)f(be)i(called)f(to)h(create)f(ne)n(w)g
(instances;)k(presumably)208 4670 y(there)19 b(is)i(some)f(other)g(w)o
(ay)g(to)g(create)g(instances,)g(lik)o(e)h(a)f(f)o(actory)f(function.)
208 4797 y(The)g(function)g(signature)g(is)444 5016 y
Fk(PyObject)847 5029 y(*)892 5016 y(tp_new\(PyTypeObject)1789
5029 y(*)1834 5016 y(subtype,)43 b(PyObject)2641 5029
y(*)2686 5016 y(args,)g(PyObject)3358 5029 y(*)3403 5016
y(kwds\))208 5201 y Fr(The)20 b(subtype)g(ar)o(gument)e(is)k(the)f
(type)f(of)h(the)g(object)f(being)g(created;)g(the)h
Fo(ar)m(gs)g Fr(and)g Fo(kwds)g Fr(ar)o(guments)e(represent)g
(positional)208 5300 y(and)f(k)o(e)o(yw)o(ord)f(ar)o(guments)g(of)i
(the)g(call)h(to)f(the)g(type.)24 b(Note)c(that)f(subtype)f(doesn')o(t)
f(ha)n(v)o(e)i(to)g(equal)g(the)g(type)f(whose)h Fj(tp_new)208
5400 y Fr(function)f(is)j(called;)f(it)h(may)f(be)g(a)h(subtype)e(of)h
(that)g(type)g(\(b)n(ut)f(not)h(an)g(unrelated)f(type\).)p
0 5549 3901 4 v 0 5649 a Fn(112)2106 b(Chapter)23 b(10.)52
b(Object)23 b(Implementation)j(Suppor)s(t)p eop end
%%Page: 113 119
TeXDict begin 113 118 bop 208 83 a Fr(The)26 b Fj(tp_new)f
Fr(function)g(should)g(call)i Fo(subtype)p Fj(->tp_alloc\()p
Fo(subtype)p Fj(,)45 b Fo(nitems)p Fj(\))26 b Fr(to)h(allocate)f(space)
g(for)g(the)g(object,)208 183 y(and)16 b(then)g(do)g(only)g(as)i(much)d
(further)h(initialization)g(as)h(is)h(absolutely)d(necessary)-5
b(.)23 b(Initialization)16 b(that)h(can)f(safely)h(be)f(ignored)208
282 y(or)24 b(repeated)g(should)g(be)g(placed)g(in)h(the)g
Fj(tp_init)f Fr(handler)-5 b(.)38 b(A)26 b(good)d(rule)i(of)f(thumb)g
(is)i(that)f(for)f(immutable)f(types,)j(all)208 382 y(initialization)e
(should)g(tak)o(e)h(place)g(in)g Fj(tp_new)p Fr(,)h(while)f(for)f
(mutable)h(types,)h(most)f(initialization)f(should)g(be)h(deferred)e
(to)208 482 y Fj(tp_init)p Fr(.)208 610 y(This)33 b(\002eld)h(is)g
(inherited)e(by)i(subtypes,)h(e)o(xcept)e(it)h(is)g(not)f(inherited)g
(by)g(static)h(types)f(whose)g Fj(tp_base)g Fr(is)i Fj(NULL)e
Fr(or)208 710 y Fj(&PyBaseObject_Type)p Fr(.)63 b(The)34
b(latter)g(e)o(xception)e(is)j(a)g(precaution)d(so)i(that)g(old)g(e)o
(xtension)f(types)g(don')o(t)g(become)208 809 y(callable)20
b(simply)f(by)h(being)f(link)o(ed)h(with)g(Python)f(2.2.)0
956 y Fj(destructor)48 b Fg(tp_free)208 1056 y Fr(An)20
b(optional)f(pointer)g(to)h(an)g(instance)g(deallocation)e(function.)
208 1184 y(The)h(signature)h(of)f(this)i(function)e(has)h(changed)e
(slightly:)25 b(in)c(Python)e(2.2)g(and)h(2.2.1,)e(its)k(signature)d
(is)i Fj(destructor)p Fr(:)444 1404 y Fk(void)44 b(tp_free\(PyObject)
1430 1417 y(*)1475 1404 y(\))208 1590 y Fr(In)19 b(Python)h(2.3)f(and)h
(be)o(yond,)d(its)22 b(signature)d(is)i Fj(freefunc)p
Fr(:)444 1809 y Fk(void)44 b(tp_free\(void)1251 1822
y(*)1296 1809 y(\))208 1995 y Fr(The)24 b(only)f(initializer)h(that)h
(is)g(compatible)e(with)i(both)e(v)o(ersions)h(is)h Fj(_PyObject_Del)p
Fr(,)e(whose)h(de\002nition)f(has)i(suitably)208 2094
y(adapted)19 b(in)h(Python)f(2.3.)208 2223 y(This)k(\002eld)g(is)g
(inherited)f(by)g(static)i(subtypes,)f(b)n(ut)f(not)h(by)f(dynamic)g
(subtypes)g(\(subtypes)f(created)i(by)f(a)h(class)h(statement\);)208
2322 y(in)f(the)h(latter)m(,)g(this)g(\002eld)g(is)h(set)f(to)g(a)g
(deallocator)e(suitable)i(to)g(match)f Fj(PyType_GenericAlloc\(\))d
Fr(and)j(the)h(v)n(alue)f(of)208 2422 y(the)d Fj(Py_TPFLAGS_HAVE_GC)d
Fr(\003ag)j(bit.)0 2569 y Fj(inquiry)49 b Fg(tp_is_gc)208
2669 y Fr(An)20 b(optional)f(pointer)g(to)h(a)h(function)d(called)i(by)
g(the)g(garbage)e(collector)-5 b(.)208 2797 y(The)22
b(garbage)f(collector)h(needs)g(to)h(kno)n(w)f(whether)g(a)h
(particular)f(object)g(is)i(collectible)f(or)f(not.)33
b(Normally)-5 b(,)22 b(it)h(is)h(suf)n(\002cient)208
2897 y(to)k(look)f(at)i(the)f(object')-5 b(s)29 b(type')-5
b(s)28 b Fj(tp_flags)f Fr(\002eld,)j(and)e(check)f(the)i
Fj(Py_TPFLAGS_HAVE_GC)c Fr(\003ag)k(bit.)49 b(But)29
b(some)208 2996 y(types)20 b(ha)n(v)o(e)g(a)h(mixture)e(of)i
(statically)g(and)f(dynamically)e(allocated)i(instances,)h(and)f(the)g
(statically)h(allocated)f(instances)h(are)208 3096 y(not)g
(collectible.)31 b(Such)22 b(types)g(should)f(de\002ne)g(this)i
(function;)f(it)h(should)e(return)g Fj(1)h Fr(for)g(a)h(collectible)e
(instance,)h(and)g Fj(0)h Fr(for)e(a)208 3196 y(non-collectible)c
(instance.)25 b(The)20 b(signature)f(is)444 3416 y Fk(int)44
b(tp_is_gc\(PyObject)1430 3429 y(*)1475 3416 y(self\))208
3601 y Fr(\(The)19 b(only)h(e)o(xample)f(of)h(this)i(are)e(types)g
(themselv)o(es.)26 b(The)20 b(metatype,)f Fj(PyType_Type)p
Fr(,)g(de\002nes)h(this)h(function)e(to)i(distin-)208
3700 y(guish)e(between)h(statically)g(and)g(dynamically)e(allocated)h
(types.\))208 3829 y(This)f(\002eld)g(is)i(inherited)d(by)h(subtypes.)
23 b(\(VERSION)18 b(NO)m(TE:)g(in)h(Python)e(2.2,)h(it)h(w)o(as)g(not)f
(inherited.)23 b(It)18 b(is)i(inherited)d(in)h(2.2.1)208
3929 y(and)h(later)h(v)o(ersions.\))0 4076 y Fj(PyObject)400
4091 y(*)498 4076 y Fg(tp_bases)208 4175 y Fr(T)l(uple)f(of)h(base)g
(types.)208 4304 y(This)g(is)h(set)g(for)f(types)g(created)f(by)h(a)g
(class)i(statement.)i(It)d(should)e(be)h Fj(NULL)g Fr(for)g(statically)
g(de\002ned)f(types.)208 4432 y(This)h(\002eld)g(is)h(not)f(inherited.)
0 4579 y Fj(PyObject)400 4594 y(*)498 4579 y Fg(tp_mro)208
4679 y Fr(T)l(uple)30 b(containing)f(the)i(e)o(xpanded)e(set)j(of)f
(base)g(types,)i(starting)e(with)g(the)h(type)e(itself)i(and)e(ending)g
(with)h Fj(object)p Fr(,)i(in)208 4778 y(Method)19 b(Resolution)g
(Order)-5 b(.)208 4907 y(This)20 b(\002eld)g(is)h(not)f(inherited;)f
(it)i(is)g(calculated)f(fresh)f(by)h Fj(PyType_Ready\(\))p
Fr(.)0 5054 y Fj(PyObject)400 5069 y(*)498 5054 y Fg(tp_cache)208
5154 y Fr(Unused.)k(Not)c(inherited.)k(Internal)19 b(use)h(only)-5
b(.)0 5300 y Fj(PyObject)400 5315 y(*)498 5300 y Fg(tp_subclasses)208
5400 y Fr(List)20 b(of)g(weak)g(references)f(to)h(subclasses.)26
b(Not)20 b(inherited.)k(Internal)19 b(use)h(only)-5 b(.)p
0 5549 3901 4 v 0 5649 a Fn(10.3.)52 b(T)-10 b(ype)23
b(Objects)3046 b(113)p eop end
%%Page: 114 120
TeXDict begin 114 119 bop 0 83 a Fj(PyObject)400 98 y(*)498
83 y Fg(tp_weaklist)208 183 y Fr(W)-7 b(eak)20 b(reference)f(list)i
(head,)e(for)h(weak)g(references)f(to)h(this)h(type)e(object.)25
b(Not)20 b(inherited.)k(Internal)19 b(use)h(only)-5 b(.)0
330 y(The)24 b(remaining)f(\002elds)i(are)g(only)f(de\002ned)f(if)i
(the)g(feature)f(test)h(macro)f Fj(COUNT_ALLOCS)f Fr(is)i(de\002ned,)g
(and)f(are)g(for)g(internal)g(use)0 429 y(only)-5 b(.)24
b(The)o(y)19 b(are)h(documented)e(here)h(for)h(completeness.)k(None)19
b(of)h(these)g(\002elds)h(are)f(inherited)f(by)h(subtypes.)0
576 y Fj(Py_ssize_t)48 b Fg(tp_allocs)208 676 y Fr(Number)18
b(of)i(allocations.)0 823 y Fj(Py_ssize_t)48 b Fg(tp_frees)208
922 y Fr(Number)18 b(of)i(frees.)0 1069 y Fj(Py_ssize_t)48
b Fg(tp_maxalloc)208 1169 y Fr(Maximum)18 b(simultaneously)h(allocated)
g(objects.)0 1316 y Fj(PyTypeObject)600 1331 y(*)697
1316 y Fg(tp_next)208 1415 y Fr(Pointer)g(to)i(the)f(ne)o(xt)f(type)h
(object)g(with)g(a)h(non-zero)c Fj(tp_allocs)i Fr(\002eld.)0
1562 y(Also,)26 b(note)e(that,)h(in)g(a)g(garbage)e(collected)h
(Python,)g(tp)p 1660 1562 25 4 v 29 w(dealloc)g(may)g(be)h(called)f
(from)g(an)o(y)g(Python)f(thread,)i(not)f(just)h(the)g(thread)0
1662 y(which)g(created)g(the)g(object)g(\(if)g(the)h(object)f(becomes)f
(part)h(of)g(a)h(refcount)e(c)o(ycle,)i(that)f(c)o(ycle)g(might)g(be)g
(collected)g(by)g(a)h(garbage)0 1761 y(collection)d(on)g(an)o(y)g
(thread\).)35 b(This)24 b(is)g(not)g(a)g(problem)e(for)h(Python)g(API)h
(calls,)h(since)f(the)g(thread)f(on)g(which)g(tp)p 3333
1761 V 30 w(dealloc)g(is)i(called)0 1861 y(will)31 b(o)n(wn)e(the)h
(Global)f(Interpreter)f(Lock)h(\(GIL\).)f(Ho)n(we)n(v)o(er)m(,)i(if)h
(the)e(object)h(being)e(destro)o(yed)h(in)h(turn)f(destro)o(ys)g
(objects)h(from)0 1961 y(some)23 b(other)f(C)h(or)g(C)619
1954 y(++)736 1961 y(library)-5 b(,)22 b(care)h(should)e(be)i(tak)o(en)
f(to)h(ensure)f(that)h(destro)o(ying)e(those)i(objects)f(on)h(the)g
(thread)e(which)i(called)0 2060 y(tp)p 70 2060 V 29 w(dealloc)d(will)h
(not)f(violate)g(an)o(y)f(assumptions)g(of)h(the)g(library)-5
b(.)0 2381 y Fl(10.4)121 b(Mapping)35 b(Object)f(Str)r(uctures)0
2592 y Fg(PyMappingMethods)208 2692 y Fr(Structure)19
b(used)h(to)g(hold)f(pointers)h(to)g(the)g(functions)f(used)h(to)g
(implement)f(the)h(mapping)f(protocol)f(for)i(an)g(e)o(xtension)e
(type.)0 3012 y Fl(10.5)121 b(Number)35 b(Object)e(Str)r(uctures)0
3224 y Fg(PyNumberMethods)208 3323 y Fr(Structure)19
b(used)h(to)g(hold)f(pointers)h(to)g(the)g(functions)f(an)h(e)o
(xtension)f(type)g(uses)i(to)g(implement)d(the)j(number)d(protocol.)0
3644 y Fl(10.6)121 b(Sequence)36 b(Object)d(Str)r(uctures)0
3855 y Fg(PySequenceMethods)208 3955 y Fr(Structure)19
b(used)h(to)g(hold)f(pointers)h(to)g(the)g(functions)f(which)h(an)g
(object)f(uses)i(to)f(implement)f(the)i(sequence)e(protocol.)0
4276 y Fl(10.7)121 b(Buff)l(er)35 b(Object)f(Str)r(uctures)0
4509 y Fr(The)18 b(b)n(uf)n(fer)e(interf)o(ace)i(e)o(xports)e(a)j
(model)e(where)g(an)h(object)g(can)g(e)o(xpose)f(its)i(internal)e(data)
h(as)h(a)f(set)h(of)f(chunks)f(of)g(data,)h(where)g(each)0
4608 y(chunk)i(is)j(speci\002ed)f(as)h(a)f(pointer/length)e(pair)-5
b(.)30 b(These)22 b(chunks)e(are)i(called)g Fo(se)m(gments)g
Fr(and)f(are)h(presumed)e(to)j(be)e(non-contiguous)0
4708 y(in)f(memory)-5 b(.)0 4855 y(If)20 b(an)h(object)f(does)g(not)g
(e)o(xport)f(the)i(b)n(uf)n(fer)e(interf)o(ace,)h(then)g(its)h
Fj(tp_as_buffer)e Fr(member)g(in)i(the)g Fj(PyTypeObject)e
Fr(structure)0 4954 y(should)g(be)h Fj(NULL)p Fr(.)g(Otherwise,)g(the)g
Fj(tp_as_buffer)f Fr(will)h(point)g(to)g(a)h Fj(PyBufferProcs)d
Fr(structure.)0 5101 y Fp(Note:)32 b Fr(It)25 b(is)g(v)o(ery)e
(important)f(that)j(your)e Fj(PyTypeObject)f Fr(structure)h(uses)i
Fj(Py_TPFLAGS_DEFAULT)c Fr(for)j(the)g(v)n(alue)g(of)g(the)0
5201 y Fj(tp_flags)d Fr(member)g(rather)g(than)h Fj(0)p
Fr(.)31 b(This)22 b(tells)h(the)f(Python)f(runtime)g(that)h(your)f
Fj(PyBufferProcs)f Fr(structure)h(contains)h(the)0 5300
y Fj(bf_getcharbuffer)16 b Fr(slot.)25 b(Older)18 b(v)o(ersions)g(of)g
(Python)g(did)g(not)g(ha)n(v)o(e)g(this)h(member)m(,)e(so)i(a)g(ne)n(w)
f(Python)g(interpreter)f(using)h(an)0 5400 y(old)i(e)o(xtension)f
(needs)g(to)i(be)f(able)g(to)g(test)h(for)f(its)h(presence)e(before)g
(using)h(it.)p 0 5549 3901 4 v 0 5649 a Fn(114)2106 b(Chapter)23
b(10.)52 b(Object)23 b(Implementation)j(Suppor)s(t)p
eop end
%%Page: 115 121
TeXDict begin 115 120 bop 0 83 a Fg(PyBufferProcs)208
183 y Fr(Structure)19 b(used)h(to)g(hold)f(the)i(function)d(pointers)h
(which)h(de\002ne)g(an)g(implementation)e(of)i(the)g(b)n(uf)n(fer)f
(protocol.)208 315 y(The)i(\002rst)h(slot)h(is)f Fj(bf_getreadbuffer)p
Fr(,)e(of)h(type)h Fj(getreadbufferproc)p Fr(.)27 b(If)21
b(this)i(slot)f(is)h Fj(NULL)p Fr(,)e(then)g(the)h(object)208
415 y(does)j(not)h(support)e(reading)g(from)h(the)h(internal)f(data.)42
b(This)26 b(is)h(non-sensical,)e(so)h(implementors)e(should)h(\002ll)i
(this)f(in,)i(b)n(ut)208 515 y(callers)20 b(should)f(test)i(that)g(the)
f(slot)g(contains)g(a)h(non-)p Fj(NULL)d Fr(v)n(alue.)208
648 y(The)g(ne)o(xt)g(slot)h(is)g Fj(bf_getwritebuffer)d
Fr(ha)n(ving)i(type)g Fj(getwritebufferproc)p Fr(.)k(This)c(slot)i(may)
e(be)g Fj(NULL)h Fr(if)g(the)208 747 y(object)g(does)h(not)g(allo)n(w)g
(writing)g(into)g(its)h(returned)d(b)n(uf)n(fers.)208
880 y(The)g(third)g(slot)h(is)h Fj(bf_getsegcount)p Fr(,)d(with)h(type)
h Fj(getsegcountproc)p Fr(.)j(This)d(slot)g(must)g(not)f(be)h
Fj(NULL)f Fr(and)g(is)i(used)208 980 y(to)26 b(inform)f(the)i(caller)f
(ho)n(w)g(man)o(y)f(se)o(gments)h(the)h(object)f(contains.)43
b(Simple)26 b(objects)g(such)g(as)i Fj(PyString_Type)c
Fr(and)208 1079 y Fj(PyBuffer_Type)18 b Fr(objects)i(contain)f(a)i
(single)f(se)o(gment.)208 1212 y(The)35 b(last)i(slot)f(is)h
Fj(bf_getcharbuffer)p Fr(,)g(of)e(type)h Fj(getcharbufferproc)p
Fr(.)69 b(This)36 b(slot)g(will)h(only)e(be)g(present)208
1312 y(if)44 b(the)g Fj(Py_TPFLAGS_HAVE_GETCHARBUFFER)39
b Fr(\003ag)44 b(is)h(present)e(in)i(the)f Fj(tp_flags)f
Fr(\002eld)h(of)g(the)g(object')-5 b(s)208 1411 y Fj(PyTypeObject)p
Fr(.)35 b(Before)24 b(using)g(this)h(slot,)h(the)e(caller)g(should)g
(test)h(whether)e(it)i(is)h(present)d(by)h(using)g(the)g
Fj(PyType_-)208 1511 y(HasFeature\(\))j Fr(function.)48
b(If)29 b(the)f(\003ag)h(is)h(present,)f Fj(bf_getcharbuffer)e
Fr(may)h(be)g Fj(NULL)p Fr(,)h(indicating)e(that)i(the)208
1611 y(object')-5 b(s)26 b(contents)f(cannot)g(be)h(used)g(as)h
Fo(8-bit)e(c)o(har)o(acter)o(s)p Fr(.)43 b(The)25 b(slot)i(function)d
(may)i(also)h(raise)f(an)g(error)f(if)i(the)f(object')-5
b(s)208 1710 y(contents)26 b(cannot)f(be)i(interpreted)e(as)j(8-bit)e
(characters.)44 b(F)o(or)26 b(e)o(xample,)h(if)g(the)g(object)f(is)i
(an)f(array)f(which)g(is)i(con\002gured)208 1810 y(to)c(hold)f
(\003oating)g(point)g(v)n(alues,)h(an)g(e)o(xception)d(may)j(be)g
(raised)f(if)h(a)h(caller)e(attempts)h(to)g(use)g Fj(bf_getcharbuffer)d
Fr(to)208 1910 y(fetch)e(a)h(sequence)e(of)h(8-bit)g(characters.)24
b(This)c(notion)e(of)h(e)o(xporting)e(the)j(internal)e(b)n(uf)n(fers)h
(as)h(\223te)o(xt\224)f(is)i(used)e(to)h(distinguish)208
2009 y(between)f(objects)h(that)g(are)g(binary)f(in)i(nature,)e(and)g
(those)h(which)g(ha)n(v)o(e)f(character)n(-based)f(content.)208
2142 y Fp(Note:)28 b Fr(The)21 b(current)g(polic)o(y)g(seems)h(to)g
(state)h(that)f(these)g(characters)f(may)h(be)g(multi-byte)e
(characters.)30 b(This)22 b(implies)g(that)g(a)208 2242
y(b)n(uf)n(fer)c(size)j(of)f Fo(N)26 b Fr(does)20 b(not)g(mean)g(there)
f(are)h Fo(N)27 b Fr(characters)19 b(present.)0 2388
y Fg(Py_TPFLAGS_HAVE_GETCHARBUFFER)208 2488 y Fr(Flag)j(bit)g(set)h(in)
g(the)f(type)g(structure)f(to)h(indicate)g(that)g(the)g
Fj(bf_getcharbuffer)e Fr(slot)j(is)g(kno)n(wn.)29 b(This)23
b(being)e(set)i(does)208 2588 y(not)c(indicate)h(that)g(the)h(object)e
(supports)g(the)h(b)n(uf)n(fer)f(interf)o(ace)h(or)g(that)g(the)g
Fj(bf_getcharbuffer)e Fr(slot)j(is)g(non-)p Fj(NULL)p
Fr(.)0 2735 y Fg(Py_ssize_t)48 b(\()598 2748 y(*)648
2735 y(readbufferproc\))f(\(PyObject)1943 2748 y(*)1993
2735 y(self,)h(Py_ssize_t)g(segment,)h(void)3537 2748
y(**)3637 2735 y(ptrptr\))208 2834 y Fr(Return)22 b(a)h(pointer)f(to)g
(a)i(readable)d(se)o(gment)h(of)g(the)h(b)n(uf)n(fer)f(in)2055
2849 y Fj(*)2105 2834 y Fo(ptrptr)r Fr(.)32 b(This)23
b(function)e(is)j(allo)n(wed)e(to)h(raise)g(an)g(e)o(xception,)208
2934 y(in)e(which)h(case)g(it)g(must)g(return)e Fj(-1)p
Fr(.)30 b(The)21 b Fo(se)m(gment)h Fr(which)g(is)g(speci\002ed)g(must)f
(be)h(zero)f(or)g(positi)n(v)o(e,)g(and)g(strictly)h(less)h(than)208
3033 y(the)e(number)e(of)j(se)o(gments)e(returned)g(by)h(the)g
Fj(bf_getsegcount)e Fr(slot)j(function.)27 b(On)21 b(success,)h(it)h
(returns)d(the)h(length)g(of)208 3133 y(the)f(se)o(gment,)f(and)g(sets)
933 3148 y Fj(*)983 3133 y Fo(ptrptr)j Fr(to)e(a)h(pointer)e(to)h(that)
g(memory)-5 b(.)0 3280 y Fg(Py_ssize_t)48 b(\()598 3293
y(*)648 3280 y(writebufferproc\))e(\(PyObject)1993 3293
y(*)2043 3280 y(self,)i(Py_ssize_t)g(segment,)g(void)3587
3293 y(**)3687 3280 y(ptrptr\))208 3380 y Fr(Return)23
b(a)i(pointer)e(to)h(a)h(writable)e(memory)g(b)n(uf)n(fer)g(in)1842
3395 y Fj(*)1892 3380 y Fo(ptrptr)r Fr(,)i(and)f(the)g(length)f(of)h
(that)g(se)o(gment)f(as)i(the)f(function)f(return)208
3479 y(v)n(alue.)h(The)c(memory)f(b)n(uf)n(fer)g(must)h(correspond)e
(to)i(b)n(uf)n(fer)f(se)o(gment)g Fo(se)m(gment)q Fr(.)25
b(Must)c(return)e Fj(-1)i Fr(and)e(set)i(an)g(e)o(xception)d(on)208
3579 y(error)-5 b(.)29 b Fj(TypeError)21 b Fr(should)g(be)h(raised)g
(if)g(the)g(object)g(only)f(supports)g(read-only)e(b)n(uf)n(fers,)j
(and)f Fj(SystemError)g Fr(should)208 3678 y(be)f(raised)g(when)f
Fo(se)m(gment)i Fr(speci\002es)g(a)g(se)o(gment)e(that)h(doesn')o(t)f
(e)o(xist.)0 3825 y Fg(Py_ssize_t)48 b(\()598 3838 y(*)648
3825 y(segcountproc\))f(\(PyObject)1843 3838 y(*)1893
3825 y(self,)i(Py_ssize_t)2740 3838 y(*)2790 3825 y(lenp\))208
3925 y Fr(Return)25 b(the)g(number)f(of)h(memory)e(se)o(gments)i(which)
g(comprise)f(the)i(b)n(uf)n(fer)-5 b(.)40 b(If)25 b Fo(lenp)g
Fr(is)h(not)f Fj(NULL)p Fr(,)g(the)h(implementation)208
4025 y(must)20 b(report)f(the)h(sum)g(of)g(the)g(sizes)h(\(in)f
(bytes\))g(of)g(all)h(se)o(gments)e(in)2229 4040 y Fj(*)2279
4025 y Fo(lenp)p Fr(.)24 b(The)c(function)e(cannot)h(f)o(ail.)0
4171 y Fg(Py_ssize_t)48 b(\()598 4184 y(*)648 4171 y(charbufferproc\))f
(\(PyObject)1943 4184 y(*)1993 4171 y(self,)h(Py_ssize_t)g(segment,)h
(const)g(char)3836 4184 y(**)3936 4171 y(ptrptr\))208
4271 y Fr(Return)20 b(the)i(size)g(of)f(the)g(se)o(gment)g
Fo(se)m(gment)h Fr(that)f Fo(ptrptr)j Fr(is)e(set)g(to.)2204
4286 y Fj(*)2254 4271 y Fo(ptrptr)h Fr(is)f(set)g(to)g(the)f(memory)f
(b)n(uf)n(fer)-5 b(.)27 b(Returns)21 b Fj(-1)h Fr(on)208
4371 y(error)-5 b(.)0 4698 y Fl(10.8)121 b(Suppor)5 b(ting)35
b(the)g(Iter)o(ator)g(Protocol)0 4981 y(10.9)121 b(Suppor)5
b(ting)35 b(Cyclic)d(Garbage)k(Collection)0 5214 y Fr(Python')-5
b(s)20 b(support)f(for)h(detecting)f(and)h(collecting)g(garbage)f
(which)h(in)m(v)n(olv)o(es)f(circular)h(references)f(requires)g
(support)h(from)f(object)0 5313 y(types)j(which)h(are)f
(\223containers\224)f(for)h(other)g(objects)h(which)f(may)g(also)h(be)f
(containers.)31 b(T)-7 b(ypes)23 b(which)f(do)g(not)h(store)f
(references)f(to)p 0 5549 3901 4 v 0 5649 a Fn(10.8.)52
b(Suppor)s(ting)25 b(the)f(Iter)o(ator)f(Protocol)2370
b(115)p eop end
%%Page: 116 122
TeXDict begin 116 121 bop 0 83 a Fr(other)20 b(objects,)h(or)f(which)h
(only)f(store)h(references)e(to)i(atomic)g(types)g(\(such)f(as)i
(numbers)d(or)i(strings\),)f(do)h(not)f(need)g(to)h(pro)o(vide)e(an)o
(y)0 183 y(e)o(xplicit)h(support)e(for)i(garbage)e(collection.)0
330 y(An)24 b(e)o(xample)e(sho)n(wing)h(the)h(use)g(of)g(these)g
(interf)o(aces)f(can)h(be)g(found)e(in)i(\223Supporting)e(the)i(Cycle)g
(Collector\224)f(in)h Fo(Extending)e(and)0 429 y(Embedding)c(the)i
(Python)f(Interpr)m(eter)p Fr(.)0 576 y(T)-7 b(o)26 b(create)f(a)h
(container)e(type,)i(the)g Fj(tp_flags)e Fr(\002eld)i(of)f(the)h(type)f
(object)g(must)g(include)g(the)g Fj(Py_TPFLAGS_HAVE_GC)e
Fr(and)0 676 y(pro)o(vide)c(an)i(implementation)d(of)j(the)g
Fj(tp_traverse)e Fr(handler)-5 b(.)26 b(If)21 b(instances)g(of)f(the)h
(type)f(are)h(mutable,)f(a)h Fj(tp_clear)f Fr(imple-)0
775 y(mentation)f(must)h(also)h(be)f(pro)o(vided.)0 922
y Fg(Py_TPFLAGS_HAVE_GC)208 1022 y Fr(Objects)28 b(with)g(a)h(type)f
(with)g(this)h(\003ag)f(set)h(must)f(conform)e(with)i(the)h(rules)f
(documented)d(here.)48 b(F)o(or)28 b(con)m(v)o(enience)d(these)208
1121 y(objects)20 b(will)g(be)h(referred)d(to)i(as)h(container)e
(objects.)0 1268 y(Constructors)g(for)h(container)e(types)i(must)h
(conform)d(to)i(tw)o(o)g(rules:)104 1469 y(1.)41 b(The)19
b(memory)g(for)g(the)i(object)e(must)i(be)f(allocated)f(using)h
Fj(PyObject_GC_New\(\))d Fr(or)j Fj(PyObject_GC_VarNew\(\))p
Fr(.)104 1623 y(2.)41 b(Once)22 b(all)g(the)h(\002elds)f(which)g(may)g
(contain)f(references)g(to)h(other)g(containers)f(are)h(initialized,)g
(it)h(must)f(call)h Fj(PyObject_-)208 1723 y(GC_Track\(\))p
Fr(.)0 1876 y Fo(TYPE)196 1891 y Fj(*)295 1876 y Fg(PyObject_GC_New)p
Fj(\()p Fo(TYPE,)18 b(PyT)-6 b(ypeObject)19 b(*type)p
Fj(\))208 1976 y Fr(Analogous)f(to)i Fj(PyObject_New\(\))f
Fr(b)n(ut)h(for)f(container)g(objects)h(with)g(the)g
Fj(Py_TPFLAGS_HAVE_GC)e Fr(\003ag)i(set.)0 2123 y Fo(TYPE)196
2138 y Fj(*)295 2123 y Fg(PyObject_GC_NewVar)p Fj(\()p
Fo(TYPE,)d(PyT)-6 b(ypeObject)19 b(*type)o(,)g(Py)p 2275
2123 25 4 v 30 w(ssize)p 2461 2123 V 31 w(t)h(size)p
Fj(\))208 2222 y Fr(Analogous)e(to)i Fj(PyObject_NewVar\(\))e
Fr(b)n(ut)i(for)g(container)e(objects)i(with)h(the)f
Fj(Py_TPFLAGS_HAVE_GC)d Fr(\003ag)k(set.)0 2369 y Fj(PyVarObject)598
2384 y(*)697 2369 y Fg(PyObject_GC_Resize)p Fj(\()p Fo(PyV)-9
b(arObject)16 b(*op,)j(Py)p 2348 2369 V 29 w(ssize)p
2533 2369 V 31 w(t)q Fj(\))208 2469 y Fr(Resize)i(an)f(object)f
(allocated)h(by)g Fj(PyObject_NewVar\(\))p Fr(.)i(Returns)e(the)g
(resized)g(object)g(or)g Fj(NULL)g Fr(on)f(f)o(ailure.)0
2616 y Fj(void)49 b Fg(PyObject_GC_Track)p Fj(\()p Fo(PyObject)16
b(*op)p Fj(\))208 2715 y Fr(Adds)22 b(the)g(object)f
Fo(op)h Fr(to)h(the)f(set)h(of)f(container)e(objects)i(track)o(ed)g(by)
f(the)i(collector)-5 b(.)30 b(The)22 b(collector)f(can)h(run)f(at)i
(une)o(xpected)208 2815 y(times)j(so)g(objects)g(must)g(be)g(v)n(alid)g
(while)g(being)f(track)o(ed.)42 b(This)26 b(should)f(be)h(called)g
(once)f(all)i(the)f(\002elds)g(follo)n(wed)f(by)h(the)208
2915 y Fj(tp_traverse)18 b Fr(handler)h(become)g(v)n(alid,)g(usually)h
(near)g(the)g(end)g(of)f(the)i(constructor)-5 b(.)0 3061
y Fj(void)49 b Fg(_PyObject_GC_TRACK)p Fj(\()p Fo(PyObject)16
b(*op)p Fj(\))208 3161 y Fr(A)k(macro)f(v)o(ersion)g(of)h
Fj(PyObject_GC_Track\(\))p Fr(.)i(It)f(should)e(not)h(be)g(used)g(for)f
(e)o(xtension)g(modules.)0 3308 y(Similarly)-5 b(,)19
b(the)h(deallocator)f(for)h(the)g(object)f(must)i(conform)d(to)i(a)h
(similar)f(pair)g(of)g(rules:)104 3509 y(1.)41 b(Before)19
b(\002elds)i(which)f(refer)f(to)h(other)g(containers)f(are)h(in)m(v)n
(alidated,)e Fj(PyObject_GC_UnTrack\(\))f Fr(must)j(be)g(called.)104
3663 y(2.)41 b(The)19 b(object')-5 b(s)20 b(memory)f(must)h(be)g
(deallocated)f(using)h Fj(PyObject_GC_Del\(\))p Fr(.)0
3816 y Fj(void)49 b Fg(PyObject_GC_Del)p Fj(\()p Fo(void)17
b(*op)p Fj(\))208 3916 y Fr(Releases)k(memory)d(allocated)i(to)g(an)g
(object)g(using)g Fj(PyObject_GC_New\(\))d Fr(or)j Fj
(PyObject_GC_NewVar\(\))p Fr(.)0 4063 y Fj(void)49 b
Fg(PyObject_GC_UnTrack)p Fj(\()p Fo(void)16 b(*op)p Fj(\))208
4162 y Fr(Remo)o(v)o(e)30 b(the)i(object)f Fo(op)g Fr(from)g(the)g(set)
i(of)e(container)f(objects)i(track)o(ed)f(by)g(the)h(collector)-5
b(.)58 b(Note)32 b(that)g Fj(PyObject_-)208 4262 y(GC_Track\(\))23
b Fr(can)i(be)h(called)f(again)f(on)h(this)g(object)g(to)g(add)g(it)h
(back)f(to)g(the)g(set)h(of)f(track)o(ed)f(objects.)40
b(The)25 b(deallocator)208 4362 y(\()p Fj(tp_dealloc)h
Fr(handler\))h(should)g(call)i(this)g(for)e(the)i(object)e(before)g(an)
o(y)h(of)g(the)g(\002elds)h(used)f(by)g(the)g Fj(tp_traverse)208
4461 y Fr(handler)18 b(become)h(in)m(v)n(alid.)0 4608
y Fj(void)49 b Fg(_PyObject_GC_UNTRACK)p Fj(\()p Fo(PyObject)16
b(*op)p Fj(\))208 4708 y Fr(A)k(macro)f(v)o(ersion)g(of)h
Fj(PyObject_GC_UnTrack\(\))p Fr(.)i(It)e(should)g(not)f(be)i(used)e
(for)h(e)o(xtension)f(modules.)0 4855 y(The)h Fj(tp_traverse)f
Fr(handler)f(accepts)i(a)h(function)d(parameter)h(of)h(this)h(type:)0
5001 y Fg(int)49 b(\()249 5014 y(*)299 5001 y(visitproc\)\(PyObject)
1295 5014 y(*)1345 5001 y(object,)f(void)1993 5014 y(*)2043
5001 y(arg\))208 5101 y Fr(T)-7 b(ype)18 b(of)g(the)h(visitor)g
(function)e(passed)i(to)g(the)g Fj(tp_traverse)e Fr(handler)-5
b(.)23 b(The)c(function)e(should)h(be)h(called)f(with)h(an)g(object)208
5201 y(to)f(tra)n(v)o(erse)f(as)h Fo(object)h Fr(and)e(the)h(third)f
(parameter)g(to)h(the)f Fj(tp_traverse)g Fr(handler)f(as)j
Fo(ar)m(g)p Fr(.)24 b(The)17 b(Python)g(core)g(uses)h(se)n(v)o(eral)208
5300 y(visitor)i(functions)e(to)j(implement)e(c)o(yclic)h(garbage)e
(detection;)h(it')-5 b(s)21 b(not)f(e)o(xpected)f(that)h(users)h(will)g
(need)e(to)i(write)f(their)g(o)n(wn)208 5400 y(visitor)g(functions.)p
0 5549 3901 4 v 0 5649 a Fn(116)2106 b(Chapter)23 b(10.)52
b(Object)23 b(Implementation)j(Suppor)s(t)p eop end
%%Page: 117 123
TeXDict begin 117 122 bop 0 83 a Fr(The)20 b Fj(tp_traverse)f
Fr(handler)f(must)j(ha)n(v)o(e)e(the)h(follo)n(wing)f(type:)0
230 y Fg(int)49 b(\()249 243 y(*)299 230 y(traverseproc\)\(PyObject)
1445 243 y(*)1495 230 y(self,)f(visitproc)g(visit,)h(void)2889
243 y(*)2939 230 y(arg\))208 330 y Fr(T)m(ra)n(v)o(ersal)23
b(function)f(for)h(a)h(container)f(object.)35 b(Implementations)22
b(must)i(call)g(the)g Fo(visit)i Fr(function)c(for)h(each)h(object)f
(directly)208 429 y(contained)15 b(by)j Fo(self)12 b
Fr(,)19 b(with)e(the)h(parameters)e(to)i Fo(visit)i Fr(being)d(the)g
(contained)f(object)h(and)g(the)h Fo(ar)m(g)f Fr(v)n(alue)g(passed)h
(to)f(the)h(handler)-5 b(.)208 529 y(The)22 b Fo(visit)i
Fr(function)d(must)i(not)f(be)g(called)g(with)h(a)f Fj(NULL)h
Fr(object)f(ar)o(gument.)29 b(If)22 b Fo(visit)j Fr(returns)c(a)i
(non-zero)d(v)n(alue)i(that)g(v)n(alue)208 628 y(should)d(be)h
(returned)e(immediately)-5 b(.)0 775 y(T)e(o)27 b(simplify)g(writing)f
Fj(tp_traverse)g Fr(handlers,)i(a)f Fj(Py_VISIT\(\))f
Fr(macro)g(is)i(pro)o(vided.)44 b(In)27 b(order)e(to)j(use)f(this)h
(macro,)g(the)0 875 y Fj(tp_traverse)19 b Fr(implementation)f(must)i
(name)f(its)j(ar)o(guments)c(e)o(xactly)h Fo(visit)k
Fr(and)c Fo(ar)m(g)p Fr(:)0 1022 y Fj(void)49 b Fg(Py_VISIT)p
Fj(\()p Fo(PyObject)18 b(*o)p Fj(\))208 1121 y Fr(Call)27
b(the)f Fo(visit)j Fr(callback,)d(with)h(ar)o(guments)d
Fo(o)i Fr(and)g Fo(ar)m(g)p Fr(.)43 b(If)26 b Fo(visit)j
Fr(returns)c(a)i(non-zero)c(v)n(alue,)k(then)f(return)f(it.)44
b(Using)26 b(this)208 1221 y(macro,)19 b Fj(tp_traverse)f
Fr(handlers)h(look)h(lik)o(e:)444 1445 y Fk(static)44
b(int)444 1537 y(my_traverse\(Noddy)1251 1550 y(*)1296
1537 y(self,)g(visitproc)f(visit,)h(void)2551 1550 y(*)2596
1537 y(arg\))444 1628 y({)623 1719 y(Py_VISIT\(self->foo\);)623
1810 y(Py_VISIT\(self->bar\);)623 1902 y(return)g(0;)444
1993 y(})208 2183 y Fr(Ne)n(w)20 b(in)g(v)o(ersion)f(2.4.)0
2329 y(The)h Fj(tp_clear)f Fr(handler)g(must)h(be)g(of)g(the)g
Fj(inquiry)g Fr(type,)f(or)h Fj(NULL)g Fr(if)h(the)f(object)g(is)h
(immutable.)0 2476 y Fg(int)49 b(\()249 2489 y(*)299
2476 y(inquiry\)\(PyObject)1196 2489 y(*)1246 2476 y(self\))208
2576 y Fr(Drop)23 b(references)g(that)h(may)g(ha)n(v)o(e)f(created)h
(reference)e(c)o(ycles.)37 b(Immutable)23 b(objects)h(do)g(not)f(ha)n
(v)o(e)h(to)g(de\002ne)g(this)h(method)208 2676 y(since)g(the)o(y)f
(can)i(ne)n(v)o(er)d(directly)i(create)g(reference)e(c)o(ycles.)40
b(Note)25 b(that)h(the)f(object)g(must)g(still)h(be)g(v)n(alid)e(after)
h(calling)g(this)208 2775 y(method)18 b(\(don')o(t)f(just)j(call)g
Fj(Py_DECREF\(\))e Fr(on)i(a)g(reference\).)i(The)d(collector)g(will)h
(call)g(this)g(method)f(if)g(it)i(detects)e(that)h(this)208
2875 y(object)f(is)i(in)m(v)n(olv)o(ed)d(in)j(a)f(reference)f(c)o
(ycle.)p 0 5549 3901 4 v 0 5649 a Fn(10.9.)52 b(Suppor)s(ting)25
b(Cyclic)e(Garbage)g(Collection)2144 b(117)p eop end
%%Page: 118 124
TeXDict begin 118 123 bop 0 5549 3901 4 v 0 5649 a Fn(118)p
eop end
%%Page: 119 125
TeXDict begin 119 124 bop 0 83 3901 9 v 3480 230 a Fn(APPENDIX)3814
427 y Fm(A)p 0 515 V 2468 978 a Fx(Repor)8 b(ting)57
b(Bugs)0 1468 y Fr(Python)23 b(is)i(a)g(mature)e(programming)e
(language)i(which)g(has)i(established)f(a)g(reputation)f(for)g
(stability)-5 b(.)37 b(In)24 b(order)f(to)i(maintain)e(this)0
1568 y(reputation,)18 b(the)i(de)n(v)o(elopers)e(w)o(ould)i(lik)o(e)g
(to)h(kno)n(w)e(of)h(an)o(y)f(de\002ciencies)h(you)f(\002nd)h(in)g
(Python)g(or)f(its)j(documentation.)0 1714 y(Before)e(submitting)g(a)h
(report,)f(you)g(will)i(be)f(required)e(to)i(log)f(into)h(SourceF)o(or)
o(ge;)e(this)i(will)h(mak)o(e)e(it)i(possible)e(for)h(the)g(de)n(v)o
(elopers)0 1814 y(to)f(contact)g(you)f(for)h(additional)f(information)e
(if)k(needed.)i(It)e(is)g(not)f(possible)g(to)g(submit)g(a)h(b)n(ug)e
(report)g(anon)o(ymously)-5 b(.)0 1961 y(All)24 b(b)n(ug)f(reports)f
(should)h(be)g(submitted)f(via)i(the)f(Python)f(Bug)i(T)m(rack)o(er)e
(at)i(\()p Fs(http://b)o(ugs)o(.p)n(ython.o)o(rg)-6 b
Fr(\).)34 b(The)23 b(b)n(ug)g(track)o(er)g(of)n(fers)f(a)0
2061 y(W)-7 b(eb)21 b(form)e(which)h(allo)n(ws)g(pertinent)f
(information)f(to)i(be)g(entered)f(and)h(submitted)f(to)i(the)f(de)n(v)
o(elopers.)0 2207 y(The)f(\002rst)i(step)f(in)f(\002ling)h(a)g(report)e
(is)j(to)f(determine)e(whether)g(the)i(problem)e(has)i(already)e(been)h
(reported.)k(The)c(adv)n(antage)f(in)i(doing)0 2307 y(so,)f(aside)g
(from)f(sa)n(ving)h(the)g(de)n(v)o(elopers)e(time,)i(is)h(that)f(you)f
(learn)g(what)h(has)g(been)g(done)f(to)h(\002x)g(it;)h(it)g(may)e(be)h
(that)g(the)g(problem)e(has)0 2407 y(already)h(been)h(\002x)o(ed)g(for)
f(the)i(ne)o(xt)e(release,)i(or)f(additional)f(information)f(is)j
(needed)e(\(in)h(which)g(case)h(you)e(are)h(welcome)g(to)h(pro)o(vide)0
2506 y(it)h(if)f(you)g(can!\).)k(T)-7 b(o)20 b(do)g(this,)g(search)g
(the)g(b)n(ug)g(database)g(using)f(the)h(search)g(box)f(on)h(the)g(top)
g(side)h(of)f(the)g(page.)0 2653 y(If)e(the)g(problem)f(you')l(re)f
(reporting)g(is)j(not)f(already)f(in)h(the)g(b)n(ug)g(track)o(er)m(,)f
(go)h(back)f(to)i(the)f(Python)f(Bug)h(T)m(rack)o(er)-5
b(.)24 b(Select)18 b(the)g(\223Create)0 2753 y(ne)n(w\224)i(link)g(at)g
(the)h(left)f(of)g(the)g(page)g(to)g(open)f(the)h(b)n(ug)g(reporting)e
(form.)0 2900 y(The)g(submission)f(form)g(has)h(a)g(number)e(of)i
(\002elds.)25 b(The)17 b(only)g(\002elds)i(that)f(are)g(required)e(are)
i(the)g(\223T)m(itle\224)g(and)f(\223T)-7 b(ype\224)17
b(\002elds.)25 b(F)o(or)18 b(the)0 2999 y(title,)24 b(enter)e(a)i
Fo(very)f Fr(short)f(description)g(of)g(the)h(problem;)g(less)h(than)e
(ten)h(w)o(ords)g(is)g(good.)32 b(In)22 b(the)h(\223Change)f(Note\224)h
(\002eld,)g(describe)0 3099 y(the)f(problem)e(in)h(detail,)h(including)
e(what)i(you)f(e)o(xpected)f(to)h(happen)f(and)i(what)f(did)h(happen.)
27 b(Be)c(sure)e(to)h(include)f(the)g(v)o(ersion)g(of)0
3199 y(Python)f(you)h(used,)g(whether)f(an)o(y)g(e)o(xtension)g
(modules)h(were)g(in)m(v)n(olv)o(ed,)e(and)i(what)g(hardw)o(are)f(and)h
(softw)o(are)f(platform)g(you)h(were)0 3298 y(using)f(\(including)e(v)o
(ersion)h(information)e(as)k(appropriate\).)0 3445 y(The)e(only)g
(other)g(\002eld)h(that)f(you)g(may)g(w)o(ant)h(to)f(set)i(is)f(the)g
(\223Components\224)e(\002eld,)h(which)g(allo)n(ws)h(you)f(to)g(place)h
(the)f(b)n(ug)g(report)g(into)0 3545 y(broad)g(cate)o(gories)g(\(such)g
(as)i(\223Documentation\224)d(or)i(\223Library\224\).)0
3692 y(Each)e(b)n(ug)g(report)f(will)j(be)e(assigned)g(to)h(a)g(de)n(v)
o(eloper)d(who)i(will)h(determine)e(what)i(needs)f(to)h(be)f(done)g(to)
g(correct)g(the)h(problem.)j(Y)-9 b(ou)0 3791 y(will)21
b(recei)n(v)o(e)e(an)h(update)f(each)h(time)g(action)g(is)h(tak)o(en)f
(on)g(the)g(b)n(ug.)0 3938 y Fp(See)h(Also:)0 4085 y
Fo(How)g(to)f(Report)g(Bugs)f(Ef)o(fectively)0 4185 y
Fa(\()p Fs(http://www-mice)o(.cs)o(.ucl.ac.uk/m)o(ultimedia)o(/softw)n
(are)o(/do)o(cumen)o(tati)o(on)o(/Re)o(por)r(tin)o(gBu)o(gs)o(.h)o(tml)
-6 b Fa(\))208 4284 y Fr(Article)32 b(which)f(goes)h(into)f(some)h
(detail)g(about)f(ho)n(w)g(to)i(create)e(a)i(useful)e(b)n(ug)g(report.)
59 b(This)32 b(describes)g(what)g(kind)f(of)208 4384
y(information)17 b(is)k(useful)f(and)g(why)f(it)i(is)g(useful.)0
4531 y Fo(Bug)f(Writing)g(Guidelines)0 4630 y Fa(\()p
Fs(http://www)l(.mozilla.org/q)o(ual)o(it)o(y/b)o(u)o(g-writin)o(g-g)o
(ui)o(de)o(li)o(nes)o(.h)o(tml)-6 b Fa(\))208 4730 y
Fr(Information)27 b(about)i(writing)h(a)g(good)f(b)n(ug)h(report.)54
b(Some)30 b(of)f(this)i(is)g(speci\002c)g(to)f(the)g(Mozilla)g
(project,)i(b)n(ut)e(describes)208 4830 y(general)19
b(good)f(practices.)p 0 5549 3901 4 v 3762 5649 a Fn(119)p
eop end
%%Page: 120 126
TeXDict begin 120 125 bop 0 5549 3901 4 v 0 5649 a Fn(120)p
eop end
%%Page: 121 127
TeXDict begin 121 126 bop 0 83 3901 9 v 3480 230 a Fn(APPENDIX)3814
427 y Fm(B)p 0 515 V 2080 978 a Fx(Histor)6 b(y)58 b(and)f(License)0
1506 y Fl(B)n(.1)120 b(Histor)t(y)32 b(of)i(the)h(softw)n(are)0
1739 y Fr(Python)k(w)o(as)i(created)f(in)g(the)h(early)e(1990s)h(by)g
(Guido)f(v)n(an)h(Rossum)g(at)h(Stichting)f(Mathematisch)f(Centrum)g
(\(CWI,)i(see)0 1839 y Fs(http://www)l(.cwi.nl/)l Fr(\))30
b(in)g(the)g(Netherlands)e(as)j(a)f(successor)g(of)f(a)i(language)d
(called)i(ABC.)g(Guido)f(remains)h(Python')-5 b(s)29
b(principal)0 1939 y(author)m(,)18 b(although)h(it)i(includes)e(man)o
(y)g(contrib)n(utions)f(from)h(others.)0 2085 y(In)36
b(1995,)j(Guido)c(continued)f(his)j(w)o(ork)e(on)h(Python)f(at)i(the)f
(Corporation)e(for)i(National)g(Research)g(Initiati)n(v)o(es)f(\(CNRI,)
i(see)0 2185 y Fs(http://www)l(.cnr)q(i.reston.v)n(a.us/)-6
b Fr(\))21 b(in)f(Reston,)g(V)-5 b(ir)o(ginia)19 b(where)h(he)g
(released)g(se)n(v)o(eral)f(v)o(ersions)g(of)h(the)g(softw)o(are.)0
2332 y(In)h(May)h(2000,)e(Guido)h(and)g(the)h(Python)e(core)h(de)n(v)o
(elopment)e(team)j(mo)o(v)o(ed)d(to)j(BeOpen.com)e(to)i(form)e(the)i
(BeOpen)f(PythonLabs)0 2432 y(team.)49 b(In)27 b(October)g(of)h(the)g
(same)h(year)m(,)g(the)f(PythonLabs)e(team)i(mo)o(v)o(ed)e(to)i
(Digital)h(Creations)f(\(no)n(w)f(Zope)g(Corporation;)j(see)0
2531 y Fs(http://www)l(.z)o(ope)o(.com/)l Fr(\).)g(In)21
b(2001,)g(the)h(Python)f(Softw)o(are)g(F)o(oundation)f(\(PSF)-7
b(,)22 b(see)h Fs(http://www)l(.p)n(ython.org/)o(psf/)-6
b Fr(\))22 b(w)o(as)h(formed,)d(a)0 2631 y(non-pro\002t)h(or)o
(ganization)f(created)i(speci\002cally)h(to)g(o)n(wn)g(Python-related)d
(Intellectual)j(Property)-5 b(.)32 b(Zope)22 b(Corporation)f(is)j(a)g
(spon-)0 2730 y(soring)19 b(member)g(of)h(the)g(PSF)-7
b(.)0 2877 y(All)26 b(Python)d(releases)j(are)e(Open)h(Source)f(\(see)h
Fs(http://www)l(.opensource)o(.o)o(rg/)19 b Fr(for)24
b(the)h(Open)g(Source)f(De\002nition\).)38 b(Historically)-5
b(,)0 2977 y(most,)20 b(b)n(ut)g(not)g(all,)h(Python)e(releases)h(ha)n
(v)o(e)g(also)g(been)g(GPL-compatible;)e(the)i(table)g(belo)n(w)g
(summarizes)f(the)h(v)n(arious)g(releases.)p 0 5549 3901
4 v 3762 5649 a Fn(121)p eop end
%%Page: 122 128
TeXDict begin 122 127 bop 670 70 a Fp(Release)p 1074
100 4 100 v 188 w(Deri)o(v)o(ed)20 b(fr)o(om)p 1648 100
V 195 w(Y)-9 b(ear)p 2107 100 V 291 w(Owner)p 2643 100
V 195 w(GPL)21 b(compatible?)p 531 103 2838 4 v 581 173
a Fr(0.9.0)e(thru)g(1.2)p 1074 203 4 100 v 285 w(n/a)p
1648 203 V 285 w(1991-1995)p 2107 203 V 233 w(CWI)p 2643
203 V 494 w(yes)581 272 y(1.3)g(thru)h(1.5.2)p 1074 302
V 283 w(1.2)p 1648 302 V 283 w(1995-1999)p 2107 302 V
214 w(CNRI)p 2643 302 V 476 w(yes)752 372 y(1.6)p 1074
402 V 423 w(1.5.2)p 1648 402 V 348 w(2000)p 2107 402
V 313 w(CNRI)p 2643 402 V 490 w(no)752 472 y(2.0)p 1074
501 V 454 w(1.6)p 1648 501 V 380 w(2000)p 2107 501 V
195 w(BeOpen.com)p 2643 501 V 368 w(no)720 571 y(1.6.1)p
1074 601 V 423 w(1.6)p 1648 601 V 380 w(2001)p 2107 601
V 313 w(CNRI)p 2643 601 V 490 w(no)752 671 y(2.1)p 1074
701 V 347 w(2.0+1.6.1)p 1648 701 V 272 w(2001)p 2107
701 V 343 w(PSF)p 2643 701 V 520 w(no)720 770 y(2.0.1)p
1074 800 V 316 w(2.0+1.6.1)p 1648 800 V 272 w(2001)p
2107 800 V 343 w(PSF)p 2643 800 V 506 w(yes)720 870 y(2.1.1)p
1074 900 V 316 w(2.1+2.0.1)p 1648 900 V 272 w(2001)p
2107 900 V 343 w(PSF)p 2643 900 V 506 w(yes)752 970 y(2.2)p
1074 1000 V 423 w(2.1.1)p 1648 1000 V 348 w(2001)p 2107
1000 V 343 w(PSF)p 2643 1000 V 506 w(yes)720 1069 y(2.1.2)p
1074 1099 V 392 w(2.1.1)p 1648 1099 V 348 w(2002)p 2107
1099 V 343 w(PSF)p 2643 1099 V 506 w(yes)720 1169 y(2.1.3)p
1074 1199 V 392 w(2.1.2)p 1648 1199 V 348 w(2002)p 2107
1199 V 343 w(PSF)p 2643 1199 V 506 w(yes)720 1269 y(2.2.1)p
1074 1298 V 423 w(2.2)p 1648 1298 V 380 w(2002)p 2107
1298 V 343 w(PSF)p 2643 1298 V 506 w(yes)720 1368 y(2.2.2)p
1074 1398 V 392 w(2.2.1)p 1648 1398 V 348 w(2002)p 2107
1398 V 343 w(PSF)p 2643 1398 V 506 w(yes)720 1468 y(2.2.3)p
1074 1498 V 392 w(2.2.2)p 1648 1498 V 251 w(2002-2003)p
2107 1498 V 244 w(PSF)p 2643 1498 V 506 w(yes)752 1567
y(2.3)p 1074 1597 V 423 w(2.2.2)p 1648 1597 V 251 w(2002-2003)p
2107 1597 V 244 w(PSF)p 2643 1597 V 506 w(yes)720 1667
y(2.3.1)p 1074 1697 V 423 w(2.3)p 1648 1697 V 283 w(2002-2003)p
2107 1697 V 244 w(PSF)p 2643 1697 V 506 w(yes)720 1767
y(2.3.2)p 1074 1797 V 392 w(2.3.1)p 1648 1797 V 348 w(2003)p
2107 1797 V 343 w(PSF)p 2643 1797 V 506 w(yes)720 1866
y(2.3.3)p 1074 1896 V 392 w(2.3.2)p 1648 1896 V 348 w(2003)p
2107 1896 V 343 w(PSF)p 2643 1896 V 506 w(yes)720 1966
y(2.3.4)p 1074 1996 V 392 w(2.3.3)p 1648 1996 V 348 w(2004)p
2107 1996 V 343 w(PSF)p 2643 1996 V 506 w(yes)720 2066
y(2.3.5)p 1074 2095 V 392 w(2.3.4)p 1648 2095 V 348 w(2005)p
2107 2095 V 343 w(PSF)p 2643 2095 V 506 w(yes)752 2165
y(2.4)p 1074 2195 V 454 w(2.3)p 1648 2195 V 380 w(2004)p
2107 2195 V 343 w(PSF)p 2643 2195 V 506 w(yes)720 2265
y(2.4.1)p 1074 2295 V 423 w(2.4)p 1648 2295 V 380 w(2005)p
2107 2295 V 343 w(PSF)p 2643 2295 V 506 w(yes)720 2364
y(2.4.2)p 1074 2394 V 392 w(2.4.1)p 1648 2394 V 348 w(2005)p
2107 2394 V 343 w(PSF)p 2643 2394 V 506 w(yes)720 2464
y(2.4.3)p 1074 2494 V 392 w(2.4.2)p 1648 2494 V 348 w(2006)p
2107 2494 V 343 w(PSF)p 2643 2494 V 506 w(yes)720 2564
y(2.4.4)p 1074 2594 V 392 w(2.4.3)p 1648 2594 V 348 w(2006)p
2107 2594 V 343 w(PSF)p 2643 2594 V 506 w(yes)752 2663
y(2.5)p 1074 2693 V 454 w(2.4)p 1648 2693 V 380 w(2006)p
2107 2693 V 343 w(PSF)p 2643 2693 V 506 w(yes)720 2763
y(2.5.1)p 1074 2793 V 423 w(2.5)p 1648 2793 V 380 w(2007)p
2107 2793 V 343 w(PSF)p 2643 2793 V 506 w(yes)720 2863
y(2.5.2)p 1074 2892 V 392 w(2.5.1)p 1648 2892 V 348 w(2008)p
2107 2892 V 343 w(PSF)p 2643 2892 V 506 w(yes)0 3088
y Fp(Note:)35 b Fr(GPL-compatible)24 b(doesn')o(t)g(mean)g(that)i(we')l
(re)f(distrib)n(uting)f(Python)h(under)f(the)h(GPL.)h(All)g(Python)f
(licenses,)i(unlik)o(e)e(the)0 3187 y(GPL,)e(let)g(you)f(distrib)n(ute)
h(a)g(modi\002ed)f(v)o(ersion)f(without)h(making)g(your)f(changes)h
(open)g(source.)32 b(The)22 b(GPL-compatible)f(licenses)0
3287 y(mak)o(e)f(it)h(possible)f(to)g(combine)f(Python)g(with)h(other)f
(softw)o(are)h(that)g(is)i(released)d(under)g(the)h(GPL;)h(the)f
(others)g(don')o(t.)0 3434 y(Thanks)f(to)i(the)f(man)o(y)f(outside)g(v)
n(olunteers)g(who)h(ha)n(v)o(e)g(w)o(ork)o(ed)f(under)f(Guido')-5
b(s)20 b(direction)f(to)h(mak)o(e)g(these)g(releases)h(possible.)0
3761 y Fl(B)n(.2)120 b(T)-14 b(er)s(ms)32 b(and)j(conditions)f(f)l(or)g
(accessing)g(or)g(otherwise)g(using)g(Python)1024 3947
y Fp(PSF)20 b(LICENSE)j(A)-5 b(GREEMENT)22 b(FOR)e(PYTHON)g(2.5.3)104
4094 y Fr(1.)41 b(This)22 b(LICENSE)g(A)m(GREEMENT)f(is)j(between)d
(the)h(Python)f(Softw)o(are)h(F)o(oundation)e(\(\223PSF\224\),)i(and)f
(the)i(Indi)n(vidual)c(or)j(Or)n(-)208 4193 y(ganization)g
(\(\223Licensee\224\))h(accessing)h(and)g(otherwise)f(using)h(Python)f
(2.5.3)g(softw)o(are)h(in)h(source)e(or)h(binary)f(form)h(and)g(its)208
4293 y(associated)c(documentation.)104 4459 y(2.)41 b(Subject)28
b(to)g(the)h(terms)f(and)g(conditions)f(of)h(this)h(License)f
(Agreement,)h(PSF)g(hereby)e(grants)h(Licensee)g(a)h(none)o(xclusi)n(v)
o(e,)208 4559 y(ro)o(yalty-free,)e(w)o(orld-wide)g(license)h(to)g
(reproduce,)f(analyze,)i(test,)i(perform)26 b(and/or)h(display)g
(publicly)-5 b(,)28 b(prepare)f(deri)n(v)n(a-)208 4658
y(ti)n(v)o(e)g(w)o(orks,)h(distrib)n(ute,)h(and)e(otherwise)g(use)h
(Python)e(2.5.3)g(alone)h(or)g(in)h(an)o(y)e(deri)n(v)n(ati)n(v)o(e)g
(v)o(ersion,)i(pro)o(vided,)e(ho)n(we)n(v)o(er)m(,)208
4758 y(that)e(PSF')-5 b(s)26 b(License)e(Agreement)f(and)h(PSF')-5
b(s)25 b(notice)f(of)g(cop)o(yright,)f(i.e.,)j(\223Cop)o(yright)2871
4755 y(c)2848 4758 y Fq(\015)f Fr(2001-2008)c(Python)i(Softw)o(are)208
4857 y(F)o(oundation;)i(All)h(Rights)g(Reserv)o(ed\224)e(are)i
(retained)e(in)h(Python)f(2.5.3)g(alone)h(or)g(in)h(an)o(y)e(deri)n(v)n
(ati)n(v)o(e)g(v)o(ersion)g(prepared)f(by)208 4957 y(Licensee.)104
5123 y(3.)41 b(In)16 b(the)h(e)n(v)o(ent)f(Licensee)h(prepares)e(a)j
(deri)n(v)n(ati)n(v)o(e)d(w)o(ork)h(that)h(is)h(based)e(on)h(or)g
(incorporates)d(Python)i(2.5.3)g(or)g(an)o(y)h(part)f(thereof,)208
5223 y(and)25 b(w)o(ants)h(to)f(mak)o(e)g(the)h(deri)n(v)n(ati)n(v)o(e)
d(w)o(ork)i(a)n(v)n(ailable)g(to)h(others)f(as)h(pro)o(vided)d(herein,)
j(then)f(Licensee)g(hereby)f(agrees)h(to)208 5322 y(include)19
b(in)h(an)o(y)f(such)h(w)o(ork)g(a)h(brief)e(summary)g(of)h(the)g
(changes)f(made)h(to)g(Python)f(2.5.3.)p 0 5549 3901
4 v 0 5649 a Fn(122)2538 b(Appendix)25 b(B)n(.)47 b(Histor)r(y)22
b(and)i(License)p eop end
%%Page: 123 129
TeXDict begin 123 128 bop 104 83 a Fr(4.)41 b(PSF)30
b(is)g(making)e(Python)h(2.5.3)f(a)n(v)n(ailable)h(to)g(Licensee)g(on)g
(an)g(\223)-7 b(AS)31 b(IS\224)e(basis.)53 b(PSF)31 b(MAKES)e(NO)h
(REPRESENT)-8 b(A-)208 183 y(TIONS)25 b(OR)h(W)-10 b(ARRANTIES,)26
b(EXPRESS)g(OR)g(IMPLIED.)f(BY)h(W)-10 b(A)h(Y)26 b(OF)g(EXAMPLE,)f(B)o
(UT)h(NO)m(T)f(LIMIT)-8 b(A)f(TION,)208 282 y(PSF)26
b(MAKES)f(NO)h(AND)g(DISCLAIMS)f(ANY)h(REPRESENT)-8 b(A)f(TION)25
b(OR)h(W)-10 b(ARRANTY)27 b(OF)f(MERCHANT)-8 b(ABIL-)208
382 y(ITY)17 b(OR)h(FITNESS)f(FOR)i(ANY)e(P)-8 b(AR)j(TICULAR)19
b(PURPOSE)f(OR)g(THA)-9 b(T)17 b(THE)g(USE)h(OF)g(PYTHON)f(2.5.3)f
(WILL)i(NO)m(T)208 482 y(INFRINGE)i(ANY)g(THIRD)h(P)-8
b(AR)j(TY)21 b(RIGHTS.)104 648 y(5.)41 b(PSF)29 b(SHALL)g(NO)m(T)g(BE)g
(LIABLE)g(T)o(O)f(LICENSEE)g(OR)i(ANY)f(O)m(THER)g(USERS)h(OF)f(PYTHON)
g(2.5.3)e(FOR)j(ANY)208 747 y(INCIDENT)-8 b(AL,)18 b(SPECIAL,)h(OR)h
(CONSEQ)o(UENTIAL)f(D)m(AMA)m(GES)f(OR)i(LOSS)g(AS)g(A)g(RESUL)-8
b(T)19 b(OF)h(MODIFYING,)208 847 y(DISTRIB)o(UTING,)j(OR)h(O)m(THER)-5
b(WISE)24 b(USING)g(PYTHON)g(2.5.3,)f(OR)h(ANY)g(DERIV)-11
b(A)i(TIVE)23 b(THEREOF)-7 b(,)24 b(EVEN)f(IF)208 946
y(AD)m(VISED)c(OF)i(THE)f(POSSIBILITY)g(THEREOF)-7 b(.)104
1112 y(6.)41 b(This)20 b(License)g(Agreement)e(will)j(automatically)e
(terminate)g(upon)g(a)i(material)f(breach)f(of)h(its)h(terms)f(and)g
(conditions.)104 1279 y(7.)41 b(Nothing)23 b(in)i(this)g(License)g
(Agreement)e(shall)i(be)g(deemed)e(to)i(create)g(an)o(y)f(relationship)
f(of)i(agenc)o(y)-5 b(,)23 b(partnership,)h(or)h(joint)208
1378 y(v)o(enture)20 b(between)h(PSF)h(and)g(Licensee.)29
b(This)22 b(License)f(Agreement)g(does)g(not)h(grant)f(permission)f(to)
i(use)g(PSF)h(trademarks)208 1478 y(or)c(trade)h(name)g(in)g(a)h
(trademark)d(sense)j(to)f(endorse)f(or)h(promote)e(products)h(or)h
(services)g(of)g(Licensee,)g(or)f(an)o(y)h(third)f(party)-5
b(.)104 1644 y(8.)41 b(By)18 b(cop)o(ying,)e(installing)h(or)h
(otherwise)f(using)g(Python)g(2.5.3,)g(Licensee)g(agrees)g(to)h(be)g
(bound)e(by)h(the)h(terms)g(and)f(conditions)208 1743
y(of)i(this)i(License)f(Agreement.)846 1926 y Fp(BEOPEN.COM)h(LICENSE)h
(A)-5 b(GREEMENT)23 b(FOR)d(PYTHON)g(2.0)579 2026 y(BEOPEN)h(PYTHON)f
(OPEN)g(SOURCE)h(LICENSE)h(A)-5 b(GREEMENT)23 b(VERSION)e(1)104
2256 y Fr(1.)41 b(This)20 b(LICENSE)g(A)m(GREEMENT)f(is)i(between)f
(BeOpen.com)e(\(\223BeOpen\224\),)h(ha)n(ving)g(an)h(of)n(\002ce)g(at)g
(160)g(Saratoga)e(A)-6 b(v)o(enue,)208 2355 y(Santa)29
b(Clara,)i(CA)f(95051,)f(and)f(the)h(Indi)n(vidual)e(or)i(Or)o
(ganization)d(\(\223Licensee\224\))h(accessing)i(and)f(otherwise)h
(using)f(this)208 2455 y(softw)o(are)19 b(in)i(source)e(or)h(binary)f
(form)g(and)h(its)h(associated)f(documentation)d(\(\223the)j(Softw)o
(are\224\).)104 2621 y(2.)41 b(Subject)18 b(to)g(the)h(terms)g(and)f
(conditions)f(of)h(this)h(BeOpen)f(Python)f(License)i(Agreement,)e
(BeOpen)h(hereby)f(grants)h(Licensee)208 2721 y(a)25
b(non-e)o(xclusi)n(v)o(e,)e(ro)o(yalty-free,)h(w)o(orld-wide)f(license)
j(to)f(reproduce,)f(analyze,)h(test,)i(perform)c(and/or)h(display)g
(publicly)-5 b(,)208 2820 y(prepare)16 b(deri)n(v)n(ati)n(v)o(e)f(w)o
(orks,)j(distrib)n(ute,)f(and)g(otherwise)g(use)h(the)g(Softw)o(are)f
(alone)g(or)g(in)h(an)o(y)f(deri)n(v)n(ati)n(v)o(e)f(v)o(ersion,)g(pro)
o(vided,)208 2920 y(ho)n(we)n(v)o(er)m(,)f(that)i(the)g(BeOpen)g
(Python)f(License)i(is)g(retained)e(in)h(the)h(Softw)o(are,)f(alone)f
(or)h(in)h(an)o(y)e(deri)n(v)n(ati)n(v)o(e)g(v)o(ersion)g(prepared)208
3019 y(by)j(Licensee.)104 3185 y(3.)41 b(BeOpen)25 b(is)j(making)c(the)
j(Softw)o(are)e(a)n(v)n(ailable)h(to)g(Licensee)g(on)g(an)g(\223)-7
b(AS)27 b(IS\224)g(basis.)43 b(BEOPEN)27 b(MAKES)f(NO)h(REPRE-)208
3285 y(SENT)-8 b(A)f(TIONS)27 b(OR)i(W)-10 b(ARRANTIES,)29
b(EXPRESS)g(OR)g(IMPLIED.)f(BY)h(W)-10 b(A)h(Y)29 b(OF)g(EXAMPLE,)e(B)o
(UT)i(NO)m(T)g(LIMI-)208 3385 y(T)-8 b(A)f(TION,)20 b(BEOPEN)h(MAKES)f
(NO)i(AND)f(DISCLAIMS)f(ANY)h(REPRESENT)-8 b(A)f(TION)21
b(OR)g(W)-10 b(ARRANTY)22 b(OF)f(MER-)208 3484 y(CHANT)-8
b(ABILITY)21 b(OR)i(FITNESS)e(FOR)i(ANY)f(P)-8 b(AR)j(TICULAR)23
b(PURPOSE)g(OR)f(THA)-9 b(T)21 b(THE)h(USE)g(OF)g(THE)g(SOFT)-8
b(-)208 3584 y(W)e(ARE)21 b(WILL)f(NO)m(T)g(INFRINGE)g(ANY)h(THIRD)f(P)
-8 b(AR)j(TY)21 b(RIGHTS.)104 3750 y(4.)41 b(BEOPEN)24
b(SHALL)f(NO)m(T)h(BE)g(LIABLE)g(T)o(O)f(LICENSEE)g(OR)i(ANY)f(O)m
(THER)f(USERS)i(OF)f(THE)g(SOFTW)-10 b(ARE)25 b(FOR)208
3850 y(ANY)c(INCIDENT)-8 b(AL,)20 b(SPECIAL,)h(OR)h(CONSEQ)o(UENTIAL)e
(D)m(AMA)m(GES)h(OR)h(LOSS)f(AS)h(A)f(RESUL)-8 b(T)22
b(OF)g(USING,)208 3949 y(MODIFYING)j(OR)i(DISTRIB)o(UTING)f(THE)h
(SOFTW)-10 b(ARE,)27 b(OR)g(ANY)f(DERIV)-11 b(A)i(TIVE)25
b(THEREOF)-7 b(,)27 b(EVEN)f(IF)g(AD-)208 4049 y(VISED)20
b(OF)h(THE)f(POSSIBILITY)g(THEREOF)-7 b(.)104 4215 y(5.)41
b(This)20 b(License)g(Agreement)e(will)j(automatically)e(terminate)g
(upon)g(a)i(material)f(breach)f(of)h(its)h(terms)f(and)g(conditions.)
104 4381 y(6.)41 b(This)27 b(License)f(Agreement)g(shall)h(be)g(go)o(v)
o(erned)d(by)j(and)f(interpreted)f(in)j(all)f(respects)g(by)g(the)g(la)
o(w)g(of)g(the)g(State)g(of)g(Cali-)208 4481 y(fornia,)22
b(e)o(xcluding)e(con\003ict)j(of)f(la)o(w)i(pro)o(visions.)31
b(Nothing)21 b(in)j(this)f(License)g(Agreement)e(shall)i(be)g(deemed)f
(to)h(create)f(an)o(y)208 4580 y(relationship)i(of)h(agenc)o(y)-5
b(,)25 b(partnership,)g(or)g(joint)h(v)o(enture)e(between)h(BeOpen)g
(and)g(Licensee.)41 b(This)26 b(License)f(Agreement)208
4680 y(does)18 b(not)h(grant)f(permission)f(to)i(use)h(BeOpen)e
(trademarks)f(or)i(trade)f(names)h(in)g(a)g(trademark)e(sense)i(to)g
(endorse)f(or)g(promote)208 4779 y(products)k(or)h(services)g(of)h
(Licensee,)f(or)h(an)o(y)e(third)h(party)-5 b(.)34 b(As)24
b(an)g(e)o(xception,)e(the)i(\223BeOpen)f(Python\224)f(logos)h(a)n(v)n
(ailable)g(at)208 4879 y(http://www)-5 b(.p)o(ythonlabs.com/logo)o
(s.htm)o(l)15 b(may)20 b(be)g(used)g(according)e(to)i(the)h
(permissions)e(granted)g(on)h(that)g(web)g(page.)104
5045 y(7.)41 b(By)19 b(cop)o(ying,)e(installing)h(or)g(otherwise)g
(using)h(the)f(softw)o(are,)h(Licensee)f(agrees)g(to)h(be)f(bound)f(by)
i(the)f(terms)h(and)f(conditions)208 5145 y(of)h(this)i(License)f
(Agreement.)992 5327 y Fp(CNRI)h(LICENSE)h(A)-5 b(GREEMENT)22
b(FOR)e(PYTHON)g(1.6.1)p 0 5549 3901 4 v 0 5649 a Fn(B)n(.2.)53
b(T)-10 b(er)r(ms)22 b(and)i(conditions)f(f)n(or)g(accessing)f(or)h
(otherwise)g(using)h(Python)1291 b(123)p eop end
%%Page: 124 130
TeXDict begin 124 129 bop 104 83 a Fr(1.)41 b(This)25
b(LICENSE)g(A)m(GREEMENT)f(is)i(between)e(the)h(Corporation)e(for)h
(National)h(Research)g(Initiati)n(v)o(es,)g(ha)n(ving)f(an)h(of)n
(\002ce)208 183 y(at)j(1895)f(Preston)h(White)h(Dri)n(v)o(e,)g(Reston,)
h(V)-11 b(A)29 b(20191)d(\(\223CNRI\224\),)i(and)f(the)i(Indi)n(vidual)
d(or)i(Or)o(ganization)d(\(\223Licensee\224\))208 282
y(accessing)18 b(and)g(otherwise)g(using)g(Python)f(1.6.1)h(softw)o
(are)g(in)h(source)e(or)i(binary)e(form)h(and)g(its)h(associated)g
(documentation.)104 443 y(2.)41 b(Subject)24 b(to)g(the)h(terms)f(and)g
(conditions)f(of)h(this)h(License)g(Agreement,)e(CNRI)j(hereby)d
(grants)h(Licensee)g(a)h(none)o(xclusi)n(v)o(e,)208 542
y(ro)o(yalty-free,)18 b(w)o(orld-wide)i(license)h(to)g(reproduce,)d
(analyze,)j(test,)g(perform)e(and/or)h(display)h(publicly)-5
b(,)19 b(prepare)g(deri)n(v)n(ati)n(v)o(e)208 642 y(w)o(orks,)28
b(distrib)n(ute,)g(and)f(otherwise)f(use)i(Python)e(1.6.1)f(alone)i(or)
g(in)g(an)o(y)f(deri)n(v)n(ati)n(v)o(e)g(v)o(ersion,)h(pro)o(vided,)f
(ho)n(we)n(v)o(er)m(,)g(that)208 741 y(CNRI')-5 b(s)30
b(License)f(Agreement)f(and)g(CNRI')-5 b(s)31 b(notice)e(of)g(cop)o
(yright,)g(i.e.,)i(\223Cop)o(yright)2893 738 y(c)2870
741 y Fq(\015)f Fr(1995-2001)25 b(Corporation)i(for)208
841 y(National)k(Research)h(Initiati)n(v)o(es;)37 b(All)32
b(Rights)g(Reserv)o(ed\224)f(are)h(retained)f(in)h(Python)e(1.6.1)h
(alone)g(or)g(in)h(an)o(y)f(deri)n(v)n(ati)n(v)o(e)208
941 y(v)o(ersion)22 b(prepared)g(by)h(Licensee.)35 b(Alternately)-5
b(,)23 b(in)h(lieu)g(of)f(CNRI')-5 b(s)25 b(License)f(Agreement,)e
(Licensee)i(may)f(substitute)h(the)208 1040 y(follo)n(wing)j(te)o(xt)i
(\(omitting)e(the)i(quotes\):)42 b(\223Python)27 b(1.6.1)h(is)h(made)g
(a)n(v)n(ailable)f(subject)h(to)g(the)g(terms)g(and)f(conditions)f(in)
208 1140 y(CNRI')-5 b(s)24 b(License)f(Agreement.)33
b(This)24 b(Agreement)d(together)h(with)i(Python)e(1.6.1)g(may)h(be)g
(located)g(on)g(the)g(Internet)f(using)208 1240 y(the)27
b(follo)n(wing)f(unique,)h(persistent)g(identi\002er)g(\(kno)n(wn)f(as)
i(a)f(handle\):)39 b(1895.22/1013.)j(This)27 b(Agreement)f(may)h(also)h
(be)208 1339 y(obtained)18 b(from)h(a)i(proxy)d(serv)o(er)i(on)g(the)g
(Internet)f(using)g(the)i(follo)n(wing)d(URL:)j Fs(http://hdl.handle)o
(.)o(ne)o(t/18)o(95)o(.2)o(2/1)o(01)o(3)-6 b Fr(.)g(\224)104
1499 y(3.)41 b(In)16 b(the)h(e)n(v)o(ent)f(Licensee)h(prepares)e(a)j
(deri)n(v)n(ati)n(v)o(e)d(w)o(ork)h(that)h(is)h(based)e(on)h(or)g
(incorporates)d(Python)i(1.6.1)g(or)g(an)o(y)h(part)f(thereof,)208
1599 y(and)25 b(w)o(ants)h(to)f(mak)o(e)g(the)h(deri)n(v)n(ati)n(v)o(e)
d(w)o(ork)i(a)n(v)n(ailable)g(to)h(others)f(as)h(pro)o(vided)d(herein,)
j(then)f(Licensee)g(hereby)f(agrees)h(to)208 1699 y(include)19
b(in)h(an)o(y)f(such)h(w)o(ork)g(a)h(brief)e(summary)g(of)h(the)g
(changes)f(made)h(to)g(Python)f(1.6.1.)104 1859 y(4.)41
b(CNRI)23 b(is)h(making)d(Python)h(1.6.1)f(a)n(v)n(ailable)h(to)h
(Licensee)g(on)f(an)h(\223)-7 b(AS)23 b(IS\224)g(basis.)34
b(CNRI)23 b(MAKES)g(NO)g(REPRESENT)-8 b(A-)208 1959 y(TIONS)25
b(OR)h(W)-10 b(ARRANTIES,)26 b(EXPRESS)g(OR)g(IMPLIED.)f(BY)h(W)-10
b(A)h(Y)26 b(OF)g(EXAMPLE,)f(B)o(UT)h(NO)m(T)f(LIMIT)-8
b(A)f(TION,)208 2058 y(CNRI)20 b(MAKES)f(NO)h(AND)g(DISCLAIMS)f(ANY)h
(REPRESENT)-8 b(A)f(TION)19 b(OR)h(W)-10 b(ARRANTY)21
b(OF)f(MERCHANT)-8 b(ABIL-)208 2158 y(ITY)17 b(OR)h(FITNESS)f(FOR)i
(ANY)e(P)-8 b(AR)j(TICULAR)19 b(PURPOSE)f(OR)g(THA)-9
b(T)17 b(THE)g(USE)h(OF)g(PYTHON)f(1.6.1)f(WILL)i(NO)m(T)208
2257 y(INFRINGE)i(ANY)g(THIRD)h(P)-8 b(AR)j(TY)21 b(RIGHTS.)104
2418 y(5.)41 b(CNRI)25 b(SHALL)g(NO)m(T)g(BE)g(LIABLE)g(T)o(O)f
(LICENSEE)g(OR)i(ANY)f(O)m(THER)g(USERS)h(OF)f(PYTHON)g(1.6.1)e(FOR)j
(ANY)208 2517 y(INCIDENT)-8 b(AL,)18 b(SPECIAL,)h(OR)h(CONSEQ)o
(UENTIAL)f(D)m(AMA)m(GES)f(OR)i(LOSS)g(AS)g(A)g(RESUL)-8
b(T)19 b(OF)h(MODIFYING,)208 2617 y(DISTRIB)o(UTING,)j(OR)h(O)m(THER)-5
b(WISE)24 b(USING)g(PYTHON)g(1.6.1,)f(OR)h(ANY)g(DERIV)-11
b(A)i(TIVE)23 b(THEREOF)-7 b(,)24 b(EVEN)f(IF)208 2717
y(AD)m(VISED)c(OF)i(THE)f(POSSIBILITY)g(THEREOF)-7 b(.)104
2877 y(6.)41 b(This)20 b(License)g(Agreement)e(will)j(automatically)e
(terminate)g(upon)g(a)i(material)f(breach)f(of)h(its)h(terms)f(and)g
(conditions.)104 3037 y(7.)41 b(This)16 b(License)f(Agreement)f(shall)j
(be)e(go)o(v)o(erned)e(by)j(the)f(federal)g(intellectual)h(property)d
(la)o(w)j(of)g(the)g(United)f(States,)i(including)208
3137 y(without)28 b(limitation)g(the)g(federal)g(cop)o(yright)f(la)o(w)
-5 b(,)30 b(and,)g(to)f(the)g(e)o(xtent)e(such)i(U.S.)g(federal)e(la)o
(w)i(does)g(not)f(apply)-5 b(,)29 b(by)g(the)208 3236
y(la)o(w)f(of)h(the)f(Commonwealth)f(of)h(V)-5 b(ir)o(ginia,)30
b(e)o(xcluding)c(V)-5 b(ir)o(ginia')g(s)28 b(con\003ict)g(of)g(la)o(w)h
(pro)o(visions.)49 b(Notwithstanding)27 b(the)208 3336
y(fore)o(going,)c(with)i(re)o(gard)f(to)h(deri)n(v)n(ati)n(v)o(e)e(w)o
(orks)i(based)g(on)g(Python)f(1.6.1)g(that)h(incorporate)e
(non-separable)g(material)h(that)208 3435 y(w)o(as)29
b(pre)n(viously)d(distrib)n(uted)i(under)f(the)h(GNU)h(General)f
(Public)g(License)h(\(GPL\),)f(the)g(la)o(w)h(of)f(the)g(Commonwealth)f
(of)208 3535 y(V)-5 b(ir)o(ginia)19 b(shall)j(go)o(v)o(ern)c(this)k
(License)e(Agreement)g(only)g(as)h(to)g(issues)h(arising)f(under)e(or)i
(with)g(respect)g(to)g(P)o(aragraphs)e(4,)i(5,)208 3635
y(and)d(7)i(of)f(this)h(License)f(Agreement.)k(Nothing)18
b(in)h(this)h(License)f(Agreement)f(shall)i(be)f(deemed)f(to)h(create)g
(an)o(y)g(relationship)208 3734 y(of)24 b(agenc)o(y)-5
b(,)24 b(partnership,)g(or)g(joint)h(v)o(enture)e(between)h(CNRI)h(and)
f(Licensee.)39 b(This)25 b(License)f(Agreement)f(does)i(not)f(grant)208
3834 y(permission)29 b(to)i(use)g(CNRI)g(trademarks)e(or)h(trade)g
(name)g(in)h(a)g(trademark)e(sense)i(to)f(endorse)g(or)g(promote)f
(products)g(or)208 3934 y(services)20 b(of)g(Licensee,)f(or)h(an)o(y)g
(third)f(party)-5 b(.)104 4094 y(8.)41 b(By)17 b(clicking)f(on)g(the)h
(\223)-7 b(A)m(CCEPT\224)18 b(b)n(utton)e(where)g(indicated,)g(or)h(by)
f(cop)o(ying,)g(installing)g(or)h(otherwise)f(using)g(Python)g(1.6.1,)
208 4193 y(Licensee)j(agrees)h(to)h(be)f(bound)e(by)i(the)g(terms)g
(and)g(conditions)e(of)i(this)h(License)f(Agreement.)1793
4362 y(A)m(CCEPT)722 4461 y Fp(CWI)h(LICENSE)h(A)-5 b(GREEMENT)23
b(FOR)d(PYTHON)g(0.9.0)e(THR)n(OUGH)h(1.2)0 4608 y Fr(Cop)o(yright)380
4605 y(c)357 4608 y Fq(\015)h Fr(1991)f(-)i(1995,)d(Stichting)i
(Mathematisch)f(Centrum)g(Amsterdam,)g(The)h(Netherlands.)k(All)d
(rights)e(reserv)o(ed.)0 4755 y(Permission)g(to)h(use,)g(cop)o(y)-5
b(,)19 b(modify)-5 b(,)17 b(and)i(distrib)n(ute)h(this)g(softw)o(are)f
(and)h(its)g(documentation)d(for)i(an)o(y)g(purpose)g(and)g(without)g
(fee)h(is)0 4855 y(hereby)i(granted,)g(pro)o(vided)f(that)i(the)h(abo)o
(v)o(e)d(cop)o(yright)h(notice)g(appear)h(in)g(all)h(copies)f(and)g
(that)g(both)g(that)g(cop)o(yright)e(notice)i(and)0 4954
y(this)f(permission)f(notice)g(appear)f(in)i(supporting)d
(documentation,)g(and)i(that)h(the)f(name)g(of)h(Stichting)f
(Mathematisch)f(Centrum)h(or)0 5054 y(CWI)26 b(not)f(be)h(used)f(in)g
(adv)o(ertising)f(or)h(publicity)f(pertaining)g(to)h(distrib)n(ution)g
(of)g(the)g(softw)o(are)g(without)g(speci\002c,)h(written)g(prior)0
5154 y(permission.)0 5300 y(STICHTING)18 b(MA)-9 b(THEMA)g(TISCH)18
b(CENTR)m(UM)g(DISCLAIMS)h(ALL)f(W)-10 b(ARRANTIES)20
b(WITH)f(REGARD)g(T)o(O)f(THIS)h(SOFT)-8 b(-)0 5400 y(W)e(ARE,)23
b(INCLUDING)e(ALL)h(IMPLIED)f(W)-10 b(ARRANTIES)23 b(OF)g(MERCHANT)-8
b(ABILITY)21 b(AND)i(FITNESS,)e(IN)i(NO)f(EVENT)p 0 5549
3901 4 v 0 5649 a Fn(124)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 125 131
TeXDict begin 125 130 bop 0 83 a Fr(SHALL)30 b(STICHTING)g(MA)-9
b(THEMA)g(TISCH)29 b(CENTR)m(UM)h(BE)g(LIABLE)g(FOR)h(ANY)f(SPECIAL,)g
(INDIRECT)g(OR)h(CON-)0 183 y(SEQ)o(UENTIAL)e(D)m(AMA)m(GES)h(OR)h(ANY)
f(D)m(AMA)m(GES)f(WHA)-9 b(TSOEVER)31 b(RESUL)-8 b(TING)30
b(FR)m(OM)g(LOSS)h(OF)g(USE,)f(D)m(A)-9 b(T)h(A)0 282
y(OR)25 b(PR)m(OFITS,)f(WHETHER)h(IN)f(AN)h(A)m(CTION)f(OF)h(CONTRA)m
(CT)-6 b(,)24 b(NEGLIGENCE)g(OR)h(O)m(THER)f(T)o(OR)-5
b(TIOUS)24 b(A)m(CTION,)0 382 y(ARISING)c(OUT)h(OF)g(OR)g(IN)f
(CONNECTION)g(WITH)h(THE)f(USE)h(OR)g(PERFORMANCE)g(OF)g(THIS)f(SOFTW)
-10 b(ARE.)0 709 y Fl(B)n(.3)120 b(Licenses)34 b(and)g(Ac)n(kno)n
(wledgements)i(f)l(or)e(Incor)t(por)o(ated)i(Softw)n(are)0
942 y Fr(This)18 b(section)f(is)h(an)g(incomplete,)e(b)n(ut)h(gro)n
(wing)f(list)i(of)g(licenses)f(and)g(ackno)n(wledgements)e(for)h
(third-party)f(softw)o(are)i(incorporated)0 1042 y(in)j(the)h(Python)e
(distrib)n(ution.)0 1327 y Fh(B)n(.3.1)100 b(Mersenne)30
b(T)-12 b(wister)0 1530 y Fr(The)15 b Fj(_random)f Fr(module)g
(includes)h(code)f(based)h(on)g(a)g(do)n(wnload)f(from)g
Fs(http://www)l(.math.k)o(eio)m(.ac.j)o(p/)g(matumoto/MT2002/emt19937)o
(ar)l(.h)o(tml)-6 b Fr(.)0 1629 y(The)20 b(follo)n(wing)e(are)j(the)f
(v)o(erbatim)e(comments)h(from)h(the)g(original)f(code:)p
0 5549 3901 4 v 0 5649 a Fn(B)n(.3.)53 b(Licenses)22
b(and)i(Ac)n(kno)o(wledgements)g(f)n(or)e(Incor)r(por)o(ated)i(Softw)o
(are)1378 b(125)p eop end
%%Page: 126 132
TeXDict begin 126 131 bop 236 174 a Fk(A)45 b(C-program)e(for)i
(MT19937,)e(with)h(initialization)f(improved)g(2002/1/26.)236
266 y(Coded)h(by)h(Takuji)f(Nishimura)f(and)h(Makoto)g(Matsumoto.)236
448 y(Before)g(using,)g(initialize)f(the)h(state)g(by)h(using)f
(init_genrand\(seed\))236 540 y(or)h(init_by_array\(init_key,)c
(key_length\).)236 722 y(Copyright)j(\(C\))g(1997)g(-)h(2002,)f(Makoto)
g(Matsumoto)f(and)h(Takuji)g(Nishimura,)236 814 y(All)h(rights)e
(reserved.)236 996 y(Redistribution)g(and)h(use)g(in)h(source)f(and)g
(binary)g(forms,)g(with)g(or)g(without)236 1088 y(modification,)f(are)h
(permitted)g(provided)f(that)h(the)g(following)g(conditions)236
1179 y(are)h(met:)281 1362 y(1.)g(Redistributions)d(of)i(source)g(code)
g(must)g(retain)g(the)h(above)f(copyright)416 1453 y(notice,)f(this)h
(list)h(of)f(conditions)f(and)h(the)h(following)e(disclaimer.)281
1636 y(2.)i(Redistributions)d(in)i(binary)g(form)g(must)g(reproduce)g
(the)g(above)g(copyright)416 1727 y(notice,)f(this)h(list)h(of)f
(conditions)f(and)h(the)h(following)e(disclaimer)g(in)i(the)416
1818 y(documentation)d(and/or)i(other)g(materials)f(provided)h(with)g
(the)g(distribution.)281 2001 y(3.)h(The)f(names)g(of)g(its)h
(contributors)e(may)h(not)g(be)h(used)f(to)g(endorse)g(or)g(promote)416
2092 y(products)f(derived)h(from)g(this)g(software)f(without)h
(specific)g(prior)g(written)416 2183 y(permission.)236
2366 y(THIS)g(SOFTWARE)g(IS)g(PROVIDED)g(BY)g(THE)h(COPYRIGHT)e
(HOLDERS)h(AND)g(CONTRIBUTORS)236 2457 y("AS)h(IS")f(AND)g(ANY)h
(EXPRESS)e(OR)i(IMPLIED)e(WARRANTIES,)g(INCLUDING,)g(BUT)i(NOT)236
2549 y(LIMITED)f(TO,)g(THE)h(IMPLIED)e(WARRANTIES)g(OF)i
(MERCHANTABILITY)d(AND)i(FITNESS)g(FOR)236 2640 y(A)h(PARTICULAR)e
(PURPOSE)h(ARE)g(DISCLAIMED.)88 b(IN)44 b(NO)h(EVENT)f(SHALL)g(THE)g
(COPYRIGHT)f(OWNER)h(OR)236 2731 y(CONTRIBUTORS)f(BE)i(LIABLE)e(FOR)i
(ANY)f(DIRECT,)g(INDIRECT,)f(INCIDENTAL,)g(SPECIAL,)236
2823 y(EXEMPLARY,)g(OR)i(CONSEQUENTIAL)e(DAMAGES)g(\(INCLUDING,)g(BUT)h
(NOT)h(LIMITED)e(TO,)236 2914 y(PROCUREMENT)g(OF)i(SUBSTITUTE)e(GOODS)h
(OR)g(SERVICES;)g(LOSS)g(OF)g(USE,)g(DATA,)g(OR)236 3005
y(PROFITS;)g(OR)g(BUSINESS)g(INTERRUPTION\))e(HOWEVER)i(CAUSED)g(AND)g
(ON)h(ANY)f(THEORY)g(OF)236 3097 y(LIABILITY,)f(WHETHER)h(IN)h
(CONTRACT,)e(STRICT)h(LIABILITY,)f(OR)h(TORT)g(\(INCLUDING)236
3188 y(NEGLIGENCE)f(OR)i(OTHERWISE\))e(ARISING)h(IN)g(ANY)g(WAY)h(OUT)f
(OF)h(THE)f(USE)g(OF)h(THIS)236 3279 y(SOFTWARE,)f(EVEN)g(IF)g(ADVISED)
g(OF)g(THE)h(POSSIBILITY)e(OF)h(SUCH)g(DAMAGE.)236 3553
y(Any)h(feedback)e(is)i(very)f(welcome.)236 3645 y
(http://www.math.keio.ac.jp/matumoto/emt.)o(html)236
3736 y(email:)g([email protected])0 4161 y Fh(B)n(.3.2)100
b(Soc)n(k)n(ets)0 4364 y Fr(The)23 b Fj(socket)g Fr(module)e(uses)j
(the)g(functions,)e Fj(getaddrinfo)p Fr(,)g(and)h Fj(getnameinfo)p
Fr(,)f(which)h(are)g(coded)f(in)i(separate)e(source)0
4463 y(\002les)f(from)e(the)i(WIDE)f(Project,)g Fs(http://www)l(.wide)o
(.ad.j)o(p/a)o(bo)o(ut/)o(ind)o(e)m(x.html)-6 b Fr(.)p
0 5549 3901 4 v 0 5649 a Fn(126)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 127 133
TeXDict begin 127 132 bop 236 83 a Fk(Copyright)44 b(\(C\))g(1995,)g
(1996,)g(1997,)g(and)g(1998)g(WIDE)g(Project.)236 174
y(All)h(rights)e(reserved.)236 357 y(Redistribution)g(and)h(use)g(in)h
(source)f(and)g(binary)g(forms,)g(with)g(or)g(without)236
448 y(modification,)f(are)h(permitted)g(provided)f(that)h(the)g
(following)g(conditions)236 540 y(are)h(met:)236 631
y(1.)g(Redistributions)d(of)j(source)e(code)i(must)f(retain)f(the)i
(above)f(copyright)371 722 y(notice,)f(this)i(list)f(of)g(conditions)f
(and)i(the)f(following)f(disclaimer.)236 814 y(2.)i(Redistributions)d
(in)j(binary)e(form)i(must)f(reproduce)f(the)h(above)g(copyright)371
905 y(notice,)f(this)i(list)f(of)g(conditions)f(and)i(the)f(following)f
(disclaimer)g(in)i(the)371 996 y(documentation)d(and/or)i(other)g
(materials)f(provided)h(with)g(the)g(distribution.)236
1088 y(3.)h(Neither)e(the)i(name)f(of)g(the)h(project)e(nor)i(the)f
(names)g(of)g(its)h(contributors)371 1179 y(may)f(be)h(used)f(to)g
(endorse)g(or)g(promote)g(products)f(derived)h(from)g(this)g(software)
371 1270 y(without)f(specific)h(prior)g(written)g(permission.)236
1453 y(THIS)g(SOFTWARE)g(IS)g(PROVIDED)g(BY)g(THE)h(PROJECT)e(AND)i
(CONTRIBUTORS)d(``AS)j(IS'')f(AND)236 1544 y(GAI_ANY)g(EXPRESS)g(OR)g
(IMPLIED)g(WARRANTIES,)f(INCLUDING,)g(BUT)h(NOT)g(LIMITED)g(TO,)g(THE)
236 1636 y(IMPLIED)g(WARRANTIES)f(OF)i(MERCHANTABILITY)d(AND)i(FITNESS)
g(FOR)g(A)h(PARTICULAR)e(PURPOSE)236 1727 y(ARE)i(DISCLAIMED.)87
b(IN)45 b(NO)f(EVENT)g(SHALL)g(THE)h(PROJECT)e(OR)i(CONTRIBUTORS)e(BE)h
(LIABLE)236 1818 y(FOR)h(GAI_ANY)e(DIRECT,)h(INDIRECT,)f(INCIDENTAL,)g
(SPECIAL,)h(EXEMPLARY,)f(OR)h(CONSEQUENTIAL)236 1910
y(DAMAGES)g(\(INCLUDING,)f(BUT)h(NOT)h(LIMITED)e(TO,)h(PROCUREMENT)f
(OF)i(SUBSTITUTE)e(GOODS)236 2001 y(OR)i(SERVICES;)e(LOSS)h(OF)h(USE,)f
(DATA,)g(OR)g(PROFITS;)g(OR)g(BUSINESS)g(INTERRUPTION\))236
2092 y(HOWEVER)g(CAUSED)g(AND)g(ON)h(GAI_ANY)e(THEORY)h(OF)g
(LIABILITY,)g(WHETHER)f(IN)i(CONTRACT,)e(STRICT)236 2183
y(LIABILITY,)g(OR)i(TORT)f(\(INCLUDING)f(NEGLIGENCE)g(OR)i(OTHERWISE\))
e(ARISING)h(IN)g(GAI_ANY)g(WAY)236 2275 y(OUT)h(OF)f(THE)g(USE)h(OF)f
(THIS)g(SOFTWARE,)g(EVEN)g(IF)g(ADVISED)g(OF)g(THE)h(POSSIBILITY)e(OF)
236 2366 y(SUCH)h(DAMAGE.)0 2789 y Fh(B)n(.3.3)100 b(Floating)29
b(point)g(e)m(xception)g(control)0 2992 y Fr(The)20 b(source)f(for)h
(the)g Fj(fpectl)g Fr(module)f(includes)g(the)h(follo)n(wing)f(notice:)
p 0 5549 3901 4 v 0 5649 a Fn(B)n(.3.)53 b(Licenses)22
b(and)i(Ac)n(kno)o(wledgements)g(f)n(or)e(Incor)r(por)o(ated)i(Softw)o
(are)1378 b(127)p eop end
%%Page: 128 134
TeXDict begin 128 133 bop 460 174 a Fk
(-----------------------------------------)o(------)o(------)o(------)o
(------)o(----)416 266 y(/)1031 b(Copyright)43 b(\(c\))h(1996.)1210
b(\\)371 357 y(|)448 b(The)44 b(Regents)g(of)g(the)h(University)e(of)h
(California.)761 b(|)371 448 y(|)1076 b(All)44 b(rights)g(reserved.)
1209 b(|)371 540 y(|)3183 b(|)371 631 y(|)134 b(Permission)43
b(to)i(use,)f(copy,)g(modify,)f(and)i(distribute)e(this)h(software)g
(for)134 b(|)371 722 y(|)g(any)44 b(purpose)g(without)g(fee)g(is)h
(hereby)e(granted,)h(provided)f(that)h(this)h(en-)134
b(|)371 814 y(|)g(tire)44 b(notice)g(is)h(included)e(in)i(all)f(copies)
g(of)g(any)g(software)g(which)g(is)g(or)135 b(|)371 905
y(|)f(includes)88 b(a)i(copy)f(or)g(modification)f(of)h(this)44
b(software)g(and)g(in)h(all)134 b(|)371 996 y(|)g(copies)44
b(of)g(the)h(supporting)e(documentation)f(for)j(such)f(software.)492
b(|)371 1088 y(|)3183 b(|)371 1179 y(|)134 b(This)89
b(work)44 b(was)h(produced)e(at)i(the)f(University)f(of)h(California,)f
(Lawrence)134 b(|)371 1270 y(|)g(Livermore)43 b(National)h(Laboratory)f
(under)89 b(contract)f(no.)h(W-7405-ENG-48)133 b(|)371
1362 y(|)h(between)89 b(the)g(U.S.)g(Department)f(of)h(Energy)44
b(and)g(The)g(Regents)g(of)h(the)134 b(|)371 1453 y(|)g(University)43
b(of)i(California)e(for)h(the)g(operation)g(of)g(UC)h(LLNL.)627
b(|)371 1544 y(|)3183 b(|)371 1636 y(|)1345 b(DISCLAIMER)1388
b(|)371 1727 y(|)3183 b(|)371 1818 y(|)134 b(This)89
b(software)44 b(was)g(prepared)f(as)i(an)f(account)g(of)g(work)h
(sponsored)e(by)h(an)135 b(|)371 1910 y(|)f(agency)44
b(of)g(the)h(United)f(States)f(Government.)g(Neither)h(the)g(United)g
(States)134 b(|)371 2001 y(|)g(Government)88 b(nor)44
b(the)h(University)e(of)h(California)f(nor)i(any)f(of)h(their)f(em-)134
b(|)371 2092 y(|)g(ployees,)44 b(makes)g(any)g(warranty,)f(express)h
(or)g(implied,)g(or)89 b(assumes)g(any)134 b(|)371 2183
y(|)g(liability)88 b(or)i(responsibility)d(for)44 b(the)g(accuracy,)g
(completeness,)e(or)135 b(|)371 2275 y(|)f(usefulness)43
b(of)i(any)f(information,)88 b(apparatus,)g(product,)g(or)h(process)134
b(|)371 2366 y(|)g(disclosed,)f(or)89 b(represents)f(that)h(its)g(use)g
(would)g(not)g(infringe)134 b(|)371 2457 y(|)g(privately-owned)42
b(rights.)i(Reference)f(herein)h(to)h(any)f(specific)88
b(commer-)134 b(|)371 2549 y(|)g(cial)89 b(products,)f(process,)h(or)g
(service)f(by)45 b(trade)f(name,)g(trademark,)133 b(|)371
2640 y(|)h(manufacturer,)43 b(or)h(otherwise,)f(does)h(not)90
b(necessarily)d(constitute)h(or)135 b(|)371 2731 y(|)f(imply)89
b(its)44 b(endorsement,)f(recommendation,)f(or)j(favoring)e(by)i(the)f
(United)134 b(|)371 2823 y(|)g(States)44 b(Government)f(or)i(the)f
(University)f(of)h(California.)f(The)i(views)89 b(and)134
b(|)371 2914 y(|)g(opinions)88 b(of)45 b(authors)f(expressed)f(herein)h
(do)g(not)g(necessarily)f(state)h(or)135 b(|)371 3005
y(|)f(reflect)44 b(those)g(of)g(the)h(United)e(States)h(Government)f
(or)90 b(the)f(University)133 b(|)371 3097 y(|)h(of)89
b(California,)f(and)45 b(shall)f(not)g(be)g(used)g(for)h(advertising)e
(or)h(product)134 b(|)416 3188 y(\\)89 b(endorsement)43
b(purposes.)2061 b(/)460 3279 y
(-----------------------------------------)o(------)o(------)o(------)o
(------)o(----)0 3703 y Fh(B)n(.3.4)100 b(MD5)28 b(message)h(digest)g
(algor)q(ithm)0 3906 y Fr(The)20 b(source)f(code)h(for)f(the)i
Fj(md5)f Fr(module)f(contains)g(the)h(follo)n(wing)f(notice:)p
0 5549 3901 4 v 0 5649 a Fn(128)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 129 135
TeXDict begin 129 134 bop 326 174 a Fk(Copyright)43 b(\(C\))i(1999,)f
(2002)g(Aladdin)f(Enterprises.)88 b(All)44 b(rights)g(reserved.)326
357 y(This)g(software)g(is)g(provided)g('as-is',)f(without)h(any)g
(express)g(or)g(implied)326 448 y(warranty.)88 b(In)45
b(no)f(event)g(will)g(the)h(authors)e(be)i(held)f(liable)g(for)g(any)g
(damages)326 540 y(arising)g(from)g(the)g(use)g(of)h(this)f(software.)
326 722 y(Permission)f(is)i(granted)e(to)i(anyone)f(to)g(use)g(this)g
(software)g(for)g(any)h(purpose,)326 814 y(including)e(commercial)g
(applications,)g(and)h(to)h(alter)f(it)g(and)h(redistribute)d(it)326
905 y(freely,)i(subject)f(to)i(the)f(following)f(restrictions:)326
1088 y(1.)h(The)h(origin)f(of)g(this)g(software)g(must)g(not)g(be)h
(misrepresented;)d(you)i(must)g(not)460 1179 y(claim)g(that)h(you)f
(wrote)g(the)g(original)g(software.)f(If)h(you)h(use)f(this)g(software)
460 1270 y(in)h(a)g(product,)e(an)i(acknowledgment)d(in)i(the)h
(product)e(documentation)g(would)h(be)460 1362 y(appreciated)f(but)i
(is)f(not)h(required.)326 1453 y(2.)f(Altered)g(source)g(versions)f
(must)i(be)f(plainly)g(marked)f(as)i(such,)f(and)g(must)g(not)h(be)460
1544 y(misrepresented)e(as)h(being)g(the)h(original)e(software.)326
1636 y(3.)h(This)h(notice)e(may)i(not)f(be)h(removed)e(or)i(altered)e
(from)h(any)h(source)f(distribution.)326 1818 y(L.)g(Peter)g(Deutsch)
326 1910 y([email protected])326 2092 y(Independent)f(implementation)f
(of)j(MD5)f(\(RFC)g(1321\).)326 2275 y(This)g(code)g(implements)f(the)i
(MD5)f(Algorithm)f(defined)h(in)g(RFC)h(1321,)f(whose)326
2366 y(text)g(is)h(available)e(at)236 2457 y
(http://www.ietf.org/rfc/rfc1321.txt)326 2549 y(The)h(code)g(is)h
(derived)f(from)g(the)g(text)g(of)h(the)f(RFC,)g(including)f(the)i
(test)f(suite)326 2640 y(\(section)f(A.5\))i(but)f(excluding)f(the)i
(rest)f(of)g(Appendix)g(A.)89 b(It)44 b(does)h(not)f(include)326
2731 y(any)g(code)g(or)h(documentation)e(that)h(is)g(identified)f(in)i
(the)f(RFC)g(as)h(being)326 2823 y(copyrighted.)326 3005
y(The)f(original)g(and)g(principal)f(author)h(of)h(md5.h)f(is)g(L.)h
(Peter)f(Deutsch)326 3097 y(<[email protected]>.)86 b(Other)44
b(authors)g(are)g(noted)g(in)h(the)f(change)g(history)326
3188 y(that)g(follows)g(\(in)g(reverse)g(chronological)e(order\):)326
3371 y(2002-04-13)h(lpd)h(Removed)g(support)g(for)g(non-ANSI)f
(compilers;)h(removed)236 3462 y(references)f(to)i(Ghostscript;)e
(clarified)g(derivation)g(from)h(RFC)h(1321;)236 3553
y(now)g(handles)e(byte)h(order)g(either)g(statically)f(or)i
(dynamically.)326 3645 y(1999-11-04)e(lpd)h(Edited)g(comments)g
(slightly)f(for)h(automatic)g(TOC)g(extraction.)326 3736
y(1999-10-18)f(lpd)h(Fixed)g(typo)h(in)f(header)g(comment)f(\(ansi2knr)
h(rather)g(than)g(md5\);)236 3827 y(added)g(conditionalization)e(for)i
(C++)h(compilation)e(from)h(Martin)236 3919 y(Purschke)g
(<[email protected]>.)326 4010 y(1999-05-03)f(lpd)h(Original)g(version.)
0 4433 y Fh(B)n(.3.5)100 b(Asynchronous)30 b(soc)n(k)n(et)e(ser)s
(vices)0 4636 y Fr(The)20 b Fj(asynchat)f Fr(and)h Fj(asyncore)f
Fr(modules)g(contain)g(the)i(follo)n(wing)d(notice:)p
0 5549 3901 4 v 0 5649 a Fn(B)n(.3.)53 b(Licenses)22
b(and)i(Ac)n(kno)o(wledgements)g(f)n(or)e(Incor)r(por)o(ated)i(Softw)o
(are)1378 b(129)p eop end
%%Page: 130 136
TeXDict begin 130 135 bop 281 174 a Fk(Copyright)43 b(1996)i(by)f(Sam)g
(Rushing)1357 357 y(All)g(Rights)g(Reserved)281 540 y(Permission)f(to)i
(use,)f(copy,)g(modify,)g(and)g(distribute)f(this)h(software)g(and)281
631 y(its)g(documentation)f(for)h(any)h(purpose)e(and)i(without)e(fee)i
(is)f(hereby)281 722 y(granted,)g(provided)f(that)h(the)h(above)f
(copyright)f(notice)h(appear)f(in)i(all)281 814 y(copies)f(and)g(that)g
(both)h(that)f(copyright)f(notice)h(and)g(this)g(permission)281
905 y(notice)g(appear)g(in)g(supporting)f(documentation,)g(and)h(that)g
(the)h(name)f(of)g(Sam)281 996 y(Rushing)g(not)g(be)h(used)f(in)g
(advertising)f(or)i(publicity)e(pertaining)g(to)281 1088
y(distribution)g(of)h(the)h(software)e(without)h(specific,)f(written)h
(prior)281 1179 y(permission.)281 1362 y(SAM)g(RUSHING)g(DISCLAIMS)f
(ALL)i(WARRANTIES)e(WITH)h(REGARD)g(TO)g(THIS)g(SOFTWARE,)281
1453 y(INCLUDING)f(ALL)i(IMPLIED)e(WARRANTIES)h(OF)g(MERCHANTABILITY)e
(AND)j(FITNESS,)e(IN)281 1544 y(NO)i(EVENT)f(SHALL)g(SAM)g(RUSHING)g
(BE)g(LIABLE)g(FOR)g(ANY)g(SPECIAL,)g(INDIRECT)f(OR)281
1636 y(CONSEQUENTIAL)g(DAMAGES)g(OR)i(ANY)f(DAMAGES)g(WHATSOEVER)f
(RESULTING)g(FROM)h(LOSS)281 1727 y(OF)h(USE,)f(DATA)g(OR)g(PROFITS,)g
(WHETHER)g(IN)g(AN)g(ACTION)g(OF)h(CONTRACT,)281 1818
y(NEGLIGENCE)e(OR)i(OTHER)f(TORTIOUS)f(ACTION,)h(ARISING)f(OUT)i(OF)f
(OR)h(IN)281 1910 y(CONNECTION)e(WITH)h(THE)h(USE)f(OR)h(PERFORMANCE)d
(OF)j(THIS)f(SOFTWARE.)0 2334 y Fh(B)n(.3.6)100 b(Cookie)29
b(management)0 2537 y Fr(The)20 b Fj(Cookie)f Fr(module)g(contains)h
(the)g(follo)n(wing)f(notice:)281 2775 y Fk(Copyright)43
b(2000)i(by)f(Timothy)g(O'Malley)f(<[email protected]>)954
2958 y(All)h(Rights)g(Reserved)281 3141 y(Permission)f(to)i(use,)f
(copy,)g(modify,)g(and)g(distribute)f(this)h(software)281
3232 y(and)g(its)h(documentation)d(for)j(any)f(purpose)g(and)g(without)
g(fee)g(is)g(hereby)281 3323 y(granted,)g(provided)f(that)h(the)h
(above)f(copyright)f(notice)h(appear)f(in)i(all)281 3415
y(copies)f(and)g(that)g(both)h(that)f(copyright)f(notice)h(and)g(this)g
(permission)281 3506 y(notice)g(appear)g(in)g(supporting)f
(documentation,)g(and)h(that)g(the)h(name)f(of)281 3597
y(Timothy)g(O'Malley)88 b(not)44 b(be)h(used)f(in)h(advertising)d(or)j
(publicity)281 3689 y(pertaining)e(to)i(distribution)e(of)h(the)g
(software)g(without)f(specific,)h(written)281 3780 y(prior)g
(permission.)281 3963 y(Timothy)g(O'Malley)f(DISCLAIMS)h(ALL)g
(WARRANTIES)f(WITH)h(REGARD)g(TO)g(THIS)281 4054 y(SOFTWARE,)f
(INCLUDING)h(ALL)g(IMPLIED)g(WARRANTIES)f(OF)h(MERCHANTABILITY)281
4145 y(AND)g(FITNESS,)g(IN)g(NO)h(EVENT)f(SHALL)g(Timothy)f(O'Malley)h
(BE)g(LIABLE)g(FOR)281 4237 y(ANY)g(SPECIAL,)g(INDIRECT)f(OR)i
(CONSEQUENTIAL)d(DAMAGES)i(OR)h(ANY)f(DAMAGES)281 4328
y(WHATSOEVER)f(RESULTING)h(FROM)g(LOSS)g(OF)g(USE,)g(DATA)h(OR)f
(PROFITS,)281 4419 y(WHETHER)g(IN)g(AN)h(ACTION)f(OF)g(CONTRACT,)f
(NEGLIGENCE)g(OR)i(OTHER)f(TORTIOUS)281 4511 y(ACTION,)g(ARISING)f(OUT)
i(OF)f(OR)h(IN)f(CONNECTION)f(WITH)h(THE)h(USE)f(OR)281
4602 y(PERFORMANCE)f(OF)i(THIS)f(SOFTWARE.)0 5026 y Fh(B)n(.3.7)100
b(Pro\002ling)0 5229 y Fr(The)20 b Fj(profile)f Fr(and)h
Fj(pstats)g Fr(modules)f(contain)g(the)h(follo)n(wing)f(notice:)p
0 5549 3901 4 v 0 5649 a Fn(130)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 131 137
TeXDict begin 131 136 bop 281 174 a Fk(Copyright)43 b(1994,)h(by)h
(InfoSeek)e(Corporation,)g(all)h(rights)g(reserved.)281
266 y(Written)g(by)g(James)g(Roskind)281 448 y(Permission)f(to)i(use,)f
(copy,)g(modify,)g(and)g(distribute)f(this)h(Python)g(software)281
540 y(and)g(its)h(associated)e(documentation)g(for)h(any)g(purpose)g
(\(subject)f(to)i(the)281 631 y(restriction)e(in)i(the)f(following)f
(sentence\))g(without)h(fee)g(is)h(hereby)f(granted,)281
722 y(provided)g(that)g(the)g(above)g(copyright)f(notice)h(appears)g
(in)g(all)h(copies,)e(and)281 814 y(that)h(both)g(that)h(copyright)e
(notice)h(and)g(this)g(permission)f(notice)h(appear)g(in)281
905 y(supporting)f(documentation,)g(and)h(that)g(the)g(name)h(of)f
(InfoSeek)g(not)g(be)g(used)h(in)281 996 y(advertising)e(or)i
(publicity)e(pertaining)g(to)h(distribution)f(of)i(the)f(software)281
1088 y(without)g(specific,)f(written)h(prior)g(permission.)87
b(This)45 b(permission)e(is)281 1179 y(explicitly)g(restricted)g(to)i
(the)f(copying)g(and)g(modification)f(of)h(the)h(software)281
1270 y(to)g(remain)e(in)i(Python,)f(compiled)f(Python,)h(or)g(other)g
(languages)f(\(such)h(as)h(C\))281 1362 y(wherein)f(the)g(modified)g
(or)g(derived)g(code)g(is)g(exclusively)f(imported)h(into)g(a)281
1453 y(Python)g(module.)281 1636 y(INFOSEEK)g(CORPORATION)f(DISCLAIMS)g
(ALL)h(WARRANTIES)f(WITH)h(REGARD)g(TO)h(THIS)281 1727
y(SOFTWARE,)e(INCLUDING)h(ALL)g(IMPLIED)g(WARRANTIES)f(OF)h
(MERCHANTABILITY)f(AND)281 1818 y(FITNESS.)h(IN)g(NO)h(EVENT)f(SHALL)g
(INFOSEEK)f(CORPORATION)g(BE)h(LIABLE)g(FOR)h(ANY)281
1910 y(SPECIAL,)f(INDIRECT)f(OR)i(CONSEQUENTIAL)d(DAMAGES)i(OR)g(ANY)h
(DAMAGES)e(WHATSOEVER)281 2001 y(RESULTING)g(FROM)i(LOSS)f(OF)g(USE,)g
(DATA)h(OR)f(PROFITS,)f(WHETHER)h(IN)h(AN)f(ACTION)g(OF)281
2092 y(CONTRACT,)f(NEGLIGENCE)h(OR)g(OTHER)g(TORTIOUS)f(ACTION,)h
(ARISING)g(OUT)g(OF)h(OR)f(IN)281 2183 y(CONNECTION)f(WITH)h(THE)h(USE)
f(OR)h(PERFORMANCE)d(OF)j(THIS)f(SOFTWARE.)0 2607 y Fh(B)n(.3.8)100
b(Ex)m(ecution)29 b(tr)o(acing)0 2810 y Fr(The)20 b Fj(trace)g
Fr(module)e(contains)i(the)g(follo)n(wing)f(notice:)p
0 5549 3901 4 v 0 5649 a Fn(B)n(.3.)53 b(Licenses)22
b(and)i(Ac)n(kno)o(wledgements)g(f)n(or)e(Incor)r(por)o(ated)i(Softw)o
(are)1378 b(131)p eop end
%%Page: 132 138
TeXDict begin 132 137 bop 281 174 a Fk(portions)44 b(copyright)f(2001,)
h(Autonomous)f(Zones)h(Industries,)f(Inc.,)h(all)g(rights...)281
266 y(err...)89 b(reserved)43 b(and)i(offered)e(to)i(the)f(public)g
(under)g(the)g(terms)g(of)h(the)281 357 y(Python)f(2.2)g(license.)281
448 y(Author:)g(Zooko)g(O'Whielacronx)281 540 y(http://zooko.com/)281
631 y(mailto:[email protected])281 814 y(Copyright)f(2000,)h(Mojam)g
(Media,)g(Inc.,)g(all)g(rights)g(reserved.)281 905 y(Author:)g(Skip)g
(Montanaro)281 1088 y(Copyright)f(1999,)h(Bioreason,)g(Inc.,)g(all)g
(rights)g(reserved.)281 1179 y(Author:)g(Andrew)g(Dalke)281
1362 y(Copyright)f(1995-1997,)h(Automatrix,)f(Inc.,)g(all)i(rights)f
(reserved.)281 1453 y(Author:)g(Skip)g(Montanaro)281
1636 y(Copyright)f(1991-1995,)h(Stichting)f(Mathematisch)g(Centrum,)g
(all)h(rights)g(reserved.)281 1910 y(Permission)f(to)i(use,)f(copy,)g
(modify,)g(and)g(distribute)f(this)h(Python)g(software)f(and)281
2001 y(its)h(associated)g(documentation)e(for)j(any)f(purpose)f
(without)h(fee)g(is)h(hereby)281 2092 y(granted,)f(provided)f(that)h
(the)h(above)f(copyright)f(notice)h(appears)f(in)i(all)f(copies,)281
2183 y(and)g(that)h(both)f(that)g(copyright)f(notice)h(and)g(this)g
(permission)g(notice)f(appear)h(in)281 2275 y(supporting)f
(documentation,)g(and)h(that)g(the)g(name)h(of)f(neither)g(Automatrix,)
281 2366 y(Bioreason)f(or)i(Mojam)f(Media)g(be)g(used)h(in)f
(advertising)f(or)h(publicity)g(pertaining)f(to)281 2457
y(distribution)g(of)h(the)h(software)e(without)h(specific,)f(written)h
(prior)g(permission.)0 2882 y Fh(B)n(.3.9)100 b(UUencode)30
b(and)e(UUdecode)i(functions)0 3084 y Fr(The)20 b Fj(uu)g
Fr(module)f(contains)h(the)g(follo)n(wing)e(notice:)p
0 5549 3901 4 v 0 5649 a Fn(132)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 133 139
TeXDict begin 133 138 bop 281 174 a Fk(Copyright)43 b(1994)i(by)f
(Lance)g(Ellinghouse)281 266 y(Cathedral)f(City,)h(California)g
(Republic,)f(United)h(States)f(of)i(America.)1312 357
y(All)g(Rights)e(Reserved)281 448 y(Permission)g(to)i(use,)f(copy,)g
(modify,)g(and)g(distribute)f(this)h(software)g(and)g(its)281
540 y(documentation)f(for)h(any)g(purpose)g(and)g(without)g(fee)g(is)h
(hereby)f(granted,)281 631 y(provided)g(that)g(the)g(above)g(copyright)
f(notice)h(appear)g(in)g(all)h(copies)f(and)g(that)281
722 y(both)g(that)g(copyright)g(notice)g(and)g(this)g(permission)f
(notice)h(appear)g(in)281 814 y(supporting)f(documentation,)g(and)h
(that)g(the)g(name)h(of)f(Lance)g(Ellinghouse)281 905
y(not)g(be)h(used)f(in)h(advertising)e(or)h(publicity)f(pertaining)g
(to)i(distribution)281 996 y(of)g(the)f(software)f(without)h(specific,)
f(written)h(prior)g(permission.)281 1088 y(LANCE)g(ELLINGHOUSE)f
(DISCLAIMS)g(ALL)i(WARRANTIES)e(WITH)h(REGARD)g(TO)281
1179 y(THIS)g(SOFTWARE,)g(INCLUDING)f(ALL)h(IMPLIED)g(WARRANTIES)f(OF)h
(MERCHANTABILITY)f(AND)281 1270 y(FITNESS,)h(IN)g(NO)h(EVENT)f(SHALL)g
(LANCE)g(ELLINGHOUSE)e(CENTRUM)i(BE)h(LIABLE)281 1362
y(FOR)f(ANY)h(SPECIAL,)e(INDIRECT)h(OR)g(CONSEQUENTIAL)f(DAMAGES)g(OR)i
(ANY)f(DAMAGES)281 1453 y(WHATSOEVER)f(RESULTING)h(FROM)g(LOSS)g(OF)g
(USE,)g(DATA)h(OR)f(PROFITS,)g(WHETHER)f(IN)i(AN)281
1544 y(ACTION)f(OF)g(CONTRACT,)g(NEGLIGENCE)f(OR)h(OTHER)g(TORTIOUS)g
(ACTION,)f(ARISING)h(OUT)281 1636 y(OF)h(OR)f(IN)h(CONNECTION)e(WITH)h
(THE)g(USE)h(OR)f(PERFORMANCE)f(OF)h(THIS)h(SOFTWARE.)281
1818 y(Modified)f(by)g(Jack)g(Jansen,)g(CWI,)g(July)g(1995:)281
1910 y(-)h(Use)f(binascii)g(module)f(to)i(do)f(the)h(actual)e
(line-by-line)g(conversion)371 2001 y(between)g(ascii)h(and)h(binary.)e
(This)i(results)e(in)i(a)f(1000-fold)g(speedup.)f(The)h(C)371
2092 y(version)f(is)i(still)f(5)h(times)f(faster,)f(though.)281
2183 y(-)i(Arguments)e(more)h(compliant)g(with)g(python)f(standard)0
2608 y Fh(B)n(.3.10)101 b(XML)28 b(Remote)h(Procedure)h(Calls)0
2811 y Fr(The)20 b Fj(xmlrpclib)f Fr(module)g(contains)g(the)h(follo)n
(wing)f(notice:)p 0 5549 3901 4 v 0 5649 a Fn(B)n(.3.)53
b(Licenses)22 b(and)i(Ac)n(kno)o(wledgements)g(f)n(or)e(Incor)r(por)o
(ated)i(Softw)o(are)1378 b(133)p eop end
%%Page: 134 140
TeXDict begin 134 139 bop 460 174 a Fk(The)45 b(XML-RPC)e(client)h
(interface)g(is)281 357 y(Copyright)f(\(c\))i(1999-2002)e(by)i(Secret)e
(Labs)h(AB)281 448 y(Copyright)f(\(c\))i(1999-2002)e(by)i(Fredrik)e
(Lundh)281 631 y(By)i(obtaining,)e(using,)h(and/or)f(copying)h(this)g
(software)g(and/or)f(its)281 722 y(associated)g(documentation,)g(you)h
(agree)g(that)g(you)g(have)h(read,)f(understood,)281
814 y(and)g(will)h(comply)e(with)i(the)f(following)f(terms)h(and)g
(conditions:)281 996 y(Permission)f(to)i(use,)f(copy,)g(modify,)g(and)g
(distribute)f(this)h(software)g(and)281 1088 y(its)g(associated)g
(documentation)e(for)j(any)f(purpose)f(and)i(without)e(fee)i(is)281
1179 y(hereby)f(granted,)f(provided)h(that)g(the)g(above)g(copyright)g
(notice)f(appears)h(in)281 1270 y(all)g(copies,)g(and)g(that)h(both)f
(that)g(copyright)f(notice)h(and)g(this)g(permission)281
1362 y(notice)g(appear)g(in)g(supporting)f(documentation,)g(and)h(that)
g(the)h(name)f(of)281 1453 y(Secret)g(Labs)g(AB)h(or)f(the)g(author)g
(not)h(be)f(used)g(in)h(advertising)e(or)h(publicity)281
1544 y(pertaining)f(to)i(distribution)e(of)h(the)g(software)g(without)f
(specific,)h(written)281 1636 y(prior)g(permission.)281
1818 y(SECRET)g(LABS)g(AB)h(AND)f(THE)g(AUTHOR)g(DISCLAIMS)f(ALL)i
(WARRANTIES)e(WITH)h(REGARD)281 1910 y(TO)h(THIS)f(SOFTWARE,)f
(INCLUDING)g(ALL)i(IMPLIED)e(WARRANTIES)g(OF)i(MERCHANT-)281
2001 y(ABILITY)f(AND)g(FITNESS.)88 b(IN)45 b(NO)f(EVENT)g(SHALL)g
(SECRET)g(LABS)g(AB)h(OR)f(THE)h(AUTHOR)281 2092 y(BE)g(LIABLE)e(FOR)i
(ANY)f(SPECIAL,)g(INDIRECT)f(OR)h(CONSEQUENTIAL)f(DAMAGES)h(OR)g(ANY)
281 2183 y(DAMAGES)g(WHATSOEVER)f(RESULTING)g(FROM)h(LOSS)g(OF)h(USE,)f
(DATA)g(OR)h(PROFITS,)281 2275 y(WHETHER)f(IN)g(AN)h(ACTION)f(OF)g
(CONTRACT,)f(NEGLIGENCE)g(OR)i(OTHER)f(TORTIOUS)281 2366
y(ACTION,)g(ARISING)f(OUT)i(OF)f(OR)h(IN)f(CONNECTION)f(WITH)h(THE)h
(USE)f(OR)h(PERFORMANCE)281 2457 y(OF)g(THIS)f(SOFTWARE.)p
0 5549 3901 4 v 0 5649 a Fn(134)2538 b(Appendix)25 b(B)n(.)47
b(Histor)r(y)22 b(and)i(License)p eop end
%%Page: 135 141
TeXDict begin 135 140 bop 3269 564 a Fx(INDEX)0 1317
y Fl(Symbols)0 1440 y Fj(_PyImport_FindExtension\(\))p
Fr(,)16 b(25)0 1540 y Fj(_PyImport_Fini\(\))p Fr(,)i(25)0
1639 y Fj(_PyImport_FixupExtension\(\))p Fr(,)e(25)0
1739 y Fj(_PyImport_Init\(\))p Fr(,)i(25)0 1838 y Fj(_PyObject_Del\(\))
p Fr(,)g(97)0 1938 y Fj(_PyObject_GC_TRACK\(\))p Fr(,)f(116)0
2038 y Fj(_PyObject_GC_UNTRACK\(\))p Fr(,)f(116)0 2137
y Fj(_PyObject_New\(\))p Fr(,)i(97)0 2237 y Fj(_PyObject_NewVar\(\))p
Fr(,)f(97)0 2337 y Fj(_PyString_Resize\(\))p Fr(,)g(55)0
2436 y Fj(_PyTuple_Resize\(\))p Fr(,)g(65)0 2536 y Fj(_Py_NoneStruct)p
Fr(,)h(98)0 2635 y Fj(_Py_c_diff\(\))p Fr(,)g(52)0 2735
y Fj(_Py_c_neg\(\))p Fr(,)g(52)0 2835 y Fj(_Py_c_pow\(\))p
Fr(,)g(52)0 2934 y Fj(_Py_c_prod\(\))p Fr(,)g(52)0 3034
y Fj(_Py_c_quot\(\))p Fr(,)g(52)0 3134 y Fj(_Py_c_sum\(\))p
Fr(,)g(52)0 3233 y Fj(__all__)h Fr(\(package)g(v)n(ariable\),)f(24)0
3333 y Fj(__builtin__)h Fr(\(b)n(uilt-in)g(module\),)f(8,)i(83)0
3432 y Fj(__dict__)f Fr(\(module)g(attrib)n(ute\),)g(73)0
3532 y Fj(__doc__)g Fr(\(module)g(attrib)n(ute\),)g(73)0
3632 y Fj(__file__)g Fr(\(module)g(attrib)n(ute\),)g(73)0
3731 y Fj(__import__\(\))g Fr(\(b)n(uilt-in)g(function\),)f(24)0
3831 y Fj(__main__)h Fr(\(b)n(uilt-in)g(module\),)g(8,)h(83)0
3931 y Fj(__name__)f Fr(\(module)g(attrib)n(ute\),)g(73)0
4030 y Fj(_ob_next)g Fr(\(PyObject)h(member\),)e(102)0
4130 y Fj(_ob_prev)h Fr(\(PyObject)h(member\),)e(102)0
4325 y Fl(A)0 4449 y Fj(abort\(\))p Fr(,)h(24)0 4548
y Fj(abs\(\))h Fr(\(b)n(uilt-in)f(function\),)f(40)0
4648 y Fj(apply\(\))h Fr(\(b)n(uilt-in)h(function\),)e(37)0
4748 y Fj(argv)i Fr(\(in)g(module)f(sys\),)h(86)0 4943
y Fl(B)0 5067 y Fj(BaseException)e Fr(\(b)n(uilt-in)i(e)o(xception\),)d
(21)0 5166 y(b)n(uf)n(fer)166 5266 y(object,)i(63)0 5365
y(b)n(uf)n(fer)g(interf)o(ace,)g(63)1992 1312 y Fj(BufferType)f
Fr(\(in)i(module)f(types\),)h(64)1992 1509 y Fl(C)1992
1632 y Fj(calloc\(\))p Fr(,)f(93)1992 1732 y Fj(classmethod\(\))f
Fr(\(b)n(uilt-in)h(function\),)f(100)1992 1831 y(cleanup)g(functions,)h
(24)1992 1931 y Fj(close\(\))g Fr(\(in)h(module)f(os\),)h(84)1992
2031 y Fj(cmp\(\))f Fr(\(b)n(uilt-in)h(function\),)d(36)1992
2130 y Fj(CO_FUTURE_DIVISION)p Fr(,)g(13)1992 2230 y(CObject)2158
2330 y(object,)i(76)1992 2429 y Fj(coerce\(\))g Fr(\(b)n(uilt-in)g
(function\),)f(41)1992 2529 y Fj(compile\(\))h Fr(\(b)n(uilt-in)g
(function\),)f(25)1992 2628 y(comple)o(x)g(number)2158
2728 y(object,)h(52)1992 2828 y Fj(copyright)g Fr(\(in)h(module)e
(sys\),)j(86)1992 3023 y Fl(D)1992 3147 y Fr(dictionary)2158
3246 y(object,)e(67)1992 3346 y Fj(DictionaryType)f Fr(\(in)i(module)e
(types\),)i(67)1992 3446 y Fj(DictType)f Fr(\(in)h(module)f(types\),)g
(67)1992 3545 y Fj(divmod\(\))g Fr(\(b)n(uilt-in)g(function\),)f(39)
1992 3738 y Fl(E)1992 3861 y Fr(en)m(vironment)f(v)n(ariables)2158
3960 y(P)-8 b(A)f(TH,)20 b(8)2158 4060 y(PYTHONDUMPREFS,)g(102)2158
4160 y(PYTHONHOME,)f(8)2158 4259 y(PYTHONP)-8 b(A)f(TH,)20
b(8)2158 4359 y(e)o(x)o(ec)p 2314 4359 25 4 v 28 w(pre\002x,)f(1,)h(2)
2158 4459 y(pre\002x,)f(1,)h(2)1992 4558 y Fj(EOFError)f
Fr(\(b)n(uilt-in)g(e)o(xception\),)f(70)1992 4658 y Fj(errno)p
Fr(,)h(87)1992 4757 y Fj(exc_info\(\))f Fr(\(in)i(module)f(sys\),)h(6)
1992 4857 y Fj(exc_traceback)e Fr(\(in)i(module)f(sys\),)h(6,)g(17)1992
4957 y Fj(exc_type)f Fr(\(in)h(module)f(sys\),)h(6,)g(17)1992
5056 y Fj(exc_value)f Fr(\(in)h(module)e(sys\),)j(6,)f(17)1992
5156 y Fj(exceptions)e Fr(\(b)n(uilt-in)i(module\),)e(8)1992
5256 y(e)o(x)o(ec)p 2148 5256 V 28 w(pre\002x,)h(1,)h(2)1992
5355 y Fj(executable)e Fr(\(in)i(module)f(sys\),)h(85)p
0 5549 3901 4 v 3762 5649 a Fn(135)p eop end
%%Page: 136 142
TeXDict begin 136 141 bop 0 83 a Fj(exit\(\))p Fr(,)19
b(24)0 266 y Fl(F)0 389 y Fr(\002le)166 489 y(object,)g(70)0
588 y Fj(FileType)g Fr(\(in)h(module)f(types\),)g(70)0
688 y Fj(float\(\))g Fr(\(b)n(uilt-in)h(function\),)e(42)0
787 y(\003oating)h(point)166 887 y(object,)g(51)0 987
y Fj(FloatType)g Fr(\(in)h(modules)f(types\),)h(51)0
1086 y Fj(fopen\(\))p Fr(,)f(70)0 1186 y Fj(free\(\))p
Fr(,)g(93)0 1286 y(freeze)g(utility)-5 b(,)20 b(25)0
1385 y(frozenset)166 1485 y(object,)f(79)0 1584 y(function)166
1684 y(object,)g(71)0 1881 y Fl(G)0 2005 y Fr(global)g(interpreter)g
(lock,)g(86)0 2200 y Fl(H)0 2324 y Fj(hash\(\))h Fr(\(b)n(uilt-in)f
(function\),)f(37,)h(105)0 2516 y Fl(I)0 2639 y Fj(ihooks)h
Fr(\(standard)e(module\),)h(24)0 2739 y Fj(incr_item\(\))p
Fr(,)f(6,)i(7)0 2839 y(instance)166 2938 y(object,)f(71)0
3038 y Fj(int\(\))h Fr(\(b)n(uilt-in)f(function\),)f(41)0
3137 y Fj(inquiry)h Fr(\(C)i(type\),)e(117)0 3237 y Fj(Py_tracefunc)g
Fr(\(C)h(type\),)f(91)0 3337 y Fj(traverseproc)g Fr(\(C)h(type\),)f
(117)0 3436 y Fj(visitproc)g Fr(\(C)i(type\),)e(116)0
3536 y(inte)o(ger)166 3636 y(object,)g(48)0 3735 y(interpreter)g(lock,)
g(86)0 3835 y Fj(IntType)g Fr(\(in)h(modules)g(types\),)f(48)0
4031 y Fl(K)0 4154 y Fj(KeyboardInterrupt)f Fr(\(b)n(uilt-in)h(e)o
(xception\),)f(20)0 4349 y Fl(L)0 4473 y Fj(len\(\))i
Fr(\(b)n(uilt-in)f(function\),)f(38,)h(42,)h(44,)g(66,)f(68,)h(80)0
4572 y(list)166 4672 y(object,)f(66)0 4772 y Fj(ListType)g
Fr(\(in)h(module)f(types\),)g(66)0 4871 y(lock,)g(interpreter)m(,)f(86)
0 4971 y Fj(long\(\))i Fr(\(b)n(uilt-in)f(function\),)f(42)0
5070 y(long)h(inte)o(ger)166 5170 y(object,)g(50)0 5270
y Fj(LONG_MAX)p Fr(,)g(49,)h(50)0 5369 y Fj(LongType)f
Fr(\(in)h(modules)f(types\),)h(50)1992 86 y Fl(M)1992
210 y Fj(main\(\))p Fr(,)f(84,)g(86)1992 309 y Fj(malloc\(\))p
Fr(,)g(93)1992 409 y(mapping)2158 509 y(object,)g(67)1992
608 y Fj(METH_CLASS)f Fr(\(data)i(in)g(\),)h(100)1992
708 y Fj(METH_COEXIST)d Fr(\(data)i(in)g(\),)g(100)1992
807 y Fj(METH_KEYWORDS)e Fr(\(data)i(in)g(\),)g(99)1992
907 y Fj(METH_NOARGS)e Fr(\(data)i(in)g(\),)g(100)1992
1007 y Fj(METH_O)f Fr(\(data)h(in)g(\),)g(100)1992 1106
y Fj(METH_OLDARGS)e Fr(\(data)i(in)g(\),)g(100)1992 1206
y Fj(METH_STATIC)e Fr(\(data)i(in)g(\),)g(100)1992 1306
y Fj(METH_VARARGS)e Fr(\(data)i(in)g(\),)g(99)1992 1405
y(method)2158 1505 y(object,)f(72)1992 1604 y Fj(MethodType)f
Fr(\(in)i(module)f(types\),)h(71,)f(72)1992 1704 y(module)2158
1804 y(object,)g(73)2158 1903 y(search)g(path,)h(8,)g(83,)f(85)1992
2003 y Fj(modules)g Fr(\(in)h(module)f(sys\),)h(24,)g(83)1992
2103 y Fj(ModuleType)e Fr(\(in)i(module)f(types\),)h(73)1992
2298 y Fl(N)1992 2421 y Fr(None)2158 2521 y(object,)f(48)1992
2621 y(numeric)2158 2720 y(object,)g(48)1992 2918 y Fl(O)1992
3041 y Fj(ob_refcnt)g Fr(\(PyObject)g(member\),)f(102)1992
3141 y Fj(ob_size)h Fr(\(PyV)-9 b(arObject)19 b(member\),)f(103)1992
3240 y Fj(ob_type)h Fr(\(PyObject)g(member\),)g(102)1992
3340 y(object)2158 3439 y(b)n(uf)n(fer)m(,)f(63)2158
3539 y(CObject,)i(76)2158 3639 y(comple)o(x)e(number)m(,)g(52)2158
3738 y(dictionary)-5 b(,)17 b(67)2158 3838 y(\002le,)j(70)2158
3938 y(\003oating)f(point,)g(51)2158 4037 y(frozenset,)f(79)2158
4137 y(function,)g(71)2158 4236 y(instance,)h(71)2158
4336 y(inte)o(ger)m(,)f(48)2158 4436 y(list,)j(66)2158
4535 y(long)e(inte)o(ger)m(,)f(50)2158 4635 y(mapping,)g(67)2158
4735 y(method,)g(72)2158 4834 y(module,)g(73)2158 4934
y(None,)h(48)2158 5034 y(numeric,)f(48)2158 5133 y(sequence,)g(53)2158
5233 y(set,)i(79)2158 5332 y(string,)f(53)p 0 5549 3901
4 v 0 5649 a Fn(136)3561 b(Inde)n(x)p eop end
%%Page: 137 143
TeXDict begin 137 142 bop 166 83 a Fr(tuple,)20 b(65)166
183 y(type,)g(2,)g(47)0 282 y Fj(OverflowError)e Fr(\(b)n(uilt-in)i(e)o
(xception\),)d(50,)j(51)0 478 y Fl(P)0 601 y Fr(package)f(v)n(ariable)
166 701 y Fj(__all__)p Fr(,)g(24)0 800 y(P)-8 b(A)f(TH,)20
b(8)0 900 y(path)166 1000 y(module)f(search,)g(8,)h(83,)g(85)0
1099 y Fj(path)g Fr(\(in)g(module)f(sys\),)h(8,)g(83,)g(85)0
1199 y Fj(platform)f Fr(\(in)h(module)f(sys\),)h(85)0
1299 y Fj(pow\(\))g Fr(\(b)n(uilt-in)f(function\),)f(39,)h(41)0
1398 y(pre\002x,)g(1,)h(2)0 1498 y Fj(Py_AtExit\(\))p
Fr(,)e(24)0 1597 y Fj(Py_BEGIN_ALLOW_THREADS)p Fr(,)e(87)0
1697 y Fj(Py_BEGIN_ALLOW_THREADS)h Fr(\(macro\),)h(89)0
1797 y Fj(Py_BLOCK_THREADS)g Fr(\(macro\),)g(89)0 1896
y Fj(Py_BuildValue\(\))p Fr(,)g(31)0 1996 y Fj(Py_CLEAR\(\))p
Fr(,)h(15)0 2096 y Fj(Py_CompileString\(\))p Fr(,)e(13)0
2195 y Fj(Py_CompileString\(\))p Fr(,)g(13)0 2295 y Fj
(Py_CompileStringFlags\(\))p Fr(,)f(13)0 2394 y Fj(Py_complex)j
Fr(\(C)i(type\),)e(52)0 2494 y Fj(Py_DECREF\(\))p Fr(,)f(15)0
2594 y Fj(Py_DECREF\(\))p Fr(,)g(2)0 2693 y Fj(Py_END_ALLOW_THREADS)p
Fr(,)f(87)0 2793 y Fj(Py_END_ALLOW_THREADS)g Fr(\(macro\),)h(89)0
2893 y Fj(Py_END_OF_BUFFER)p Fr(,)g(64)0 2992 y Fj
(Py_EndInterpreter\(\))p Fr(,)f(84)0 3092 y Fj(Py_eval_input)p
Fr(,)h(13)0 3191 y Fj(Py_Exit\(\))p Fr(,)h(24)0 3291
y Fj(Py_False)p Fr(,)g(49)0 3391 y Fj(Py_FatalError\(\))p
Fr(,)f(23)0 3490 y Fj(Py_FatalError\(\))p Fr(,)g(86)0
3590 y Fj(Py_FdIsInteractive\(\))p Fr(,)f(23)0 3690 y
Fj(Py_file_input)p Fr(,)h(13)0 3789 y Fj(Py_Finalize\(\))p
Fr(,)g(83)0 3889 y Fj(Py_Finalize\(\))p Fr(,)g(24,)i(83,)f(84)0
3988 y Fj(Py_FindMethod\(\))p Fr(,)f(100)0 4088 y Fj
(Py_GetBuildInfo\(\))p Fr(,)f(86)0 4188 y Fj(Py_GetBuildNumber\(\))p
Fr(,)g(85)0 4287 y Fj(Py_GetCompiler\(\))p Fr(,)h(86)0
4387 y Fj(Py_GetCopyright\(\))p Fr(,)f(85)0 4487 y Fj
(Py_GetExecPrefix\(\))p Fr(,)g(84)0 4586 y Fj(Py_GetExecPrefix\(\))p
Fr(,)g(8)0 4686 y Fj(Py_GetPath\(\))p Fr(,)h(85)0 4786
y Fj(Py_GetPath\(\))p Fr(,)g(8,)i(84)0 4885 y Fj(Py_GetPlatform\(\))p
Fr(,)e(85)0 4985 y Fj(Py_GetPrefix\(\))p Fr(,)g(84)0
5084 y Fj(Py_GetPrefix\(\))p Fr(,)g(8)0 5184 y Fj
(Py_GetProgramFullPath\(\))p Fr(,)e(85)0 5284 y Fj
(Py_GetProgramFullPath\(\))p Fr(,)g(8)0 5383 y Fj
(Py_GetProgramName\(\))p Fr(,)h(84)1992 83 y Fj(Py_GetVersion\(\))p
Fr(,)g(85)1992 183 y Fj(Py_INCREF\(\))p Fr(,)h(15)1992
282 y Fj(Py_INCREF\(\))p Fr(,)g(2)1992 382 y Fj(Py_Initialize\(\))p
Fr(,)f(83)1992 482 y Fj(Py_Initialize\(\))p Fr(,)g(8,)j(84,)g(88)1992
581 y Fj(Py_InitializeEx\(\))p Fr(,)d(83)1992 681 y Fj
(Py_InitModule\(\))p Fr(,)g(98)1992 780 y Fj(Py_InitModule3\(\))p
Fr(,)g(98)1992 880 y Fj(Py_InitModule4\(\))p Fr(,)g(98)1992
980 y Fj(Py_IsInitialized\(\))p Fr(,)g(83)1992 1079 y
Fj(Py_IsInitialized\(\))p Fr(,)g(8)1992 1179 y Fj(Py_Main\(\))p
Fr(,)h(11)1992 1279 y Fj(Py_NewInterpreter\(\))p Fr(,)e(83)1992
1378 y Fj(Py_None)p Fr(,)j(48)1992 1478 y Fj(Py_PRINT_RAW)p
Fr(,)f(71)1992 1577 y Fj(Py_RETURN_FALSE)f Fr(\(macro\),)i(49)1992
1677 y Fj(Py_RETURN_NONE)f Fr(\(macro\),)g(48)1992 1777
y Fj(Py_RETURN_TRUE)g Fr(\(macro\),)g(49)1992 1876 y
Fj(Py_SetProgramName\(\))p Fr(,)e(84)1992 1976 y Fj
(Py_SetProgramName\(\))p Fr(,)g(8,)k(83\22685)1992 2076
y Fj(Py_single_input)p Fr(,)d(13)1992 2175 y Fj(getcharbufferproc)g
Fr(\(C)k(type\),)e(115)1992 2275 y Fj(getreadbufferproc)e
Fr(\(C)k(type\),)e(115)1992 2374 y Fj(getsegcountproc)e
Fr(\(C)k(type\),)e(115)1992 2474 y Fj(getwritebufferproc)e
Fr(\(C)k(type\),)e(115)1992 2574 y Fj(Py_TPFLAGS_BASETYPE)e
Fr(\(data)i(in)i(\),)f(107)1992 2673 y Fj(Py_TPFLAGS_CHECKTYPES)c
Fr(\(data)k(in)g(\),)h(106)1992 2773 y Fj(Py_TPFLAGS_DEFAULT)c
Fr(\(data)j(in)g(\),)g(107)1992 2873 y Fj(Py_TPFLAGS_GC)e
Fr(\(data)i(in)g(\),)g(106)1992 2972 y Fj(Py_TPFLAGS_HAVE_CLASS)c
Fr(\(data)k(in)g(\),)h(107)1992 3072 y Fj(Py_TPFLAGS_HAVE_GC)c
Fr(\(data)j(in)g(\),)g(107,)f(116)1992 3171 y Fj
(Py_TPFLAGS_HAVE_GETCHARBUFFER)56 b Fr(\(data)k(in)i(\),)2324
3271 y(106,)19 b(115)1992 3371 y Fj(Py_TPFLAGS_HAVE_INPLACEOPS)c
Fr(\(data)20 b(in)g(\),)h(106)1992 3470 y Fj(Py_TPFLAGS_HAVE_ITER)c
Fr(\(data)i(in)i(\),)f(107)1992 3570 y Fj(Py_TPFLAGS_HAVE_RICHCOMPARE)
15 b Fr(\(data)20 b(in)g(\),)g(107)1992 3670 y Fj
(Py_TPFLAGS_HAVE_SEQUENCE_IN)15 b Fr(\(data)20 b(in)g(\),)g(106)1992
3769 y Fj(Py_TPFLAGS_HAVE_WEAKREFS)c Fr(\(data)j(in)i(\),)f(107)1992
3869 y Fj(Py_TPFLAGS_HEAPTYPE)d Fr(\(data)i(in)i(\),)f(107)1992
3968 y Fj(Py_TPFLAGS_READY)d Fr(\(data)j(in)g(\),)g(107)1992
4068 y Fj(Py_TPFLAGS_READYING)d Fr(\(data)i(in)i(\),)f(107)1992
4168 y Fj(Py_True)p Fr(,)f(49)1992 4267 y Fj(Py_UNBLOCK_THREADS)e
Fr(\(macro\),)h(89)1992 4367 y Fj(Py_UNICODE)g Fr(\(C)j(type\),)e(56)
1992 4467 y Fj(Py_UNICODE_ISALNUM\(\))p Fr(,)d(57)1992
4566 y Fj(Py_UNICODE_ISALPHA\(\))p Fr(,)g(57)1992 4666
y Fj(Py_UNICODE_ISDECIMAL\(\))p Fr(,)g(57)1992 4765 y
Fj(Py_UNICODE_ISDIGIT\(\))p Fr(,)g(57)1992 4865 y Fj
(Py_UNICODE_ISLINEBREAK\(\))p Fr(,)g(56)1992 4965 y Fj
(Py_UNICODE_ISLOWER\(\))p Fr(,)g(56)1992 5064 y Fj
(Py_UNICODE_ISNUMERIC\(\))p Fr(,)g(57)1992 5164 y Fj
(Py_UNICODE_ISSPACE\(\))p Fr(,)g(56)1992 5264 y Fj
(Py_UNICODE_ISTITLE\(\))p Fr(,)g(56)1992 5363 y Fj
(Py_UNICODE_ISUPPER\(\))p Fr(,)g(56)p 0 5549 3901 4 v
0 5649 a Fn(Inde)n(x)3561 b(137)p eop end
%%Page: 138 144
TeXDict begin 138 143 bop 0 83 a Fj(Py_UNICODE_TODECIMAL\(\))p
Fr(,)16 b(57)0 183 y Fj(Py_UNICODE_TODIGIT\(\))p Fr(,)h(57)0
282 y Fj(Py_UNICODE_TOLOWER\(\))p Fr(,)g(57)0 382 y Fj
(Py_UNICODE_TONUMERIC\(\))p Fr(,)f(57)0 482 y Fj
(Py_UNICODE_TOTITLE\(\))p Fr(,)h(57)0 581 y Fj(Py_UNICODE_TOUPPER\(\))p
Fr(,)g(57)0 681 y Fj(Py_VISIT\(\))p Fr(,)i(117)0 780
y Fj(Py_XDECREF\(\))p Fr(,)f(15)0 880 y Fj(Py_XDECREF\(\))p
Fr(,)g(7)0 980 y Fj(Py_XINCREF\(\))p Fr(,)g(15)0 1079
y Fj(PyAnySet_Check\(\))p Fr(,)g(80)0 1179 y Fj
(PyAnySet_CheckExact\(\))p Fr(,)f(80)0 1279 y Fj(PyArg_Parse\(\))p
Fr(,)h(31)0 1378 y Fj(PyArg_ParseTuple\(\))p Fr(,)f(30)0
1478 y Fj(PyArg_ParseTupleAndKeywords\(\))p Fr(,)e(30)0
1577 y Fj(PyArg_UnpackTuple\(\))p Fr(,)i(31)0 1677 y
Fj(PyArg_VaParse\(\))p Fr(,)h(30)0 1777 y Fj
(PyArg_VaParseTupleAndKeywords\(\))p Fr(,)d(30)0 1876
y Fj(PyBool_Check\(\))p Fr(,)j(49)0 1976 y Fj(PyBool_FromLong\(\))p
Fr(,)f(49)0 2076 y Fj(PyBuffer_Check\(\))p Fr(,)h(64)0
2175 y Fj(PyBuffer_FromMemory\(\))p Fr(,)f(64)0 2275
y Fj(PyBuffer_FromObject\(\))p Fr(,)g(64)0 2374 y Fj
(PyBuffer_FromReadWriteMemory\(\))p Fr(,)e(64)0 2474
y Fj(PyBuffer_FromReadWriteObject\(\))p Fr(,)g(64)0 2574
y Fj(PyBuffer_New\(\))p Fr(,)j(64)0 2673 y Fj(PyBuffer_Type)p
Fr(,)g(64)0 2773 y Fj(PyBufferObject)g Fr(\(C)j(type\),)e(64)0
2873 y Fj(PyBufferProcs)p Fr(,)f(64)0 2972 y Fj(PyBufferProcs)g
Fr(\(C)j(type\),)e(115)0 3072 y Fj(PyCallable_Check\(\))p
Fr(,)e(37)0 3171 y Fj(PyCallIter_Check\(\))p Fr(,)g(74)0
3271 y Fj(PyCallIter_New\(\))p Fr(,)h(74)0 3371 y Fj(PyCallIter_Type)p
Fr(,)g(74)0 3470 y Fj(PyCell_Check\(\))p Fr(,)g(77)0
3570 y Fj(PyCell_GET\(\))p Fr(,)g(77)0 3670 y Fj(PyCell_Get\(\))p
Fr(,)g(77)0 3769 y Fj(PyCell_New\(\))p Fr(,)g(77)0 3869
y Fj(PyCell_SET\(\))p Fr(,)g(77)0 3968 y Fj(PyCell_Set\(\))p
Fr(,)g(77)0 4068 y Fj(PyCell_Type)p Fr(,)g(77)0 4168
y Fj(PyCellObject)h Fr(\(C)h(type\),)f(77)0 4267 y Fj(PyCFunction)g
Fr(\(C)h(type\),)g(99)0 4367 y Fj(PyCObject)f Fr(\(C)i(type\),)e(76)0
4467 y Fj(PyCObject_AsVoidPtr\(\))p Fr(,)e(76)0 4566
y Fj(PyCObject_Check\(\))p Fr(,)g(76)0 4666 y Fj
(PyCObject_FromVoidPtr\(\))p Fr(,)f(76)0 4765 y Fj
(PyCObject_FromVoidPtrAndDesc\(\))p Fr(,)f(76)0 4865
y Fj(PyCObject_GetDesc\(\))p Fr(,)i(76)0 4965 y Fj
(PyCObject_SetVoidPtr\(\))p Fr(,)f(76)0 5064 y Fj
(PyComplex_AsCComplex\(\))p Fr(,)g(53)0 5164 y Fj(PyComplex_Check\(\))p
Fr(,)h(52)0 5264 y Fj(PyComplex_CheckExact\(\))p Fr(,)f(52)0
5363 y Fj(PyComplex_FromCComplex\(\))p Fr(,)g(53)1992
83 y Fj(PyComplex_FromDoubles\(\))p Fr(,)g(53)1992 183
y Fj(PyComplex_ImagAsDouble\(\))p Fr(,)g(53)1992 282
y Fj(PyComplex_RealAsDouble\(\))p Fr(,)g(53)1992 382
y Fj(PyComplex_Type)p Fr(,)h(52)1992 482 y Fj(PyComplexObject)g
Fr(\(C)k(type\),)e(52)1992 581 y Fj(PyDate_Check\(\))p
Fr(,)e(78)1992 681 y Fj(PyDate_CheckExact\(\))p Fr(,)f(78)1992
780 y Fj(PyDate_FromDate\(\))p Fr(,)h(78)1992 880 y Fj
(PyDate_FromTimestamp\(\))p Fr(,)f(79)1992 980 y Fj
(PyDateTime_Check\(\))p Fr(,)h(78)1992 1079 y Fj
(PyDateTime_CheckExact\(\))p Fr(,)f(78)1992 1179 y Fj
(PyDateTime_DATE_GET_HOUR\(\))p Fr(,)f(79)1992 1279 y
Fj(PyDateTime_DATE_GET_MICROSECOND\(\))o Fr(,)g(79)1992
1378 y Fj(PyDateTime_DATE_GET_MINUTE\(\))p Fr(,)g(79)1992
1478 y Fj(PyDateTime_DATE_GET_SECOND\(\))p Fr(,)g(79)1992
1577 y Fj(PyDateTime_FromDateAndTime\(\))p Fr(,)g(78)1992
1677 y Fj(PyDateTime_FromTimestamp\(\))p Fr(,)g(79)1992
1777 y Fj(PyDateTime_GET_DAY\(\))p Fr(,)h(79)1992 1876
y Fj(PyDateTime_GET_MONTH\(\))p Fr(,)g(79)1992 1976 y
Fj(PyDateTime_GET_YEAR\(\))p Fr(,)g(79)1992 2076 y Fj
(PyDateTime_TIME_GET_HOUR\(\))p Fr(,)f(79)1992 2175 y
Fj(PyDateTime_TIME_GET_MICROSECOND\(\))o Fr(,)g(79)1992
2275 y Fj(PyDateTime_TIME_GET_MINUTE\(\))p Fr(,)g(79)1992
2374 y Fj(PyDateTime_TIME_GET_SECOND\(\))p Fr(,)g(79)1992
2474 y Fj(PyDelta_Check\(\))p Fr(,)i(78)1992 2574 y Fj
(PyDelta_CheckExact\(\))p Fr(,)f(78)1992 2673 y Fj(PyDelta_FromDSU\(\))
p Fr(,)h(78)1992 2773 y Fj(PyDescr_IsData\(\))p Fr(,)g(74)1992
2873 y Fj(PyDescr_NewClassMethod\(\))p Fr(,)f(74)1992
2972 y Fj(PyDescr_NewGetSet\(\))p Fr(,)g(74)1992 3072
y Fj(PyDescr_NewMember\(\))p Fr(,)g(74)1992 3171 y Fj
(PyDescr_NewMethod\(\))p Fr(,)g(74)1992 3271 y Fj
(PyDescr_NewWrapper\(\))p Fr(,)g(74)1992 3371 y Fj(PyDict_Check\(\))p
Fr(,)h(67)1992 3470 y Fj(PyDict_CheckExact\(\))p Fr(,)f(67)1992
3570 y Fj(PyDict_Clear\(\))p Fr(,)h(67)1992 3670 y Fj
(PyDict_Contains\(\))p Fr(,)g(67)1992 3769 y Fj(PyDict_Copy\(\))p
Fr(,)h(67)1992 3869 y Fj(PyDict_DelItem\(\))p Fr(,)f(68)1992
3968 y Fj(PyDict_DelItemString\(\))p Fr(,)f(68)1992 4068
y Fj(PyDict_GetItem\(\))p Fr(,)h(68)1992 4168 y Fj
(PyDict_GetItemString\(\))p Fr(,)f(68)1992 4267 y Fj(PyDict_Items\(\))p
Fr(,)h(68)1992 4367 y Fj(PyDict_Keys\(\))p Fr(,)h(68)1992
4467 y Fj(PyDict_Merge\(\))p Fr(,)f(69)1992 4566 y Fj
(PyDict_MergeFromSeq2\(\))p Fr(,)f(69)1992 4666 y Fj(PyDict_New\(\))p
Fr(,)i(67)1992 4765 y Fj(PyDict_Next\(\))p Fr(,)g(68)1992
4865 y Fj(PyDict_SetItem\(\))p Fr(,)f(68)1992 4965 y
Fj(PyDict_SetItemString\(\))p Fr(,)f(68)1992 5064 y Fj(PyDict_Size\(\))
p Fr(,)i(68)1992 5164 y Fj(PyDict_Type)p Fr(,)g(67)1992
5264 y Fj(PyDict_Update\(\))p Fr(,)f(69)1992 5363 y Fj
(PyDict_Values\(\))p Fr(,)g(68)p 0 5549 3901 4 v 0 5649
a Fn(138)3561 b(Inde)n(x)p eop end
%%Page: 139 145
TeXDict begin 139 144 bop 0 83 a Fj(PyDictObject)19 b
Fr(\(C)h(type\),)f(67)0 183 y Fj(PyDictProxy_New\(\))p
Fr(,)e(67)0 282 y Fj(PyErr_BadArgument\(\))p Fr(,)g(18)0
382 y Fj(PyErr_BadInternalCall\(\))p Fr(,)f(19)0 482
y Fj(PyErr_CheckSignals\(\))p Fr(,)h(20)0 581 y Fj(PyErr_Clear\(\))p
Fr(,)h(18)0 681 y Fj(PyErr_Clear\(\))p Fr(,)g(6,)i(7)0
780 y Fj(PyErr_ExceptionMatches\(\))p Fr(,)c(17)0 880
y Fj(PyErr_ExceptionMatches\(\))p Fr(,)g(7)0 980 y Fj(PyErr_Fetch\(\))p
Fr(,)i(18)0 1079 y Fj(PyErr_Format\(\))p Fr(,)g(18)0
1179 y Fj(PyErr_GivenExceptionMatches\(\))p Fr(,)d(17)0
1279 y Fj(PyErr_NewException\(\))p Fr(,)i(20)0 1378 y
Fj(PyErr_NoMemory\(\))p Fr(,)h(19)0 1478 y Fj
(PyErr_NormalizeException\(\))p Fr(,)e(17)0 1577 y Fj
(PyErr_Occurred\(\))p Fr(,)i(17)0 1677 y Fj(PyErr_Occurred\(\))p
Fr(,)g(6)0 1777 y Fj(PyErr_Print\(\))p Fr(,)g(17)0 1876
y Fj(PyErr_Restore\(\))p Fr(,)g(18)0 1976 y Fj
(PyErr_SetExcFromWindowsErr\(\))p Fr(,)d(19)0 2076 y
Fj(PyErr_SetExcFromWindowsErrWithFilen)o(ame\(\))p Fr(,)332
2175 y(19)0 2275 y Fj(PyErr_SetFromErrno\(\))p Fr(,)i(19)0
2374 y Fj(PyErr_SetFromErrnoWithFilename\(\))p Fr(,)e(19)0
2474 y Fj(PyErr_SetFromWindowsErr\(\))p Fr(,)h(19)0 2574
y Fj(PyErr_SetFromWindowsErrWithFilename)o(\(\))p Fr(,)332
2673 y(19)0 2773 y Fj(PyErr_SetInterrupt\(\))p Fr(,)h(20)0
2873 y Fj(PyErr_SetNone\(\))p Fr(,)h(18)0 2972 y Fj
(PyErr_SetObject\(\))p Fr(,)f(18)0 3072 y Fj(PyErr_SetString\(\))p
Fr(,)g(18)0 3171 y Fj(PyErr_SetString\(\))p Fr(,)g(6)0
3271 y Fj(PyErr_Warn\(\))p Fr(,)h(20)0 3371 y Fj(PyErr_WarnEx\(\))p
Fr(,)g(19)0 3470 y Fj(PyErr_WarnExplicit\(\))p Fr(,)f(20)0
3570 y Fj(PyErr_WriteUnraisable\(\))p Fr(,)f(20)0 3670
y Fj(PyEval_AcquireLock\(\))p Fr(,)h(88)0 3769 y Fj
(PyEval_AcquireLock\(\))p Fr(,)g(83,)i(87)0 3869 y Fj
(PyEval_AcquireThread\(\))p Fr(,)d(89)0 3968 y Fj
(PyEval_InitThreads\(\))p Fr(,)h(88)0 4068 y Fj(PyEval_InitThreads\(\))
p Fr(,)g(83)0 4168 y Fj(PyEval_ReleaseLock\(\))p Fr(,)g(89)0
4267 y Fj(PyEval_ReleaseLock\(\))p Fr(,)g(83,)i(87,)h(88)0
4367 y Fj(PyEval_ReleaseThread\(\))p Fr(,)c(89)0 4467
y Fj(PyEval_ReleaseThread\(\))p Fr(,)g(88)0 4566 y Fj
(PyEval_RestoreThread\(\))p Fr(,)g(89)0 4666 y Fj
(PyEval_RestoreThread\(\))p Fr(,)g(87,)k(88)0 4765 y
Fj(PyEval_SaveThread\(\))p Fr(,)d(89)0 4865 y Fj(PyEval_SaveThread\(\))
p Fr(,)g(87,)i(88)0 4965 y Fj(PyEval_SetProfile\(\))p
Fr(,)e(91)0 5064 y Fj(PyEval_SetTrace\(\))p Fr(,)g(92)0
5164 y Fj(PyEval_ThreadsInitialized\(\))p Fr(,)e(88)0
5264 y Fj(PyExc_ArithmeticError)p Fr(,)i(21)0 5363 y
Fj(PyExc_AssertionError)p Fr(,)g(21)1992 83 y Fj(PyExc_AttributeError)p
Fr(,)f(21)1992 183 y Fj(PyExc_BaseException)p Fr(,)g(21)1992
282 y Fj(PyExc_EnvironmentError)p Fr(,)g(21)1992 382
y Fj(PyExc_EOFError)p Fr(,)h(21)1992 482 y Fj(PyExc_Exception)p
Fr(,)g(21)1992 581 y Fj(PyExc_FloatingPointError)p Fr(,)f(21)1992
681 y Fj(PyExc_ImportError)p Fr(,)h(21)1992 780 y Fj(PyExc_IndexError)p
Fr(,)g(21)1992 880 y Fj(PyExc_IOError)p Fr(,)h(21)1992
980 y Fj(PyExc_KeyboardInterrupt)p Fr(,)e(21)1992 1079
y Fj(PyExc_KeyError)p Fr(,)h(21)1992 1179 y Fj(PyExc_LookupError)p
Fr(,)g(21)1992 1279 y Fj(PyExc_MemoryError)p Fr(,)g(21)1992
1378 y Fj(PyExc_NameError)p Fr(,)g(21)1992 1478 y Fj
(PyExc_NotImplementedError)p Fr(,)e(21)1992 1577 y Fj(PyExc_OSError)p
Fr(,)j(21)1992 1677 y Fj(PyExc_OverflowError)p Fr(,)e(21)1992
1777 y Fj(PyExc_ReferenceError)p Fr(,)g(21)1992 1876
y Fj(PyExc_RuntimeError)p Fr(,)h(21)1992 1976 y Fj(PyExc_StandardError)
p Fr(,)f(21)1992 2076 y Fj(PyExc_SyntaxError)p Fr(,)h(21)1992
2175 y Fj(PyExc_SystemError)p Fr(,)g(21)1992 2275 y Fj
(PyExc_SystemExit)p Fr(,)g(21)1992 2374 y Fj(PyExc_TypeError)p
Fr(,)g(21)1992 2474 y Fj(PyExc_ValueError)p Fr(,)g(21)1992
2574 y Fj(PyExc_WindowsError)p Fr(,)g(21)1992 2673 y
Fj(PyExc_ZeroDivisionError)p Fr(,)f(21)1992 2773 y Fj
(PyFile_AsFile\(\))p Fr(,)h(70)1992 2873 y Fj(PyFile_Check\(\))p
Fr(,)g(70)1992 2972 y Fj(PyFile_CheckExact\(\))p Fr(,)f(70)1992
3072 y Fj(PyFile_FromFile\(\))p Fr(,)h(70)1992 3171 y
Fj(PyFile_FromString\(\))p Fr(,)f(70)1992 3271 y Fj(PyFile_GetLine\(\))
p Fr(,)h(70)1992 3371 y Fj(PyFile_Name\(\))p Fr(,)h(70)1992
3470 y Fj(PyFile_SetBufSize\(\))p Fr(,)e(70)1992 3570
y Fj(PyFile_SetEncoding\(\))p Fr(,)g(70)1992 3670 y Fj
(PyFile_SoftSpace\(\))p Fr(,)h(70)1992 3769 y Fj(PyFile_Type)p
Fr(,)h(70)1992 3869 y Fj(PyFile_WriteObject\(\))p Fr(,)e(70)1992
3968 y Fj(PyFile_WriteString\(\))p Fr(,)g(71)1992 4068
y Fj(PyFileObject)i Fr(\(C)j(type\),)e(70)1992 4168 y
Fj(PyFloat_AS_DOUBLE\(\))p Fr(,)d(51)1992 4267 y Fj
(PyFloat_AsDouble\(\))p Fr(,)h(51)1992 4367 y Fj(PyFloat_Check\(\))p
Fr(,)g(51)1992 4467 y Fj(PyFloat_CheckExact\(\))p Fr(,)f(51)1992
4566 y Fj(PyFloat_FromDouble\(\))p Fr(,)g(51)1992 4666
y Fj(PyFloat_FromString\(\))p Fr(,)g(51)1992 4765 y Fj(PyFloat_Type)p
Fr(,)i(51)1992 4865 y Fj(PyFloatObject)g Fr(\(C)j(type\),)e(51)1992
4965 y Fj(PyFrozenSet_CheckExact\(\))p Fr(,)d(80)1992
5064 y Fj(PyFrozenSet_New\(\))p Fr(,)h(80)1992 5164 y
Fj(PyFrozenSet_Type)p Fr(,)g(80)1992 5264 y Fj(PyFunction_Check\(\))p
Fr(,)g(71)1992 5363 y Fj(PyFunction_GetClosure\(\))p
Fr(,)f(72)p 0 5549 3901 4 v 0 5649 a Fn(Inde)n(x)3561
b(139)p eop end
%%Page: 140 146
TeXDict begin 140 145 bop 0 83 a Fj(PyFunction_GetCode\(\))p
Fr(,)17 b(71)0 183 y Fj(PyFunction_GetDefaults\(\))p
Fr(,)f(72)0 282 y Fj(PyFunction_GetGlobals\(\))p Fr(,)g(71)0
382 y Fj(PyFunction_GetModule\(\))p Fr(,)g(71)0 482 y
Fj(PyFunction_New\(\))p Fr(,)i(71)0 581 y Fj(PyFunction_SetClosure\(\))
p Fr(,)e(72)0 681 y Fj(PyFunction_SetDefaults\(\))p Fr(,)g(72)0
780 y Fj(PyFunction_Type)p Fr(,)i(71)0 880 y Fj(PyFunctionObject)g
Fr(\(C)j(type\),)e(71)0 980 y Fj(PyGen_Check\(\))p Fr(,)f(77)0
1079 y Fj(PyGen_CheckExact\(\))p Fr(,)f(77)0 1179 y Fj(PyGen_New\(\))p
Fr(,)h(77)0 1279 y Fj(PyGen_Type)p Fr(,)h(77)0 1378 y
Fj(PyGenObject)g Fr(\(C)h(type\),)g(77)0 1478 y Fj
(PyGILState_Ensure\(\))p Fr(,)d(90)0 1577 y Fj(PyGILState_Release\(\))p
Fr(,)g(90)0 1677 y Fj(PyImport_AddModule\(\))p Fr(,)g(24)0
1777 y Fj(PyImport_AppendInittab\(\))p Fr(,)f(26)0 1876
y Fj(PyImport_Cleanup\(\))p Fr(,)h(25)0 1976 y Fj
(PyImport_ExecCodeModule\(\))p Fr(,)f(25)0 2076 y Fj
(PyImport_ExtendInittab\(\))p Fr(,)g(26)0 2175 y Fj
(PyImport_FrozenModules)p Fr(,)g(25)0 2275 y Fj
(PyImport_GetMagicNumber\(\))p Fr(,)g(25)0 2374 y Fj
(PyImport_GetModuleDict\(\))p Fr(,)g(25)0 2474 y Fj
(PyImport_Import\(\))p Fr(,)h(24)0 2574 y Fj
(PyImport_ImportFrozenModule\(\))p Fr(,)e(25)0 2673 y
Fj(PyImport_ImportModule\(\))p Fr(,)h(24)0 2773 y Fj
(PyImport_ImportModuleEx\(\))p Fr(,)g(24)0 2873 y Fj
(PyImport_ReloadModule\(\))p Fr(,)g(24)0 2972 y Fj(PyIndex_Check\(\))p
Fr(,)i(42)0 3072 y Fj(PyInstance_Check\(\))p Fr(,)f(71)0
3171 y Fj(PyInstance_New\(\))p Fr(,)h(71)0 3271 y Fj
(PyInstance_NewRaw\(\))p Fr(,)f(71)0 3371 y Fj(PyInstance_Type)p
Fr(,)h(71)0 3470 y Fj(PyInt_AS_LONG\(\))p Fr(,)g(49)0
3570 y Fj(PyInt_AsLong\(\))p Fr(,)g(49)0 3670 y Fj(PyInt_AsSsize_t\(\))
p Fr(,)f(49)0 3769 y Fj(PyInt_AsUnsignedLongLongMask\(\))p
Fr(,)e(49)0 3869 y Fj(PyInt_AsUnsignedLongMask\(\))p
Fr(,)h(49)0 3968 y Fj(PyInt_Check\(\))p Fr(,)i(48)0 4068
y Fj(PyInt_CheckExact\(\))p Fr(,)f(48)0 4168 y Fj(PyInt_FromLong\(\))p
Fr(,)h(48)0 4267 y Fj(PyInt_FromSsize_t\(\))p Fr(,)f(49)0
4367 y Fj(PyInt_FromString\(\))p Fr(,)g(48)0 4467 y Fj
(PyInt_GetMax\(\))p Fr(,)h(49)0 4566 y Fj(PyInt_Type)p
Fr(,)h(48)0 4666 y Fj(PyInterpreterState)e Fr(\(C)k(type\),)e(88)0
4765 y Fj(PyInterpreterState_Clear\(\))p Fr(,)d(89)0
4865 y Fj(PyInterpreterState_Delete\(\))p Fr(,)f(89)0
4965 y Fj(PyInterpreterState_Head\(\))p Fr(,)h(92)0 5064
y Fj(PyInterpreterState_New\(\))p Fr(,)g(89)0 5164 y
Fj(PyInterpreterState_Next\(\))p Fr(,)g(92)0 5264 y Fj
(PyInterpreterState_ThreadHead\(\))p Fr(,)f(92)0 5363
y Fj(PyIntObject)k Fr(\(C)h(type\),)g(48)1992 83 y Fj(PyIter_Check\(\))
p Fr(,)d(45)1992 183 y Fj(PyIter_Next\(\))p Fr(,)h(45)1992
282 y Fj(PyList_Append\(\))p Fr(,)f(66)1992 382 y Fj
(PyList_AsTuple\(\))p Fr(,)g(67)1992 482 y Fj(PyList_Check\(\))p
Fr(,)g(66)1992 581 y Fj(PyList_CheckExact\(\))p Fr(,)f(66)1992
681 y Fj(PyList_GET_ITEM\(\))p Fr(,)h(66)1992 780 y Fj
(PyList_GET_SIZE\(\))p Fr(,)g(66)1992 880 y Fj(PyList_GetItem\(\))p
Fr(,)g(66)1992 980 y Fj(PyList_GetItem\(\))p Fr(,)g(4)1992
1079 y Fj(PyList_GetSlice\(\))p Fr(,)g(67)1992 1179 y
Fj(PyList_Insert\(\))p Fr(,)g(66)1992 1279 y Fj(PyList_New\(\))p
Fr(,)h(66)1992 1378 y Fj(PyList_Reverse\(\))p Fr(,)f(67)1992
1478 y Fj(PyList_SET_ITEM\(\))p Fr(,)g(66)1992 1577 y
Fj(PyList_SetItem\(\))p Fr(,)g(66)1992 1677 y Fj(PyList_SetItem\(\))p
Fr(,)g(3)1992 1777 y Fj(PyList_SetSlice\(\))p Fr(,)g(67)1992
1876 y Fj(PyList_Size\(\))p Fr(,)h(66)1992 1976 y Fj(PyList_Sort\(\))p
Fr(,)g(67)1992 2076 y Fj(PyList_Type)p Fr(,)g(66)1992
2175 y Fj(PyListObject)g Fr(\(C)j(type\),)e(66)1992 2275
y Fj(PyLong_AsDouble\(\))p Fr(,)e(51)1992 2374 y Fj(PyLong_AsLong\(\))p
Fr(,)g(50)1992 2474 y Fj(PyLong_AsLongLong\(\))p Fr(,)f(51)1992
2574 y Fj(PyLong_AsUnsignedLong\(\))p Fr(,)g(50)1992
2673 y Fj(PyLong_AsUnsignedLongLong\(\))p Fr(,)f(51)1992
2773 y Fj(PyLong_AsUnsignedLongLongMask\(\))p Fr(,)f(51)1992
2873 y Fj(PyLong_AsUnsignedLongMask\(\))p Fr(,)h(51)1992
2972 y Fj(PyLong_AsVoidPtr\(\))p Fr(,)i(51)1992 3072
y Fj(PyLong_Check\(\))p Fr(,)g(50)1992 3171 y Fj(PyLong_CheckExact\(\))
p Fr(,)f(50)1992 3271 y Fj(PyLong_FromDouble\(\))p Fr(,)g(50)1992
3371 y Fj(PyLong_FromLong\(\))p Fr(,)h(50)1992 3470 y
Fj(PyLong_FromLongLong\(\))p Fr(,)f(50)1992 3570 y Fj
(PyLong_FromString\(\))p Fr(,)g(50)1992 3670 y Fj
(PyLong_FromUnicode\(\))p Fr(,)g(50)1992 3769 y Fj
(PyLong_FromUnsignedLong\(\))p Fr(,)f(50)1992 3869 y
Fj(PyLong_FromUnsignedLongLong\(\))p Fr(,)g(50)1992 3968
y Fj(PyLong_FromVoidPtr\(\))p Fr(,)h(50)1992 4068 y Fj(PyLong_Type)p
Fr(,)i(50)1992 4168 y Fj(PyLongObject)g Fr(\(C)j(type\),)e(50)1992
4267 y Fj(PyMapping_Check\(\))p Fr(,)e(44)1992 4367 y
Fj(PyMapping_DelItem\(\))p Fr(,)f(44)1992 4467 y Fj
(PyMapping_DelItemString\(\))p Fr(,)f(44)1992 4566 y
Fj(PyMapping_GetItemString\(\))p Fr(,)g(44)1992 4666
y Fj(PyMapping_HasKey\(\))p Fr(,)i(44)1992 4765 y Fj
(PyMapping_HasKeyString\(\))p Fr(,)f(44)1992 4865 y Fj
(PyMapping_Items\(\))p Fr(,)h(44)1992 4965 y Fj(PyMapping_Keys\(\))p
Fr(,)g(44)1992 5064 y Fj(PyMapping_Length\(\))p Fr(,)g(44)1992
5164 y Fj(PyMapping_SetItemString\(\))p Fr(,)e(44)1992
5264 y Fj(PyMapping_Values\(\))p Fr(,)i(44)1992 5363
y Fj(PyMappingMethods)g Fr(\(C)k(type\),)e(114)p 0 5549
3901 4 v 0 5649 a Fn(140)3561 b(Inde)n(x)p eop end
%%Page: 141 147
TeXDict begin 141 146 bop 0 83 a Fj
(PyMarshal_ReadLastObjectFromFile\(\))p Fr(,)14 b(27)0
183 y Fj(PyMarshal_ReadLongFromFile\(\))p Fr(,)h(27)0
282 y Fj(PyMarshal_ReadObjectFromFile\(\))p Fr(,)g(27)0
382 y Fj(PyMarshal_ReadObjectFromString\(\))p Fr(,)g(27)0
482 y Fj(PyMarshal_ReadShortFromFile\(\))p Fr(,)g(27)0
581 y Fj(PyMarshal_WriteLongToFile\(\))p Fr(,)g(26)0
681 y Fj(PyMarshal_WriteObjectToFile\(\))p Fr(,)g(26)0
780 y Fj(PyMarshal_WriteObjectToString\(\))p Fr(,)g(26)0
880 y Fj(PyMem_Del\(\))p Fr(,)j(94)0 980 y Fj(PyMem_Free\(\))p
Fr(,)g(94)0 1079 y Fj(PyMem_Malloc\(\))p Fr(,)g(94)0
1179 y Fj(PyMem_New\(\))p Fr(,)g(94)0 1279 y Fj(PyMem_Realloc\(\))p
Fr(,)g(94)0 1378 y Fj(PyMem_Resize\(\))p Fr(,)g(94)0
1478 y Fj(PyMethod_Check\(\))p Fr(,)g(72)0 1577 y Fj
(PyMethod_Class\(\))p Fr(,)g(72)0 1677 y Fj(PyMethod_Function\(\))p
Fr(,)f(72)0 1777 y Fj(PyMethod_GET_CLASS\(\))p Fr(,)g(72)0
1876 y Fj(PyMethod_GET_FUNCTION\(\))p Fr(,)f(72)0 1976
y Fj(PyMethod_GET_SELF\(\))p Fr(,)h(73)0 2076 y Fj(PyMethod_New\(\))p
Fr(,)h(72)0 2175 y Fj(PyMethod_Self\(\))p Fr(,)g(72)0
2275 y Fj(PyMethod_Type)p Fr(,)g(72)0 2374 y Fj(PyMethodDef)h
Fr(\(C)h(type\),)g(99)0 2474 y Fj(PyModule_AddIntConstant\(\))p
Fr(,)c(73)0 2574 y Fj(PyModule_AddObject\(\))p Fr(,)h(73)0
2673 y Fj(PyModule_AddStringConstant\(\))p Fr(,)e(73)0
2773 y Fj(PyModule_Check\(\))p Fr(,)j(73)0 2873 y Fj
(PyModule_CheckExact\(\))p Fr(,)f(73)0 2972 y Fj(PyModule_GetDict\(\))p
Fr(,)g(73)0 3072 y Fj(PyModule_GetFilename\(\))p Fr(,)f(73)0
3171 y Fj(PyModule_GetName\(\))p Fr(,)h(73)0 3271 y Fj
(PyModule_New\(\))p Fr(,)h(73)0 3371 y Fj(PyModule_Type)p
Fr(,)g(73)0 3470 y Fj(PyNumber_Absolute\(\))p Fr(,)f(40)0
3570 y Fj(PyNumber_Add\(\))p Fr(,)h(39)0 3670 y Fj(PyNumber_And\(\))p
Fr(,)g(40)0 3769 y Fj(PyNumber_AsSsize_t\(\))p Fr(,)f(42)0
3869 y Fj(PyNumber_Check\(\))p Fr(,)h(39)0 3968 y Fj
(PyNumber_Coerce\(\))p Fr(,)f(41)0 4068 y Fj(PyNumber_Divide\(\))p
Fr(,)g(39)0 4168 y Fj(PyNumber_Divmod\(\))p Fr(,)g(39)0
4267 y Fj(PyNumber_Float\(\))p Fr(,)h(42)0 4367 y Fj
(PyNumber_FloorDivide\(\))p Fr(,)e(39)0 4467 y Fj(PyNumber_Index\(\))p
Fr(,)i(42)0 4566 y Fj(PyNumber_InPlaceAdd\(\))p Fr(,)f(40)0
4666 y Fj(PyNumber_InPlaceAnd\(\))p Fr(,)g(41)0 4765
y Fj(PyNumber_InPlaceDivide\(\))p Fr(,)f(40)0 4865 y
Fj(PyNumber_InPlaceFloorDivide\(\))p Fr(,)f(40)0 4965
y Fj(PyNumber_InPlaceLshift\(\))p Fr(,)h(41)0 5064 y
Fj(PyNumber_InPlaceMultiply\(\))p Fr(,)g(40)0 5164 y
Fj(PyNumber_InPlaceOr\(\))p Fr(,)h(41)0 5264 y Fj
(PyNumber_InPlacePower\(\))p Fr(,)f(41)0 5363 y Fj
(PyNumber_InPlaceRemainder\(\))p Fr(,)f(41)1992 83 y
Fj(PyNumber_InPlaceRshift\(\))p Fr(,)h(41)1992 183 y
Fj(PyNumber_InPlaceSubtract\(\))p Fr(,)f(40)1992 282
y Fj(PyNumber_InPlaceTrueDivide\(\))p Fr(,)g(40)1992
382 y Fj(PyNumber_InPlaceXor\(\))p Fr(,)h(41)1992 482
y Fj(PyNumber_Int\(\))p Fr(,)h(41)1992 581 y Fj(PyNumber_Invert\(\))p
Fr(,)g(40)1992 681 y Fj(PyNumber_Long\(\))p Fr(,)g(41)1992
780 y Fj(PyNumber_Lshift\(\))p Fr(,)g(40)1992 880 y Fj
(PyNumber_Multiply\(\))p Fr(,)f(39)1992 980 y Fj(PyNumber_Negative\(\))
p Fr(,)g(39)1992 1079 y Fj(PyNumber_Or\(\))p Fr(,)i(40)1992
1179 y Fj(PyNumber_Positive\(\))p Fr(,)e(39)1992 1279
y Fj(PyNumber_Power\(\))p Fr(,)h(39)1992 1378 y Fj
(PyNumber_Remainder\(\))p Fr(,)f(39)1992 1478 y Fj(PyNumber_Rshift\(\))
p Fr(,)h(40)1992 1577 y Fj(PyNumber_Subtract\(\))p Fr(,)f(39)1992
1677 y Fj(PyNumber_TrueDivide\(\))p Fr(,)g(39)1992 1777
y Fj(PyNumber_Xor\(\))p Fr(,)h(40)1992 1876 y Fj(PyNumberMethods)g
Fr(\(C)k(type\),)e(114)1992 1976 y Fj(PyObject)g Fr(\(C)i(type\),)e(98)
1992 2076 y Fj(PyObject_AsCharBuffer\(\))p Fr(,)d(45)1992
2175 y Fj(PyObject_AsFileDescriptor\(\))p Fr(,)f(38)1992
2275 y Fj(PyObject_AsReadBuffer\(\))p Fr(,)h(45)1992
2374 y Fj(PyObject_AsWriteBuffer\(\))p Fr(,)g(45)1992
2474 y Fj(PyObject_Call\(\))p Fr(,)h(37)1992 2574 y Fj
(PyObject_CallFunction\(\))p Fr(,)f(37)1992 2673 y Fj
(PyObject_CallFunctionObjArgs\(\))p Fr(,)e(37)1992 2773
y Fj(PyObject_CallMethod\(\))p Fr(,)i(37)1992 2873 y
Fj(PyObject_CallMethodObjArgs\(\))p Fr(,)f(37)1992 2972
y Fj(PyObject_CallObject\(\))p Fr(,)h(37)1992 3072 y
Fj(PyObject_CheckReadBuffer\(\))p Fr(,)f(45)1992 3171
y Fj(PyObject_Cmp\(\))p Fr(,)i(36)1992 3271 y Fj(PyObject_Compare\(\))p
Fr(,)g(36)1992 3371 y Fj(PyObject_Del\(\))p Fr(,)g(97)1992
3470 y Fj(PyObject_DelAttr\(\))p Fr(,)g(36)1992 3570
y Fj(PyObject_DelAttrString\(\))p Fr(,)f(35)1992 3670
y Fj(PyObject_DelItem\(\))p Fr(,)h(38)1992 3769 y Fj(PyObject_Dir\(\))p
Fr(,)g(38)1992 3869 y Fj(PyObject_GC_Del\(\))p Fr(,)g(116)1992
3968 y Fj(PyObject_GC_New\(\))p Fr(,)g(116)1992 4068
y Fj(PyObject_GC_NewVar\(\))p Fr(,)f(116)1992 4168 y
Fj(PyObject_GC_Resize\(\))p Fr(,)g(116)1992 4267 y Fj
(PyObject_GC_Track\(\))p Fr(,)g(116)1992 4367 y Fj
(PyObject_GC_UnTrack\(\))p Fr(,)g(116)1992 4467 y Fj
(PyObject_GetAttr\(\))p Fr(,)h(35)1992 4566 y Fj
(PyObject_GetAttrString\(\))p Fr(,)f(35)1992 4666 y Fj
(PyObject_GetItem\(\))p Fr(,)h(38)1992 4765 y Fj(PyObject_GetIter\(\))p
Fr(,)g(38)1992 4865 y Fj(PyObject_HasAttr\(\))p Fr(,)g(35)1992
4965 y Fj(PyObject_HasAttrString\(\))p Fr(,)f(35)1992
5064 y Fj(PyObject_Hash\(\))p Fr(,)h(37)1992 5164 y Fj(PyObject_HEAD)h
Fr(\(macro\),)g(98)1992 5264 y Fj(PyObject_Init\(\))p
Fr(,)f(97)1992 5363 y Fj(PyObject_InitVar\(\))p Fr(,)g(97)p
0 5549 3901 4 v 0 5649 a Fn(Inde)n(x)3561 b(141)p eop
end
%%Page: 142 148
TeXDict begin 142 147 bop 0 83 a Fj(PyObject_IsInstance\(\))p
Fr(,)17 b(36)0 183 y Fj(PyObject_IsSubclass\(\))p Fr(,)g(37)0
282 y Fj(PyObject_IsTrue\(\))p Fr(,)g(38)0 382 y Fj
(PyObject_Length\(\))p Fr(,)g(38)0 482 y Fj(PyObject_New\(\))p
Fr(,)h(97)0 581 y Fj(PyObject_NewVar\(\))p Fr(,)f(97)0
681 y Fj(PyObject_Not\(\))p Fr(,)h(38)0 780 y Fj(PyObject_Print\(\))p
Fr(,)g(35)0 880 y Fj(PyObject_Repr\(\))p Fr(,)g(36)0
980 y Fj(PyObject_RichCompare\(\))p Fr(,)e(36)0 1079
y Fj(PyObject_RichCompareBool\(\))p Fr(,)g(36)0 1179
y Fj(PyObject_SetAttr\(\))p Fr(,)h(35)0 1279 y Fj
(PyObject_SetAttrString\(\))p Fr(,)f(35)0 1378 y Fj
(PyObject_SetItem\(\))p Fr(,)h(38)0 1478 y Fj(PyObject_Size\(\))p
Fr(,)h(38)0 1577 y Fj(PyObject_Str\(\))p Fr(,)g(36)0
1677 y Fj(PyObject_Type\(\))p Fr(,)g(38)0 1777 y Fj
(PyObject_TypeCheck\(\))p Fr(,)f(38)0 1876 y Fj(PyObject_Unicode\(\))p
Fr(,)g(36)0 1976 y Fj(PyObject_VAR_HEAD)h Fr(\(macro\),)g(99)0
2076 y Fj(PyOS_AfterFork\(\))p Fr(,)g(23)0 2175 y Fj
(PyOS_ascii_atof\(\))p Fr(,)f(33)0 2275 y Fj(PyOS_ascii_formatd\(\))p
Fr(,)g(33)0 2374 y Fj(PyOS_ascii_strtod\(\))p Fr(,)g(33)0
2474 y Fj(PyOS_CheckStack\(\))p Fr(,)g(23)0 2574 y Fj
(PyOS_GetLastModificationTime\(\))p Fr(,)e(23)0 2673
y Fj(PyOS_getsig\(\))p Fr(,)j(23)0 2773 y Fj(PyOS_setsig\(\))p
Fr(,)g(23)0 2873 y Fj(PyOS_snprintf\(\))p Fr(,)g(33)0
2972 y Fj(PyOS_vsnprintf\(\))p Fr(,)g(33)0 3072 y Fj
(PyParser_SimpleParseFile\(\))p Fr(,)e(12)0 3171 y Fj
(PyParser_SimpleParseFileFlags\(\))p Fr(,)f(12)0 3271
y Fj(PyParser_SimpleParseString\(\))p Fr(,)g(12)0 3371
y Fj(PyParser_SimpleParseStringFlags\(\))p Fr(,)f(12)0
3470 y Fj(PyParser_SimpleParseStringFlagsFile)o(name\(\))o
Fr(,)332 3570 y(12)0 3670 y Fj(PyProperty_Type)p Fr(,)k(74)0
3769 y Fj(PyRun_AnyFile\(\))p Fr(,)g(11)0 3869 y Fj
(PyRun_AnyFileEx\(\))p Fr(,)f(11)0 3968 y Fj(PyRun_AnyFileExFlags\(\))p
Fr(,)f(11)0 4068 y Fj(PyRun_AnyFileFlags\(\))p Fr(,)h(11)0
4168 y Fj(PyRun_File\(\))p Fr(,)h(13)0 4267 y Fj(PyRun_FileEx\(\))p
Fr(,)g(13)0 4367 y Fj(PyRun_FileExFlags\(\))p Fr(,)f(13)0
4467 y Fj(PyRun_FileFlags\(\))p Fr(,)g(13)0 4566 y Fj
(PyRun_InteractiveLoop\(\))p Fr(,)f(12)0 4666 y Fj
(PyRun_InteractiveLoopFlags\(\))p Fr(,)f(12)0 4765 y
Fj(PyRun_InteractiveOne\(\))p Fr(,)h(12)0 4865 y Fj
(PyRun_InteractiveOneFlags\(\))p Fr(,)f(12)0 4965 y Fj
(PyRun_SimpleFile\(\))p Fr(,)i(11)0 5064 y Fj(PyRun_SimpleFileEx\(\))p
Fr(,)g(12)0 5164 y Fj(PyRun_SimpleFileExFlags\(\))p Fr(,)f(12)0
5264 y Fj(PyRun_SimpleFileFlags\(\))p Fr(,)g(12)0 5363
y Fj(PyRun_SimpleString\(\))p Fr(,)h(11)1992 83 y Fj
(PyRun_SimpleStringFlags\(\))p Fr(,)e(11)1992 183 y Fj
(PyRun_String\(\))p Fr(,)i(12)1992 282 y Fj(PyRun_StringFlags\(\))p
Fr(,)f(12)1992 382 y Fj(PySeqIter_Check\(\))p Fr(,)h(74)1992
482 y Fj(PySeqIter_New\(\))p Fr(,)g(74)1992 581 y Fj(PySeqIter_Type)p
Fr(,)g(73)1992 681 y Fj(PySequence_Check\(\))p Fr(,)g(42)1992
780 y Fj(PySequence_Concat\(\))p Fr(,)f(42)1992 880 y
Fj(PySequence_Contains\(\))p Fr(,)g(43)1992 980 y Fj
(PySequence_Count\(\))p Fr(,)h(43)1992 1079 y Fj
(PySequence_DelItem\(\))p Fr(,)f(43)1992 1179 y Fj
(PySequence_DelSlice\(\))p Fr(,)g(43)1992 1279 y Fj
(PySequence_Fast\(\))p Fr(,)h(43)1992 1378 y Fj
(PySequence_Fast_GET_ITEM\(\))p Fr(,)e(43)1992 1478 y
Fj(PySequence_Fast_GET_SIZE\(\))p Fr(,)g(44)1992 1577
y Fj(PySequence_Fast_ITEMS\(\))p Fr(,)h(43)1992 1677
y Fj(PySequence_GetItem\(\))p Fr(,)g(42)1992 1777 y Fj
(PySequence_GetItem\(\))p Fr(,)g(4)1992 1876 y Fj
(PySequence_GetSlice\(\))p Fr(,)g(42)1992 1976 y Fj
(PySequence_Index\(\))p Fr(,)h(43)1992 2076 y Fj
(PySequence_InPlaceConcat\(\))p Fr(,)e(42)1992 2175 y
Fj(PySequence_InPlaceRepeat\(\))p Fr(,)g(42)1992 2275
y Fj(PySequence_ITEM\(\))p Fr(,)i(43)1992 2374 y Fj
(PySequence_Length\(\))p Fr(,)f(42)1992 2474 y Fj(PySequence_List\(\))p
Fr(,)h(43)1992 2574 y Fj(PySequence_Repeat\(\))p Fr(,)f(42)1992
2673 y Fj(PySequence_SetItem\(\))p Fr(,)g(43)1992 2773
y Fj(PySequence_SetSlice\(\))p Fr(,)g(43)1992 2873 y
Fj(PySequence_Size\(\))p Fr(,)h(42)1992 2972 y Fj(PySequence_Tuple\(\))
p Fr(,)g(43)1992 3072 y Fj(PySequenceMethods)g Fr(\(C)k(type\),)e(114)
1992 3171 y Fj(PySet_Add\(\))p Fr(,)f(80)1992 3271 y
Fj(PySet_Clear\(\))p Fr(,)g(81)1992 3371 y Fj(PySet_Contains\(\))p
Fr(,)f(80)1992 3470 y Fj(PySet_Discard\(\))p Fr(,)g(81)1992
3570 y Fj(PySet_GET_SIZE\(\))p Fr(,)g(80)1992 3670 y
Fj(PySet_New\(\))p Fr(,)h(80)1992 3769 y Fj(PySet_Pop\(\))p
Fr(,)g(81)1992 3869 y Fj(PySet_Size\(\))p Fr(,)g(80)1992
3968 y Fj(PySet_Type)p Fr(,)g(80)1992 4068 y Fj(PySetObject)g
Fr(\(C)j(type\),)e(80)1992 4168 y Fj(PySlice_Check\(\))p
Fr(,)e(75)1992 4267 y Fj(PySlice_GetIndices\(\))p Fr(,)f(75)1992
4367 y Fj(PySlice_GetIndicesEx\(\))p Fr(,)g(75)1992 4467
y Fj(PySlice_New\(\))p Fr(,)i(75)1992 4566 y Fj(PySlice_Type)p
Fr(,)g(75)1992 4666 y Fj(PyString_AS_STRING\(\))p Fr(,)e(54)1992
4765 y Fj(PyString_AsDecodedObject\(\))p Fr(,)f(55)1992
4865 y Fj(PyString_AsEncodedObject\(\))p Fr(,)g(55)1992
4965 y Fj(PyString_AsString\(\))p Fr(,)h(54)1992 5064
y Fj(PyString_AsStringAndSize\(\))p Fr(,)f(54)1992 5164
y Fj(PyString_Check\(\))p Fr(,)i(53)1992 5264 y Fj
(PyString_CheckExact\(\))p Fr(,)f(53)1992 5363 y Fj
(PyString_Concat\(\))p Fr(,)h(54)p 0 5549 3901 4 v 0
5649 a Fn(142)3561 b(Inde)n(x)p eop end
%%Page: 143 149
TeXDict begin 143 148 bop 0 83 a Fj(PyString_ConcatAndDel\(\))p
Fr(,)16 b(54)0 183 y Fj(PyString_Decode\(\))p Fr(,)h(55)0
282 y Fj(PyString_Encode\(\))p Fr(,)g(55)0 382 y Fj
(PyString_Format\(\))p Fr(,)g(55)0 482 y Fj(PyString_FromFormat\(\))p
Fr(,)g(53)0 581 y Fj(PyString_FromFormatV\(\))p Fr(,)f(54)0
681 y Fj(PyString_FromString\(\))p Fr(,)h(53)0 780 y
Fj(PyString_FromString\(\))p Fr(,)g(68)0 880 y Fj
(PyString_FromStringAndSize\(\))p Fr(,)e(53)0 980 y Fj
(PyString_GET_SIZE\(\))p Fr(,)i(54)0 1079 y Fj
(PyString_InternFromString\(\))p Fr(,)e(55)0 1179 y Fj
(PyString_InternInPlace\(\))p Fr(,)h(55)0 1279 y Fj(PyString_Size\(\))p
Fr(,)i(54)0 1378 y Fj(PyString_Type)p Fr(,)g(53)0 1478
y Fj(PyStringObject)g Fr(\(C)j(type\),)e(53)0 1577 y
Fj(PySys_SetArgv\(\))p Fr(,)f(86)0 1677 y Fj(PySys_SetArgv\(\))p
Fr(,)g(8,)i(83)0 1777 y(Python)f(Enhancement)f(Proposals)166
1876 y(PEP)j(238,)e(14)0 1976 y(PYTHONDUMPREFS,)h(102)0
2076 y(PYTHONHOME,)g(8)0 2175 y(PYTHONP)-8 b(A)f(TH,)20
b(8)0 2275 y Fj(PyThreadState)p Fr(,)e(86)0 2374 y Fj(PyThreadState)g
Fr(\(C)j(type\),)e(88)0 2474 y Fj(PyThreadState_Clear\(\))p
Fr(,)e(90)0 2574 y Fj(PyThreadState_Delete\(\))p Fr(,)f(90)0
2673 y Fj(PyThreadState_Get\(\))p Fr(,)h(90)0 2773 y
Fj(PyThreadState_GetDict\(\))p Fr(,)f(90)0 2873 y Fj
(PyThreadState_New\(\))p Fr(,)h(89)0 2972 y Fj(PyThreadState_Next\(\))p
Fr(,)g(92)0 3072 y Fj(PyThreadState_SetAsyncExc\(\))p
Fr(,)e(90)0 3171 y Fj(PyThreadState_Swap\(\))p Fr(,)i(90)0
3271 y Fj(PyTime_Check\(\))p Fr(,)h(78)0 3371 y Fj
(PyTime_CheckExact\(\))p Fr(,)f(78)0 3470 y Fj(PyTime_FromTime\(\))p
Fr(,)g(78)0 3570 y Fj(PyTrace_C_CALL)p Fr(,)h(91)0 3670
y Fj(PyTrace_C_EXCEPTION)p Fr(,)f(91)0 3769 y Fj(PyTrace_C_RETURN)p
Fr(,)h(91)0 3869 y Fj(PyTrace_CALL)p Fr(,)g(91)0 3968
y Fj(PyTrace_EXCEPTION)p Fr(,)f(91)0 4068 y Fj(PyTrace_LINE)p
Fr(,)h(91)0 4168 y Fj(PyTrace_RETURN)p Fr(,)g(91)0 4267
y Fj(PyTuple_Check\(\))p Fr(,)g(65)0 4367 y Fj(PyTuple_CheckExact\(\))p
Fr(,)f(65)0 4467 y Fj(PyTuple_GET_ITEM\(\))p Fr(,)g(65)0
4566 y Fj(PyTuple_GET_SIZE\(\))p Fr(,)g(65)0 4666 y Fj
(PyTuple_GetItem\(\))p Fr(,)g(65)0 4765 y Fj(PyTuple_GetSlice\(\))p
Fr(,)g(65)0 4865 y Fj(PyTuple_New\(\))p Fr(,)h(65)0 4965
y Fj(PyTuple_Pack\(\))p Fr(,)g(65)0 5064 y Fj(PyTuple_SET_ITEM\(\))p
Fr(,)f(65)0 5164 y Fj(PyTuple_SetItem\(\))p Fr(,)g(65)0
5264 y Fj(PyTuple_SetItem\(\))p Fr(,)g(3)0 5363 y Fj(PyTuple_Size\(\))p
Fr(,)h(65)1992 83 y Fj(PyTuple_Type)p Fr(,)g(65)1992
183 y Fj(PyTupleObject)g Fr(\(C)j(type\),)e(65)1992 282
y Fj(PyType_Check\(\))p Fr(,)e(47)1992 382 y Fj(PyType_CheckExact\(\))p
Fr(,)f(47)1992 482 y Fj(PyType_GenericAlloc\(\))p Fr(,)g(47)1992
581 y Fj(PyType_GenericNew\(\))p Fr(,)g(48)1992 681 y
Fj(PyType_HasFeature\(\))p Fr(,)g(47)1992 780 y Fj
(PyType_HasFeature\(\))p Fr(,)g(115)1992 880 y Fj(PyType_IS_GC\(\))p
Fr(,)h(47)1992 980 y Fj(PyType_IsSubtype\(\))p Fr(,)g(47)1992
1079 y Fj(PyType_Ready\(\))p Fr(,)g(48)1992 1179 y Fj(PyType_Type)p
Fr(,)h(47)1992 1279 y Fj(PyTypeObject)g Fr(\(C)j(type\),)e(47)1992
1378 y Fj(PyTZInfo_Check\(\))p Fr(,)e(78)1992 1478 y
Fj(PyTZInfo_CheckExact\(\))p Fr(,)f(78)1992 1577 y Fj
(PyUnicode_AS_DATA\(\))p Fr(,)g(56)1992 1677 y Fj
(PyUnicode_AS_UNICODE\(\))p Fr(,)g(56)1992 1777 y Fj
(PyUnicode_AsASCIIString\(\))p Fr(,)f(61)1992 1876 y
Fj(PyUnicode_AsCharmapString\(\))p Fr(,)g(61)1992 1976
y Fj(PyUnicode_AsEncodedString\(\))p Fr(,)g(58)1992 2076
y Fj(PyUnicode_AsLatin1String\(\))p Fr(,)g(60)1992 2175
y Fj(PyUnicode_AsMBCSString\(\))p Fr(,)h(62)1992 2275
y Fj(PyUnicode_AsRawUnicodeEscapeStrin)o(g\(\))p Fr(,)2324
2374 y(60)1992 2474 y Fj(PyUnicode_AsUnicode\(\))p Fr(,)g(57)1992
2574 y Fj(PyUnicode_AsUnicodeEscapeString\(\))o Fr(,)f(60)1992
2673 y Fj(PyUnicode_AsUTF16String\(\))p Fr(,)g(60)1992
2773 y Fj(PyUnicode_AsUTF8String\(\))p Fr(,)h(59)1992
2873 y Fj(PyUnicode_AsWideChar\(\))p Fr(,)g(58)1992 2972
y Fj(PyUnicode_Check\(\))p Fr(,)h(56)1992 3072 y Fj
(PyUnicode_CheckExact\(\))p Fr(,)f(56)1992 3171 y Fj
(PyUnicode_Compare\(\))p Fr(,)g(63)1992 3271 y Fj(PyUnicode_Concat\(\))
p Fr(,)h(62)1992 3371 y Fj(PyUnicode_Contains\(\))p Fr(,)f(63)1992
3470 y Fj(PyUnicode_Count\(\))p Fr(,)h(63)1992 3570 y
Fj(PyUnicode_Decode\(\))p Fr(,)g(58)1992 3670 y Fj
(PyUnicode_DecodeASCII\(\))p Fr(,)f(61)1992 3769 y Fj
(PyUnicode_DecodeCharmap\(\))p Fr(,)f(61)1992 3869 y
Fj(PyUnicode_DecodeLatin1\(\))p Fr(,)h(60)1992 3968 y
Fj(PyUnicode_DecodeMBCS\(\))p Fr(,)g(62)1992 4068 y Fj
(PyUnicode_DecodeMBCSStateful\(\))p Fr(,)e(62)1992 4168
y Fj(PyUnicode_DecodeRawUnicodeEscape\()o(\))p Fr(,)h(60)1992
4267 y Fj(PyUnicode_DecodeUnicodeEscape\(\))p Fr(,)f(60)1992
4367 y Fj(PyUnicode_DecodeUTF16\(\))p Fr(,)i(59)1992
4467 y Fj(PyUnicode_DecodeUTF16Stateful\(\))p Fr(,)e(59)1992
4566 y Fj(PyUnicode_DecodeUTF8\(\))p Fr(,)i(59)1992 4666
y Fj(PyUnicode_DecodeUTF8Stateful\(\))p Fr(,)e(59)1992
4765 y Fj(PyUnicode_Encode\(\))p Fr(,)j(58)1992 4865
y Fj(PyUnicode_EncodeASCII\(\))p Fr(,)f(61)1992 4965
y Fj(PyUnicode_EncodeCharmap\(\))p Fr(,)f(61)1992 5064
y Fj(PyUnicode_EncodeLatin1\(\))p Fr(,)h(60)1992 5164
y Fj(PyUnicode_EncodeMBCS\(\))p Fr(,)g(62)1992 5264 y
Fj(PyUnicode_EncodeRawUnicodeEscape\()o(\))p Fr(,)f(60)1992
5363 y Fj(PyUnicode_EncodeUnicodeEscape\(\))p Fr(,)f(60)p
0 5549 3901 4 v 0 5649 a Fn(Inde)n(x)3561 b(143)p eop
end
%%Page: 144 150
TeXDict begin 144 149 bop 0 83 a Fj(PyUnicode_EncodeUTF16\(\))p
Fr(,)16 b(59)0 183 y Fj(PyUnicode_EncodeUTF8\(\))p Fr(,)g(59)0
282 y Fj(PyUnicode_Find\(\))p Fr(,)i(63)0 382 y Fj
(PyUnicode_Format\(\))p Fr(,)f(63)0 482 y Fj
(PyUnicode_FromEncodedObject\(\))p Fr(,)e(57)0 581 y
Fj(PyUnicode_FromObject\(\))p Fr(,)h(58)0 681 y Fj
(PyUnicode_FromUnicode\(\))p Fr(,)g(57)0 780 y Fj
(PyUnicode_FromWideChar\(\))p Fr(,)g(58)0 880 y Fj
(PyUnicode_GET_DATA_SIZE\(\))p Fr(,)g(56)0 980 y Fj
(PyUnicode_GET_SIZE\(\))p Fr(,)h(56)0 1079 y Fj(PyUnicode_GetSize\(\))p
Fr(,)g(57)0 1179 y Fj(PyUnicode_Join\(\))p Fr(,)h(63)0
1279 y Fj(PyUnicode_Replace\(\))p Fr(,)f(63)0 1378 y
Fj(PyUnicode_RichCompare\(\))p Fr(,)f(63)0 1478 y Fj
(PyUnicode_Split\(\))p Fr(,)h(62)0 1577 y Fj(PyUnicode_Splitlines\(\))p
Fr(,)f(62)0 1677 y Fj(PyUnicode_Tailmatch\(\))p Fr(,)h(63)0
1777 y Fj(PyUnicode_Translate\(\))p Fr(,)g(62)0 1876
y Fj(PyUnicode_TranslateCharmap\(\))p Fr(,)e(61)0 1976
y Fj(PyUnicode_Type)p Fr(,)j(56)0 2076 y Fj(PyUnicodeObject)g
Fr(\(C)j(type\),)e(56)0 2175 y Fj(PyVarObject)g Fr(\(C)h(type\),)g(98)0
2275 y Fj(PyWeakref_Check\(\))p Fr(,)d(75)0 2374 y Fj
(PyWeakref_CheckProxy\(\))p Fr(,)f(75)0 2474 y Fj
(PyWeakref_CheckRef\(\))p Fr(,)h(75)0 2574 y Fj
(PyWeakref_GET_OBJECT\(\))p Fr(,)f(76)0 2673 y Fj
(PyWeakref_GetObject\(\))p Fr(,)h(76)0 2773 y Fj
(PyWeakref_NewProxy\(\))p Fr(,)g(76)0 2873 y Fj(PyWeakref_NewRef\(\))p
Fr(,)g(75)0 2972 y Fj(PyWrapper_New\(\))p Fr(,)h(74)0
3155 y Fl(R)0 3278 y Fj(realloc\(\))p Fr(,)h(93)0 3378
y Fj(reload\(\))g Fr(\(b)n(uilt-in)g(function\),)f(24)0
3477 y Fj(repr\(\))i Fr(\(b)n(uilt-in)f(function\),)f(36,)h(105)0
3577 y Fj(rexec)h Fr(\(standard)e(module\),)h(24)0 3771
y Fl(S)0 3894 y Fr(search)166 3994 y(path,)h(module,)e(8,)i(83,)g(85)0
4094 y(sequence)166 4193 y(object,)f(53)0 4293 y(set)166
4393 y(object,)g(79)0 4492 y Fj(set_all\(\))p Fr(,)g(4)0
4592 y Fj(setcheckinterval\(\))e Fr(\(in)j(module)f(sys\),)h(86)0
4691 y Fj(setvbuf\(\))p Fr(,)f(70)0 4791 y Fj(SIGINT)p
Fr(,)g(20)0 4891 y Fj(signal)h Fr(\(b)n(uilt-in)f(module\),)f(20)0
4990 y Fj(SliceType)h Fr(\(in)h(module)f(types\),)g(75)0
5090 y Fj(softspace)g Fr(\(\002le)i(attrib)n(ute\),)e(70)0
5190 y Fj(staticmethod\(\))f Fr(\(b)n(uilt-in)h(function\),)f(100)0
5289 y Fj(stderr)i Fr(\(in)g(module)e(sys\),)j(84)0 5389
y Fj(stdin)f Fr(\(in)g(module)f(sys\),)h(84)1992 83 y
Fj(stdout)f Fr(\(in)h(module)f(sys\),)h(84)1992 183 y
Fj(str\(\))f Fr(\(b)n(uilt-in)h(function\),)d(36)1992
282 y Fj(strerror\(\))p Fr(,)h(19)1992 382 y(string)2158
482 y(object,)h(53)1992 581 y Fj(StringType)f Fr(\(in)i(module)f
(types\),)h(53)1992 681 y Fj(_frozen)f Fr(\(C)i(type\),)e(25)1992
780 y Fj(_inittab)g Fr(\(C)i(type\),)e(26)1992 880 y
Fj(PyCompilerFlags)e Fr(\(C)k(type\),)e(13)1992 980 y
Fj(sum_list\(\))p Fr(,)f(5)1992 1079 y Fj(sum_sequence\(\))p
Fr(,)f(5,)j(6)1992 1179 y Fj(sys)g Fr(\(b)n(uilt-in)f(module\),)f(8,)i
(83)1992 1279 y Fj(SystemError)e Fr(\(b)n(uilt-in)h(e)o(xception\),)f
(73)1992 1474 y Fl(T)1992 1597 y Fj(thread)h Fr(\(b)n(uilt-in)g
(module\),)g(88)1992 1697 y Fj(tp_alloc)g Fr(\(PyT)-7
b(ypeObject)18 b(member\),)g(112)1992 1797 y Fj(tp_allocs)h
Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(114)1992 1896
y Fj(tp_as_buffer)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(106)1992
1996 y Fj(tp_base)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(110)1992
2096 y Fj(tp_bases)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(113)1992
2195 y Fj(tp_basicsize)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(103)
1992 2295 y Fj(tp_cache)g Fr(\(PyT)-7 b(ypeObject)18
b(member\),)g(113)1992 2394 y Fj(tp_call)h Fr(\(PyT)-7
b(ypeObject)18 b(member\),)h(105)1992 2494 y Fj(tp_clear)g
Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(108)1992 2594
y Fj(tp_compare)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(104)1992
2693 y Fj(tp_dealloc)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(104)
1992 2793 y Fj(tp_descr_get)g Fr(\(PyT)-7 b(ypeObject)18
b(member\),)h(111)1992 2893 y Fj(tp_descr_set)f Fr(\(PyT)-7
b(ypeObject)18 b(member\),)h(111)1992 2992 y Fj(tp_dict)g
Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(110)1992 3092
y Fj(tp_dictoffset)f Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(111)1992
3191 y Fj(tp_doc)h Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(107)1992
3291 y Fj(tp_flags)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(106)1992
3391 y Fj(tp_free)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(113)1992
3490 y Fj(tp_frees)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(114)1992
3590 y Fj(tp_getattr)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(104)
1992 3690 y Fj(tp_getattro)g Fr(\(PyT)-7 b(ypeObject)19
b(member\),)f(105)1992 3789 y Fj(tp_getset)h Fr(\(PyT)-7
b(ypeObject)18 b(member\),)g(110)1992 3889 y Fj(tp_hash)h
Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(105)1992 3988
y Fj(tp_init)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(112)1992
4088 y Fj(tp_is_gc)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(113)1992
4188 y Fj(tp_itemsize)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(103)
1992 4287 y Fj(tp_iter)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(109)
1992 4387 y Fj(tp_iternext)f Fr(\(PyT)-7 b(ypeObject)19
b(member\),)f(110)1992 4487 y Fj(tp_maxalloc)g Fr(\(PyT)-7
b(ypeObject)19 b(member\),)f(114)1992 4586 y Fj(tp_members)g
Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(110)1992 4686
y Fj(tp_methods)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(110)1992
4786 y Fj(tp_mro)h Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(113)1992
4885 y Fj(tp_name)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(103)1992
4985 y Fj(tp_new)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(112)1992
5084 y Fj(tp_next)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(114)1992
5184 y Fj(tp_print)g Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(104)1992
5284 y Fj(tp_repr)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)h(105)1992
5383 y Fj(tp_richcompare)f Fr(\(PyT)-7 b(ypeObject)18
b(member\),)g(109)p 0 5549 3901 4 v 0 5649 a Fn(144)3561
b(Inde)n(x)p eop end
%%Page: 145 151
TeXDict begin 145 150 bop 0 83 a Fj(tp_setattr)19 b Fr(\(PyT)-7
b(ypeObject)18 b(member\),)g(104)0 183 y Fj(tp_setattro)h
Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(106)0 282 y
Fj(tp_str)i Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(105)0
382 y Fj(tp_subclasses)g Fr(\(PyT)-7 b(ypeObject)19 b(member\),)f(113)0
482 y Fj(tp_traverse)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(107)0
581 y Fj(tp_weaklist)h Fr(\(PyT)-7 b(ypeObject)18 b(member\),)g(114)0
681 y Fj(tp_weaklistoffset)g Fr(\(PyT)-7 b(ypeObject)18
b(member\),)g(109)0 780 y(tuple)166 880 y(object,)h(65)0
980 y Fj(tuple\(\))g Fr(\(b)n(uilt-in)h(function\),)e(43,)h(67)0
1079 y Fj(TupleType)g Fr(\(in)h(module)f(types\),)g(65)0
1179 y(type)166 1279 y(object,)g(2,)h(47)0 1378 y Fj(type\(\))g
Fr(\(b)n(uilt-in)f(function\),)f(38)0 1478 y Fj(TypeType)h
Fr(\(in)h(module)f(types\),)g(47)0 1673 y Fl(U)0 1797
y Fj(ULONG_MAX)p Fr(,)g(51)0 1896 y Fj(unicode\(\))g
Fr(\(b)n(uilt-in)g(function\),)f(36)0 2089 y Fl(V)0 2212
y Fj(version)h Fr(\(in)h(module)f(sys\),)i(85,)e(86)p
0 5549 3901 4 v 0 5649 a Fn(Inde)n(x)3561 b(145)p eop
end
%%Trailer

userdict /end-hook known{end-hook}if
%%EOF