35
35
Py_ssize_t PyTuple_GET_SIZE(object t)
36
36
int PyString_CheckExact(object)
37
37
char *PyString_AS_STRING(object s)
38
PyObject *PyString_FromStringAndSize_ptr "PyString_FromStringAndSize" (char *, Py_ssize_t)
38
39
Py_ssize_t PyString_GET_SIZE(object)
40
void PyString_InternInPlace(PyObject **)
39
41
unsigned long PyInt_AsUnsignedLongMask(object) except? -1
41
43
int PyDict_SetItem(object d, object k, object v) except -1
99
cdef object safe_interned_string_from_size(char *s, Py_ssize_t size):
100
cdef PyObject *py_str
102
raise AssertionError(
103
'tried to create a string with an invalid size: %d @0x%x'
105
py_str = PyString_FromStringAndSize_ptr(s, size)
106
PyString_InternInPlace(&py_str)
107
result = <object>py_str
108
# Casting a PyObject* to an <object> triggers an INCREF from Pyrex, so we
109
# DECREF it to avoid geting immortal strings
110
Py_DECREF_ptr(py_str)
96
114
def _search_key_16(key):
97
115
"""See chk_map._search_key_16."""
98
116
cdef Py_ssize_t num_bits
395
413
result._node_width = len(item_prefix)
396
414
result._search_prefix = PyString_FromStringAndSize(prefix, prefix_length)
418
def _bytes_to_text_key(bytes):
419
"""Take a CHKInventory value string and return a (file_id, rev_id) tuple"""
421
cdef char *byte_str, *cur_end, *file_id_str, *byte_end
422
cdef char *revision_str
423
cdef Py_ssize_t byte_size, pos, file_id_len
425
if not PyString_CheckExact(bytes):
426
raise TypeError('bytes must be a string')
427
byte_str = PyString_AS_STRING(bytes)
428
byte_size = PyString_GET_SIZE(bytes)
429
byte_end = byte_str + byte_size
430
cur_end = <char*>memchr(byte_str, c':', byte_size)
432
raise ValueError('No kind section found.')
433
if cur_end[1] != ' ':
434
raise ValueError('Kind section should end with ": "')
435
file_id_str = cur_end + 2
436
# file_id is now the data up until the next newline
437
cur_end = <char*>memchr(file_id_str, c'\n', byte_end - file_id_str)
439
raise ValueError('no newline after file-id')
440
file_id = safe_interned_string_from_size(file_id_str,
441
cur_end - file_id_str)
442
# this is the end of the parent_str
443
cur_end = <char*>memchr(cur_end + 1, c'\n', byte_end - cur_end - 1)
445
raise ValueError('no newline after parent_str')
446
# end of the name str
447
cur_end = <char*>memchr(cur_end + 1, c'\n', byte_end - cur_end - 1)
449
raise ValueError('no newline after name str')
450
# the next section is the revision info
451
revision_str = cur_end + 1
452
cur_end = <char*>memchr(cur_end + 1, c'\n', byte_end - cur_end - 1)
454
# This is probably a dir: entry, which has revision as the last item
456
revision = safe_interned_string_from_size(revision_str,
457
cur_end - revision_str)
458
key = StaticTuple_New(2)
460
StaticTuple_SET_ITEM(key, 0, file_id)
462
StaticTuple_SET_ITEM(key, 1, revision)
463
return StaticTuple_Intern(key)