Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 725850 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-7 / +511 lines)
Line  Link Here
0
-- a/py3c/include/py3c/capsulethunk.h
0
++ b/py3c/include/py3c/capsulethunk.h
Line 0 Link Here
0
-- a/py3c/include/py3c/comparison.h
1
/* Copyright (c) 2011, Larry Hastings
2
 * Copyright (c) 2015, py3c contributors
3
 * Licensed under the MIT license; see py3c.h
4
 *
5
 * (Note: Relicensed from PSF: http://bugs.python.org/issue24937#msg250191 )
6
 */
7
8
#ifndef __CAPSULETHUNK_H
9
#define __CAPSULETHUNK_H
10
11
#if (    (PY_VERSION_HEX <  0x02070000) \
12
     || ((PY_VERSION_HEX >= 0x03000000) \
13
      && (PY_VERSION_HEX <  0x03010000)) )
14
15
#define __PyCapsule_GetField(capsule, field, error_value) \
16
    ( PyCapsule_CheckExact(capsule) \
17
        ? (((PyCObject *)capsule)->field) \
18
        : (PyErr_SetString(PyExc_TypeError, "CObject required"), (error_value)) \
19
    ) \
20
21
#define __PyCapsule_SetField(capsule, field, value) \
22
    ( PyCapsule_CheckExact(capsule) \
23
        ? (((PyCObject *)capsule)->field = value), 0 \
24
        : (PyErr_SetString(PyExc_TypeError, "CObject required"), 1) \
25
    ) \
26
27
28
#define PyCapsule_Type PyCObject_Type
29
30
#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule))
31
#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule))
32
33
34
#define PyCapsule_New(pointer, name, destructor) \
35
    (PyCObject_FromVoidPtr(pointer, (void (*)(void*)) (destructor)))
36
37
38
#define PyCapsule_GetPointer(capsule, name) \
39
    (PyCObject_AsVoidPtr(capsule))
40
41
/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */
42
#define PyCapsule_SetPointer(capsule, pointer) \
43
    __PyCapsule_SetField(capsule, cobject, pointer)
44
45
46
#define PyCapsule_GetDestructor(capsule) \
47
    __PyCapsule_GetField(capsule, destructor, (void (*)(void*)) NULL)
48
49
#define PyCapsule_SetDestructor(capsule, dtor) \
50
    __PyCapsule_SetField(capsule, destructor, (void (*)(void*)) dtor)
51
52
53
/*
54
 * Sorry, there's simply no place
55
 * to store a Capsule "name" in a CObject.
56
 */
57
#define PyCapsule_GetName(capsule) NULL
58
59
static int
60
PyCapsule_SetName(PyObject *capsule, const char *unused)
61
{
62
    unused = unused;
63
    PyErr_SetString(PyExc_NotImplementedError,
64
        "can't use PyCapsule_SetName with CObjects");
65
    return 1;
66
}
67
68
69
70
#define PyCapsule_GetContext(capsule) \
71
    __PyCapsule_GetField(capsule, desc, (void*) NULL)
72
73
#define PyCapsule_SetContext(capsule, context) \
74
    __PyCapsule_SetField(capsule, desc, context)
