~cjwatson/storm/zope-interface-class-decorators

« back to all changes in this revision

Viewing changes to storm/cextensions.c

  • Committer: Colin Watson
  • Date: 2019-06-05 09:54:30 UTC
  • mfrom: (492.2.2 drop-pre-2.6)
  • Revision ID: cjwatson@canonical.com-20190605095430-3vx2td78sr0dkghx
Remove support for Python < 2.6. [r=adam-collard]

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <structmember.h>
25
25
 
26
26
 
27
 
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
28
 
typedef int Py_ssize_t;
29
 
#define PY_SSIZE_T_MAX INT_MAX
30
 
#define PY_SSIZE_T_MIN INT_MIN
31
 
#endif
32
 
 
33
 
 
34
27
#define CATCH(error_value, expression) \
35
28
        do { \
36
29
            if ((expression) == error_value) {\
47
40
        } while(0)
48
41
 
49
42
 
50
 
/* Python 2.4 does not include the PySet_* API, so provide a minimal
51
 
   implementation for the calls we care about. */
52
 
#if PY_VERSION_HEX < 0x02050000 && !defined(PySet_GET_SIZE)
53
 
#  define PySet_GET_SIZE(so) \
54
 
     ((PyDictObject *)((PySetObject *)so)->data)->ma_used
55
 
static PyObject *
56
 
PySet_New(PyObject *p)
57
 
{
58
 
    return PyObject_CallObject((PyObject *)&PySet_Type, NULL);
59
 
}
60
 
 
61
 
static int
62
 
PySet_Add(PyObject *set, PyObject *key)
63
 
{
64
 
    PyObject *dict;
65
 
 
66
 
    if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
67
 
        PyErr_BadInternalCall();
68
 
        return -1;
69
 
    }
70
 
    dict = ((PySetObject *)set)->data;
71
 
    return PyDict_SetItem(dict, key, Py_True);
72
 
}
73
 
 
74
 
static int
75
 
PySet_Discard(PyObject *set, PyObject *key)
76
 
{
77
 
    PyObject *dict;
78
 
    int result;
79
 
 
80
 
    if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
81
 
        PyErr_BadInternalCall();
82
 
        return -1;
83
 
    }
84
 
    dict = ((PySetObject *)set)->data;
85
 
    result = PyDict_DelItem(dict, key);
86
 
    if (result == 0) {
87
 
        /* key found and removed */
88
 
        result = 1;
89
 
    } else {
90
 
        if (PyErr_ExceptionMatches(PyExc_KeyError)) {
91
 
            /* key not found */
92
 
            PyErr_Clear();
93
 
            result = 0;
94
 
        }
95
 
    }
96
 
    return result;
97
 
}
98
 
#endif
99
 
 
100
43
static PyObject *Undef = NULL;
101
44
static PyObject *LazyValue = NULL;
102
45
static PyObject *raise_none_error = NULL;