From 252675a5788059dbcc49b175b56fa6c6a35ef74a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 16:44:42 +0100 Subject: python: Add some utility functions for working with Python objects based on talloc pointers. (This used to be commit 9366ddba92e192cd88e12eafba4a90af8c266f1c) --- source4/scripting/python/pytalloc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source4/scripting/python/pytalloc.c (limited to 'source4/scripting/python/pytalloc.c') diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c new file mode 100644 index 00000000000..55ed56a6278 --- /dev/null +++ b/source4/scripting/python/pytalloc.c @@ -0,0 +1,34 @@ +/* + Unix SMB/CIFS implementation. + Python/Talloc glue + Copyright (C) Jelmer Vernooij 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" + +void py_talloc_dealloc(PyObject* self) +{ + py_talloc_Object *obj = (py_talloc_Object *)self; + talloc_free(obj->object); + PyObject_Del(self); +} + +PyObject *py_talloc_import(PyTypeObject *py_type, void *ptr) +{ + PyObject *ret = PyObject_New(py_talloc_Object, &py_type); + ret->talloc_ptr = talloc_reference(NULL, ptr); + return ret; +} -- cgit From f7a0ef04f00cd44845bcee0a171e4cc05a545350 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 18:38:12 +0100 Subject: pidl/python: Support repr() for python types. (This used to be commit cf3664594d3540db20d32bc844f18e20abfa0d96) --- source4/scripting/python/pytalloc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source4/scripting/python/pytalloc.c') diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index 55ed56a6278..4032ff75a4b 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -22,7 +22,7 @@ void py_talloc_dealloc(PyObject* self) { py_talloc_Object *obj = (py_talloc_Object *)self; - talloc_free(obj->object); + talloc_free(obj->talloc_ptr); PyObject_Del(self); } @@ -32,3 +32,11 @@ PyObject *py_talloc_import(PyTypeObject *py_type, void *ptr) ret->talloc_ptr = talloc_reference(NULL, ptr); return ret; } + +PyObject *py_talloc_default_repr(PyObject *py_obj) +{ + py_talloc_Object *obj = (py_talloc_Object *)py_obj; + + return PyString_FromFormat("", + talloc_get_name(obj->talloc_ptr)); +} -- cgit From bfab9862fcdd657a1bddafde49cdd182f89fcf8b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 20:41:34 +0100 Subject: python: Allow wrapping pointers within talloc'ed memory that are not talloc contexts. (This used to be commit 9c038a74113fb55ed5eb12a7d0ae4a46bad9050c) --- source4/scripting/python/pytalloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/scripting/python/pytalloc.c') diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index 4032ff75a4b..d0b8cb83f20 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -22,14 +22,16 @@ void py_talloc_dealloc(PyObject* self) { py_talloc_Object *obj = (py_talloc_Object *)self; - talloc_free(obj->talloc_ptr); + talloc_free(obj->talloc_ctx); PyObject_Del(self); } -PyObject *py_talloc_import(PyTypeObject *py_type, void *ptr) +PyObject *py_talloc_import(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, + void *ptr) { PyObject *ret = PyObject_New(py_talloc_Object, &py_type); - ret->talloc_ptr = talloc_reference(NULL, ptr); + ret->talloc_ctx = talloc_reference(mem_ctx, ptr); + ret->ptr = ptr; return ret; } @@ -38,5 +40,5 @@ PyObject *py_talloc_default_repr(PyObject *py_obj) py_talloc_Object *obj = (py_talloc_Object *)py_obj; return PyString_FromFormat("", - talloc_get_name(obj->talloc_ptr)); + talloc_get_name(obj->talloc_ctx)); } -- cgit From d5903fd75e9640831f0e78fc04d3ffa5ea3b1b4a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 02:48:50 +0100 Subject: pidl/python: Fix compilation of py_echo. (This used to be commit 5ee99ff31c80ece6861b2a0323d71170ef9346b9) --- source4/scripting/python/pytalloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/scripting/python/pytalloc.c') diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index d0b8cb83f20..dc61a0a13d7 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "scripting/python/pytalloc.h" void py_talloc_dealloc(PyObject* self) { @@ -26,13 +27,13 @@ void py_talloc_dealloc(PyObject* self) PyObject_Del(self); } -PyObject *py_talloc_import(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, +PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr) { - PyObject *ret = PyObject_New(py_talloc_Object, &py_type); + py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type); ret->talloc_ctx = talloc_reference(mem_ctx, ptr); ret->ptr = ptr; - return ret; + return (PyObject *)ret; } PyObject *py_talloc_default_repr(PyObject *py_obj) -- cgit From aca6bd5a2a2c5fe266509499be624bbab7b5c3c0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 06:03:33 +0100 Subject: python: Fix deallocation bug in pytalloc. (This used to be commit b849b4a6c4c9b03a9704449a69f00a59fc0df9c5) --- source4/scripting/python/pytalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/python/pytalloc.c') diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index dc61a0a13d7..d8d3efe69c1 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -31,7 +31,7 @@ PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr) { py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type); - ret->talloc_ctx = talloc_reference(mem_ctx, ptr); + ret->talloc_ctx = talloc_reference(NULL, mem_ctx); ret->ptr = ptr; return (PyObject *)ret; } -- cgit