75
76
77
static void *
78
PyCapsule_Import(const char *name, int no_block)
79
{
80
    PyObject *object = NULL;
81
    void *return_value = NULL;
82
    char *trace;
83
    size_t name_length = (strlen(name) + 1) * sizeof(char);
84
    char *name_dup = (char *)PyMem_MALLOC(name_length);
85
86
    if (!name_dup) {
87
        return NULL;
88
    }
89
90
    memcpy(name_dup, name, name_length);
91
92
    trace = name_dup;
93
    while (trace) {
94
        char *dot = strchr(trace, '.');
95
        if (dot) {
96
            *dot++ = '\0';
97
        }
98
99
        if (object == NULL) {
100
            if (no_block) {
101
                object = PyImport_ImportModuleNoBlock(trace);
102
            } else {
103
                object = PyImport_ImportModule(trace);
104
                if (!object) {
105
                    PyErr_Format(PyExc_ImportError,
106
                        "PyCapsule_Import could not "
107
                        "import module \"%s\"", trace);
108
                }
109
            }
110
        } else {
111
            PyObject *object2 = PyObject_GetAttrString(object, trace);
112
            Py_DECREF(object);
113
            object = object2;
114
        }
115
        if (!object) {
116
            goto EXIT;
117
        }
118
119
        trace = dot;
120
    }
121
122
    if (PyCObject_Check(object)) {
123
        PyCObject *cobject = (PyCObject *)object;
124
        return_value = cobject->cobject;
125
    } else {
126
        PyErr_Format(PyExc_AttributeError,
127
            "PyCapsule_Import \"%s\" is not valid",
128
            name);
129
    }
130
131
EXIT:
132
    Py_XDECREF(object);
133
    if (name_dup) {
134
        PyMem_FREE(name_dup);
135
    }
136
    return return_value;
137
}
138
139
#endif /* #if PY_VERSION_HEX < 0x02070000 */
140
141
#endif /* __CAPSULETHUNK_H */
142
++ b/py3c/include/py3c/comparison.h
Line 0 Link Here
0
-- a/py3c/include/py3c/compat.h
1
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
2
 * Licensed under the MIT license; see py3c.h
3
 */
4
5
#ifndef _PY3C_COMPARISON_H_
6
#define _PY3C_COMPARISON_H_
7
#include <Python.h>
8
9
/* Rich comparisons */
10
11
#ifndef Py_RETURN_NOTIMPLEMENTED
12
#define Py_RETURN_NOTIMPLEMENTED \
13
    return Py_INCREF(Py_NotImplemented), Py_NotImplemented
14
#endif
15
16
#ifndef Py_UNREACHABLE
17
#define Py_UNREACHABLE() abort()
18
#endif
19
20
#ifndef Py_RETURN_RICHCOMPARE
21
#define Py_RETURN_RICHCOMPARE(val1, val2, op)                               \
22
    do {                                                                    \
23
        switch (op) {                                                       \
24
        case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;  \
25
        case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;  \
26
        case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;   \
27
        case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;   \
28
        case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;  \
29
        case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE;  \
30
        default:                                                            \
31
            Py_UNREACHABLE();                                               \
32
        }                                                                   \
33
    } while (0)
34
#endif
35
36
#define PY3C_RICHCMP(val1, val2, op) \
37
    ((op) == Py_EQ) ? PyBool_FromLong((val1) == (val2)) : \
38
    ((op) == Py_NE) ? PyBool_FromLong((val1) != (val2)) : \
39
    ((op) == Py_LT) ? PyBool_FromLong((val1) < (val2)) : \
40
    ((op) == Py_GT) ? PyBool_FromLong((val1) > (val2)) : \
41
    ((op) == Py_LE) ? PyBool_FromLong((val1) <= (val2)) : \
42
    ((op) == Py_GE) ? PyBool_FromLong((val1) >= (val2)) : \
43
    (Py_INCREF(Py_NotImplemented), Py_NotImplemented)
44
45
#endif
46
++ b/py3c/include/py3c/compat.h
Line 0 Link Here
0
-- a/py3c/include/py3c/fileshim.h
1
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
2
 * Licensed under the MIT license; see py3c.h
3
 */
