##// 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
undumprevlog
49 lines | 1.2 KiB | text/plain | TextLexer
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 #!/usr/bin/env python
# Undump a dump from dumprevlog
# $ hg init
# $ undumprevlog < repo.dump
Augie Fackler
undumprevlog: update to valid Python 3 syntax...
r33874 from __future__ import absolute_import, print_function
Pulkit Goyal
py3: make contrib/undumprevlog use absolute_import
r29167
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 import sys
Pulkit Goyal
py3: make contrib/undumprevlog use absolute_import
r29167 from mercurial import (
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 encoding,
Pulkit Goyal
py3: make contrib/undumprevlog use absolute_import
r29167 node,
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 pycompat,
Pulkit Goyal
py3: make contrib/undumprevlog use absolute_import
r29167 revlog,
transaction,
Pierre-Yves David
vfs: use 'vfs' module directly in 'contrib/undumprevlog'...
r31248 vfs as vfsmod,
Pulkit Goyal
py3: make contrib/undumprevlog use absolute_import
r29167 )
Gregory Szorc
black: blacken scripts...
r44058 from mercurial.utils import procutil
Matt Mackall
add simple dump and undump scripts to contrib/
r6433
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)
Adrian Buehlmann
contrib: fix binary file issues with dumprevlog on Windows...
r6466
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 opener = vfsmod.vfs(b'.', False)
Gregory Szorc
black: blacken scripts...
r44058 tr = transaction.transaction(
sys.stderr.write, opener, {b'store': opener}, b"undump.journal"
)
Mads Kiilerich
tests: run check-code on Python files without .py extension
r19022 while True:
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 l = sys.stdin.readline()
if not l:
break
if l.startswith("file:"):
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 f = encoding.strtolocal(l[6:-1])
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 r = revlog.revlog(opener, f)
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 pycompat.stdout.write(b'%s\n' % f)
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 elif l.startswith("node:"):
n = node.bin(l[6:-1])
elif l.startswith("linkrev:"):
lr = int(l[9:-1])
elif l.startswith("parents:"):
p = l[9:-1].split()
p1 = node.bin(p[0])
p2 = node.bin(p[1])
elif l.startswith("length:"):
length = int(l[8:-1])
Gregory Szorc
black: blacken scripts...
r44058 sys.stdin.readline() # start marker
Matt Harbison
py3: byteify contrib/dumprevlog
r39983 d = encoding.strtolocal(sys.stdin.read(length))
Gregory Szorc
black: blacken scripts...
r44058 sys.stdin.readline() # end marker
Matt Mackall
add simple dump and undump scripts to contrib/
r6433 r.addrevision(d, tr, lr, p1, p2)
tr.close()