##// END OF EJS Templates
rust-cpython: mark all PyLeaked methods as unsafe...
rust-cpython: mark all PyLeaked methods as unsafe Unfortunately, these methods can be abused to obtain the inner 'static reference. The simplest (pseudo-code) example is: let leaked: PyLeaked<&'static _> = shared.leak_immutable(); let static_ref: &'static _ = &*leaked.try_borrow(py)?; // PyLeakedRef::deref() tries to bound the lifetime to itself, but // the underlying data is a &'static reference, so the returned // reference can be &'static. This problem can be easily fixed by coercing the lifetime, but there are many other ways to achieve that, and there wouldn't be a generic solution: let leaked: PyLeaked<&'static [_]> = shared.leak_immutable(); let leaked_iter: PyLeaked<slice::Iter<'static, _>> = unsafe { leaked.map(|v| v.iter()) }; let static_slice: &'static [_] = leaked_iter.try_borrow(py)?.as_slice(); So basically I failed to design the safe borrowing interface. Maybe we'll instead have to add much more restricted interface on top of the unsafe PyLeaked methods? For instance, Iterator::next() could be implemented if its Item type is not &'a (where 'a may be cheated.) Anyway, this seems not an easy issue, so it's probably better to leave the current interface as unsafe, and get broader comments while upstreaming this feature.

File last commit:

r44058:99e231af default
r44689:e960c30d default
Show More
dumprevlog
47 lines | 1.1 KiB | text/plain | TextLexer
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 #!/usr/bin/env python
# Dump revlogs as raw data stream
# $ find .hg/store/ -name "*.i" | xargs dumprevlog > repo.dump
Pulkit Goyal
py3: make contrib/dumprevlog use print_function
r29166 from __future__ import absolute_import, print_function
Pulkit Goyal
py3: make contrib/dumprevlog use absolute_import
r29165
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 import sys
Pulkit Goyal
py3: make contrib/dumprevlog use absolute_import
r29165 from mercurial import (
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 encoding,
Pulkit Goyal
py3: make contrib/dumprevlog use absolute_import
r29165 node,
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 pycompat,
Pulkit Goyal
py3: make contrib/dumprevlog use absolute_import
r29165 revlog,
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 )
Gregory Szorc
black: blacken scripts...
r44058 from mercurial.utils import procutil
Adrian Buehlmann
contrib: fix binary file issues with dumprevlog on Windows...
r6466
for fp in (sys.stdin, sys.stdout, sys.stderr):
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 procutil.setbinary(fp)
Matt Mackall
add simple dump and undump scripts to contrib/
r6433
Gregory Szorc
black: blacken scripts...
r44058
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 def binopen(path, mode=b'rb'):
if b'b' not in mode:
mode = mode + b'b'
return open(path, pycompat.sysstr(mode))
Gregory Szorc
black: blacken scripts...
r44058
vfs: give all vfs an options attribute by default...
r43295 binopen.options = {}
Matt Harbison
py3: byteify contrib/dumprevlog
r39983
Gregory Szorc
black: blacken scripts...
r44058
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 def printb(data, end=b'\n'):
sys.stdout.flush()
pycompat.stdout.write(data + end)
Boris Feld
dumprevlog: handle being passed a mode parameter...
r35982
Gregory Szorc
black: blacken scripts...
r44058
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 for f in sys.argv[1:]:
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 r = revlog.revlog(binopen, encoding.strtolocal(f))
Pulkit Goyal
py3: make contrib/dumprevlog use print_function
r29166 print("file:", f)
Matt Mackall
add __len__ and __iter__ methods to repo and revlog
r6750 for i in r:
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 n = r.node(i)
p = r.parents(n)
d = r.revision(n)
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 printb(b"node: %s" % node.hex(n))
printb(b"linkrev: %d" % r.linkrev(i))
printb(b"parents: %s %s" % (node.hex(p[0]), node.hex(p[1])))
printb(b"length: %d" % len(d))
printb(b"-start-")
printb(d)
printb(b"-end-")