1 /**
2   Mirror _cobject.h
3 
4    C objects to be exported from one extension module to another.
5  
6    C objects are used for communication between extension modules.
7    They provide a way for an extension module to export a C interface
8    to other extension modules, so that extension modules can use the
9    Python import mechanism to link to one another.
10 
11   Note CObjects are pending deprecation in 2.7 and gone in 3.2.  
12   It is recommended you switch all use of CObjects to capsules.  
13 
14 See_Also:
15    <a href="pycapsule.html"> pycapsule.d </a> $(BR)
16    <a href="http://docs.python.org/c-api/capsule.html"> Capsules </a>
17   */
18 module deimos.python.cobject;
19 
20 import deimos.python.pyport;
21 import deimos.python.object;
22 
23 version(Python_3_2_Or_Later) {
24     // cobject.h not in python 3
25 }else {
26 extern(C):
27 // Python-header-file: Include/cobject.h:
28 
29 // PyCObject_Type is a Python type for transporting an arbitrary C pointer
30 // from the C level to Python and back (in essence, an opaque handle).
31 
32 /// Availaibility: 2.*, 3.0, 3.1
33 mixin(PyAPI_DATA!"PyTypeObject PyCObject_Type");
34 
35 // D translation of C macro:
36 /// Availaibility: 2.*, 3.0, 3.1
37 int PyCObject_Check()(PyObject *op) {
38     return Py_TYPE(op) == &PyCObject_Type;
39 }
40 
41 /// Availaibility: 2.*, 3.0, 3.1
42 PyObject* PyCObject_FromVoidPtr(void* cobj, void function(void*) destruct);
43 /// Availaibility: 2.*, 3.0, 3.1
44 PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc,
45         void function(void*,void*) destruct);
46 /// Availaibility: 2.*, 3.0, 3.1
47 void* PyCObject_AsVoidPtr(PyObject*);
48 /// Availaibility: 2.*, 3.0, 3.1
49 void* PyCObject_GetDesc(PyObject*);
50 /// Availaibility: 2.*, 3.0, 3.1
51 void* PyCObject_Import(const(char)* module_name, const(char)* cobject_name);
52 /// Availaibility: 2.*, 3.0, 3.1
53 int PyCObject_SetVoidPtr(PyObject* self, void* cobj);
54 
55 version(Python_2_6_Or_Later){
56     /// subclass of PyObject.
57     /// Availaibility: 2.6, 2.7, 3.0, 3.1
58     struct PyCObject {
59         mixin PyObject_HEAD;
60         void* cobject;
61         void* desc;
62         void function(void*) destructor;
63     };
64 }
65 
66 
67 }