/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_c.h

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2009 Canonical Ltd
2
 
 * 
3
 
 * This program is free software; you can redistribute it and/or modify
4
 
 * it under the terms of the GNU General Public License as published by
5
 
 * the Free Software Foundation; either version 2 of the License, or
6
 
 * (at your option) any later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program; if not, write to the Free Software
15
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 */
17
 
 
18
 
#ifndef _STATIC_TUPLE_H_
19
 
#define _STATIC_TUPLE_H_
20
 
#include <Python.h>
21
 
#include <string.h>
22
 
 
23
 
#define STATIC_TUPLE_HAS_HASH 0
24
 
/* Caching the hash adds memory, but allows us to save a little time during
25
 
 * lookups. TIMEIT hash(key) shows it as
26
 
 *  0.108usec w/ hash
27
 
 *  0.160usec w/o hash
28
 
 * Note that the entries themselves are strings, which already cache their
29
 
 * hashes. So while there is a 1.5:1 difference in the time for hash(), it is
30
 
 * already a function which is quite fast. Probably the only reason we might
31
 
 * want to do so, is if we customized SimpleSet to the point that the item
32
 
 * pointers were exactly certain types, and then accessed table[i]->hash
33
 
 * directly. So far StaticTuple_hash() is fast enough to not warrant the memory
34
 
 * difference.
35
 
 */
36
 
 
37
 
/* This defines a single variable-width key.
38
 
 * It is basically the same as a tuple, but
39
 
 * 1) Lighter weight in memory
40
 
 * 2) Only supports strings or other static types (that don't reference other
41
 
 *    objects.)
42
 
 */
43
 
 
44
 
#define STATIC_TUPLE_INTERNED_FLAG 0x01
45
 
typedef struct {
46
 
    PyObject_HEAD
47
 
    // We could go with unsigned short here, and support 64k width tuples
48
 
    // without any memory impact, might be worthwhile
49
 
    unsigned char size;
50
 
    unsigned char flags;
51
 
    unsigned char _unused0;
52
 
    unsigned char _unused1;
53
 
    // Note that on 64-bit, we actually have 4-more unused bytes
54
 
    // because items will always be aligned to a 64-bit boundary
55
 
#if STATIC_TUPLE_HAS_HASH
56
 
    long hash;
57
 
#endif
58
 
    PyObject *items[0];
59
 
} StaticTuple;
60
 
extern PyTypeObject StaticTuple_Type;
61
 
 
62
 
typedef struct {
63
 
    PyObject_VAR_HEAD
64
 
    PyObject *table[0];
65
 
} KeyIntern;
66
 
 
67
 
#define StaticTuple_SET_ITEM(key, offset, val) \
68
 
    ((((StaticTuple*)(key))->items[(offset)]) = ((PyObject *)(val)))
69
 
#define StaticTuple_GET_ITEM(key, offset) (((StaticTuple*)key)->items[offset])
70
 
 
71
 
 
72
 
#ifdef STATIC_TUPLE_MODULE
73
 
/* Used when compiling _static_tuple_c.c */
74
 
 
75
 
static StaticTuple * StaticTuple_New(Py_ssize_t);
76
 
static StaticTuple * StaticTuple_Intern(StaticTuple *self);
77
 
static StaticTuple * StaticTuple_FromSequence(PyObject *);
78
 
#define StaticTuple_CheckExact(op) (Py_TYPE(op) == &StaticTuple_Type)
79
 
 
80
 
#else
81
 
/* Used as the foreign api */
82
 
 
83
 
#include "_import_c_api.h"
84
 
 
85
 
static StaticTuple *(*StaticTuple_New)(Py_ssize_t);
86
 
static StaticTuple *(*StaticTuple_Intern)(StaticTuple *);
87
 
static StaticTuple *(*StaticTuple_FromSequence)(PyObject *);
88
 
static PyTypeObject *_p_StaticTuple_Type;
89
 
 
90
 
#define StaticTuple_CheckExact(op) (Py_TYPE(op) == _p_StaticTuple_Type)
91
 
static int (*_StaticTuple_CheckExact)(PyObject *);
92
 
 
93
 
 
94
 
/* Return -1 and set exception on error, 0 on success */
95
 
static int
96
 
import_static_tuple_c(void)
97
 
{
98
 
    struct function_description functions[] = {
99
 
        {"StaticTuple_New", (void **)&StaticTuple_New,
100
 
            "StaticTuple *(Py_ssize_t)"},
101
 
        {"StaticTuple_Intern", (void **)&StaticTuple_Intern,
102
 
            "StaticTuple *(StaticTuple *)"},
103
 
        {"StaticTuple_FromSequence", (void **)&StaticTuple_FromSequence,
104
 
            "StaticTuple *(PyObject *)"},
105
 
        {"_StaticTuple_CheckExact", (void **)&_StaticTuple_CheckExact,
106
 
            "int(PyObject *)"},
107
 
        {NULL}};
108
 
    struct type_description types[] = {
109
 
        {"StaticTuple", &_p_StaticTuple_Type},
110
 
        {NULL}};
111
 
    return _import_extension_module("bzrlib._static_tuple_c",
112
 
        functions, types);
113
 
}
114
 
 
115
 
#endif // !STATIC_TUPLE_MODULE
116
 
#endif // !_STATIC_TUPLE_H_