[SCM] Samba Shared Repository - branch master updated
Jelmer Vernooij
jelmer at samba.org
Tue Nov 30 18:34:02 MST 2010
The branch, master has been updated
via 8428311 pygensec: Fix initialization.
via efd8fc0 pytalloc: Make py_talloc_default_cmp private.
via b8dc3c8 pytalloc: Make py_talloc_dealloc private.
via 4f0436f pytalloc: Make py_talloc_default_repr private (now exposed by talloc.Object).
via a9fb47b pyparam: Use talloc.Object.
via 1f0cc6f pyregistry: Use talloc.Object.
via f43ffed pyauth: Use talloc.Object.
via fce73d7 pygensec: Use talloc.Object.
via 00251d9 pycredentials: Use talloc.Object.
via 5891e98 pytalloc: Expose PyTalloc_GetObjectType
via 3bff037 pidl/python: Allow import of talloc, even though it doesn't live in the samba.dcerpc. namespace.
via ba2110d pidl: Allow more flexibility importing modules using convenience function.
via 36bdb3b pytalloc: Add convenience function for checking if something is a talloc object.
via dd0fbc4 pidl: Base new objects off of talloc object.
from 0acc93c waf: added a help target for the other waf builds
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 8428311ce5c0fab9c5bbb3fbcbecd37fca472d93
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 01:13:20 2010 +0100
pygensec: Fix initialization.
Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
Autobuild-Date: Wed Dec 1 02:33:06 CET 2010 on sn-devel-104
commit efd8fc0672ee48a40f5e302353ca63590a6d7b45
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:19:37 2010 +0100
pytalloc: Make py_talloc_default_cmp private.
commit b8dc3c8a83af38adf0ee5874331b04692f2dec8d
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:14:27 2010 +0100
pytalloc: Make py_talloc_dealloc private.
commit 4f0436f107422826f93d194370b256b6d278502f
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:07:11 2010 +0100
pytalloc: Make py_talloc_default_repr private (now exposed by talloc.Object).
commit a9fb47b5d6b06d2a528c17803e64b980f1f38805
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:05:05 2010 +0100
pyparam: Use talloc.Object.
commit 1f0cc6f0816abc15a24a8aa5f97e09c069e29927
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:03:08 2010 +0100
pyregistry: Use talloc.Object.
commit f43ffed781196d25a7230f6cfd6abcaf6e5d85f6
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:03:00 2010 +0100
pyauth: Use talloc.Object.
commit fce73d7eff516a981795efa902339cd5bfb19810
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:02:53 2010 +0100
pygensec: Use talloc.Object.
commit 00251d9e5627f041b9585dbe6c380f88f796e3b9
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:02:19 2010 +0100
pycredentials: Use talloc.Object.
commit 5891e9863c87c8a03fef2671be0572187404afa5
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Dec 1 00:01:51 2010 +0100
pytalloc: Expose PyTalloc_GetObjectType
commit 3bff03723d8920faece76dd57bcf5d19b84d7b02
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Nov 30 23:48:46 2010 +0100
pidl/python: Allow import of talloc, even though it doesn't live in the
samba.dcerpc. namespace.
commit ba2110d19060c4d84656917eb6be7b78afc6df6b
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Nov 30 23:06:32 2010 +0100
pidl: Allow more flexibility importing modules using convenience function.
commit 36bdb3b9af271a8dcde23d40737117d7ce5daef8
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Nov 30 22:59:51 2010 +0100
pytalloc: Add convenience function for checking if something is a talloc
object.
commit dd0fbc47c798acfb003e37afbee5f0748e30ad1b
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Tue Nov 30 22:59:32 2010 +0100
pidl: Base new objects off of talloc object.
-----------------------------------------------------------------------
Summary of changes:
lib/talloc/pytalloc.c | 38 ++++++++++++++++++++
lib/talloc/pytalloc.h | 8 +---
lib/talloc/pytalloc_util.c | 57 ++++++++++++-----------------
pidl/lib/Parse/Pidl/Samba4/Python.pm | 54 ++++++++++++++++++----------
source4/auth/credentials/pycredentials.c | 7 +++-
source4/auth/gensec/pygensec.c | 5 ++-
source4/auth/pyauth.c | 8 +++--
source4/lib/registry/pyregistry.c | 13 +++++--
source4/param/pyparam.c | 8 +++-
9 files changed, 127 insertions(+), 71 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
index 7bdebb0..262ba49 100644
--- a/lib/talloc/pytalloc.c
+++ b/lib/talloc/pytalloc.c
@@ -74,6 +74,44 @@ static PyMethodDef talloc_methods[] = {
{ NULL }
};
+/**
+ * Default (but only slightly more useful than the default) implementation of Repr().
+ */
+static PyObject *py_talloc_default_repr(PyObject *obj)
+{
+ py_talloc_Object *talloc_obj = (py_talloc_Object *)obj;
+ PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
+
+ return PyString_FromFormat("<%s talloc object at 0x%p>",
+ type->tp_name, talloc_obj->ptr);
+}
+
+/**
+ * Simple dealloc for talloc-wrapping PyObjects
+ */
+static void py_talloc_dealloc(PyObject* self)
+{
+ py_talloc_Object *obj = (py_talloc_Object *)self;
+ assert(talloc_unlink(NULL, obj->talloc_ctx) != -1);
+ obj->talloc_ctx = NULL;
+ self->ob_type->tp_free(self);
+}
+
+/**
+ * Default (but only slightly more useful than the default) implementation of cmp.
+ */
+static int py_talloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
+{
+ py_talloc_Object *obj1 = (py_talloc_Object *)_obj1,
+ *obj2 = (py_talloc_Object *)_obj2;
+ if (obj1->ob_type != obj2->ob_type)
+ return (obj1->ob_type - obj2->ob_type);
+
+ return ((char *)py_talloc_get_ptr(obj1) - (char *)py_talloc_get_ptr(obj2));
+}
+
+
+
static PyTypeObject TallocObject_Type = {
.tp_name = "talloc.Object",
.tp_basicsize = sizeof(py_talloc_Object),
diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
index b17977a..bfd9c2e 100644
--- a/lib/talloc/pytalloc.h
+++ b/lib/talloc/pytalloc.h
@@ -29,8 +29,8 @@ typedef struct {
void *ptr;
} py_talloc_Object;
-/* Deallocate a py_talloc_Object */
-void py_talloc_dealloc(PyObject* self);
+PyTypeObject *PyTalloc_GetObjectType(void);
+int PyTalloc_Check(PyObject *);
/* Retrieve the pointer for a py_talloc_object. Like talloc_get_type()
* but for py_talloc_Objects. */
@@ -47,14 +47,10 @@ PyObject *py_talloc_steal(PyTypeObject *py_type, void *ptr);
PyObject *py_talloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
#define py_talloc_reference(py_type, talloc_ptr) py_talloc_reference_ex(py_type, talloc_ptr, talloc_ptr)
-/* Sane default implementation of reprfunc. */
-PyObject *py_talloc_default_repr(PyObject *py_obj);
-
#define py_talloc_new(type, typeobj) py_talloc_steal(typeobj, talloc_zero(NULL, type))
PyObject *PyCObject_FromTallocPtr(void *);
PyObject *PyString_FromString_check_null(const char *ptr);
-int py_talloc_default_cmp(PyObject *obj1, PyObject *obj2);
#endif /* _PY_TALLOC_H_ */
diff --git a/lib/talloc/pytalloc_util.c b/lib/talloc/pytalloc_util.c
index d5ef919..d082ee8 100644
--- a/lib/talloc/pytalloc_util.c
+++ b/lib/talloc/pytalloc_util.c
@@ -23,15 +23,24 @@
#include "pytalloc.h"
#include <assert.h>
-/**
- * Simple dealloc for talloc-wrapping PyObjects
- */
-void py_talloc_dealloc(PyObject* self)
+PyTypeObject *PyTalloc_GetObjectType(void)
{
- py_talloc_Object *obj = (py_talloc_Object *)self;
- assert(talloc_unlink(NULL, obj->talloc_ctx) != -1);
- obj->talloc_ctx = NULL;
- self->ob_type->tp_free(self);
+ static PyTypeObject *type = NULL;
+ PyObject *mod;
+
+ if (type != NULL) {
+ return type;
+ }
+
+ mod = PyImport_ImportModule("talloc");
+ if (mod == NULL) {
+ return NULL;
+ }
+
+ type = (PyTypeObject *)PyObject_GetAttrString(mod, "Object");
+ Py_DECREF(mod);
+
+ return type;
}
/**
@@ -88,31 +97,6 @@ PyObject *py_talloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, voi
return (PyObject *)ret;
}
-/**
- * Default (but only slightly more useful than the default) implementation of Repr().
- */
-PyObject *py_talloc_default_repr(PyObject *obj)
-{
- py_talloc_Object *talloc_obj = (py_talloc_Object *)obj;
- PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
-
- return PyString_FromFormat("<%s talloc object at 0x%p>",
- type->tp_name, talloc_obj->ptr);
-}
-
-/**
- * Default (but only slightly more useful than the default) implementation of cmp.
- */
-int py_talloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
-{
- py_talloc_Object *obj1 = (py_talloc_Object *)_obj1,
- *obj2 = (py_talloc_Object *)_obj2;
- if (obj1->ob_type != obj2->ob_type)
- return (obj1->ob_type - obj2->ob_type);
-
- return ((char *)py_talloc_get_ptr(obj1) - (char *)py_talloc_get_ptr(obj2));
-}
-
static void py_cobject_talloc_free(void *ptr)
{
talloc_free(ptr);
@@ -133,3 +117,10 @@ PyObject *PyString_FromString_check_null(const char *ptr)
}
return PyString_FromString(ptr);
}
+
+int PyTalloc_Check(PyObject *obj)
+{
+ PyTypeObject *tp = PyTalloc_GetObjectType();
+
+ return PyObject_TypeCheck(obj, tp);
+}
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 00ada47..3e9178b 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -24,7 +24,7 @@ sub new($) {
my ($class) = @_;
my $self = { res => "", res_hdr => "", tabs => "", constants => {},
module_methods => [], module_objects => [], ready_types => [],
- module_imports => [], type_imports => {},
+ module_imports => {}, type_imports => {},
patch_type_calls => [], prereadycode => [],
postreadycode => []};
bless($self, $class);
@@ -64,8 +64,11 @@ sub PrettifyTypeName($$)
{
my ($name, $basename) = @_;
+ $basename =~ s/^.*\.([^.]+)$/\1/;
+
$name =~ s/^$basename\_//;
+
return $name;
}
@@ -77,7 +80,7 @@ sub Import
$_ = unmake_str($_);
s/\.idl$//;
$self->pidl_hdr("#include \"librpc/gen_ndr/$_\.h\"\n");
- $self->register_module_import($_);
+ $self->register_module_import("samba.dcerpc.$_");
}
}
@@ -321,22 +324,22 @@ sub PythonStruct($$$$$$)
$self->indent;
$self->pidl("PyObject_HEAD_INIT(NULL) 0,");
$self->pidl(".tp_name = \"$modulename.$prettyname\",");
- $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");
- $self->pidl(".tp_dealloc = py_talloc_dealloc,");
$self->pidl(".tp_getset = $getsetters,");
- $self->pidl(".tp_repr = py_talloc_default_repr,");
- $self->pidl(".tp_compare = py_talloc_default_cmp,");
if ($docstring) {
$self->pidl(".tp_doc = $docstring,");
}
$self->pidl(".tp_methods = $py_methods,");
$self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
+ $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");
$self->pidl(".tp_new = py_$name\_new,");
$self->deindent;
$self->pidl("};");
$self->pidl("");
+ my $talloc_typename = $self->import_type_variable("talloc", "Object");
+ $self->register_module_prereadycode(["$name\_Type.tp_base = $talloc_typename;", ""]);
+
return "&$typeobject";
}
@@ -720,7 +723,7 @@ sub Interface($$$)
$self->pidl("");
$self->register_module_typeobject($interface->{NAME}, "&$if_typename");
- my $dcerpc_typename = $self->import_type_variable("base", "ClientConnection");
+ my $dcerpc_typename = $self->import_type_variable("samba.dcerpc.base", "ClientConnection");
$self->register_module_prereadycode(["$if_typename.tp_base = $dcerpc_typename;", ""]);
$self->register_module_postreadycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]);
}
@@ -754,9 +757,15 @@ sub check_ready_type($$)
sub register_module_import($$)
{
- my ($self, $basename) = @_;
+ my ($self, $module_path) = @_;
+
+ my $var_name = $module_path;
+ $var_name =~ s/\./_/g;
+ $var_name = "dep_$var_name";
+
+ $self->{module_imports}->{$var_name} = $module_path;
- push (@{$self->{module_imports}}, $basename) unless (grep(/^$basename$/,@{$self->{module_imports}}));
+ return $var_name;
}
sub import_type_variable($$$)
@@ -784,7 +793,7 @@ sub use_type_variable($$)
}
# If this is an external type, make sure we do the right imports.
if (($ctype->{BASEFILE} ne $self->{BASENAME})) {
- return $self->import_type_variable($ctype->{BASEFILE}, $ctype->{NAME});
+ return $self->import_type_variable("samba.dcerpc.$ctype->{BASEFILE}", $ctype->{NAME});
}
return "&$ctype->{NAME}_Type";
}
@@ -1294,24 +1303,29 @@ sub Parse($$$$$)
$self->pidl("{");
$self->indent;
$self->pidl("PyObject *m;");
- foreach (@{$self->{module_imports}}) {
- $self->pidl("PyObject *dep_$_;");
+ foreach (keys %{$self->{module_imports}}) {
+ $self->pidl("PyObject *$_;");
}
$self->pidl("");
- foreach (@{$self->{module_imports}}) {
- $self->pidl("dep_$_ = PyImport_ImportModule(\"samba.dcerpc.$_\");");
- $self->pidl("if (dep_$_ == NULL)");
+ foreach (keys %{$self->{module_imports}}) {
+ my $var_name = $_;
+ my $module_path = $self->{module_imports}->{$var_name};
+ $self->pidl("$var_name = PyImport_ImportModule(\"$module_path\");");
+ $self->pidl("if ($var_name == NULL)");
$self->pidl("\treturn;");
$self->pidl("");
}
foreach (keys %{$self->{type_imports}}) {
- my $basefile = $self->{type_imports}->{$_};
- $self->pidl_hdr("static PyTypeObject *$_\_Type;\n");
- my $pretty_name = PrettifyTypeName($_, $basefile);
- $self->pidl("$_\_Type = (PyTypeObject *)PyObject_GetAttrString(dep_$basefile, \"$pretty_name\");");
- $self->pidl("if ($_\_Type == NULL)");
+ my $type_var = "$_\_Type";
+ my $module_path = $self->{type_imports}->{$_};
+ $self->pidl_hdr("static PyTypeObject *$type_var;\n");
+ my $pretty_name = PrettifyTypeName($_, $module_path);
+ my $module_var = "dep_$module_path";
+ $module_var =~ s/\./_/g;
+ $self->pidl("$type_var = (PyTypeObject *)PyObject_GetAttrString($module_var, \"$pretty_name\");");
+ $self->pidl("if ($type_var == NULL)");
$self->pidl("\treturn;");
$self->pidl("");
}
diff --git a/source4/auth/credentials/pycredentials.c b/source4/auth/credentials/pycredentials.c
index b7de754..c51e5e1 100644
--- a/source4/auth/credentials/pycredentials.c
+++ b/source4/auth/credentials/pycredentials.c
@@ -420,7 +420,6 @@ static PyMethodDef py_creds_methods[] = {
PyTypeObject PyCredentials = {
.tp_name = "Credentials",
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_new = py_creds_new,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = py_creds_methods,
@@ -430,13 +429,17 @@ PyTypeObject PyCredentials = {
PyTypeObject PyCredentialCacheContainer = {
.tp_name = "CredentialCacheContainer",
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
};
void initcredentials(void)
{
PyObject *m;
+ PyTypeObject *talloc_type = PyTalloc_GetObjectType();
+ if (talloc_type == NULL)
+ return;
+
+ PyCredentials.tp_base = PyCredentialCacheContainer.tp_base = talloc_type;
if (PyType_Ready(&PyCredentials) < 0)
return;
diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c
index f8825b8..e16ba37 100644
--- a/source4/auth/gensec/pygensec.c
+++ b/source4/auth/gensec/pygensec.c
@@ -203,13 +203,16 @@ static PyTypeObject Py_Security = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = py_gensec_security_methods,
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
};
void initgensec(void)
{
PyObject *m;
+ Py_Security.tp_base = PyTalloc_GetObjectType();
+ if (Py_Security.tp_base == NULL)
+ return;
+
if (PyType_Ready(&Py_Security) < 0)
return;
diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c
index c2a5e40..2ef5ebb 100644
--- a/source4/auth/pyauth.c
+++ b/source4/auth/pyauth.c
@@ -25,12 +25,10 @@
#include "libcli/security/security.h"
-PyTypeObject PyAuthSession = {
+static PyTypeObject PyAuthSession = {
.tp_name = "AuthSession",
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_repr = py_talloc_default_repr,
};
PyObject *PyAuthSession_FromSession(struct auth_session_info *session)
@@ -114,6 +112,10 @@ void initauth(void)
{
PyObject *m;
+ PyAuthSession.tp_base = PyTalloc_GetObjectType();
+ if (PyAuthSession.tp_base == NULL)
+ return;
+
if (PyType_Ready(&PyAuthSession) < 0)
return;
diff --git a/source4/lib/registry/pyregistry.c b/source4/lib/registry/pyregistry.c
index 8b75bbb..b93258a 100644
--- a/source4/lib/registry/pyregistry.c
+++ b/source4/lib/registry/pyregistry.c
@@ -159,7 +159,6 @@ PyTypeObject PyRegistry = {
.tp_methods = registry_methods,
.tp_new = registry_new,
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
};
@@ -297,14 +296,12 @@ PyTypeObject PyHiveKey = {
.tp_methods = hive_key_methods,
.tp_new = hive_new,
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
};
PyTypeObject PyRegistryKey = {
.tp_name = "RegistryKey",
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
};
@@ -354,7 +351,7 @@ static PyObject *py_open_samba(PyObject *self, PyObject *args, PyObject *kwargs)
PyErr_SetWERROR(result);
return NULL;
}
-
+
return py_talloc_steal(&PyRegistry, reg_ctx);
}
@@ -474,6 +471,14 @@ static PyMethodDef py_registry_methods[] = {
void initregistry(void)
{
PyObject *m;
+ PyTypeObject *talloc_type = PyTalloc_GetObjectType();
+
+ if (talloc_type == NULL)
+ return;
+
+ PyHiveKey.tp_base = talloc_type;
+ PyRegistry.tp_base = talloc_type;
+ PyRegistryKey.tp_base = talloc_type;
if (PyType_Ready(&PyHiveKey) < 0)
return;
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
index be29c72..4e4d041 100644
--- a/source4/param/pyparam.c
+++ b/source4/param/pyparam.c
@@ -362,7 +362,6 @@ static PyMappingMethods py_lp_ctx_mapping = {
PyTypeObject PyLoadparmContext = {
.tp_name = "LoadParm",
.tp_basicsize = sizeof(py_talloc_Object),
- .tp_dealloc = py_talloc_dealloc,
.tp_getset = py_lp_ctx_getset,
.tp_methods = py_lp_ctx_methods,
.tp_new = py_lp_ctx_new,
@@ -409,7 +408,6 @@ static PyMethodDef py_lp_service_methods[] = {
PyTypeObject PyLoadparmService = {
.tp_name = "LoadparmService",
- .tp_dealloc = py_talloc_dealloc,
.tp_basicsize = sizeof(py_talloc_Object),
.tp_methods = py_lp_service_methods,
.tp_flags = Py_TPFLAGS_DEFAULT,
@@ -429,6 +427,12 @@ static PyMethodDef pyparam_methods[] = {
void initparam(void)
{
PyObject *m;
+ PyTypeObject *talloc_type = PyTalloc_GetObjectType();
+ if (talloc_type == NULL)
+ return;
+
+ PyLoadparmContext.tp_base = talloc_type;
+ PyLoadparmService.tp_base = talloc_type;
if (PyType_Ready(&PyLoadparmContext) < 0)
return;
--
Samba Shared Repository
More information about the samba-cvs
mailing list