From 39adc2418a0586261c6c4aea36f72596c6cf8897 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 13:07:16 +0100 Subject: r26088: Import some native-python python modules and move original python swig torture code to common python directory as well. (This used to be commit cbf656ff054ab2b0b5ca81e1d4f16ac54c8098f1) --- source4/scripting/python/uuidmodule.c | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 source4/scripting/python/uuidmodule.c (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c new file mode 100644 index 0000000000..9ae432dfa5 --- /dev/null +++ b/source4/scripting/python/uuidmodule.c @@ -0,0 +1,57 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2007 + + 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" +#include "Python.h" +#include "librpc/ndr/libndr.h" + +static PyObject *uuid_random(PyObject *self, PyObject *args) +{ + struct GUID guid; + char *str; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + guid = GUID_random(); + + str = GUID_string(NULL, &guid); + if (str == NULL) { + PyErr_SetString(PyExc_TypeError, "can't convert uuid to string"); + return NULL; + } + + talloc_free(str); + + return PyString_FromString(str); +} + +static PyMethodDef methods[] = { + { "random", (PyCFunction)uuid_random, METH_VARARGS, NULL}, + { NULL, NULL } +}; + +PyDoc_STRVAR(param_doc, "UUID helper routines"); + +PyMODINIT_FUNC inituuid(void) +{ + PyObject *mod = Py_InitModule3("uuid", methods, param_doc); + if (mod == NULL) + return; +} -- cgit From be33f4c611d37ebba59ff618033dc73601339ad1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 23:54:30 -0600 Subject: r26576: Allow the static module loading code to be used for the Python modules. Simplify the way module initialization functions are handled. (This used to be commit ba8be2dfc0de4434c798663336b81f7f95cde520) --- source4/scripting/python/uuidmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index 9ae432dfa5..02c929d4a5 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -26,7 +26,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args) struct GUID guid; char *str; - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, (char *)"")) return NULL; guid = GUID_random(); @@ -51,7 +51,7 @@ PyDoc_STRVAR(param_doc, "UUID helper routines"); PyMODINIT_FUNC inituuid(void) { - PyObject *mod = Py_InitModule3("uuid", methods, param_doc); + PyObject *mod = Py_InitModule3((char *)"uuid", methods, param_doc); if (mod == NULL) return; } -- cgit From 53c33aa2b42732304f247798a4dbe3bcae14e407 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 03:32:44 +0100 Subject: python: Avoid PyDoc_STRVAR() macro which doesn't exist in Python2.2. (This used to be commit dec3f421be5d7fd4ead3b71f8b69921c41bad39a) --- source4/scripting/python/uuidmodule.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index 02c929d4a5..9b952d31b9 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -18,7 +18,7 @@ */ #include "includes.h" -#include "Python.h" +#include #include "librpc/ndr/libndr.h" static PyObject *uuid_random(PyObject *self, PyObject *args) @@ -47,11 +47,9 @@ static PyMethodDef methods[] = { { NULL, NULL } }; -PyDoc_STRVAR(param_doc, "UUID helper routines"); - PyMODINIT_FUNC inituuid(void) { - PyObject *mod = Py_InitModule3((char *)"uuid", methods, param_doc); + PyObject *mod = Py_InitModule3((char *)"uuid", methods, "UUID helper routines"); if (mod == NULL) return; } -- cgit From 6ef36c1f82fa9d48a3418f25202cab55b2f54d2f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 06:07:20 +0100 Subject: python: Avoid PyMODINIT_FUNC because it doesn't exist in older pythons. (This used to be commit e179db6d0fcf093082f2ad441980a2bb77ac6b17) --- source4/scripting/python/uuidmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index 9b952d31b9..e05b286dd0 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -47,7 +47,7 @@ static PyMethodDef methods[] = { { NULL, NULL } }; -PyMODINIT_FUNC inituuid(void) +void inituuid(void) { PyObject *mod = Py_InitModule3((char *)"uuid", methods, "UUID helper routines"); if (mod == NULL) -- cgit From 6f2935d082687eee23dbc9f1108162cf1670831a Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 13 Mar 2008 09:53:32 +1100 Subject: Don't talloc_free() the UUID before we return. This error caused us to put a 0x80 byte at the end of GUID, which was only detected by OpenLDAP's schema checking. Andrew Bartlett (This used to be commit fd99b7719bcb503e2695b2cbad0230fa23a094ca) --- source4/scripting/python/uuidmodule.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index e05b286dd0..cd9a1cb4d5 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -24,6 +24,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args) { struct GUID guid; + PyObject *pyobj; char *str; if (!PyArg_ParseTuple(args, (char *)"")) @@ -37,9 +38,11 @@ static PyObject *uuid_random(PyObject *self, PyObject *args) return NULL; } + pyobj = PyString_FromString(str); + talloc_free(str); - return PyString_FromString(str); + return pyobj; } static PyMethodDef methods[] = { -- cgit From 1a8bfba5452f7b72d9f0b2a178f7e8a66557c463 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 12:15:43 +0200 Subject: Fix warnings. (This used to be commit 88013ca9775a6ff5e5a393f9d8238dbcd197f26f) --- source4/scripting/python/uuidmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index cd9a1cb4d5..18cfb6ce32 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -27,7 +27,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args) PyObject *pyobj; char *str; - if (!PyArg_ParseTuple(args, (char *)"")) + if (!PyArg_ParseTuple(args, "")) return NULL; guid = GUID_random(); @@ -52,7 +52,7 @@ static PyMethodDef methods[] = { void inituuid(void) { - PyObject *mod = Py_InitModule3((char *)"uuid", methods, "UUID helper routines"); + PyObject *mod = Py_InitModule3("uuid", methods, "UUID helper routines"); if (mod == NULL) return; } -- cgit From 5319d9620b9ef68b3687d76aeaba5fa5d5c57a18 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 May 2008 03:31:26 +0200 Subject: Use consistent function names with the standard Python uuid module that is available in >= 2.4. (This used to be commit 60d458e3195eef6baf655fee0da7c3f68517e8e6) --- source4/scripting/python/uuidmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/python/uuidmodule.c') diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c index 18cfb6ce32..98ef9adaa9 100644 --- a/source4/scripting/python/uuidmodule.c +++ b/source4/scripting/python/uuidmodule.c @@ -46,7 +46,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args) } static PyMethodDef methods[] = { - { "random", (PyCFunction)uuid_random, METH_VARARGS, NULL}, + { "uuid4", (PyCFunction)uuid_random, METH_VARARGS, NULL}, { NULL, NULL } }; -- cgit