캡슐¶
이 객체 사용에 대한 자세한 정보는 확장 모듈을 위한 C API 제공하기를 참조하십시오.
버전 3.1에 추가.
-
type
PyCapsule
¶ 이
PyObject
의 서브 형은 불투명한 값을 나타내며, 파이썬 코드를 통해 다른 C 코드로 불투명한 값(void*
포인터로)을 전달해야 하는 C 확장 모듈에 유용합니다. 이것은 한 모듈에서 정의된 C 함수 포인터를 다른 모듈에서 사용할 수 있게 만드는 데 종종 사용되므로, 일반 임포트 메커니즘을 사용하여 동적으로 로드된 모듈에 정의된 C API에 액세스할 수 있습니다.
-
type
PyCapsule_Destructor
¶ - Part of the Stable ABI.
캡슐에 대한 파괴자(destructor) 콜백 형. 이렇게 정의됩니다:
typedef void (*PyCapsule_Destructor)(PyObject *);
PyCapsule_Destructor 콜백의 의미는
PyCapsule_New()
를 참조하십시오.
-
PyObject *
PyCapsule_New
(void *pointer, const char *name, PyCapsule_Destructor destructor)¶ - 반환값: 새 참조. Part of the Stable ABI.
pointer를 캡슐화하는
PyCapsule
을 만듭니다. pointer 인자는NULL
이 아닐 수도 있습니다.실패하면, 예외를 설정하고
NULL
을 반환합니다.name 문자열은
NULL
이나 유효한 C 문자열에 대한 포인터일 수 있습니다.NULL
이 아니면, 이 문자열은 캡슐보다 오래 유지되어야 합니다. (destructor 내부에서 해제할 수는 있습니다.)destructor 인자가
NULL
이 아니면, 캡슐이 파괴될 때 캡슐을 인자로 호출됩니다.이 캡슐을 모듈의 어트리뷰트로 저장하려면, name을
modulename.attributename
로 지정해야 합니다. 이렇게 하면 다른 모듈이PyCapsule_Import()
를 사용하여 캡슐을 임포트 할 수 있습니다.
-
void *
PyCapsule_GetPointer
(PyObject *capsule, const char *name)¶ - Part of the Stable ABI.
캡슐에 저장된 pointer를 가져옵니다. 실패하면, 예외를 설정하고
NULL
을 반환합니다.The name parameter must compare exactly to the name stored in the capsule. If the name stored in the capsule is
NULL
, the name passed in must also beNULL
. Python uses the C functionstrcmp()
to compare capsule names.
-
PyCapsule_Destructor
PyCapsule_GetDestructor
(PyObject *capsule)¶ - Part of the Stable ABI.
캡슐에 저장된 현재 파괴자를 반환합니다. 실패하면, 예외를 설정하고
NULL
을 반환합니다.캡슐이
NULL
파괴자를 갖는 것은 합법적입니다. 이것은NULL
반환 코드를 다소 모호하게 만듭니다; 명확히 하려면PyCapsule_IsValid()
나PyErr_Occurred()
를 사용하십시오.
-
void *
PyCapsule_GetContext
(PyObject *capsule)¶ - Part of the Stable ABI.
캡슐에 저장된 현재 컨텍스트를 반환합니다. 실패하면, 예외를 설정하고
NULL
을 반환합니다.캡슐이
NULL
컨텍스트를 갖는 것은 합법적입니다. 이것은NULL
반환 코드를 다소 모호하게 만듭니다; 명확히 하려면PyCapsule_IsValid()
나PyErr_Occurred()
를 사용하십시오.
-
const char *
PyCapsule_GetName
(PyObject *capsule)¶ - Part of the Stable ABI.
캡슐에 저장된 현재 이름을 반환합니다. 실패하면, 예외를 설정하고
NULL
을 반환합니다.캡슐이
NULL
이름을 갖는 것은 합법적입니다. 이것은NULL
반환 코드를 다소 모호하게 만듭니다; 명확히 하려면PyCapsule_IsValid()
나PyErr_Occurred()
를 사용하십시오.
-
void *
PyCapsule_Import
(const char *name, int no_block)¶ - Part of the Stable ABI.
Import a pointer to a C object from a capsule attribute in a module. The name parameter should specify the full name to the attribute, as in
module.attribute
. The name stored in the capsule must match this string exactly. If no_block is true, import the module without blocking (usingPyImport_ImportModuleNoBlock()
). If no_block is false, import the module conventionally (usingPyImport_ImportModule()
).성공하면 캡슐의 내부 pointer를 반환합니다. 실패하면, 예외를 설정하고
NULL
를 반환합니다.
-
int
PyCapsule_IsValid
(PyObject *capsule, const char *name)¶ - Part of the Stable ABI.
capsule이 유효한 캡슐인지를 판단합니다. 유효한 캡슐은
NULL
이 아니며,PyCapsule_CheckExact()
를 통과하고,NULL
이 아닌 포인터가 저장되며, 내부 이름이 name 매개 변수와 일치합니다. (캡슐 이름을 비교하는 방법에 대한 정보는PyCapsule_GetPointer()
를 참조하십시오.)In other words, if
PyCapsule_IsValid()
returns a true value, calls to any of the accessors (any function starting withPyCapsule_Get()
) are guaranteed to succeed.객체가 유효하고 전달된 이름과 일치하면 0이 아닌 값을 반환합니다. 그렇지 않으면
0
을 반환합니다. 이 함수는 실패하지 않습니다.
-
int
PyCapsule_SetContext
(PyObject *capsule, void *context)¶ - Part of the Stable ABI.
capsule 내부의 컨텍스트 포인터를 context로 설정합니다.
성공하면
0
을 반환합니다. 실패하면 0이 아닌 값을 반환하고 예외를 설정합니다.
-
int
PyCapsule_SetDestructor
(PyObject *capsule, PyCapsule_Destructor destructor)¶ - Part of the Stable ABI.
capsule 내부의 파괴자를 destructor로 설정합니다.
성공하면
0
을 반환합니다. 실패하면 0이 아닌 값을 반환하고 예외를 설정합니다.
-
int
PyCapsule_SetName
(PyObject *capsule, const char *name)¶ - Part of the Stable ABI.
capsule 내부의 이름을 name으로 설정합니다.
NULL
이 아니면, 이름은 캡슐보다 오래 유지되어야 합니다. 캡슐에 저장된 이전 name이NULL
이 아니면, 이를 해제하려고 시도하지 않습니다.성공하면
0
을 반환합니다. 실패하면 0이 아닌 값을 반환하고 예외를 설정합니다.
-
int
PyCapsule_SetPointer
(PyObject *capsule, void *pointer)¶ - Part of the Stable ABI.
capsule 내부의 void 포인터를 pointer로 설정합니다. 포인터는
NULL
이 아닐 수 있습니다.성공하면
0
을 반환합니다. 실패하면 0이 아닌 값을 반환하고 예외를 설정합니다.