Results of 1 - 1 of about 1 for CustomType (0.002 sec.)
- 2. 拡張の型の定義: チュートリアル 9414
- 2. 拡張の型の定義: チュートリアル Python では、組み込みの str 型や list 型のような Python コードから操作できる新しい型を C 拡張モジュールの作者が定義できます。 全ての拡張の型のコードはあるパターンに従うのですが、書き始める前に理解しておくべ
...Python.h> typedef struct { PyObject_HEAD /* 型固有のフィールドをここに記述します。 */ } CustomObject ; static PyTypeObject CustomType = { . ob_base = PyVarObject_HEAD_INIT ( NULL , 0 ) . tp_name = "custom.Custom" , . tp_doc = PyDoc_STR ( "Custom オブジェク...TPFLAGS_DEFAULT , . tp_new = PyType_GenericNew , }; static int custom_module_exec ( PyObject * m ) { if ( PyType_Ready ( & CustomType ) < 0 ) { return -1 ; } if ( PyModule_AddObjectRef ( m , "Custom" , ( PyObject * ) & CustomType ) < 0 ) { return -1 ; } re...CustomObject 構造体で、 Custom インスタンスごとに1回だけメモリ確保が行われます。 Custom 型 がどのように振る舞うか: これが CustomType 構造体で、フラグと関数ポインタの集まりを定義しています。特定の操作が要求されたときに、この関数ポインタをインタープリターが... - https://man.mtool.work/python/3.14/extending/newtypes_tutorial.html
PREV
1
NEXT