Author: jelmer
Date: 2008-01-04 03:44:38 +0000 (Fri, 04 Jan 2008)
New Revision: 26662

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26662

Log:
pidl/python: Add constructors for struct/union types.

Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm


Changeset:

Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm      
2008-01-04 03:44:32 UTC (rev 26661)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm      
2008-01-04 03:44:38 UTC (rev 26662)
@@ -84,15 +84,64 @@
 {
        my ($self, $type) = @_;
 
-       $self->pidl("static PyObject *py_$type->{NAME}(PyObject *self, PyObject 
*args)");
+       $self->pidl("staticforward PyTypeObject $type->{NAME}_ObjectType;");
+       $self->pidl("typedef struct {");
+       $self->indent;
+       $self->pidl("PyObject_HEAD");
+       $self->pidl("void *object;"); # FIXME: Use real type rather than void
+       $self->deindent;
+       $self->pidl("} $type->{NAME}_Object;");
+
+       $self->pidl("");
+
+       $self->pidl("static PyObject *py_$type->{NAME}_getattr(PyTypeObject 
*obj, char *name)");
        $self->pidl("{");
        $self->indent;
-       #FIXME
+       $self->pidl("return Py_None;");
+       $self->deindent;
+       $self->pidl("}");
+       $self->pidl("");
 
+       $self->pidl("static void py_$type->{NAME}_dealloc(PyObject* self)");
+       $self->pidl("{");
+       $self->indent;
+       $self->pidl("$type->{NAME}_Object *obj = ($type->{NAME}_Object 
*)self;");
+       $self->pidl("talloc_free(obj->object);");
+       $self->pidl("PyObject_Del(self);");
+       $self->deindent;
+       $self->pidl("}");
+       $self->pidl("");
+
+       $self->pidl("static PyObject *py_$type->{NAME}_setattr(PyTypeObject 
*obj, char *name, PyObject *value)");
+       $self->pidl("{");
+       $self->indent;
        $self->pidl("return Py_None;");
        $self->deindent;
        $self->pidl("}");
        $self->pidl("");
+
+       $self->pidl("static PyTypeObject $type->{NAME}_ObjectType = {");
+       $self->indent;
+       $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
+       $self->pidl(".tp_name = (char *)\"$type->{NAME}\",");
+       $self->pidl(".tp_basicsize = sizeof($type->{NAME}_Object),");
+       $self->pidl(".tp_dealloc = py_$type->{NAME}_dealloc,");
+       $self->pidl(".tp_getattr = py_$type->{NAME}_getattr,");
+       $self->pidl(".tp_setattr = py_$type->{NAME}_setattr,");
+       $self->deindent;
+       $self->pidl("};");
+
+       $self->pidl("");
+
+       $self->pidl("static PyObject *py_$type->{NAME}(PyObject *self, PyObject 
*args)");
+       $self->pidl("{");
+       $self->indent;
+       $self->pidl("$type->{NAME}\_Object *ret;");
+       $self->pidl("ret = PyObject_New($type->{NAME}_Object, 
&$type->{NAME}_ObjectType);");
+       $self->pidl("return (PyObject *) ret;");
+       $self->deindent;
+       $self->pidl("}");
+       $self->pidl("");
 }
 
 sub PythonFunction($$$)
@@ -199,7 +248,7 @@
        $self->pidl("static PyTypeObject $interface->{NAME}_InterfaceType = {");
        $self->indent;
        $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
-       $self->pidl(".tp_name = \"$interface->{NAME}\",");
+       $self->pidl(".tp_name = (char *)\"$interface->{NAME}\",");
        $self->pidl(".tp_basicsize = 
sizeof($interface->{NAME}_InterfaceObject),");
        $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,");
        $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,");

Reply via email to