The Samba-Bugzilla – Attachment 10152 Details for
Bug 10028
Samba Python 3 support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
port pytalloc to python 3
0001-port-pytalloc-to-python-3.patch (text/plain), 3.75 KB, created by
ttomecek
on 2014-07-25 12:13:41 UTC
(
hide
)
Description:
port pytalloc to python 3
Filename:
MIME Type:
Creator:
ttomecek
Created:
2014-07-25 12:13:41 UTC
Size:
3.75 KB
patch
obsolete
>From 5cea8a157363672fcae118c09cd077b0591b7dc0 Mon Sep 17 00:00:00 2001 >From: Tomas Tomecek <ttomecek@redhat.com> >Date: Fri, 25 Jul 2014 13:43:44 +0200 >Subject: [PATCH] port pytalloc to python 3 > >This was done at EuroPython 2014 hackaton. @hackerfleet #ep14boat >--- > pytalloc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- > pytalloc_util.c | 4 ++++ > 2 files changed, 57 insertions(+), 5 deletions(-) > >diff --git a/pytalloc.c b/pytalloc.c >index 80196c6..e4c9791 100644 >--- a/pytalloc.c >+++ b/pytalloc.c >@@ -1,4 +1,4 @@ >-/* >+/* > Unix SMB/CIFS implementation. > Python Talloc Module > Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010-2011 >@@ -21,7 +21,11 @@ > #include <talloc.h> > #include <pytalloc.h> > >+#if PY_MAJOR_VERSION >= 3 >+PyMODINIT_FUNC PyInit_talloc(void); >+#else > void inittalloc(void); >+#endif > > /* print a talloc tree report for a talloc python object */ > static PyObject *pytalloc_report_full(PyObject *self, PyObject *args) >@@ -78,9 +82,12 @@ static PyObject *pytalloc_default_repr(PyObject *obj) > { > pytalloc_Object *talloc_obj = (pytalloc_Object *)obj; > PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj); >- >- return PyString_FromFormat("<%s talloc object at 0x%p>", >- type->tp_name, talloc_obj->ptr); >+#if PY_MAJOR_VERSION >= 3 >+ return PyUnicode_FromFormat("<%s talloc object at 0x%p>", >+#else >+ return PyString_FromFormat("<%s talloc object at 0x%p>", >+#endif >+ type->tp_name, talloc_obj->ptr); > } > > /** >@@ -101,9 +108,13 @@ static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2) > { > pytalloc_Object *obj1 = (pytalloc_Object *)_obj1, > *obj2 = (pytalloc_Object *)_obj2; >+#if PY_MAJOR_VERSION >= 3 >+ if (Py_TYPE(obj1) != Py_TYPE(obj2)) >+ return Py_TYPE(obj1) - Py_TYPE(obj2); >+#else > if (obj1->ob_type != obj2->ob_type) > return (obj1->ob_type - obj2->ob_type); >- >+#endif > return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2)); > } > >@@ -114,21 +125,58 @@ static PyTypeObject TallocObject_Type = { > .tp_dealloc = (destructor)pytalloc_dealloc, > .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, > .tp_repr = pytalloc_default_repr, >+#if PY_MAJOR_VERSION >= 3 >+ .tp_reserved = pytalloc_default_cmp, >+#else > .tp_compare = pytalloc_default_cmp, >+#endif > }; > >+#if PY_MAJOR_VERSION >= 3 >+ static struct PyModuleDef moduledef = { >+ PyModuleDef_HEAD_INIT, >+ "talloc", /* m_name */ >+ "Python wrapping of talloc-maintained objects.", /* m_doc */ >+ -1, /* m_size */ >+ talloc_methods, /* m_methods */ >+ NULL, /* m_reload */ >+ NULL, /* m_traverse */ >+ NULL, /* m_clear */ >+ NULL, /* m_free */ >+ }; >+#endif >+ >+#if PY_MAJOR_VERSION >= 3 >+PyMODINIT_FUNC PyInit_talloc(void) >+#else > void inittalloc(void) >+#endif > { > PyObject *m; > > if (PyType_Ready(&TallocObject_Type) < 0) >+#if PY_MAJOR_VERSION >= 3 >+ return NULL; >+#else > return; >+#endif > >+#if PY_MAJOR_VERSION >= 3 >+ m = PyModule_Create(&moduledef); >+#else > m = Py_InitModule3("talloc", talloc_methods, > "Python wrapping of talloc-maintained objects."); >+#endif > if (m == NULL) >+#if PY_MAJOR_VERSION >= 3 >+ return NULL; >+#else > return; >+#endif > > Py_INCREF(&TallocObject_Type); > PyModule_AddObject(m, "Object", (PyObject *)&TallocObject_Type); >+#if PY_MAJOR_VERSION >= 3 >+ return m; >+#endif > } >diff --git a/pytalloc_util.c b/pytalloc_util.c >index 89a093b..e139269 100644 >--- a/pytalloc_util.c >+++ b/pytalloc_util.c >@@ -107,7 +107,11 @@ _PUBLIC_ PyObject *pytalloc_CObject_FromTallocPtr(void *ptr) > if (ptr == NULL) { > Py_RETURN_NONE; > } >+#if PY_MAJOR_VERSION >= 3 >+ return PyCapsule_New(ptr, NULL, py_cobject_talloc_free); >+#else > return PyCObject_FromVoidPtr(ptr, py_cobject_talloc_free); >+#endif > } > > _PUBLIC_ int pytalloc_Check(PyObject *obj) >-- >1.9.3 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 10028
: 10152