[Freeciv-Dev] (PR#6933) Don't skip the iterate_end macros
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6933 >
For a new implementation of the genlists it is very nice if each
genlists knows it is is inside an iterate. This can be done by doing a
counter++ at the start of the iterate and a counter-- at the end.
If the body of the iterate however contains a goto or return statement
the _iterate_end macro isn't executed and the counter is wrong. The
idea here is to forbid such behavior.
The attached script tries to find such places. Run it like
$ find . -name "*.c" | xargs -n 1 python balanced_iterate.py
It finds 96 instances.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"I do feel kind of sorry for Microsoft. Their attornies and marketing
force must have tons of ulcers trying to figure out how to beat (not
just co-exist with) a product that has no clearly defined (read
suable) human owner, and that changes on an hourly basis like the
sea changes the layout of the sand on a beach. Severely tough to
fight something like that."
-- David D.W. Downey at linux-kernel
import sys,re
file=sys.argv[1]
lines=open(file).readlines()
stack=[]
for no in range(len(lines)):
line=lines[no]
mo=re.search("^\s*([a-z_]*)_list_iterate\s*\\(.*$",line)
if mo:
stack.append(mo.group(1))
mo=re.search("^\s*}?\s*([a-z_]*)_list_iterate_end.*$",line)
if mo:
if not stack:
print "%s:%d"%(file,no)
print " no stack for",mo.group(1)
assert 0
if stack[-1]!=mo.group(1):
print "%s:%d"%(file,no)
print " stack=",stack
print " ended=",mo.group(1)
assert 0
del stack[-1]
mo=re.search("^\s*(return|goto ).*$",line)
if mo and stack:
print "%s:%d %s: %s"%(file,no,stack,line),
mo=re.search("^\s*\S+\s*(return|goto ).*$",line)
if mo and stack:
print "%s:%d POSSIBLE %s: %s"%(file,no,stack,line),
./ai/aiunit.c:224 ['unit']: return TRUE;
./ai/aiunit.c:658 ['city']: return pcity;
./ai/aiunit.c:887 ['unit']: return TRUE; /* Thanks, Markus --
Syela */
./ai/aiunit.c:892 ['unit']: return FALSE;
./ai/aiunit.c:2285 ['unit']: return TRUE;
./client/agents/agents.c:100 ['call']: return;
./client/climisc.c:559 ['unit']: return TRUE;
./client/climisc.c:576 ['unit']: return TRUE;
./client/control.c:330 ['unit']: return punit;
./client/control.c:1281 ['unit']: goto out;
./client/gui-gtk/citydlg.c:395 ['dialog']: return pdialog;
./client/gui-gtk/cma_fe.c:127 ['dialog']: return pdialog;
./client/gui-gtk/diplodlg.c:672 ['clause']: return;
./client/gui-gtk/diplodlg.c:871 ['dialog']: return pdialog;
./client/gui-gtk/diplodlg.c:885 ['dialog']: return pdialog;
./client/gui-gtk/happiness.c:95 ['dialog']: return pdialog;
./client/gui-gtk/spaceshipdlg.c:100 ['dialog']: return pdialog;
./client/gui-gtk/spaceshipdlg.c:369 ['dialog']: return;
./client/gui-gtk-2.0/citydlg.c:336 ['dialog']: return pdialog;
./client/gui-gtk-2.0/cma_fe.c:132 ['dialog']: return pdialog;
./client/gui-gtk-2.0/diplodlg.c:380 ['clause']: return;
./client/gui-gtk-2.0/diplodlg.c:823 ['dialog']: return pdialog;
./client/gui-gtk-2.0/happiness.c:94 ['dialog']: return pdialog;
./client/gui-gtk-2.0/spaceshipdlg.c:95 ['dialog']: return pdialog;
./client/gui-mui/diplodlg.c:130 ['clause']: return;
./client/gui-mui/diplodlg.c:733 ['dialog']: return pdialog;
./client/gui-mui/spaceshipdlg.c:101 ['dialog']: return pdialog;
./client/gui-win32/diplodlg.c:434 ['clause']: return;
./client/gui-win32/diplodlg.c:715 ['dialog']: return pdialog;
./client/gui-win32/spaceshipdlg.c:91 ['dialog']: return pdialog;
./client/gui-xaw/citydlg.c:334 ['dialog']: return pdialog;
./client/gui-xaw/citydlg.c:2457 ['dialog']: return;
./client/gui-xaw/diplodlg.c:756 ['clause']: return;
./client/gui-xaw/diplodlg.c:949 ['dialog']: return pdialog;
./client/gui-xaw/diplodlg.c:963 ['dialog']: return pdialog;
./client/gui-xaw/spaceshipdlg.c:110 ['dialog']: return pdialog;
./client/gui-xaw/spaceshipdlg.c:372 ['dialog']: return;
./client/gui-sdl/cityrep.c:1099 ['city']: return;
./client/gui-sdl/spaceshipdlg.c:86 ['dialog']: return pDialog;
./common/city.c:1169 ['city']: return pcity;
./common/city.c:1184 ['city']: return pcity;
./common/combat.c:53 ['unit']: return FALSE;
./common/combat.c:125 ['unit']: return FALSE;
./common/combat.c:650 ['unit']: return NULL;
./common/connection.c:383 ['conn']: return pconn;
./common/connection.c:426 ['conn']: return pconn;
./common/diptreaty.c:106 ['clause']: return TRUE;
./common/diptreaty.c:145 ['clause']: return FALSE;
./common/diptreaty.c:153 ['clause']: return TRUE;
./common/diptreaty.c:161 ['clause']: return TRUE;
./common/player.c:243 ['unit']: return TRUE;
./common/player.c:481 ['city']: return pcity;
./common/registry.c:1151 ['section', 'entry']: return result;
./common/unit.c:382 ['unit']: return TRUE;
./common/unit.c:689 POSSIBLE ['unit']: if(tunit->activity==ACTIVITY_IRRIGATE)
return FALSE;
./common/unit.c:714 POSSIBLE ['unit']: if(tunit->activity==ACTIVITY_MINE)
return FALSE;
./common/unit.c:836 ['unit']: return TRUE;
./common/unit.c:941 ['unit']: return punit;
./common/unit.c:1101 ['unit']: return NULL;
./common/unit.c:1115 ['unit']: return punit;
./common/unit.c:1130 ['unit']: return punit;
./common/unit.c:1145 ['unit']: return punit;
./common/unittype.c:440 ['unit']: return FALSE;
./server/citytools.c:487 ['city']: return TRUE;
./server/citytools.c:502 ['city']: return TRUE;
./server/citytools.c:1144 ['unit']: goto OUT;
./server/citytools.c:1159 ['unit']: goto MOVE_SEA_UNITS;
./server/cityturn.c:556 ['unit']: return;
./server/diplhand.c:102 ['treaty']: return ptreaty;
./server/diplhand.c:161 ['clause']: return;
./server/diplhand.c:172 ['clause']: return;
./server/diplhand.c:181 ['clause']: return;
./server/diplhand.c:187 ['clause']: return;
./server/diplhand.c:194 ['clause']: return;
./server/diplhand.c:203 ['clause']: return;
./server/diplhand.c:210 ['clause']: return;
./server/diplhand.c:218 ['clause']: return;
./server/diplhand.c:279 ['clause']: goto cleanup;
./server/diplhand.c:292 ['clause']: goto cleanup;
./server/diplhand.c:307 ['clause']: goto cleanup;
./server/diplhand.c:320 ['clause']: goto cleanup;
./server/diplomats.c:1132 ['unit']: return FALSE;
./server/diplomats.c:1148 ['unit']: return FALSE;
./server/settlers.c:481 ['unit']: return TRUE; /* oops, tile is
occupied! */
./server/settlers.c:483 ['unit']: return TRUE;
./server/unittools.c:473 ['unit']: goto OUT;
./server/unittools.c:942 ['unit']: goto START;
./server/unittools.c:964 ['unit']: goto START;
./server/unittools.c:977 ['unit']: goto START;
./server/unittools.c:1002 ['unit']: goto START;
./server/unittools.c:1023 ['unit']: goto START;
./server/unittools.c:1036 ['unit']: goto START;
./server/unittools.c:1264 ['unit']: return TRUE;
./server/stdinhand.c:2155 ['conn']: return TRUE;
./server/unithand.c:1087 ['unit']: return FALSE;
./server/connecthand.c:258 ['conn']: return FALSE;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#6933) Don't skip the iterate_end macros,
Raimar Falke <=
|
|