|
13 | 13 | * Portions Copyright (c) 1994, Regents of the University of California
|
14 | 14 | *
|
15 | 15 | * IDENTIFICATION
|
16 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.36 2002/09/23 01:43:23 momjian Exp $ |
| 16 | + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.37 2002/10/17 14:53:32 tgl Exp $ |
17 | 17 | *
|
18 | 18 | *-------------------------------------------------------------------------
|
19 | 19 | */
|
@@ -340,30 +340,34 @@ PgSetResultId(Tcl_Interp *interp, char *connid_c, PGresult *res)
|
340 | 340 | returnTCL_ERROR;
|
341 | 341 | connid= (Pg_ConnectionId*)Tcl_GetChannelInstanceData(conn_chan);
|
342 | 342 |
|
343 |
| -for (resid=connid->res_last+1;resid!=connid->res_last;resid++) |
| 343 | +/* search, starting at slot after the last one used */ |
| 344 | +resid=connid->res_last; |
| 345 | +for (;;) |
344 | 346 | {
|
345 |
| -if (resid==connid->res_max) |
346 |
| -{ |
| 347 | +/* advance, with wraparound */ |
| 348 | +if (++resid >=connid->res_max) |
347 | 349 | resid=0;
|
348 |
| -break; |
349 |
| -} |
| 350 | +/* this slot empty? */ |
350 | 351 | if (!connid->results[resid])
|
351 | 352 | {
|
352 | 353 | connid->res_last=resid;
|
353 |
| -break; |
| 354 | +break;/* success exit */ |
354 | 355 | }
|
| 356 | +/* checked all slots? */ |
| 357 | +if (resid==connid->res_last) |
| 358 | +break;/* failure exit */ |
355 | 359 | }
|
356 | 360 |
|
357 | 361 | if (connid->results[resid])
|
358 | 362 | {
|
359 |
| -if (connid->res_max==connid->res_hardmax) |
| 363 | +/* no free slot found, so try to enlarge array */ |
| 364 | +if (connid->res_max >=connid->res_hardmax) |
360 | 365 | {
|
361 | 366 | Tcl_SetResult(interp,"hard limit on result handles reached",
|
362 | 367 | TCL_STATIC);
|
363 | 368 | returnTCL_ERROR;
|
364 | 369 | }
|
365 |
| -connid->res_last=connid->res_max; |
366 |
| -resid=connid->res_max; |
| 370 | +connid->res_last=resid=connid->res_max; |
367 | 371 | connid->res_max *=2;
|
368 | 372 | if (connid->res_max>connid->res_hardmax)
|
369 | 373 | connid->res_max=connid->res_hardmax;
|
|