Ignore:
Timestamp:
05/31/10 15:20:34 (14 years ago)
Author:
tim
Message:

misc tweaks to run under python2.5-dbg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python2/class_parser.py

    r196 r198  
    2020        self.classes = {}
    2121        self.headers = '#include <Python.h>\n'
     22
    2223        self.files = []
    2324
     
    4142    def initialization(self):
    4243        result = self.init_string + """
    43 talloc_set_log_fn((void *)printf);
     44talloc_set_log_fn((void(*)(const char*))printf);
    4445//talloc_enable_leak_report();
    4546"""
     
    119120     Py_INCREF(Py_None);
    120121     return (Gen_wrapper *)Py_None;
    121    };
     122   }
    122123
    123124   // Search for subclasses
     
    128129
    129130         result = (Gen_wrapper *)_PyObject_New(python_wrappers[i].python_type);
    130          result->ctx = talloc_asprintf(NULL, "new_class_wrapper %%s@%%p", NAMEOF(item), item);
     131         result->ctx = talloc_asprintf(NULL, "new_class_wrapper %%s@%%p",
     132                                       NAMEOF(item), (void*)item);
    131133         result->base = (void *)item;
    132134
     
    138140
    139141         return result;
    140        };
    141      };
    142    };
     142       }
     143     }
     144   }
    143145
    144146  PyErr_Format(PyExc_RuntimeError, "Unable to find a wrapper for object %%s", NAMEOF(item));
    145147  return NULL;
    146 };
     148}
    147149
    148150static PyObject *resolve_exception(char **error_buff) {
     
    160162    return PyExc_RuntimeError;
    161163};
    162 };
     164}
    163165
    164166static int type_check(PyObject *obj, PyTypeObject *type) {
     
    169171     for(tmp = obj->ob_type; tmp && tmp != &PyBaseObject_Type; tmp = tmp->tp_base) {
    170172       if(tmp == type) return 1;
    171      };
     173     }
    172174
    173175  return 0;
    174 };
     176}
    175177
    176178static int check_error() {
     
    182184         ClearError();
    183185         return 1;
    184    };
     186   }
    185187  return 0;
    186 };
     188}
    187189
    188190#define CHECK_ERROR if(check_error()) goto error;
     
    376378
    377379        result = """PyErr_Clear();
    378    if(!%(name)s) { PyErr_Format(PyExc_RuntimeError, "%(name)s is NULL"); goto error; };
     380   if(!%(name)s) { PyErr_Format(PyExc_RuntimeError, "%(name)s is NULL"); goto error; }
    379381   %(result)s = PyString_FromStringAndSize((char *)%(name)s, %(length)s);\nif(!%(result)s) goto error;
    380382""" % dict(name=name, result=result,length=self.length)
     
    398400  memcpy(%(destination)s, buff, length);
    399401  %(destination)s[length]=0;
    400 };
     402}
    401403""" % dict(source = source, destination = destination, context =context)
    402404
     
    495497    %(result)s = PyString_FromStringAndSize(str_%(name)s, 1);
    496498if(!%(result)s) goto error;
    497 };
     499}
    498500""" % dict(result=result, name = name or self.name)
    499501
     
    513515          "You must only provide a single character for arg %(name)r");
    514516  goto error;
    515 };
     517}
    516518
    517519%(name)s = str_%(name)s[0];
     
    579581        return  """if(func_return > %(length)s) {
    580582  func_return = 0;
    581 };
     583}
    582584
    583585_PyString_Resize(&tmp_%(name)s, func_return); \n%(result)s = tmp_%(name)s;\n""" % \
     
    594596    Py_DECREF(%(result)s);
    595597    %(result)s = PyLong_FromLong(tmp_len);
    596 };
     598}
    597599""" % dict(result = result, name=self.name)
    598600
     
    631633  if(-1==PyString_AsStringAndSize(%(source)s, &buf, &tmp)) {
    632634  goto error;
    633 };
     635}
    634636
    635637  // Take a copy of the python string
     
    698700     PyErr_Format(PyExc_ValueError, "%(destination)s must be a sequence");
    699701     goto error;
    700    };
     702   }
    701703
    702704   size = PySequence_Size(%(source)s);
    703 };
     705}
    704706
    705707%(destination)s = talloc_zero_array(NULL, char *, size + 1);
     
    712714   Py_DECREF(tmp);
    713715   goto error;
    714  };
     716 }
    715717 Py_DECREF(tmp);
    716 };
    717 
    718 };""" % dict(source = source, destination = destination, context = context)
     718}
     719
     720}""" % dict(source = source, destination = destination, context = context)
    719721
    720722    def pre_call(self, method):
     
    735737  PyErr_Format(PyExc_RuntimeError, "function must return an %(type)s instance");
    736738  goto error;
    737 };
     739}
    738740
    739741%(destination)s = ((Gen_wrapper *)%(source)s)->base;
     
    768770} else {
    769771   call_%(name)s = %(name)s->base;
    770 };\n""" % self.__dict__
     772}\n""" % self.__dict__
    771773
    772774    def assign(self, call, method, target=None):
     
    810812            result += "           talloc_reference(%(name)s->ctx, %(name)s->base);\n" % args
    811813
    812         result += """       };
     814        result += """       }
    813815    }
    814816"""
     
    850852} else {
    851853   call_%(name)s = (%(type)s *)&%(name)s->base;
    852 };\n""" % self.__dict__
     854}\n""" % self.__dict__
    853855
    854856class StructWrapper(Wrapper):
     
    864866
    865867        if "NULL_OK" in self.attributes:
    866             result += "if(!%(name)s->base) { Py_DECREF(%(name)s); return NULL; };" % args
     868            result += "if(!%(name)s->base) { Py_DECREF(%(name)s); return NULL; }" % args
    867869
    868870        result += """
     
    9991001    def write(self, out):
    10001002        out.write("\n//Handle exceptions\n")
    1001         out.write("if(%s) {\n    PyErr_Format(PyExc_%s, %s);\n  goto error; \n};\n\n" % (
     1003        out.write("if(%s) {\n    PyErr_Format(PyExc_%s, %s);\n  goto error; \n}\n\n" % (
    10021004                self.check, self.exception, self.message))
    10031005
     
    11531155         PyErr_Format(PyExc_RuntimeError, "%(class_name)s.%(method)s is not implemented");
    11541156         goto error;
    1155      };
    1156   };
     1157     }
     1158  }
    11571159""" % dict(def_class_name = self.definition_class_name, method=self.name,
    11581160           class_name = self.class_name))
     
    12081210            out.write("error:\n    " + self.error_condition());
    12091211
    1210         out.write("\n};\n\n")
     1212        out.write("\n}\n\n")
    12111213
    12121214    def add_arg(self, type, name):
     
    13141316          ((%(class_name)s)self->base)->%(method)s((%(class_name)s)self->base);
    13151317          return PyObject_SelfIter((PyObject *)self);
    1316 };
     1318}
    13171319""" % args)
    13181320
     
    13351337        talloc_free(self->ctx);
    13361338        self->base=NULL;
    1337     };
     1339    }
    13381340"""
    13391341        out.write("""static void
     
    13411343%(free)s
    13421344 PyObject_Del(self);
    1343 };\n
     1345}\n
    13441346""" % dict(class_name = self.class_name, free=free))
    13451347
     
    13791381    PyErr_Format(PyExc_IOError, "Unable to construct class %s");
    13801382    goto error;
    1381   };
     1383  }
    13821384""" % (tmp, self.class_name))
    13831385
     
    13881390            out.write("error:\n    " + self.error_condition());
    13891391
    1390         out.write("\n};\n\n")
     1392        out.write("\n}\n\n")
    13911393
    13921394class GetattrMethod(Method):
     
    14631465     tmp = PyString_FromString(i->ml_name);
    14641466    PyList_Append(result, tmp); Py_DECREF(tmp);
    1465     }; """ % self.class_name)
     1467    }""" % self.class_name)
    14661468
    14671469        out.write("""
     
    15041506    %(python_obj)s
    15051507    return py_result;
    1506 };""" % dict(name = attr.name, python_obj = attr.to_python_object(),
     1508}""" % dict(name = attr.name, python_obj = attr.to_python_object(),
    15071509             python_assign = attr.assign(call, self),
    15081510             python_def = attr.definition(sense='out')))
     
    15431545     tmp = PyString_FromString(i->ml_name);
    15441546    PyList_Append(result, tmp); Py_DECREF(tmp);
    1545     }; """ % self.class_name)
     1547    } """ % self.class_name)
    15461548
    15471549        out.write("""
     
    15521554   PyObject *result = PyObject_GetAttrString(self->base->proxied, name);
    15531555   if(result) return result;
    1554 }; """)
     1556} """)
    15551557
    15561558class ProxiedMethod(Method):
     
    16151617                                           sense='proxied', BORROWED=True))
    16161618
    1617         out.write('if(!((%s)self)->proxied) {\n RaiseError(ERuntimeError, "No proxied object in %s"); goto error;\n};\n' % (self.myclass.class_name, self.myclass.class_name))
     1619        out.write('if(!((%s)self)->proxied) {\n RaiseError(ERuntimeError, "No proxied object in %s"); goto error;\n}\n' % (self.myclass.class_name, self.myclass.class_name))
    16181620
    16191621        out.write("\n//Now call the method\n")
     
    16451647      error_str[BUFF_SIZE-1]=0;
    16461648      *error_type = ERuntimeError;
    1647    };
     1649   }
    16481650   Py_DECREF(str);
    16491651   goto error;
    1650 };
     1652}
    16511653
    16521654""");
     
    16581660        out.write(self.return_type.from_python_object('py_result',self.return_type.name, self, context = "self"))
    16591661
    1660         out.write("if(py_result) { Py_DECREF(py_result);};\nPy_DECREF(method_name);\n\n");
     1662        out.write("if(py_result) { Py_DECREF(py_result);}\nPy_DECREF(method_name);\n\n");
    16611663        out.write("PyGILState_Release(gstate);\n")
    16621664
    16631665        ## Decref all our python objects:
    16641666        for arg in self.args:
    1665             out.write("if(py_%s) { Py_DECREF(py_%s);};\n" %( arg.name, arg.name))
     1667            out.write("if(py_%s) { Py_DECREF(py_%s);}\n" %( arg.name, arg.name))
    16661668
    16671669        out.write(self.return_type.return_value('func_return'))
    16681670        if self.error_set:
    16691671            out.write("\nerror:\n")
    1670             out.write("if(py_result) { Py_DECREF(py_result);};\nPy_DECREF(method_name);\n\n");
     1672            out.write("if(py_result) { Py_DECREF(py_result);}\nPy_DECREF(method_name);\n\n");
    16711673            ## Decref all our python objects:
    16721674            for arg in self.args:
    1673                 out.write("if(py_%s) { Py_DECREF(py_%s);};\n" % (arg.name, arg.name))
     1675                out.write("if(py_%s) { Py_DECREF(py_%s);}\n" % (arg.name, arg.name))
    16741676
    16751677            out.write("PyGILState_Release(gstate);\n %s;\n" % self.error_condition())
    16761678
    1677         out.write("   };\n};\n")
     1679        out.write("   }\n}\n")
    16781680
    16791681    def error_condition(self):
     
    16881690        out.write("\nself->ctx = talloc_strdup(NULL, \"%s\");" % self.class_name)
    16891691        out.write("\nself->base = talloc(self->ctx, %s);\n" % self.class_name)
    1690         out.write("  return 0;\n};\n\n")
     1692        out.write("  return 0;\n}\n\n")
    16911693
    16921694    def write_destructor(self, out):
     
    16941696%(class_name)s_dealloc(py%(class_name)s *self) {
    16951697   talloc_free(self->ctx);
    1696 };\n
     1698}\n
    16971699""" % dict(class_name = self.class_name))
    16981700
     
    17061708        talloc_free(self->ctx);
    17071709        self->base = NULL;
    1708     };
    1709 };\n
     1710    }
     1711}\n
    17101712
    17111713static int %(class_name)s_destructor(void *this) {
     
    17131715  Py_DECREF(self->base->proxied);
    17141716  return 0;
    1715 };
     1717}
    17161718""" % dict(class_name = self.class_name))
    17171719
     
    17301732       ((%(definition_class_name)s)self->base)->%(name)s = tmp;
    17311733       Py_DECREF(py_result);
    1732   };
     1734  }
    17331735  PyErr_Clear();
    1734 };""" % dict(definition = attribute.definition(), name=attribute.name,
     1736}""" % dict(definition = attribute.definition(), name=attribute.name,
    17351737             attribute_name = attribute.__class__.__name__,
    17361738             type = attribute.type,
     
    17601762                                           BORROWED=True))
    17611763
    1762         out.write('if(!((%s)self)->proxied) {\n RaiseError(ERuntimeError, "No proxied object in %s"); goto error;\n};\n' % (self.myclass.class_name, self.myclass.class_name))
     1764        out.write('if(!((%s)self)->proxied) {\n RaiseError(ERuntimeError, "No proxied object in %s"); goto error;\n}\n' % (self.myclass.class_name, self.myclass.class_name))
    17631765
    17641766        out.write("""
     
    17821784   PyErr_Clear();
    17831785   py_result = PyObject_CallFunctionObjArgs(((%(name)s)self)->proxied, %(call)s);
    1784 };
     1786}
    17851787
    17861788/** Check for python errors */
     
    18021804      error_str[BUFF_SIZE-1]=0;
    18031805      *error_type = ERuntimeError;
    1804    };
     1806   }
    18051807   Py_DECREF(str);
    18061808   goto error;
    1807 };
     1809}
    18081810
    18091811// Take over the proxied object now
     
    18251827                                              "((%s)self)->%s" % (class_name, attr.name),
    18261828                                              self))
    1827             out.write("}\nPy_DECREF(py_result);\n};\n};\n")
     1829            out.write("}\nPy_DECREF(py_result);\n}\n}\n")
    18281830
    18291831        out.write("PyGILState_Release(gstate);\n")
     
    18321834            out.write("error:\n PyGILState_Release(gstate);\ntalloc_free(self); return NULL;\n")
    18331835
    1834         out.write("};\n\n")
     1836        out.write("}\n\n")
    18351837
    18361838    def write_definition(self, out):
     
    18811883   if(1 || PyDict_GetItemString(proxied->ob_type->tp_dict, "%(name)s")) {
    18821884     ((%(definition_class_name)s)self->base)->%(name)s = py%(class_name)s_%(name)s;
    1883    };
     1885   }
    18841886""" % dict(definition_class_name = method.definition_class_name,
    18851887           name = method.name,
     
    18991901            out.write("error:\n  PyGILState_Release(gstate);\n  " + self.error_condition());
    19001902
    1901         out.write("\n};\n\n")
     1903        out.write("\n}\n\n")
    19021904
    19031905class EmptyConstructor(ConstructorMethod):
    19041906    def write_definition(self, out):
    19051907        out.write("""static int py%(class_name)s_init(py%(class_name)s *self, PyObject *args, PyObject *kwds) {\n""" % dict(method = self.name, class_name = self.class_name))
    1906         out.write("""return 0;};\n\n""")
     1908        out.write("""return 0;}\n\n""")
    19071909
    19081910class ClassGenerator:
     
    20352037{
    20362038        return v->base != 0;
    2037 };
     2039}
    20382040""" % self.__dict__
    20392041
     
    25242526 Py_DECREF(self->value);
    25252527 PyObject_Del(self);
    2526 };\n
     2528}\n
    25272529""" % dict(class_name = self.class_name))
    25282530    def write_definition(self, out):
     
    25402542error:
    25412543    return -1;
    2542 };
     2544}
    25432545
    25442546static PyObject *py%(class_name)s___str__(py%(class_name)s *self) {
     
    25492551 } else {
    25502552     result = PyObject_Str(self->value);
    2551  };
     2553 }
    25522554
    25532555 return result;
    2554 };
     2556}
    25552557
    25562558""" % self.__dict__)
     
    25992601    Py_INCREF(self->value);
    26002602    return self->value;
    2601 };
     2603}
    26022604""" % self.__dict__
    26032605
     
    26482650    PyErr_Format(PyExc_RuntimeError, "value %%lu is not valid for Enum %(type)s of arg '%(name)s'", (unsigned long)%(name)s);
    26492651    goto error;
    2650   };
     2652  }
    26512653  Py_DECREF(tmp);
    2652 };
     2654}
    26532655""" % self.__dict__
    26542656
Note: See TracChangeset for help on using the changeset viewer.