[PATCH 10 of 10] extensions: devel-warn ui object escaping from ui/extsetup

Yuya Nishihara yuya at tcha.org
Sun Jul 3 00:53:28 EDT 2016


On Thu, 30 Jun 2016 17:59:05 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1467296787 -3600
> #      Thu Jun 30 15:26:27 2016 +0100
> # Node ID caf11c2daf24c7f94a506acb440e80ea37898870
> # Parent  7c2dc6643d1c37dbc388ce4ac7112341f0926f28
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r caf11c2daf24
> extensions: devel-warn ui object escaping from ui/extsetup

> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -7,8 +7,10 @@
>  
>  from __future__ import absolute_import
>  
> +import contextlib
>  import imp
>  import os
> +import sys
>  
>  from .i18n import (
>      _,
> @@ -127,20 +129,31 @@ def load(ui, name, path):
>          fn(loaded=True)
>      return mod
>  
> + at contextlib.contextmanager
> +def _checkuiescape(name, ui):
> +    nref = sys.getrefcount(ui)
> +    yield
> +    nrefchange = sys.getrefcount(ui) - nref
> +    if nrefchange > 0 and (ui.configbool('devel', 'all-warnings')
> +                           or ui.configbool('devel', 'check-uiescape')):
> +        ui.develwarn('"ui" escaped from %s' % name, stacklevel=None)

I'm sure this won't work on PyPy.

Can you make a separate series of the refcount patches? Reviewing them will
require expertise about CPython.


More information about the Mercurial-devel mailing list