4
5
#ifndef _PY3C_COMPAT_H_
6
#define _PY3C_COMPAT_H_
7
#include <Python.h>
8
9
#if PY_MAJOR_VERSION >= 3
10
11
/***** Python 3 *****/
12
13
#define IS_PY3 1
14
15
/* Strings */
16
17
#define PyStr_Type PyUnicode_Type
18
#define PyStr_Check PyUnicode_Check
19
#define PyStr_CheckExact PyUnicode_CheckExact
20
#define PyStr_FromString PyUnicode_FromString
21
#define PyStr_FromStringAndSize PyUnicode_FromStringAndSize
22
#define PyStr_FromFormat PyUnicode_FromFormat
23
#define PyStr_FromFormatV PyUnicode_FromFormatV
24
#define PyStr_AsString PyUnicode_AsUTF8
25
#define PyStr_Concat PyUnicode_Concat
26
#define PyStr_Format PyUnicode_Format
27
#define PyStr_InternInPlace PyUnicode_InternInPlace
28
#define PyStr_InternFromString PyUnicode_InternFromString
29
#define PyStr_Decode PyUnicode_Decode
30
31
#define PyStr_AsUTF8String PyUnicode_AsUTF8String /* returns PyBytes */
32
#define PyStr_AsUTF8 PyUnicode_AsUTF8
33
#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
34
35
/* Ints */
36
37
#define PyInt_Type PyLong_Type
38
#define PyInt_Check PyLong_Check
39
#define PyInt_CheckExact PyLong_CheckExact
40
#define PyInt_FromString PyLong_FromString
41
#define PyInt_FromLong PyLong_FromLong
42
#define PyInt_FromSsize_t PyLong_FromSsize_t
43
#define PyInt_FromSize_t PyLong_FromSize_t
44
#define PyInt_AsLong PyLong_AsLong
45
#define PyInt_AS_LONG PyLong_AS_LONG
46
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
47
#define PyInt_AsSsize_t PyLong_AsSsize_t
48
49
/* Module init */
50
51
#define MODULE_INIT_FUNC(name) \
52
    PyMODINIT_FUNC PyInit_ ## name(void); \
53
    PyMODINIT_FUNC PyInit_ ## name(void)
54
55
#else
56
57
/***** Python 2 *****/
58
59
#define IS_PY3 0
60
61
/* Strings */
62
63
#define PyStr_Type PyString_Type
64
#define PyStr_Check PyString_Check
65
#define PyStr_CheckExact PyString_CheckExact
66
#define PyStr_FromString PyString_FromString
67
#define PyStr_FromStringAndSize PyString_FromStringAndSize
68
#define PyStr_FromFormat PyString_FromFormat
69
#define PyStr_FromFormatV PyString_FromFormatV
70
#define PyStr_AsString PyString_AsString
71
#define PyStr_Format PyString_Format
72
#define PyStr_InternInPlace PyString_InternInPlace
73
#define PyStr_InternFromString PyString_InternFromString
74
#define PyStr_Decode PyString_Decode
75
76
#ifdef __GNUC__
77
static PyObject *PyStr_Concat(PyObject *left, PyObject *right) __attribute__ ((unused));
78
#endif
79
static PyObject *PyStr_Concat(PyObject *left, PyObject *right) {
80
    PyObject *str = left;
81
    Py_INCREF(left);  /* reference to old left will be stolen */
82
    PyString_Concat(&str, right);
83
    if (str) {
84
        return str;
85
    } else {
86
        return NULL;
87
    }
88
}
89
90
#define PyStr_AsUTF8String(str) (Py_INCREF(str), (str))
91
#define PyStr_AsUTF8 PyString_AsString
92
#define PyStr_AsUTF8AndSize(pystr, sizeptr) \
93
    ((*sizeptr=PyString_Size(pystr)), PyString_AsString(pystr))
94
95
#define PyBytes_Type PyString_Type
96
#define PyBytes_Check PyString_Check
97
#define PyBytes_CheckExact PyString_CheckExact
98
#define PyBytes_FromString PyString_FromString
99
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
100
#define PyBytes_FromFormat PyString_FromFormat
101
#define PyBytes_FromFormatV PyString_FromFormatV
102
#define PyBytes_Size PyString_Size
103
#define PyBytes_GET_SIZE PyString_GET_SIZE
104
#define PyBytes_AsString PyString_AsString
105
#define PyBytes_AS_STRING PyString_AS_STRING
106
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
107
#define PyBytes_Concat PyString_Concat
108
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
109
#define _PyBytes_Resize _PyString_Resize
110
111
/* Floats */
112
113
#define PyFloat_FromString(str) PyFloat_FromString(str, NULL)
114
115
/* Module init */
116
117
#define PyModuleDef_HEAD_INIT 0
118
119
typedef struct PyModuleDef {
120
    int m_base;
121
    const char* m_name;
122
    const char* m_doc;
123
    Py_ssize_t m_size;
124
    PyMethodDef *m_methods;
125
} PyModuleDef;
126
127
#define PyModule_Create(def) \
128
    Py_InitModule3((def)->m_name, (def)->m_methods, (def)->m_doc)
129
130
#define MODULE_INIT_FUNC(name) \
131
    static PyObject *PyInit_ ## name(void); \
132
    PyMODINIT_FUNC init ## name(void); \
133
    PyMODINIT_FUNC init ## name(void) { PyInit_ ## name(); } \
134
    static PyObject *PyInit_ ## name(void)
135
136
137
#endif
138
139
#endif
140
++ b/py3c/include/py3c/fileshim.h
Line 0 Link Here
0
-- a/py3c/include/py3c/py3shims.h
1
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
2
 * Licensed under the MIT license; see py3c.h
3
 */
4
5
#ifndef _PY3C_FILESHIM_H_
6
#define _PY3C_FILESHIM_H_
7
#include <Python.h>
8
9
/*
10
11
For debugging purposes only.
12
Caveats:
13
 * Only works on file-like objects backed by an actual file
14
 * All C-level writes should be done before additional
15
   Python-level writes are allowed (e.g. by running Python code).
16
 * Though the function tries to flush, there is no guarantee that
17
   writes will be reordered due to different layers of buffering.
18
19
*/
20
21
static char FLUSH[] = "flush";
22
static char EMPTY_STRING[] = "";
23
24
static FILE* py3c_PyFile_AsFileWithMode(PyObject *py_file, const char *mode) {
25
    FILE *f;
26
    PyObject *ret;
27
    int fd;
28
29
    ret = PyObject_CallMethod(py_file, FLUSH, EMPTY_STRING);
30
    if (ret == NULL) {
31
        return NULL;
32
    }
33
    Py_DECREF(ret);
34
35
    fd = PyObject_AsFileDescriptor(py_file);
36
    if (fd == -1) {
37
        return NULL;
38
    }
39
40
        f = fdopen(fd, mode);
41
    if (f == NULL) {
42
        PyErr_SetFromErrno(PyExc_OSError);
43
        return NULL;
44
    }
45
46
    return f;
47
}
48
49
#endif /* _PY3C_FILESHIM_H_ */
50
++ b/py3c/include/py3c/py3shims.h
Line 0 Link Here
0
-- a/py3c/include/py3c/tpflags.h
1
/* Copyright (c) 2016, Red Hat, Inc. and/or its affiliates
2
 * Licensed under the MIT license; see py3c.h
3
 */
4
5
/*
6
 * Shims for new functionality from in Python 3.3+
7
 *
8
 * See https://docs.python.org/3/c-api/memory.html#raw-memory-interface
9
 */
10
11
#ifndef _PY3C_RAWMALLOC_H_
12
#define _PY3C_RAWMALLOC_H_
13
#include <Python.h>
14
#include <stdlib.h>
15
16
17
/* Py_UNUSED - added in Python 3.4, documneted in 3.7 */
18
19
#ifndef Py_UNUSED
20
#ifdef __GNUC__
21
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
22
#else
23
#define Py_UNUSED(name) _unused_ ## name
24
#endif
25
#endif
26
27
28
/* PyMem_Raw{Malloc,Realloc,Free} - added in Python 3.4 */
29
30
#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4)
31
#define PyMem_RawMalloc(n) malloc((n) || 1)
32
#define PyMem_RawRealloc(p, n) realloc(p, (n) || 1)
33
#define PyMem_RawFree(p) free(p)
34
#endif /* version < 3.4 */
35
36
37
/* PyMem_RawCalloc - added in Python 3.5 */
38
39
#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 5)
40
#define PyMem_RawCalloc(n, s) calloc((n) || 1, (s) || 1)
41
#endif /* version < 3.5 */
42
43
44
#endif /* _PY3C_RAWMALLOC_H_ */
45
++ b/py3c/include/py3c/tpflags.h
Line 0 Link Here
0
-- a/py3c/include/py3c.h
1
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
2
 * Licensed under the MIT license; see py3c.h
3
 */
4
5
/*
6
 * WARNING: These flags are only to be used in class definitions.
7
 *
8
 * Before including this header file, check that you do not use
9
 * these flags with with PyType_HasFeature. Example command:
10
 *      grep -r PyType_HasFeature .
11
 *
12
 * In Python 3, *all objects* have the features corresponding to removed flags.
13
 */
14
15
#ifndef _PY3C_TPFLAGS_H_
16
#define _PY3C_TPFLAGS_H_
17
#include <Python.h>
18
19
#if PY_MAJOR_VERSION >= 3
20
21
#define Py_TPFLAGS_HAVE_GETCHARBUFFER  0
22
#define Py_TPFLAGS_HAVE_SEQUENCE_IN 0
23
#define Py_TPFLAGS_HAVE_INPLACEOPS 0
24
#define Py_TPFLAGS_CHECKTYPES 0
25
#define Py_TPFLAGS_HAVE_RICHCOMPARE 0
26
#define Py_TPFLAGS_HAVE_WEAKREFS 0
27
#define Py_TPFLAGS_HAVE_ITER 0
28
#define Py_TPFLAGS_HAVE_CLASS 0
29
/* Py_TPFLAGS_HEAPTYPE is still optional in py3 */
30
/* Py_TPFLAGS_BASETYPE is still optional in py3 */
31
/* Py_TPFLAGS_READY is still useful in py3 */
32
/* Py_TPFLAGS_READYING is still useful in py3 */
33
/* Py_TPFLAGS_HAVE_GC is still optional in py3 */
34
/* Py_TPFLAGS_HAVE_STACKLESS_EXTENSION is still optional in py3 */
35
#define Py_TPFLAGS_HAVE_INDEX 0
36
/* Py_TPFLAGS_HAVE_VERSION_TAG is still optional in py3 */
37
/* Py_TPFLAGS_VALID_VERSION_TAG is still optional in py3 */
38
/* Py_TPFLAGS_IS_ABSTRACT is still optional in py3 */
39
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
40
/* Py_TPFLAGS_INT_SUBCLASS is still optional in py3 */
41
/* Py_TPFLAGS_LONG_SUBCLASS is still optional in py3 */
42
/* Py_TPFLAGS_LIST_SUBCLASS is still optional in py3 */
43
/* Py_TPFLAGS_TUPLE_SUBCLASS is still optional in py3 */
44
/* Py_TPFLAGS_STRING_SUBCLASS is still optional in py3 */
45
/* Py_TPFLAGS_UNICODE_SUBCLASS is still optional in py3 */
46
/* Py_TPFLAGS_DICT_SUBCLASS is still optional in py3 */
47
/* Py_TPFLAGS_BASE_EXC_SUBCLASS is still optional in py3 */
48
/* Py_TPFLAGS_TYPE_SUBCLASS is still optional in py3 */
49
50
/* py 3.4 adds Py_TPFLAGS_HAVE_FINALIZE */
51
#endif
52
#endif /* _PY3C_TPFLAGS_H_ */
53
++ b/py3c/include/py3c.h
Line 0 Link Here
1
/*
2
The MIT License (MIT)
3
4
Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
25
#ifndef _PY3COMPAT_H_
26
#define _PY3COMPAT_H_
27
28
#include <Python.h>
29
30
#include <py3c/comparison.h>
31
#include <py3c/compat.h>
32
#include <py3c/py3shims.h>
33
34
#endif

Return to bug 725850