Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pythonを読む

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for tera tera
August 27, 2017

 Pythonを読む

第9回 HojiroLTで話したスライドです。

Avatar for tera

tera

August 27, 2017
Tweet

More Decks by tera

Other Decks in Technology

Transcript

  1. CPythonとは • Pythonの処理系には様々な種類がある ◦ pypy ◦ IronPython ◦ etc... •

    その中でも最も有名なのがCPython • C言語で実装されている • ”Python”とだけかかれている場合は概ねCPythonのことを指す
  2. モジュール作成に必要な関数・構造体 • PyMethodDefの配列 ◦ メソッドテーブル ◦ メソッド名とメソッドへの関数ポインタ • PyModuleDef ◦

    モジュール名、ドキュメント、メソッドテーブルの参照を持つ • PyMODINIT_FUNC PyInit_<modulename> ◦ <modulename> == PyModuleDefで定義したメソッド名 ◦ 事実上の__init__.py
  3. 型作成に必要な構造体 • 型自体の構造体 ◦ フィールドを持つ • PyTypeObject ◦ 型名、__hoge__メソッドとなる関数のポインタを持つ •

    PyModuleDef • PyInit_<modulename> ◦ このInitがいつ呼ばれるかは謎 (たすけて) ◦ たぶんインポートされるとき ……