Python インタプリタの拡張と埋め込み
***********************************

This document describes how to write modules in C or C++ to extend the
Python interpreter with new modules.  Those modules can not only
define new functions but also new object types and their methods.  The
document also describes how to embed the Python interpreter in another
application, for use as an extension language.  Finally, it shows how
to compile and link extension modules so that they can be loaded
dynamically (at run time) into the interpreter, if the underlying
operating system supports this feature.

This document assumes basic knowledge about Python.  For an informal
introduction to the language, see Python チュートリアル.  Python 言語
リファレンス gives a more formal definition of the language.  Python
標準ライブラリ documents the existing object types, functions and
modules (both built-in and written in Python) that give the language
its wide application range.

Python/C API 全体の詳しい説明は、別のドキュメントである、 Python/C API
reference manual を参照してください。


おすすめのサードパーティツール
==============================

This guide only covers the basic tools for creating extensions
provided as part of this version of CPython. Some third party tools
offer both simpler and more sophisticated approaches to creating C and
C++ extensions for Python.


Creating extensions without third party tools
=============================================

ガイドのこの節ではサードパーティツールの補助無しに C および C++ 拡張を
作成する方法を説明します。 これは自分自身の C 拡張を作成するおすすめの
方法というよりも、主にそれらのツールを作成する人向けのものです。

参考: **PEP 489** -- Multi-phase extension module initialization

* 1. Extending Python with C or C++

  * 1.1. A Simple Example

  * 1.2. Intermezzo: Errors and Exceptions

  * 1.3. Back to the Example

  * 1.4. The Module's Method Table and Initialization Function

  * 1.5. Compilation and Linkage

  * 1.6. C から Python 関数を呼び出す

  * 1.7. 拡張モジュール関数でのパラメタ展開

  * 1.8. 拡張モジュール関数のキーワードパラメタ

  * 1.9. 任意の値を構築する

  * 1.10. 参照カウント法

  * 1.11. C++での拡張モジュール作成

  * 1.12. 拡張モジュールに C API を提供する

* 2. 拡張の型の定義: チュートリアル

  * 2.1. 基本的なこと

  * 2.2. 基本のサンプルにデータとメソッドを追加する

  * 2.3. データ属性をこまかく制御する

  * 2.4. 循環ガベージコレクションをサポートする

  * 2.5. 他の型のサブクラスを作る

* 3. 拡張の型の定義: 雑多なトピック

  * 3.1. ファイナライズとメモリ解放

  * 3.2. オブジェクト表現

  * 3.3. 属性を管理する

  * 3.4. オブジェクトの比較

  * 3.5. 抽象的なプロトコルのサポート

  * 3.6. 弱参照(Weak Reference)のサポート

  * 3.7. その他いろいろ

* 4. C および C++ 拡張のビルド

  * 4.1. setuptools による C および C++ 拡張のビルド

* 5. Windows 上での C および C++ 拡張モジュールのビルド

  * 5.1. 型どおりのアプローチ

  * 5.2. Unix と Windows の相違点

  * 5.3. DLL 使用の実際


大規模なアプリケーションへの Python ランタイムの埋め込み
========================================================

Python インタープリタの中でメインアプリケーションとして実行される拡張
を作るのではなく、 CPython をより大きなアプリケーションの中に埋め込む
方が望ましいことがあります。 この節ではその上手い埋め込みに関わる詳細
について説明します。

* 1. 他のアプリケーションへの Python の埋め込み

  * 1.1. 高水準の埋め込み

  * 1.2. 超高水準の埋め込みから踏み出す: 概要

  * 1.3. 純粋な埋め込み

  * 1.4. 埋め込まれた Python の拡張

  * 1.5. C++による Python の埋め込み

  * 1.6. Unix 系システムにおけるコンパイルとリンク
