xref: /aosp_15_r20/external/libxml2/python/libxml_wrap.h (revision 7c5688314b92172186c154356a6374bf7684c3ca)
1 #include <Python.h>
2 #include <libxml/tree.h>
3 #include <libxml/parser.h>
4 #include <libxml/parserInternals.h>
5 #include <libxml/catalog.h>
6 #include <libxml/threads.h>
7 #include <libxml/nanohttp.h>
8 #include <libxml/uri.h>
9 #include <libxml/xpath.h>
10 #include <libxml/xpathInternals.h>
11 #include <libxml/debugXML.h>
12 #include <libxml/HTMLparser.h>
13 #include <libxml/HTMLtree.h>
14 #include <libxml/xinclude.h>
15 #include <libxml/xpointer.h>
16 #include <libxml/xmlunicode.h>
17 #include <libxml/xmlregexp.h>
18 #include <libxml/xmlautomata.h>
19 #include <libxml/xmlreader.h>
20 #include <libxml/globals.h>
21 #include <libxml/xmlsave.h>
22 #ifdef LIBXML_SCHEMAS_ENABLED
23 #include <libxml/relaxng.h>
24 #include <libxml/xmlschemas.h>
25 #endif
26 
27 /*
28  * for older versions of Python, we don't use PyBytes, but keep PyString
29  * and don't use Capsule but CObjects
30  */
31 #if PY_VERSION_HEX < 0x02070000
32 #ifndef PyBytes_Check
33 #define PyBytes_Check PyString_Check
34 #define PyBytes_Size PyString_Size
35 #define PyBytes_AsString PyString_AsString
36 #define PyBytes_AS_STRING PyString_AS_STRING
37 #define PyBytes_GET_SIZE PyString_GET_SIZE
38 #endif
39 #ifndef PyCapsule_New
40 #define PyCapsule_New PyCObject_FromVoidPtrAndDesc
41 #define PyCapsule_CheckExact PyCObject_Check
42 #define PyCapsule_GetPointer(o, n) PyCObject_GetDesc((o))
43 #endif
44 #endif
45 
46 /**
47  * ATTRIBUTE_UNUSED:
48  *
49  * Macro used to signal to GCC unused function parameters
50  * Repeated here since the definition is not available when
51  * compiled outside the libxml2 build tree.
52  */
53 #if defined(__GNUC__) || defined(__clang__)
54 #ifdef ATTRIBUTE_UNUSED
55 #undef ATTRIBUTE_UNUSED
56 #endif
57 #ifndef ATTRIBUTE_UNUSED
58 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
59 #endif /* ATTRIBUTE_UNUSED */
60 #else
61 #define ATTRIBUTE_UNUSED
62 #endif
63 
64 /*
65  * Macros to ignore deprecation warnings
66  */
67 #if defined(__LCC__)
68 #define XML_IGNORE_DEPRECATION_WARNINGS \
69     _Pragma("diag_suppress 1215")
70 #elif defined(__clang__) || \
71     (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
72 #define XML_IGNORE_DEPRECATION_WARNINGS \
73     _Pragma("GCC diagnostic push") \
74     _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
75 #elif defined (_MSC_VER) && (_MSC_VER >= 1400)
76 #define XML_IGNORE_DEPRECATION_WARNINGS \
77     __pragma(warning(push)) \
78     __pragma(warning(disable : 4996))
79 #else
80 #define XML_IGNORE_DEPRECATION_WARNINGS
81 #endif
82 
83 #define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
84 	(((PyxmlNode_Object *)(v))->obj))
85 
86 typedef struct {
87     PyObject_HEAD
88     xmlNodePtr obj;
89 } PyxmlNode_Object;
90 
91 #ifdef LIBXML_XPATH_ENABLED
92 #define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
93 	(((PyxmlXPathContext_Object *)(v))->obj))
94 
95 typedef struct {
96     PyObject_HEAD
97     xmlXPathContextPtr obj;
98 } PyxmlXPathContext_Object;
99 
100 #define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
101 	(((PyxmlXPathParserContext_Object *)(v))->obj))
102 
103 typedef struct {
104     PyObject_HEAD
105     xmlXPathParserContextPtr obj;
106 } PyxmlXPathParserContext_Object;
107 #endif /* LIBXML_XPATH_ENABLED */
108 
109 #define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
110         (((PyparserCtxt_Object *)(v))->obj))
111 
112 typedef struct {
113     PyObject_HEAD
114     xmlParserCtxtPtr obj;
115 } PyparserCtxt_Object;
116 
117 #define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
118 	(((PyValidCtxt_Object *)(v))->obj))
119 
120 typedef struct {
121 	PyObject_HEAD
122 	xmlValidCtxtPtr obj;
123 } PyValidCtxt_Object;
124 
125 #ifdef LIBXML_CATALOG_ENABLED
126 #define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
127         (((Pycatalog_Object *)(v))->obj))
128 
129 typedef struct {
130     PyObject_HEAD
131     xmlCatalogPtr obj;
132 } Pycatalog_Object;
133 #endif /* LIBXML_CATALOG_ENABLED */
134 
135 #ifdef LIBXML_REGEXP_ENABLED
136 #define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
137         (((PyxmlReg_Object *)(v))->obj))
138 
139 typedef struct {
140     PyObject_HEAD
141     xmlRegexpPtr obj;
142 } PyxmlReg_Object;
143 #endif /* LIBXML_REGEXP_ENABLED */
144 
145 #ifdef LIBXML_READER_ENABLED
146 #define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
147         (((PyxmlTextReader_Object *)(v))->obj))
148 
149 typedef struct {
150     PyObject_HEAD
151     xmlTextReaderPtr obj;
152 } PyxmlTextReader_Object;
153 
154 #define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
155         (((PyxmlTextReaderLocator_Object *)(v))->obj))
156 
157 typedef struct {
158     PyObject_HEAD
159     xmlTextReaderLocatorPtr obj;
160 } PyxmlTextReaderLocator_Object;
161 #endif
162 
163 #define PyURI_Get(v) (((v) == Py_None) ? NULL : \
164 	(((PyURI_Object *)(v))->obj))
165 
166 typedef struct {
167     PyObject_HEAD
168     xmlErrorPtr obj;
169 } PyError_Object;
170 
171 #define PyError_Get(v) (((v) == Py_None) ? NULL : \
172 	(((PyError_Object *)(v))->obj))
173 
174 typedef struct {
175     PyObject_HEAD
176     xmlOutputBufferPtr obj;
177 } PyoutputBuffer_Object;
178 
179 #define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
180 	(((PyoutputBuffer_Object *)(v))->obj))
181 
182 typedef struct {
183     PyObject_HEAD
184     xmlParserInputBufferPtr obj;
185 } PyinputBuffer_Object;
186 
187 #define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
188 	(((PyinputBuffer_Object *)(v))->obj))
189 
190 typedef struct {
191     PyObject_HEAD
192     xmlURIPtr obj;
193 } PyURI_Object;
194 
195 /* FILE * have their own internal representation */
196 #if PY_MAJOR_VERSION >= 3
197 FILE *libxml_PyFileGet(PyObject *f);
198 void libxml_PyFileRelease(FILE *f);
199 #define PyFile_Get(v) (((v) == Py_None) ? NULL : libxml_PyFileGet(v))
200 #define PyFile_Release(f) libxml_PyFileRelease(f)
201 #else
202 #define PyFile_Get(v) (((v) == Py_None) ? NULL : \
203 	(PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
204 #define PyFile_Release(f)
205 #endif
206 
207 #ifdef LIBXML_SCHEMAS_ENABLED
208 typedef struct {
209     PyObject_HEAD
210     xmlRelaxNGPtr obj;
211 } PyrelaxNgSchema_Object;
212 
213 #define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
214 	(((PyrelaxNgSchema_Object *)(v))->obj))
215 
216 typedef struct {
217     PyObject_HEAD
218     xmlRelaxNGParserCtxtPtr obj;
219 } PyrelaxNgParserCtxt_Object;
220 
221 #define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
222 	(((PyrelaxNgParserCtxt_Object *)(v))->obj))
223 
224 typedef struct {
225     PyObject_HEAD
226     xmlRelaxNGValidCtxtPtr obj;
227 } PyrelaxNgValidCtxt_Object;
228 
229 #define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
230 	(((PyrelaxNgValidCtxt_Object *)(v))->obj))
231 
232 typedef struct {
233 	PyObject_HEAD
234 	xmlSchemaPtr obj;
235 } PySchema_Object;
236 
237 #define PySchema_Get(v) (((v) == Py_None) ? NULL : \
238 	(((PySchema_Object *)(v))->obj))
239 
240 typedef struct {
241 	PyObject_HEAD
242 	xmlSchemaParserCtxtPtr obj;
243 } PySchemaParserCtxt_Object;
244 
245 #define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
246 	(((PySchemaParserCtxt_Object *)(v))->obj))
247 
248 typedef struct {
249 	PyObject_HEAD
250 	xmlSchemaValidCtxtPtr obj;
251 } PySchemaValidCtxt_Object;
252 
253 #define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
254 	(((PySchemaValidCtxt_Object *)(v))->obj))
255 
256 #endif /* LIBXML_SCHEMAS_ENABLED */
257 
258 PyObject * libxml_intWrap(int val);
259 PyObject * libxml_longWrap(long val);
260 PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
261 PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
262 PyObject * libxml_charPtrWrap(char *str);
263 PyObject * libxml_constcharPtrWrap(const char *str);
264 PyObject * libxml_charPtrConstWrap(const char *str);
265 PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
266 PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
267 PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
268 PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
269 PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
270 PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
271 PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
272 PyObject * libxml_doubleWrap(double val);
273 PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
274 #ifdef LIBXML_XPATH_ENABLED
275 PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
276 PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
277 PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
278 xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
279 #endif
280 PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
281 #ifdef LIBXML_CATALOG_ENABLED
282 PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
283 #endif
284 PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
285 PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
286 PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
287 #ifdef LIBXML_REGEXP_ENABLED
288 PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
289 #endif /* LIBXML_REGEXP_ENABLED */
290 #ifdef LIBXML_READER_ENABLED
291 PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
292 PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
293 #endif
294 
295 #ifdef LIBXML_SCHEMAS_ENABLED
296 PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
297 PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
298 PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
299 PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
300 PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
301 PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
302 #endif /* LIBXML_SCHEMAS_ENABLED */
303 PyObject * libxml_xmlErrorPtrWrap(const xmlError *error);
304 PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
305 PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
306 PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
307 PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
308 
309 int libxml_deprecationWarning(const char *func);
310