1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-14 20:01:04 +03:00

Cleanup of the python Makefiles based on Jacob and James feedback, fixed

* libxml.spec.in python/Makefile.am python/tests/Makefile.am
  python/generator.py python/libxml.c python/types.c: Cleanup
  of the python Makefiles based on Jacob and James feedback,
  fixed the spec file accordingly, fixed the number of warning
  that passing my pedantic CFLAGS was generating. Conclusion
  is that Python includes are real crap.
Daniel
This commit is contained in:
Daniel Veillard
2002-03-15 22:24:56 +00:00
parent e7dd2b8dc6
commit d2379010b1
7 changed files with 1033 additions and 878 deletions

View File

@ -9,256 +9,288 @@
#include "libxml_wrap.h"
PyObject *
libxml_intWrap(int val) {
libxml_intWrap(int val)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_intWrap: val = %d\n", val);
#endif
ret = PyInt_FromLong((long) val);
return(ret);
return (ret);
}
PyObject *
libxml_longWrap(long val) {
libxml_longWrap(long val)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_longWrap: val = %ld\n", val);
#endif
ret = PyInt_FromLong(val);
return(ret);
return (ret);
}
PyObject *
libxml_doubleWrap(double val) {
libxml_doubleWrap(double val)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_doubleWrap: val = %f\n", val);
#endif
ret = PyFloat_FromDouble((double) val);
return(ret);
return (ret);
}
PyObject *
libxml_charPtrWrap(char *str) {
libxml_charPtrWrap(char *str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
xmlFree(str);
return(ret);
return (ret);
}
PyObject *
libxml_charPtrConstWrap(const char *str) {
libxml_charPtrConstWrap(const char *str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
return(ret);
return (ret);
}
PyObject *
libxml_xmlCharPtrWrap(xmlChar *str) {
libxml_xmlCharPtrWrap(xmlChar * str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
ret = PyString_FromString((char *) str);
xmlFree(str);
return(ret);
return (ret);
}
PyObject *
libxml_xmlCharPtrConstWrap(const xmlChar *str) {
libxml_xmlCharPtrConstWrap(const xmlChar * str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
return(ret);
ret = PyString_FromString((char *) str);
return (ret);
}
PyObject *
libxml_constcharPtrWrap(const char *str) {
libxml_constcharPtrWrap(const char *str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlcharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
return(ret);
return (ret);
}
PyObject *
libxml_constxmlCharPtrWrap(const xmlChar *str) {
libxml_constxmlCharPtrWrap(const xmlChar * str)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlCharPtrWrap: str = %s\n", str);
#endif
if (str == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyString_FromString(str);
return(ret);
ret = PyString_FromString((char *) str);
return (ret);
}
PyObject *
libxml_xmlDocPtrWrap(xmlDocPtr doc) {
libxml_xmlDocPtrWrap(xmlDocPtr doc)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlDocPtrWrap: doc = %p\n", doc);
#endif
if (doc == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
/* TODO: look at deallocation */
ret = PyCObject_FromVoidPtrAndDesc((void *) doc, "xmlDocPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlNodePtrWrap(xmlNodePtr node) {
libxml_xmlNodePtrWrap(xmlNodePtr node)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlNodePtrWrap: node = %p\n", node);
#endif
if (node == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) node, "xmlNodePtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlURIPtrWrap(xmlURIPtr uri) {
libxml_xmlURIPtrWrap(xmlURIPtr uri)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlURIPtrWrap: uri = %p\n", uri);
#endif
if (uri == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) uri, "xmlURIPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlNsPtrWrap(xmlNsPtr ns) {
libxml_xmlNsPtrWrap(xmlNsPtr ns)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlNsPtrWrap: node = %p\n", ns);
#endif
if (ns == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) ns, "xmlNsPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) ns, (char *) "xmlNsPtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlAttrPtrWrap(xmlAttrPtr attr) {
libxml_xmlAttrPtrWrap(xmlAttrPtr attr)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlAttrNodePtrWrap: attr = %p\n", attr);
#endif
if (attr == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) attr, "xmlAttrPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) attr, (char *) "xmlAttrPtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlAttributePtrWrap(xmlAttributePtr attr) {
libxml_xmlAttributePtrWrap(xmlAttributePtr attr)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlAttributePtrWrap: attr = %p\n", attr);
#endif
if (attr == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) attr, "xmlAttributePtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) attr,
(char *) "xmlAttributePtr", NULL);
return (ret);
}
PyObject *
libxml_xmlElementPtrWrap(xmlElementPtr elem) {
libxml_xmlElementPtrWrap(xmlElementPtr elem)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlElementNodePtrWrap: elem = %p\n", elem);
#endif
if (elem == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) elem, "xmlElementPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) elem,
(char *) "xmlElementPtr", NULL);
return (ret);
}
PyObject *
libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt) {
libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlXPathContextPtrWrap: ctxt = %p\n", ctxt);
#endif
if (ctxt == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xmlXPathContextPtr",
NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) ctxt,
(char *) "xmlXPathContextPtr", NULL);
return (ret);
}
PyObject *
@ -274,153 +306,166 @@ libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
"xmlXPathParserContextPtr", NULL);
(char *) "xmlXPathParserContextPtr",
NULL);
return (ret);
}
PyObject *
libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt) {
libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlParserCtxtPtrWrap: ctxt = %p\n", ctxt);
#endif
if (ctxt == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xmlParserCtxtPtr",
NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) ctxt,
(char *) "xmlParserCtxtPtr", NULL);
return (ret);
}
PyObject *
libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) {
libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlXPathObjectPtrWrap: ctxt = %p\n", obj);
#endif
if (obj == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
switch(obj->type) {
switch (obj->type) {
case XPATH_XSLT_TREE:
/* TODO !!!! Allocation problems */
/* TODO !!!! Allocation problems */
case XPATH_NODESET:
if ((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0))
ret = PyList_New(0);
else {
int i;
xmlNodePtr node;
if ((obj->nodesetval == NULL)
|| (obj->nodesetval->nodeNr == 0))
ret = PyList_New(0);
else {
int i;
xmlNodePtr node;
ret = PyList_New(obj->nodesetval->nodeNr);
for (i = 0;i < obj->nodesetval->nodeNr;i++) {
node = obj->nodesetval->nodeTab[i];
/* TODO: try to cast directly to the proper node type */
PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
}
}
break;
ret = PyList_New(obj->nodesetval->nodeNr);
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
node = obj->nodesetval->nodeTab[i];
/* TODO: try to cast directly to the proper node type */
PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));
}
}
break;
case XPATH_BOOLEAN:
ret = PyInt_FromLong((long) obj->boolval);
break;
ret = PyInt_FromLong((long) obj->boolval);
break;
case XPATH_NUMBER:
ret = PyFloat_FromDouble(obj->floatval);
break;
ret = PyFloat_FromDouble(obj->floatval);
break;
case XPATH_STRING:
ret = PyString_FromString(obj->stringval);
break;
ret = PyString_FromString((char *) obj->stringval);
break;
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
default:
printf("Unable to convert XPath object type %d\n", obj->type);
Py_INCREF(Py_None);
ret = Py_None;
default:
printf("Unable to convert XPath object type %d\n", obj->type);
Py_INCREF(Py_None);
ret = Py_None;
}
xmlXPathFreeObject(obj);
return(ret);
return (ret);
}
xmlXPathObjectPtr
libxml_xmlXPathObjectPtrConvert(PyObject * obj) {
libxml_xmlXPathObjectPtrConvert(PyObject * obj)
{
xmlXPathObjectPtr ret = NULL;
#ifdef DEBUG
printf("libxml_xmlXPathObjectPtrConvert: obj = %p\n", obj);
#endif
if (obj == NULL) {
return(NULL);
return (NULL);
}
if PyFloat_Check(obj) {
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
} else if PyString_Check(obj) {
xmlChar *str;
if PyFloat_Check
(obj) {
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
} else if PyString_Check
(obj) {
xmlChar *str;
str = xmlStrndup((const xmlChar *)PyString_AS_STRING(obj),
PyString_GET_SIZE(obj));
ret = xmlXPathWrapString(str);
} else if PyList_Check(obj) {
int i;
PyObject *node;
xmlNodePtr cur;
xmlNodeSetPtr set;
str = xmlStrndup((const xmlChar *) PyString_AS_STRING(obj),
PyString_GET_SIZE(obj));
ret = xmlXPathWrapString(str);
} else if PyList_Check
(obj) {
int i;
PyObject *node;
xmlNodePtr cur;
xmlNodeSetPtr set;
set = xmlXPathNodeSetCreate(NULL);
set = xmlXPathNodeSetCreate(NULL);
for (i = 0;i < PyList_Size(obj);i++) {
node = PyList_GetItem(obj, i);
if ((node == NULL) || (node->ob_type == NULL))
continue;
for (i = 0; i < PyList_Size(obj); i++) {
node = PyList_GetItem(obj, i);
if ((node == NULL) || (node->ob_type == NULL))
continue;
cur = NULL;
if (PyCObject_Check(node)) {
printf("Got a CObject\n");
cur = PyxmlNode_Get(node);
} else if (PyInstance_Check(node)) {
PyInstanceObject *inst = (PyInstanceObject *) node;
PyObject *name = inst->in_class->cl_name;
if PyString_Check(name) {
char *type = PyString_AS_STRING(name);
PyObject *wrapper;
cur = NULL;
if (PyCObject_Check(node)) {
printf("Got a CObject\n");
cur = PyxmlNode_Get(node);
} else if (PyInstance_Check(node)) {
PyInstanceObject *inst = (PyInstanceObject *) node;
PyObject *name = inst->in_class->cl_name;
if (!strcmp(type, "xmlNode")) {
wrapper = PyObject_GetAttrString(node, "_o");
if (wrapper != NULL) {
cur = PyxmlNode_Get(wrapper);
}
}
}
} else {
printf("Unknown object in Python return list\n");
}
if (cur != NULL) {
xmlXPathNodeSetAdd(set, cur);
}
}
ret = xmlXPathWrapNodeSet(set);
if PyString_Check
(name) {
char *type = PyString_AS_STRING(name);
PyObject *wrapper;
if (!strcmp(type, "xmlNode")) {
wrapper =
PyObject_GetAttrString(node, (char *) "_o");
if (wrapper != NULL) {
cur = PyxmlNode_Get(wrapper);
}
}
}
} else {
printf("Unknown object in Python return list\n");
}
if (cur != NULL) {
xmlXPathNodeSetAdd(set, cur);
}
}
ret = xmlXPathWrapNodeSet(set);
} else {
printf("Unable to convert Python Object to XPath");
printf("Unable to convert Python Object to XPath");
}
Py_DECREF(obj);
return(ret);
return (ret);
}
PyObject *
libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal) {
libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal)
{
PyObject *ret;
#ifdef DEBUG
printf("libxml_xmlNodePtrWrap: catal = %p\n", catal);
#endif
if (catal == NULL) {
Py_INCREF(Py_None);
return(Py_None);
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) catal, "xmlCatalogPtr", NULL);
return(ret);
ret =
PyCObject_FromVoidPtrAndDesc((void *) catal,
(char *) "xmlCatalogPtr", NULL);
return (ret);
}