1 /*
2  * types.c: converter functions between the internal representation
3  *          and the Python objects
4  *
5  * See Copyright for the status of this software.
6  *
7  * daniel@veillard.com
8  */
9 #include "libxml_wrap.h"
10 #include <libxml/xpathInternals.h>
11 
12 PyObject *
libxml_intWrap(int val)13 libxml_intWrap(int val)
14 {
15     PyObject *ret;
16 
17 #ifdef DEBUG
18     printf("libxml_intWrap: val = %d\n", val);
19 #endif
20     ret = PyInt_FromLong((long) val);
21     return (ret);
22 }
23 
24 PyObject *
libxml_longWrap(long val)25 libxml_longWrap(long val)
26 {
27     PyObject *ret;
28 
29 #ifdef DEBUG
30     printf("libxml_longWrap: val = %ld\n", val);
31 #endif
32     ret = PyInt_FromLong(val);
33     return (ret);
34 }
35 
36 PyObject *
libxml_doubleWrap(double val)37 libxml_doubleWrap(double val)
38 {
39     PyObject *ret;
40 
41 #ifdef DEBUG
42     printf("libxml_doubleWrap: val = %f\n", val);
43 #endif
44     ret = PyFloat_FromDouble((double) val);
45     return (ret);
46 }
47 
48 PyObject *
libxml_charPtrWrap(char * str)49 libxml_charPtrWrap(char *str)
50 {
51     PyObject *ret;
52 
53 #ifdef DEBUG
54     printf("libxml_xmlcharPtrWrap: str = %s\n", str);
55 #endif
56     if (str == NULL) {
57         Py_INCREF(Py_None);
58         return (Py_None);
59     }
60     /* TODO: look at deallocation */
61     ret = PyString_FromString(str);
62     xmlFree(str);
63     return (ret);
64 }
65 
66 PyObject *
libxml_charPtrConstWrap(const char * str)67 libxml_charPtrConstWrap(const char *str)
68 {
69     PyObject *ret;
70 
71 #ifdef DEBUG
72     printf("libxml_xmlcharPtrWrap: str = %s\n", str);
73 #endif
74     if (str == NULL) {
75         Py_INCREF(Py_None);
76         return (Py_None);
77     }
78     /* TODO: look at deallocation */
79     ret = PyString_FromString(str);
80     return (ret);
81 }
82 
83 PyObject *
libxml_xmlCharPtrWrap(xmlChar * str)84 libxml_xmlCharPtrWrap(xmlChar * str)
85 {
86     PyObject *ret;
87 
88 #ifdef DEBUG
89     printf("libxml_xmlCharPtrWrap: str = %s\n", str);
90 #endif
91     if (str == NULL) {
92         Py_INCREF(Py_None);
93         return (Py_None);
94     }
95     /* TODO: look at deallocation */
96     ret = PyString_FromString((char *) str);
97     xmlFree(str);
98     return (ret);
99 }
100 
101 PyObject *
libxml_xmlCharPtrConstWrap(const xmlChar * str)102 libxml_xmlCharPtrConstWrap(const xmlChar * str)
103 {
104     PyObject *ret;
105 
106 #ifdef DEBUG
107     printf("libxml_xmlCharPtrWrap: str = %s\n", str);
108 #endif
109     if (str == NULL) {
110         Py_INCREF(Py_None);
111         return (Py_None);
112     }
113     /* TODO: look at deallocation */
114     ret = PyString_FromString((char *) str);
115     return (ret);
116 }
117 
118 PyObject *
libxml_constcharPtrWrap(const char * str)119 libxml_constcharPtrWrap(const char *str)
120 {
121     PyObject *ret;
122 
123 #ifdef DEBUG
124     printf("libxml_xmlcharPtrWrap: str = %s\n", str);
125 #endif
126     if (str == NULL) {
127         Py_INCREF(Py_None);
128         return (Py_None);
129     }
130     /* TODO: look at deallocation */
131     ret = PyString_FromString(str);
132     return (ret);
133 }
134 
135 PyObject *
libxml_constxmlCharPtrWrap(const xmlChar * str)136 libxml_constxmlCharPtrWrap(const xmlChar * str)
137 {
138     PyObject *ret;
139 
140 #ifdef DEBUG
141     printf("libxml_xmlCharPtrWrap: str = %s\n", str);
142 #endif
143     if (str == NULL) {
144         Py_INCREF(Py_None);
145         return (Py_None);
146     }
147     /* TODO: look at deallocation */
148     ret = PyString_FromString((char *) str);
149     return (ret);
150 }
151 
152 PyObject *
libxml_xmlDocPtrWrap(xmlDocPtr doc)153 libxml_xmlDocPtrWrap(xmlDocPtr doc)
154 {
155     PyObject *ret;
156 
157 #ifdef DEBUG
158     printf("libxml_xmlDocPtrWrap: doc = %p\n", doc);
159 #endif
160     if (doc == NULL) {
161         Py_INCREF(Py_None);
162         return (Py_None);
163     }
164     /* TODO: look at deallocation */
165     ret =
166         PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr",
167                                      NULL);
168     return (ret);
169 }
170 
171 PyObject *
libxml_xmlNodePtrWrap(xmlNodePtr node)172 libxml_xmlNodePtrWrap(xmlNodePtr node)
173 {
174     PyObject *ret;
175 
176 #ifdef DEBUG
177     printf("libxml_xmlNodePtrWrap: node = %p\n", node);
178 #endif
179     if (node == NULL) {
180         Py_INCREF(Py_None);
181         return (Py_None);
182     }
183     ret =
184         PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr",
185                                      NULL);
186     return (ret);
187 }
188 
189 PyObject *
libxml_xmlURIPtrWrap(xmlURIPtr uri)190 libxml_xmlURIPtrWrap(xmlURIPtr uri)
191 {
192     PyObject *ret;
193 
194 #ifdef DEBUG
195     printf("libxml_xmlURIPtrWrap: uri = %p\n", uri);
196 #endif
197     if (uri == NULL) {
198         Py_INCREF(Py_None);
199         return (Py_None);
200     }
201     ret =
202         PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr",
203                                      NULL);
204     return (ret);
205 }
206 
207 PyObject *
libxml_xmlNsPtrWrap(xmlNsPtr ns)208 libxml_xmlNsPtrWrap(xmlNsPtr ns)
209 {
210     PyObject *ret;
211 
212 #ifdef DEBUG
213     printf("libxml_xmlNsPtrWrap: node = %p\n", ns);
214 #endif
215     if (ns == NULL) {
216         Py_INCREF(Py_None);
217         return (Py_None);
218     }
219     ret =
220         PyCObject_FromVoidPtrAndDesc((void *) ns, (char *) "xmlNsPtr",
221                                      NULL);
222     return (ret);
223 }
224 
225 PyObject *
libxml_xmlAttrPtrWrap(xmlAttrPtr attr)226 libxml_xmlAttrPtrWrap(xmlAttrPtr attr)
227 {
228     PyObject *ret;
229 
230 #ifdef DEBUG
231     printf("libxml_xmlAttrNodePtrWrap: attr = %p\n", attr);
232 #endif
233     if (attr == NULL) {
234         Py_INCREF(Py_None);
235         return (Py_None);
236     }
237     ret =
238         PyCObject_FromVoidPtrAndDesc((void *) attr, (char *) "xmlAttrPtr",
239                                      NULL);
240     return (ret);
241 }
242 
243 PyObject *
libxml_xmlAttributePtrWrap(xmlAttributePtr attr)244 libxml_xmlAttributePtrWrap(xmlAttributePtr attr)
245 {
246     PyObject *ret;
247 
248 #ifdef DEBUG
249     printf("libxml_xmlAttributePtrWrap: attr = %p\n", attr);
250 #endif
251     if (attr == NULL) {
252         Py_INCREF(Py_None);
253         return (Py_None);
254     }
255     ret =
256         PyCObject_FromVoidPtrAndDesc((void *) attr,
257                                      (char *) "xmlAttributePtr", NULL);
258     return (ret);
259 }
260 
261 PyObject *
libxml_xmlElementPtrWrap(xmlElementPtr elem)262 libxml_xmlElementPtrWrap(xmlElementPtr elem)
263 {
264     PyObject *ret;
265 
266 #ifdef DEBUG
267     printf("libxml_xmlElementNodePtrWrap: elem = %p\n", elem);
268 #endif
269     if (elem == NULL) {
270         Py_INCREF(Py_None);
271         return (Py_None);
272     }
273     ret =
274         PyCObject_FromVoidPtrAndDesc((void *) elem,
275                                      (char *) "xmlElementPtr", NULL);
276     return (ret);
277 }
278 
279 PyObject *
libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt)280 libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt)
281 {
282     PyObject *ret;
283 
284 #ifdef DEBUG
285     printf("libxml_xmlXPathContextPtrWrap: ctxt = %p\n", ctxt);
286 #endif
287     if (ctxt == NULL) {
288         Py_INCREF(Py_None);
289         return (Py_None);
290     }
291     ret =
292         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
293                                      (char *) "xmlXPathContextPtr", NULL);
294     return (ret);
295 }
296 
297 PyObject *
libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)298 libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)
299 {
300     PyObject *ret;
301 
302 #ifdef DEBUG
303     printf("libxml_xmlXPathParserContextPtrWrap: ctxt = %p\n", ctxt);
304 #endif
305     if (ctxt == NULL) {
306         Py_INCREF(Py_None);
307         return (Py_None);
308     }
309     ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
310                                        (char *) "xmlXPathParserContextPtr",
311                                        NULL);
312     return (ret);
313 }
314 
315 PyObject *
libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt)316 libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt)
317 {
318     PyObject *ret;
319 
320 #ifdef DEBUG
321     printf("libxml_xmlParserCtxtPtrWrap: ctxt = %p\n", ctxt);
322 #endif
323     if (ctxt == NULL) {
324         Py_INCREF(Py_None);
325         return (Py_None);
326     }
327 
328     ret =
329         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
330                                      (char *) "xmlParserCtxtPtr", NULL);
331     return (ret);
332 }
333 
334 /**
335  * libxml_xmlXPathDestructNsNode:
336  * cobj: xmlNsPtr namespace node
337  * desc: ignored string
338  *
339  * This function is called if and when a namespace node returned in
340  * an XPath node set is to be destroyed. That's the only kind of
341  * object returned in node set not directly linked to the original
342  * xmlDoc document, see xmlXPathNodeSetDupNs.
343  */
344 static void
libxml_xmlXPathDestructNsNode(void * cobj,void * desc ATTRIBUTE_UNUSED)345 libxml_xmlXPathDestructNsNode(void *cobj, void *desc ATTRIBUTE_UNUSED) {
346 #ifdef DEBUG
347     fprintf(stderr, "libxml_xmlXPathDestructNsNode called %p\n", cobj);
348 #endif
349     xmlXPathNodeSetFreeNs((xmlNsPtr) cobj);
350 }
351 
352 PyObject *
libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)353 libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
354 {
355     PyObject *ret;
356 
357 #ifdef DEBUG
358     printf("libxml_xmlXPathObjectPtrWrap: ctxt = %p\n", obj);
359 #endif
360     if (obj == NULL) {
361         Py_INCREF(Py_None);
362         return (Py_None);
363     }
364     switch (obj->type) {
365         case XPATH_XSLT_TREE: {
366             if ((obj->nodesetval == NULL) ||
367 		(obj->nodesetval->nodeNr == 0) ||
368 		(obj->nodesetval->nodeTab == NULL)) {
369                 ret = PyList_New(0);
370 	    } else {
371 		int i, len = 0;
372 		xmlNodePtr node;
373 
374 		node = obj->nodesetval->nodeTab[0]->children;
375 		while (node != NULL) {
376 		    len++;
377 		    node = node->next;
378 		}
379 		ret = PyList_New(len);
380 		node = obj->nodesetval->nodeTab[0]->children;
381 		for (i = 0;i < len;i++) {
382                     PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
383 		    node = node->next;
384 		}
385 	    }
386 	    /*
387 	     * Return now, do not free the object passed down
388 	     */
389 	    return (ret);
390 	}
391         case XPATH_NODESET:
392             if ((obj->nodesetval == NULL)
393                 || (obj->nodesetval->nodeNr == 0)) {
394                 ret = PyList_New(0);
395 	    } else {
396                 int i;
397                 xmlNodePtr node;
398 
399                 ret = PyList_New(obj->nodesetval->nodeNr);
400                 for (i = 0; i < obj->nodesetval->nodeNr; i++) {
401                     node = obj->nodesetval->nodeTab[i];
402                     if (node->type == XML_NAMESPACE_DECL) {
403 		        PyObject *ns =
404 			    PyCObject_FromVoidPtrAndDesc((void *) node,
405                                      (char *) "xmlNsPtr",
406 				     libxml_xmlXPathDestructNsNode);
407 			PyList_SetItem(ret, i, ns);
408 			/* make sure the xmlNsPtr is not destroyed now */
409 			obj->nodesetval->nodeTab[i] = NULL;
410 		    } else {
411 			PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
412 		    }
413                 }
414             }
415             break;
416         case XPATH_BOOLEAN:
417             ret = PyInt_FromLong((long) obj->boolval);
418             break;
419         case XPATH_NUMBER:
420             ret = PyFloat_FromDouble(obj->floatval);
421             break;
422         case XPATH_STRING:
423             ret = PyString_FromString((char *) obj->stringval);
424             break;
425         case XPATH_POINT:
426         {
427             PyObject *node;
428             PyObject *indexIntoNode;
429             PyObject *tuple;
430 
431             node = libxml_xmlNodePtrWrap(obj->user);
432             indexIntoNode = PyInt_FromLong((long) obj->index);
433 
434             tuple = PyTuple_New(2);
435             PyTuple_SetItem(tuple, 0, node);
436             PyTuple_SetItem(tuple, 1, indexIntoNode);
437 
438             ret = tuple;
439             break;
440         }
441         case XPATH_RANGE:
442         {
443             unsigned short bCollapsedRange;
444 
445             bCollapsedRange = ( (obj->user2 == NULL) ||
446 		                ((obj->user2 == obj->user) && (obj->index == obj->index2)) );
447             if ( bCollapsedRange ) {
448                 PyObject *node;
449                 PyObject *indexIntoNode;
450                 PyObject *tuple;
451                 PyObject *list;
452 
453                 list = PyList_New(1);
454 
455                 node = libxml_xmlNodePtrWrap(obj->user);
456                 indexIntoNode = PyInt_FromLong((long) obj->index);
457 
458                 tuple = PyTuple_New(2);
459                 PyTuple_SetItem(tuple, 0, node);
460                 PyTuple_SetItem(tuple, 1, indexIntoNode);
461 
462                 PyList_SetItem(list, 0, tuple);
463 
464                 ret = list;
465             } else {
466                 PyObject *node;
467                 PyObject *indexIntoNode;
468                 PyObject *tuple;
469                 PyObject *list;
470 
471                 list = PyList_New(2);
472 
473                 node = libxml_xmlNodePtrWrap(obj->user);
474                 indexIntoNode = PyInt_FromLong((long) obj->index);
475 
476                 tuple = PyTuple_New(2);
477                 PyTuple_SetItem(tuple, 0, node);
478                 PyTuple_SetItem(tuple, 1, indexIntoNode);
479 
480                 PyList_SetItem(list, 0, tuple);
481 
482                 node = libxml_xmlNodePtrWrap(obj->user2);
483                 indexIntoNode = PyInt_FromLong((long) obj->index2);
484 
485                 tuple = PyTuple_New(2);
486                 PyTuple_SetItem(tuple, 0, node);
487                 PyTuple_SetItem(tuple, 1, indexIntoNode);
488 
489                 PyList_SetItem(list, 1, tuple);
490 
491                 ret = list;
492             }
493             break;
494         }
495         case XPATH_LOCATIONSET:
496         {
497             xmlLocationSetPtr set;
498 
499             set = obj->user;
500             if ( set && set->locNr > 0 ) {
501                 int i;
502                 PyObject *list;
503 
504                 list = PyList_New(set->locNr);
505 
506                 for (i=0; i<set->locNr; i++) {
507                     xmlXPathObjectPtr setobj;
508                     PyObject *pyobj;
509 
510                     setobj = set->locTab[i]; /*xmlXPathObjectPtr setobj*/
511 
512                     pyobj = libxml_xmlXPathObjectPtrWrap(setobj);
513                     /* xmlXPathFreeObject(setobj) is called */
514                     set->locTab[i] = NULL;
515 
516                     PyList_SetItem(list, i, pyobj);
517                 }
518                 set->locNr = 0;
519                 ret = list;
520             } else {
521                 Py_INCREF(Py_None);
522                 ret = Py_None;
523             }
524             break;
525         }
526         default:
527 #ifdef DEBUG
528             printf("Unable to convert XPath object type %d\n", obj->type);
529 #endif
530             Py_INCREF(Py_None);
531             ret = Py_None;
532     }
533     xmlXPathFreeObject(obj);
534     return (ret);
535 }
536 
537 xmlXPathObjectPtr
libxml_xmlXPathObjectPtrConvert(PyObject * obj)538 libxml_xmlXPathObjectPtrConvert(PyObject * obj)
539 {
540     xmlXPathObjectPtr ret = NULL;
541 
542 #ifdef DEBUG
543     printf("libxml_xmlXPathObjectPtrConvert: obj = %p\n", obj);
544 #endif
545     if (obj == NULL) {
546         return (NULL);
547     }
548     if PyFloat_Check
549         (obj) {
550         ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
551 
552     } else if PyInt_Check(obj) {
553 
554         ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
555 
556 #ifdef PyBool_Check
557     } else if PyBool_Check (obj) {
558 
559         if (obj == Py_True) {
560           ret = xmlXPathNewBoolean(1);
561         }
562         else {
563           ret = xmlXPathNewBoolean(0);
564         }
565 #endif
566     } else if PyString_Check
567         (obj) {
568         xmlChar *str;
569 
570         str = xmlStrndup((const xmlChar *) PyString_AS_STRING(obj),
571                          PyString_GET_SIZE(obj));
572         ret = xmlXPathWrapString(str);
573     } else if PyList_Check
574         (obj) {
575         int i;
576         PyObject *node;
577         xmlNodePtr cur;
578         xmlNodeSetPtr set;
579 
580         set = xmlXPathNodeSetCreate(NULL);
581 
582         for (i = 0; i < PyList_Size(obj); i++) {
583             node = PyList_GetItem(obj, i);
584             if ((node == NULL) || (node->ob_type == NULL))
585                 continue;
586 
587             cur = NULL;
588             if (PyCObject_Check(node)) {
589 #ifdef DEBUG
590                 printf("Got a CObject\n");
591 #endif
592                 cur = PyxmlNode_Get(node);
593             } else if (PyInstance_Check(node)) {
594                 PyInstanceObject *inst = (PyInstanceObject *) node;
595                 PyObject *name = inst->in_class->cl_name;
596 
597                 if PyString_Check
598                     (name) {
599                     char *type = PyString_AS_STRING(name);
600                     PyObject *wrapper;
601 
602                     if (!strcmp(type, "xmlNode")) {
603                         wrapper =
604                             PyObject_GetAttrString(node, (char *) "_o");
605                         if (wrapper != NULL) {
606                             cur = PyxmlNode_Get(wrapper);
607                         }
608                     }
609                     }
610             } else {
611 #ifdef DEBUG
612                 printf("Unknown object in Python return list\n");
613 #endif
614             }
615             if (cur != NULL) {
616                 xmlXPathNodeSetAdd(set, cur);
617             }
618         }
619         ret = xmlXPathWrapNodeSet(set);
620     } else {
621 #ifdef DEBUG
622         printf("Unable to convert Python Object to XPath");
623 #endif
624     }
625     Py_DECREF(obj);
626     return (ret);
627 }
628 
629 PyObject *
libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid)630 libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid)
631 {
632 	PyObject *ret;
633 
634 #ifdef DEBUG
635 	printf("libxml_xmlValidCtxtPtrWrap: valid = %p\n", valid);
636 #endif
637 	if (valid == NULL) {
638 		Py_INCREF(Py_None);
639 		return (Py_None);
640 	}
641 
642 	ret =
643 		PyCObject_FromVoidPtrAndDesc((void *) valid,
644 									 (char *) "xmlValidCtxtPtr", NULL);
645 
646 	return (ret);
647 }
648 
649 PyObject *
libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal)650 libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal)
651 {
652     PyObject *ret;
653 
654 #ifdef DEBUG
655     printf("libxml_xmlNodePtrWrap: catal = %p\n", catal);
656 #endif
657     if (catal == NULL) {
658         Py_INCREF(Py_None);
659         return (Py_None);
660     }
661     ret =
662         PyCObject_FromVoidPtrAndDesc((void *) catal,
663                                      (char *) "xmlCatalogPtr", NULL);
664     return (ret);
665 }
666 
667 PyObject *
libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer)668 libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer)
669 {
670     PyObject *ret;
671 
672 #ifdef DEBUG
673     printf("libxml_xmlOutputBufferPtrWrap: buffer = %p\n", buffer);
674 #endif
675     if (buffer == NULL) {
676         Py_INCREF(Py_None);
677         return (Py_None);
678     }
679     ret =
680         PyCObject_FromVoidPtrAndDesc((void *) buffer,
681                                      (char *) "xmlOutputBufferPtr", NULL);
682     return (ret);
683 }
684 
685 PyObject *
libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer)686 libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer)
687 {
688     PyObject *ret;
689 
690 #ifdef DEBUG
691     printf("libxml_xmlParserInputBufferPtrWrap: buffer = %p\n", buffer);
692 #endif
693     if (buffer == NULL) {
694         Py_INCREF(Py_None);
695         return (Py_None);
696     }
697     ret =
698         PyCObject_FromVoidPtrAndDesc((void *) buffer,
699                                      (char *) "xmlParserInputBufferPtr", NULL);
700     return (ret);
701 }
702 
703 #ifdef LIBXML_REGEXP_ENABLED
704 PyObject *
libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp)705 libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp)
706 {
707     PyObject *ret;
708 
709 #ifdef DEBUG
710     printf("libxml_xmlRegexpPtrWrap: regexp = %p\n", regexp);
711 #endif
712     if (regexp == NULL) {
713         Py_INCREF(Py_None);
714         return (Py_None);
715     }
716     ret =
717         PyCObject_FromVoidPtrAndDesc((void *) regexp,
718                                      (char *) "xmlRegexpPtr", NULL);
719     return (ret);
720 }
721 #endif /* LIBXML_REGEXP_ENABLED */
722 
723 PyObject *
libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader)724 libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader)
725 {
726     PyObject *ret;
727 
728 #ifdef DEBUG
729     printf("libxml_xmlTextReaderPtrWrap: reader = %p\n", reader);
730 #endif
731     if (reader == NULL) {
732         Py_INCREF(Py_None);
733         return (Py_None);
734     }
735     ret =
736         PyCObject_FromVoidPtrAndDesc((void *) reader,
737                                      (char *) "xmlTextReaderPtr", NULL);
738     return (ret);
739 }
740 
741 PyObject *
libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator)742 libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator)
743 {
744     PyObject *ret;
745 
746 #ifdef DEBUG
747     printf("libxml_xmlTextReaderLocatorPtrWrap: locator = %p\n", locator);
748 #endif
749     if (locator == NULL) {
750         Py_INCREF(Py_None);
751         return (Py_None);
752     }
753     ret =
754         PyCObject_FromVoidPtrAndDesc((void *) locator,
755                                      (char *) "xmlTextReaderLocatorPtr", NULL);
756     return (ret);
757 }
758 
759 #ifdef LIBXML_SCHEMAS_ENABLED
760 PyObject *
libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt)761 libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt)
762 {
763     PyObject *ret;
764 
765 #ifdef DEBUG
766     printf("libxml_xmlRelaxNGPtrWrap: ctxt = %p\n", ctxt);
767 #endif
768     if (ctxt == NULL) {
769         Py_INCREF(Py_None);
770         return (Py_None);
771     }
772     ret =
773         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
774                                      (char *) "xmlRelaxNGPtr", NULL);
775     return (ret);
776 }
777 
778 PyObject *
libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt)779 libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt)
780 {
781     PyObject *ret;
782 
783 #ifdef DEBUG
784     printf("libxml_xmlRelaxNGParserCtxtPtrWrap: ctxt = %p\n", ctxt);
785 #endif
786     if (ctxt == NULL) {
787         Py_INCREF(Py_None);
788         return (Py_None);
789     }
790     ret =
791         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
792                                      (char *) "xmlRelaxNGParserCtxtPtr", NULL);
793     return (ret);
794 }
795 PyObject *
libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid)796 libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid)
797 {
798     PyObject *ret;
799 
800 #ifdef DEBUG
801     printf("libxml_xmlRelaxNGValidCtxtPtrWrap: valid = %p\n", valid);
802 #endif
803     if (valid == NULL) {
804         Py_INCREF(Py_None);
805         return (Py_None);
806     }
807     ret =
808         PyCObject_FromVoidPtrAndDesc((void *) valid,
809                                      (char *) "xmlRelaxNGValidCtxtPtr", NULL);
810     return (ret);
811 }
812 
813 PyObject *
libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt)814 libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt)
815 {
816 	PyObject *ret;
817 
818 #ifdef DEBUG
819 	printf("libxml_xmlSchemaPtrWrap: ctxt = %p\n", ctxt);
820 #endif
821 	if (ctxt == NULL) {
822 		Py_INCREF(Py_None);
823 		return (Py_None);
824 	}
825 	ret =
826 		PyCObject_FromVoidPtrAndDesc((void *) ctxt,
827 									 (char *) "xmlSchemaPtr", NULL);
828 	return (ret);
829 }
830 
831 PyObject *
libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt)832 libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt)
833 {
834 	PyObject *ret;
835 
836 #ifdef DEBUG
837 	printf("libxml_xmlSchemaParserCtxtPtrWrap: ctxt = %p\n", ctxt);
838 #endif
839 	if (ctxt == NULL) {
840 		Py_INCREF(Py_None);
841 		return (Py_None);
842 	}
843 	ret =
844 		PyCObject_FromVoidPtrAndDesc((void *) ctxt,
845 									 (char *) "xmlSchemaParserCtxtPtr", NULL);
846 
847 	return (ret);
848 }
849 
850 PyObject *
libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid)851 libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid)
852 {
853 	PyObject *ret;
854 
855 #ifdef DEBUG
856 	printf("libxml_xmlSchemaValidCtxtPtrWrap: valid = %p\n", valid);
857 #endif
858 	if (valid == NULL) {
859 		Py_INCREF(Py_None);
860 		return (Py_None);
861 	}
862 
863 	ret =
864 		PyCObject_FromVoidPtrAndDesc((void *) valid,
865 									 (char *) "xmlSchemaValidCtxtPtr", NULL);
866 
867 	return (ret);
868 }
869 #endif /* LIBXML_SCHEMAS_ENABLED */
870 
871 PyObject *
libxml_xmlErrorPtrWrap(xmlErrorPtr error)872 libxml_xmlErrorPtrWrap(xmlErrorPtr error)
873 {
874     PyObject *ret;
875 
876 #ifdef DEBUG
877     printf("libxml_xmlErrorPtrWrap: error = %p\n", error);
878 #endif
879     if (error == NULL) {
880         Py_INCREF(Py_None);
881         return (Py_None);
882     }
883     ret =
884         PyCObject_FromVoidPtrAndDesc((void *) error,
885                                      (char *) "xmlErrorPtr", NULL);
886     return (ret);
887 }
888