Outparamdel: Difference between revisions
No edit summary |
(added general disc) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
[http://blog.mozilla.com/tglek/2007/08/06/outparams-take-2/ Blog entry]. | Once FF is using [[exceptions]], <code>nsresult</code> methods become <code>void</code>-returning methods. Thus, methods with an "outparam" (more formally, a pointer-typed argument designated for passing a result out of the called method) will be able to place their result directly in the return value. This will make life easier for programmers and may save a few processor cycles. | ||
This page describes the '''outparamdel''' refactoring tool. It hasn't been used yet because it can't really be done before exceptions. (Many getter methods always succeed, so we could technically apply outparamdel without exceptions, but it's risky because it assumes (a) the method will never be changed so that it can fail, and (b) the method isn't implemented in JavaScript. Neither assumption is safe.) | |||
See also [http://blog.mozilla.com/tglek/2007/08/06/outparams-take-2/ Blog entry]. | |||
Line 11: | Line 15: | ||
* Run outparamdel | * Run outparamdel | ||
../../pork-barrel/pork-barrel 4 /tmp/list.txt ./outparamdel -od-list /tmp/outparams > outparams.diff 2> /tmp/outparams.err | ../../pork-barrel/pork-barrel 4 /tmp/list.txt ./outparamdel -od-list /tmp/outparams > outparams.diff 2> /tmp/outparams.err | ||
* apply patch and enjoy | |||
sed 's/.home.tglek.work.actionmonkey.//' /tmp/outparams.diff |patch -p0 | |||
* outparamdel produces various diagnostics during processing, those can be grep + seded to produce something like egrep -v 'ParseCFHTML|GetHostName|GetChildNodes|GetNextSibling|GetOffsetParent|GetParentNode|GetPreviousSibling' and used in the above xargs pipeline | |||
==TODO== | ==TODO== | ||
===Manual Mozilla changes=== | ===Manual Mozilla changes=== |
Latest revision as of 22:48, 17 January 2008
Once FF is using exceptions, nsresult
methods become void
-returning methods. Thus, methods with an "outparam" (more formally, a pointer-typed argument designated for passing a result out of the called method) will be able to place their result directly in the return value. This will make life easier for programmers and may save a few processor cycles.
This page describes the outparamdel refactoring tool. It hasn't been used yet because it can't really be done before exceptions. (Many getter methods always succeed, so we could technically apply outparamdel without exceptions, but it's risky because it assumes (a) the method will never be changed so that it can fail, and (b) the method isn't implemented in JavaScript. Neither assumption is safe.)
See also Blog entry.
Running Outparamdel
- Produce a list of files to run
find ~/work/ff-build/ -name \*.ii
- Optional: produce a list of outparams to rewrite. Can use dehydra to detect them
../../pork-barrel/pork-barrel --save-output .outparamdel 4 /tmp/list.txt ./dehydra -dehydra-javascript dehydra_scripts/outparams.js 2> /tmp/outparams.err find ~/work/ff-build/ -name \*.outparamdel|xargs cat|sort|uniq |grep OUTPARAMS:|sed 's/OUTPARAMS://' > /tmp/outparams
- Run outparamdel
../../pork-barrel/pork-barrel 4 /tmp/list.txt ./outparamdel -od-list /tmp/outparams > outparams.diff 2> /tmp/outparams.err
- apply patch and enjoy
sed 's/.home.tglek.work.actionmonkey.//' /tmp/outparams.diff |patch -p0
- outparamdel produces various diagnostics during processing, those can be grep + seded to produce something like egrep -v 'ParseCFHTML|GetHostName|GetChildNodes|GetNextSibling|GetOffsetParent|GetParentNode|GetPreviousSibling' and used in the above xargs pipeline
TODO
Manual Mozilla changes
- Convert NS_ERROR errors to constants
Automatically Detect Outparam Candidates (dehydra_scripts/outparams.js)
- Process function body ensuring that only errors codes can be returned. NS_OK + some error
- Then check the class hierarchy if this is the only implementation of the method
- Use class hierarchy to start rewriting at the oldest virtual method that target method overloads
- Ensure that the virtual method isn't originally defined by XPIDL
- Ensure that all overloads of this method will be rewritten (can't change return value otherwise)
Near Future
- Write an optimizer for ?: caller rewrites
- Need a macro to annotate getters where assigning NULL to the outparam has a special meaning. ie nsresult getterFunc(NOT_NULL(nsISupports **outval))