summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-04 03:44:38 -0600
committerStefan Metzmacher <metze@samba.org>2008-01-03 21:51:02 -0600
commit4ba6e6c1593bc7a9e1bd9b891a325a842e93d951 (patch)
tree3ba812c5e8fe8b5761c9b1da95ad4e1ae6f60015 /source4
parentc9afddd42c916328980390251938508165ad130f (diff)
downloadsamba-4ba6e6c1593bc7a9e1bd9b891a325a842e93d951.tar.gz
samba-4ba6e6c1593bc7a9e1bd9b891a325a842e93d951.tar.bz2
samba-4ba6e6c1593bc7a9e1bd9b891a325a842e93d951.zip
r26662: pidl/python: Add constructors for struct/union types.
(This used to be commit bc6aa49d8e33add2efa6f66630029f5305b56280)
Diffstat (limited to 'source4')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm55
1 files changed, 52 insertions, 3 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 7e2ded1ff7..874e7f8346 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -84,15 +84,64 @@ sub TypeConstructor($$)
{
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 @@ sub Interface($$)
$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,");