List Info

Thread: Automatic Scope Macros




Automatic Scope Macros
user name
2007-04-24 10:36:13
Could we use and add this macro to object.h? It could be a
much
cleaner and safer way of dealing with new references you
want to clean
up in the same scope. The first one will make sure to decref
your new
reference when you are done with it. The second one will
make sure to
set a borrowed reference to NULL afterward, so you can't
access it
after you are done with it. The second might be useless, but
it seems
like it might be useful for debugging and being sure you
stopped using
a reference when you thought you did.

Anyone, please let me know if this is a dumb idea.

/* Obtain a New Reference and clean it up at the end of the
scope. */
#define Py_CLEANREF(_refname, _newref, _scopecode)
	(PyObject *) _refname = _newref;
	_scopecode;
	Py_XDECREF(_refname);

/* Obtain a Borrowed Reference and forget about it at the
end of the scope. */
#define Py_FORGETREF(_refname, _newref, _scopecode)
	(PyObject *) _refname = _newref;
	_scopecode;
	_refname = NULL;

-- 
Read my blog! I depend on your acceptance of my opinion! I
am interesting!
http://ironfrogg
y-code.blogspot.com/
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Automatic Scope Macros
country flaguser name
Germany
2007-04-24 15:59:35
Calvin Spealman schrieb:
> Could we use and add this macro to object.h? It could
be a much
> cleaner and safer way of dealing with new references
you want to clean
> up in the same scope. The first one will make sure to
decref your new
> reference when you are done with it. The second one
will make sure to
> set a borrowed reference to NULL afterward, so you
can't access it
> after you are done with it. The second might be
useless, but it seems
> like it might be useful for debugging and being sure
you stopped using
> a reference when you thought you did.
> 
> Anyone, please let me know if this is a dumb idea.
> 
> /* Obtain a New Reference and clean it up at the end of
the scope. */
> #define Py_CLEANREF(_refname, _newref, _scopecode)
> 	(PyObject *) _refname = _newref;
> 	_scopecode;
> 	Py_XDECREF(_refname);
> 
> /* Obtain a Borrowed Reference and forget about it at
the end of the scope. */
> #define Py_FORGETREF(_refname, _newref, _scopecode)
> 	(PyObject *) _refname = _newref;
> 	_scopecode;
> 	_refname = NULL;

In most cases, you will have error checking in _scopecode
which DECREFs the
variable and returns, or jumps to a "cleanup"
label. I can't see how this would
be possible with these macros.

Georg

_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

Re: Automatic Scope Macros
user name
2007-04-24 16:11:53
What you really want is to use C++.
However, that is a brash and immature language that is still
awaiting wider acceptance
and is therefore not supported.
K

-----Original Message-----
From: python-dev-bounces+kristjan=ccpgames.compython.org
[mailto:python-dev-bounces+kristjan=ccpgames.compython.org] On Behalf Of Georg Brandl
Sent: Tuesday, April 24, 2007 21:00
To: python-devpython.org
Subject: Re: [Python-Dev] Automatic Scope Macros

Calvin Spealman schrieb:
> Could we use and add this macro to object.h? It could
be a much
> cleaner and safer way of dealing with new references
you want to clean
> up in the same scope.

In most cases, you will have error checking in _scopecode
which DECREFs the
variable and returns, or jumps to a "cleanup"
label. I can't see how this would
be possible with these macros.


_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )