Annotation of embedaddon/libxml2/python/types.c, revision 1.1

1.1     ! misho       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 *
        !            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 *
        !            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 *
        !            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 *
        !            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 *
        !            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 *
        !            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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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
        !           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 *
        !           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
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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 *
        !           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: #ifdef LIBXML_READER_ENABLED
        !           724: PyObject *
        !           725: libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader)
        !           726: {
        !           727:     PyObject *ret;
        !           728: 
        !           729: #ifdef DEBUG
        !           730:     printf("libxml_xmlTextReaderPtrWrap: reader = %p\n", reader);
        !           731: #endif
        !           732:     if (reader == NULL) {
        !           733:         Py_INCREF(Py_None);
        !           734:         return (Py_None);
        !           735:     }
        !           736:     ret =
        !           737:         PyCObject_FromVoidPtrAndDesc((void *) reader,
        !           738:                                      (char *) "xmlTextReaderPtr", NULL);
        !           739:     return (ret);
        !           740: }
        !           741: 
        !           742: PyObject *
        !           743: libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator)
        !           744: {
        !           745:     PyObject *ret;
        !           746: 
        !           747: #ifdef DEBUG
        !           748:     printf("libxml_xmlTextReaderLocatorPtrWrap: locator = %p\n", locator);
        !           749: #endif
        !           750:     if (locator == NULL) {
        !           751:         Py_INCREF(Py_None);
        !           752:         return (Py_None);
        !           753:     }
        !           754:     ret =
        !           755:         PyCObject_FromVoidPtrAndDesc((void *) locator,
        !           756:                                      (char *) "xmlTextReaderLocatorPtr", NULL);
        !           757:     return (ret);
        !           758: }
        !           759: #endif /* LIBXML_READER_ENABLED */
        !           760: 
        !           761: #ifdef LIBXML_SCHEMAS_ENABLED
        !           762: PyObject *
        !           763: libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt)
        !           764: {
        !           765:     PyObject *ret;
        !           766: 
        !           767: #ifdef DEBUG
        !           768:     printf("libxml_xmlRelaxNGPtrWrap: ctxt = %p\n", ctxt);
        !           769: #endif
        !           770:     if (ctxt == NULL) {
        !           771:         Py_INCREF(Py_None);
        !           772:         return (Py_None);
        !           773:     }
        !           774:     ret =
        !           775:         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
        !           776:                                      (char *) "xmlRelaxNGPtr", NULL);
        !           777:     return (ret);
        !           778: }
        !           779: 
        !           780: PyObject *
        !           781: libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt)
        !           782: {
        !           783:     PyObject *ret;
        !           784: 
        !           785: #ifdef DEBUG
        !           786:     printf("libxml_xmlRelaxNGParserCtxtPtrWrap: ctxt = %p\n", ctxt);
        !           787: #endif
        !           788:     if (ctxt == NULL) {
        !           789:         Py_INCREF(Py_None);
        !           790:         return (Py_None);
        !           791:     }
        !           792:     ret =
        !           793:         PyCObject_FromVoidPtrAndDesc((void *) ctxt,
        !           794:                                      (char *) "xmlRelaxNGParserCtxtPtr", NULL);
        !           795:     return (ret);
        !           796: }
        !           797: PyObject *
        !           798: libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid)
        !           799: {
        !           800:     PyObject *ret;
        !           801: 
        !           802: #ifdef DEBUG
        !           803:     printf("libxml_xmlRelaxNGValidCtxtPtrWrap: valid = %p\n", valid);
        !           804: #endif
        !           805:     if (valid == NULL) {
        !           806:         Py_INCREF(Py_None);
        !           807:         return (Py_None);
        !           808:     }
        !           809:     ret =
        !           810:         PyCObject_FromVoidPtrAndDesc((void *) valid,
        !           811:                                      (char *) "xmlRelaxNGValidCtxtPtr", NULL);
        !           812:     return (ret);
        !           813: }
        !           814: 
        !           815: PyObject *
        !           816: libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt)
        !           817: {
        !           818:        PyObject *ret;
        !           819: 
        !           820: #ifdef DEBUG
        !           821:        printf("libxml_xmlSchemaPtrWrap: ctxt = %p\n", ctxt);
        !           822: #endif
        !           823:        if (ctxt == NULL) {
        !           824:                Py_INCREF(Py_None);
        !           825:                return (Py_None);
        !           826:        }
        !           827:        ret =
        !           828:                PyCObject_FromVoidPtrAndDesc((void *) ctxt,
        !           829:                                                                         (char *) "xmlSchemaPtr", NULL);
        !           830:        return (ret);
        !           831: }
        !           832: 
        !           833: PyObject *
        !           834: libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt)
        !           835: {
        !           836:        PyObject *ret;
        !           837: 
        !           838: #ifdef DEBUG
        !           839:        printf("libxml_xmlSchemaParserCtxtPtrWrap: ctxt = %p\n", ctxt);
        !           840: #endif
        !           841:        if (ctxt == NULL) {
        !           842:                Py_INCREF(Py_None);
        !           843:                return (Py_None);
        !           844:        }
        !           845:        ret = 
        !           846:                PyCObject_FromVoidPtrAndDesc((void *) ctxt,
        !           847:                                                                         (char *) "xmlSchemaParserCtxtPtr", NULL);
        !           848: 
        !           849:        return (ret);
        !           850: }
        !           851: 
        !           852: PyObject *
        !           853: libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid)
        !           854: {
        !           855:        PyObject *ret;
        !           856:        
        !           857: #ifdef DEBUG
        !           858:        printf("libxml_xmlSchemaValidCtxtPtrWrap: valid = %p\n", valid);
        !           859: #endif
        !           860:        if (valid == NULL) {
        !           861:                Py_INCREF(Py_None);
        !           862:                return (Py_None);
        !           863:        }
        !           864: 
        !           865:        ret = 
        !           866:                PyCObject_FromVoidPtrAndDesc((void *) valid,
        !           867:                                                                         (char *) "xmlSchemaValidCtxtPtr", NULL);
        !           868: 
        !           869:        return (ret);
        !           870: }
        !           871: #endif /* LIBXML_SCHEMAS_ENABLED */
        !           872: 
        !           873: PyObject *
        !           874: libxml_xmlErrorPtrWrap(xmlErrorPtr error)
        !           875: {
        !           876:     PyObject *ret;
        !           877: 
        !           878: #ifdef DEBUG
        !           879:     printf("libxml_xmlErrorPtrWrap: error = %p\n", error);
        !           880: #endif
        !           881:     if (error == NULL) {
        !           882:         Py_INCREF(Py_None);
        !           883:         return (Py_None);
        !           884:     }
        !           885:     ret =
        !           886:         PyCObject_FromVoidPtrAndDesc((void *) error,
        !           887:                                      (char *) "xmlErrorPtr", NULL);
        !           888:     return (ret);
        !           889: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>