api.pdf

(631 KB) Pobierz
Python/C API Reference Manual
Python/CAPIReferenceManual
Release2.5
GuidovanRossum
FredL.Drake,Jr.,editor
19thSeptember,2006
PythonSoftwareFoundation
Email: docs@python.org
Copyrightc 2001-2006PythonSoftwareFoundation.Allrightsreserved.
Copyright c 2000BeOpen.com.Allrightsreserved.
Copyrightc 1995-2000CorporationforNationalResearchInitiatives.Allrightsreserved.
Copyright c 1991-1995StichtingMathematischCentrum.Allrightsreserved.
Seetheendofthisdocumentforcompletelicenseandpermissionsinformation.
Abstract
ThismanualdocumentstheAPIusedbyCandC ++ programmerswhowanttowriteextensionmodulesorembed
Python.Itisacompanionto ExtendingandEmbeddingthePythonInterpreter ,whichdescribesthegeneral
principlesofextensionwritingbutdoesnotdocumenttheAPIfunctionsindetail.
Warning:Thecurrentversionofthisdocumentisincomplete.Ihopethatitisneverthelessuseful.Iwillcontinue
toworkonit,andreleasenewversionsfromtimetotime,independentfromPythonsourcecodereleases.
CONTENTS
1Introduction 1
1.1 IncludeFiles ............................................. 1
1.2Objects,TypesandReferenceCounts ................................ 2
1.3Exceptions .............................................. 5
1.4EmbeddingPython ......................................... 7
1.5DebuggingBuilds .......................................... 8
2TheVeryHighLevelLayer
11
3ReferenceCounting
15
4ExceptionHandling 17
4.1StandardExceptions ......................................... 20
4.2DeprecationofStringExceptions .................................. 21
5Utilities 23
5.1OperatingSystemUtilities ..................................... 23
5.2ProcessControl ........................................... 23
5.3 ImportingModules ......................................... 24
5.4Datamarshallingsupport ...................................... 26
5.5Parsingargumentsandbuildingvalues ............................... 27
6AbstractObjectsLayer 33
6.1ObjectProtocol ........................................... 33
6.2NumberProtocol .......................................... 36
6.3SequenceProtocol .......................................... 39
6.4MappingProtocol .......................................... 41
6.5 IteratorProtocol ........................................... 42
6.6BufferProtocol ........................................... 43
7ConcreteObjectsLayer 45
7.1FundamentalObjects ........................................ 45
7.2NumericObjects ........................................... 46
7.3SequenceObjects .......................................... 51
7.4MappingObjects .......................................... 64
7.5OtherObjects ............................................ 66
8Initialization,Finalization,andThreads 79
8.1ThreadStateandtheGlobalInterpreterLock ............................ 82
8.2ProfilingandTracing ........................................ 86
8.3AdvancedDebuggerSupport .................................... 87
9MemoryManagement 89
9.1Overview .............................................. 89
i
Zgłoś jeśli naruszono regulamin