~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_chk_map_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-10-21 20:53:21 UTC
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091021205321-j62yud7d5lfx2za1
Revert previous change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#python2.4 support
19
19
cdef extern from "python-compat.h":
20
 
    # PyString_InternInPlace takes a **, and mutate the pointer supplied.
21
 
    # Neither Pyrex nor Cython handles that particularly well.
22
 
    # We also cannot use intern() directly, because our strings have '\x00' in
23
 
    # them, and pyrex and cython both translate intern() into
24
 
    # PyString_InternFromString(PyString_AsString()) which assumes a regular
25
 
    # null terminated C string
26
 
    # 
27
 
    void INTERN_STRING(object)
 
20
    pass
28
21
 
29
22
cdef extern from *:
30
23
    ctypedef unsigned int size_t
57
50
    Py_ssize_t PyString_GET_SIZE_ptr "PyString_GET_SIZE" (PyObject *s)
58
51
    char *PyString_AS_STRING_ptr "PyString_AS_STRING" (PyObject *s)
59
52
    object PyString_FromStringAndSize(char*, Py_ssize_t)
60
 
    void PyString_InternInPlace(PyObject **)
61
 
    int PyString_CHECK_INTERNED(object)
62
53
 
63
54
# It seems we need to import the definitions so that the pyrex compiler has
64
55
# local names to access them.
301
292
            # SET_ITEM 'steals' a reference
302
293
            Py_INCREF(entry)
303
294
            StaticTuple_SET_ITEM(entry_bits, i, entry)
304
 
        # TODO: Consider interning the value lines
305
 
        #       Often there will be many leaf nodes that only have a single
306
 
        #       line or two that is different among many (60+) lines
307
295
        value = PyString_FromStringAndSize(value_start, next_line - value_start)
308
 
        INTERN_STRING(value)
309
 
        if not PyString_CHECK_INTERNED(value):
310
 
            raise AssertionError('i asked to intern, but it didn\'t work')
311
296
        # The next entry bit needs the 'tail' from the prefix, and first part
312
297
        # of the line
313
298
        entry_start = line_start
415
400
        next_null = <char *>_my_memrchr(cur, c'\0', next_line - cur)
416
401
        if next_null == NULL:
417
402
            raise ValueError('bad no null')
418
 
        # TODO: intern item_prefix, it will almost always be redundant with all
419
 
        #       of the other internal node instances at this depth.
420
403
        item_prefix = PyString_FromStringAndSize(NULL,
421
404
            prefix_length + next_null - cur)
422
405
        c_item_prefix = PyString_AS_STRING(item_prefix)
423
406
        if prefix_length:
424
407
            memcpy(c_item_prefix, prefix, prefix_length)
425
408
        memcpy(c_item_prefix + prefix_length, cur, next_null - cur)
426
 
        c_item_prefix = NULL # Done with this
427
409
        flat_key = PyString_FromStringAndSize(next_null + 1,
428
410
                                              next_line - next_null - 1)
429
411
        flat_key = StaticTuple(flat_key).intern()
430
 
        INTERN_STRING(item_prefix)
431
 
        if not PyString_CHECK_INTERNED(item_prefix):
432
 
            raise AssertionError('i asked to intern, but it didn\'t work')
433
412
        PyDict_SetItem(items, item_prefix, flat_key)
434
413
        cur = next_line + 1
435
414
    assert len(items) > 0