Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/talloc/pytalloc.c

    r740 r988  
    22   Unix SMB/CIFS implementation.
    33   Python Talloc Module
    4    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
     4   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010-2011
    55
    66   This program is free software; you can redistribute it and/or modify
     
    2121#include <talloc.h>
    2222#include <pytalloc.h>
    23 
    24 void inittalloc(void);
     23#include "pytalloc_private.h"
     24
     25static PyTypeObject TallocObject_Type;
     26
     27#if PY_MAJOR_VERSION >= 3
     28#define PyStr_FromFormat PyUnicode_FromFormat
     29#else
     30#define PyStr_FromFormat PyString_FromFormat
     31#endif
    2532
    2633/* print a talloc tree report for a talloc python object */
    27 static PyObject *py_talloc_report_full(PyObject *self, PyObject *args)
     34static PyObject *pytalloc_report_full(PyObject *self, PyObject *args)
    2835{
    2936        PyObject *py_obj = Py_None;
    30         PyTypeObject *type;
    3137
    3238        if (!PyArg_ParseTuple(args, "|O", &py_obj))
     
    3642                talloc_report_full(NULL, stdout);
    3743        } else {
    38                 type = (PyTypeObject*)PyObject_Type(py_obj);
    39                 talloc_report_full(py_talloc_get_mem_ctx(py_obj), stdout);
     44                talloc_report_full(pytalloc_get_mem_ctx(py_obj), stdout);
    4045        }
    4146        return Py_None;
     
    4348
    4449/* enable null tracking */
    45 static PyObject *py_talloc_enable_null_tracking(PyObject *self)
     50static PyObject *pytalloc_enable_null_tracking(PyObject *self)
    4651{
    4752        talloc_enable_null_tracking();
     
    5055
    5156/* return the number of talloc blocks */
    52 static PyObject *py_talloc_total_blocks(PyObject *self, PyObject *args)
     57static PyObject *pytalloc_total_blocks(PyObject *self, PyObject *args)
    5358{
    5459        PyObject *py_obj = Py_None;
    55         PyTypeObject *type;
    5660
    5761        if (!PyArg_ParseTuple(args, "|O", &py_obj))
     
    6266        }
    6367
    64         type = (PyTypeObject*)PyObject_Type(py_obj);
    65 
    66         return PyLong_FromLong(talloc_total_blocks(py_talloc_get_mem_ctx(py_obj)));
     68        return PyLong_FromLong(talloc_total_blocks(pytalloc_get_mem_ctx(py_obj)));
    6769}
    6870
    6971static PyMethodDef talloc_methods[] = {
    70         { "report_full", (PyCFunction)py_talloc_report_full, METH_VARARGS,
     72        { "report_full", (PyCFunction)pytalloc_report_full, METH_VARARGS,
    7173                "show a talloc tree for an object"},
    72         { "enable_null_tracking", (PyCFunction)py_talloc_enable_null_tracking, METH_NOARGS,
     74        { "enable_null_tracking", (PyCFunction)pytalloc_enable_null_tracking, METH_NOARGS,
    7375                "enable tracking of the NULL object"},
    74         { "total_blocks", (PyCFunction)py_talloc_total_blocks, METH_VARARGS,
     76        { "total_blocks", (PyCFunction)pytalloc_total_blocks, METH_VARARGS,
    7577                "return talloc block count"},
    7678        { NULL }
     
    8082 * Default (but only slightly more useful than the default) implementation of Repr().
    8183 */
    82 static PyObject *py_talloc_default_repr(PyObject *obj)
    83 {
    84         py_talloc_Object *talloc_obj = (py_talloc_Object *)obj;
     84static PyObject *pytalloc_default_repr(PyObject *obj)
     85{
     86        pytalloc_Object *talloc_obj = (pytalloc_Object *)obj;
    8587        PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
    8688
    87         return PyString_FromFormat("<%s talloc object at 0x%p>",
    88                                    type->tp_name, talloc_obj->ptr);
     89        return PyStr_FromFormat("<%s talloc object at 0x%p>",
     90                                type->tp_name, talloc_obj->ptr);
    8991}
    9092
     
    9294 * Simple dealloc for talloc-wrapping PyObjects
    9395 */
    94 static void py_talloc_dealloc(PyObject* self)
    95 {
    96         py_talloc_Object *obj = (py_talloc_Object *)self;
     96static void pytalloc_dealloc(PyObject* self)
     97{
     98        pytalloc_Object *obj = (pytalloc_Object *)self;
    9799        assert(talloc_unlink(NULL, obj->talloc_ctx) != -1);
    98100        obj->talloc_ctx = NULL;
     
    103105 * Default (but only slightly more useful than the default) implementation of cmp.
    104106 */
    105 static int py_talloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
    106 {
    107         py_talloc_Object *obj1 = (py_talloc_Object *)_obj1,
    108                                          *obj2 = (py_talloc_Object *)_obj2;
     107#if PY_MAJOR_VERSION >= 3
     108static PyObject *pytalloc_default_richcmp(PyObject *obj1, PyObject *obj2, int op)
     109{
     110        void *ptr1;
     111        void *ptr2;
     112        if (Py_TYPE(obj1) == Py_TYPE(obj2)) {
     113                /* When types match, compare pointers */
     114                ptr1 = pytalloc_get_ptr(obj1);
     115                ptr2 = pytalloc_get_ptr(obj2);
     116        } else if (PyObject_TypeCheck(obj2, &TallocObject_Type)) {
     117                /* Otherwise, compare types */
     118                ptr1 = Py_TYPE(obj1);
     119                ptr2 = Py_TYPE(obj2);
     120        } else {
     121                Py_INCREF(Py_NotImplemented);
     122                return Py_NotImplemented;
     123        }
     124        switch (op) {
     125                case Py_EQ: return PyBool_FromLong(ptr1 == ptr2);
     126                case Py_NE: return PyBool_FromLong(ptr1 != ptr2);
     127                case Py_LT: return PyBool_FromLong(ptr1 < ptr2);
     128                case Py_GT: return PyBool_FromLong(ptr1 > ptr2);
     129                case Py_LE: return PyBool_FromLong(ptr1 <= ptr2);
     130                case Py_GE: return PyBool_FromLong(ptr1 >= ptr2);
     131        }
     132        Py_INCREF(Py_NotImplemented);
     133        return Py_NotImplemented;
     134}
     135#else
     136static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
     137{
     138        pytalloc_Object *obj1 = (pytalloc_Object *)_obj1,
     139                                         *obj2 = (pytalloc_Object *)_obj2;
    109140        if (obj1->ob_type != obj2->ob_type)
    110                 return (obj1->ob_type - obj2->ob_type);
    111 
    112         return ((char *)py_talloc_get_ptr(obj1) - (char *)py_talloc_get_ptr(obj2));
    113 }
     141                return ((char *)obj1->ob_type - (char *)obj2->ob_type);
     142
     143        return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2));
     144}
     145#endif
    114146
    115147static PyTypeObject TallocObject_Type = {
    116148        .tp_name = "talloc.Object",
    117149        .tp_doc = "Python wrapper for a talloc-maintained object.",
    118         .tp_basicsize = sizeof(py_talloc_Object),
    119         .tp_dealloc = (destructor)py_talloc_dealloc,
     150        .tp_basicsize = sizeof(pytalloc_Object),
     151        .tp_dealloc = (destructor)pytalloc_dealloc,
    120152        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
    121         .tp_repr = py_talloc_default_repr,
    122         .tp_compare = py_talloc_default_cmp,
    123 };
    124 
    125 void inittalloc(void)
     153        .tp_repr = pytalloc_default_repr,
     154#if PY_MAJOR_VERSION >= 3
     155        .tp_richcompare = pytalloc_default_richcmp,
     156#else
     157        .tp_compare = pytalloc_default_cmp,
     158#endif
     159};
     160
     161/**
     162 * Default (but only slightly more useful than the default) implementation of Repr().
     163 */
     164static PyObject *pytalloc_base_default_repr(PyObject *obj)
     165{
     166        pytalloc_BaseObject *talloc_obj = (pytalloc_BaseObject *)obj;
     167        PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
     168
     169        return PyStr_FromFormat("<%s talloc based object at 0x%p>",
     170                                type->tp_name, talloc_obj->ptr);
     171}
     172
     173/**
     174 * Simple dealloc for talloc-wrapping PyObjects
     175 */
     176static void pytalloc_base_dealloc(PyObject* self)
     177{
     178        pytalloc_BaseObject *obj = (pytalloc_BaseObject *)self;
     179        assert(talloc_unlink(NULL, obj->talloc_ctx) != -1);
     180        obj->talloc_ctx = NULL;
     181        self->ob_type->tp_free(self);
     182}
     183
     184/**
     185 * Default (but only slightly more useful than the default) implementation of cmp.
     186 */
     187#if PY_MAJOR_VERSION >= 3
     188static PyObject *pytalloc_base_default_richcmp(PyObject *obj1, PyObject *obj2, int op)
     189{
     190        void *ptr1;
     191        void *ptr2;
     192        if (Py_TYPE(obj1) == Py_TYPE(obj2)) {
     193                /* When types match, compare pointers */
     194                ptr1 = pytalloc_get_ptr(obj1);
     195                ptr2 = pytalloc_get_ptr(obj2);
     196        } else if (PyObject_TypeCheck(obj2, &TallocObject_Type)) {
     197                /* Otherwise, compare types */
     198                ptr1 = Py_TYPE(obj1);
     199                ptr2 = Py_TYPE(obj2);
     200        } else {
     201                Py_INCREF(Py_NotImplemented);
     202                return Py_NotImplemented;
     203        }
     204        switch (op) {
     205                case Py_EQ: return PyBool_FromLong(ptr1 == ptr2);
     206                case Py_NE: return PyBool_FromLong(ptr1 != ptr2);
     207                case Py_LT: return PyBool_FromLong(ptr1 < ptr2);
     208                case Py_GT: return PyBool_FromLong(ptr1 > ptr2);
     209                case Py_LE: return PyBool_FromLong(ptr1 <= ptr2);
     210                case Py_GE: return PyBool_FromLong(ptr1 >= ptr2);
     211        }
     212        Py_INCREF(Py_NotImplemented);
     213        return Py_NotImplemented;
     214}
     215#else
     216static int pytalloc_base_default_cmp(PyObject *_obj1, PyObject *_obj2)
     217{
     218        pytalloc_BaseObject *obj1 = (pytalloc_BaseObject *)_obj1,
     219                                         *obj2 = (pytalloc_BaseObject *)_obj2;
     220        if (obj1->ob_type != obj2->ob_type)
     221                return ((char *)obj1->ob_type - (char *)obj2->ob_type);
     222
     223        return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2));
     224}
     225#endif
     226
     227static PyTypeObject TallocBaseObject_Type = {
     228        .tp_name = "talloc.BaseObject",
     229        .tp_doc = "Python wrapper for a talloc-maintained object.",
     230        .tp_basicsize = sizeof(pytalloc_BaseObject),
     231        .tp_dealloc = (destructor)pytalloc_base_dealloc,
     232        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
     233        .tp_repr = pytalloc_base_default_repr,
     234#if PY_MAJOR_VERSION >= 3
     235        .tp_richcompare = pytalloc_base_default_richcmp,
     236#else
     237        .tp_compare = pytalloc_base_default_cmp,
     238#endif
     239};
     240
     241#define MODULE_DOC PyDoc_STR("Python wrapping of talloc-maintained objects.")
     242
     243#if PY_MAJOR_VERSION >= 3
     244static struct PyModuleDef moduledef = {
     245    PyModuleDef_HEAD_INIT,
     246    .m_name = "talloc",
     247    .m_doc = MODULE_DOC,
     248    .m_size = -1,
     249    .m_methods = talloc_methods,
     250};
     251#endif
     252
     253static PyObject *module_init(void);
     254static PyObject *module_init(void)
    126255{
    127256        PyObject *m;
    128257
    129258        if (PyType_Ready(&TallocObject_Type) < 0)
    130                 return;
    131 
    132         m = Py_InitModule3("talloc", talloc_methods,
    133                                            "Python wrapping of talloc-maintained objects.");
     259                return NULL;
     260
     261        if (PyType_Ready(&TallocBaseObject_Type) < 0)
     262                return NULL;
     263
     264#if PY_MAJOR_VERSION >= 3
     265        m = PyModule_Create(&moduledef);
     266#else
     267        m = Py_InitModule3("talloc", talloc_methods, MODULE_DOC);
     268#endif
    134269        if (m == NULL)
    135                 return;
     270                return NULL;
    136271
    137272        Py_INCREF(&TallocObject_Type);
    138273        PyModule_AddObject(m, "Object", (PyObject *)&TallocObject_Type);
    139 }
     274        Py_INCREF(&TallocBaseObject_Type);
     275        PyModule_AddObject(m, "BaseObject", (PyObject *)&TallocBaseObject_Type);
     276        return m;
     277}
     278
     279#if PY_MAJOR_VERSION >= 3
     280PyMODINIT_FUNC PyInit_talloc(void);
     281PyMODINIT_FUNC PyInit_talloc(void)
     282{
     283        return module_init();
     284}
     285#else
     286void inittalloc(void);
     287void inittalloc(void)
     288{
     289        module_init();
     290}
     291#endif
Note: See TracChangeset for help on using the changeset viewer.