--- ray/src/common/readobj.c 2017/04/08 03:56:44 2.22 +++ ray/src/common/readobj.c 2023/02/07 20:28:16 2.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readobj.c,v 2.22 2017/04/08 03:56:44 greg Exp $"; +static const char RCSid[] = "$Id: readobj.c,v 2.25 2023/02/07 20:28:16 greg Exp $"; #endif /* * readobj.c - routines for reading in object descriptions. @@ -47,6 +47,9 @@ readobj( /* read in an object file or stream */ sprintf(errmsg, "cannot open scene file \"%s\"", inpspec); error(SYSTEM, errmsg); } +#ifdef getc_unlocked /* avoid stupid semaphores */ + flockfile(infp); +#endif while ((c = getc(infp)) != EOF) { if (isspace(c)) continue; @@ -63,8 +66,12 @@ readobj( /* read in an object file or stream */ } if (inpspec[0] == '!') pclose(infp); - else + else if (infp != stdin) fclose(infp); +#ifdef getc_unlocked + else + funlockfile(infp); +#endif if (nobjects == lastobj) { sprintf(errmsg, "(%s): empty file", inpspec); error(WARNING, errmsg); @@ -198,16 +205,17 @@ freeobjects( /* free a range of objects */ freefargs(&o->oargs); memset((void *)o, '\0', sizeof(OBJREC)); } - clearobjndx(); /* free objects off end */ for (obj = nobjects; obj-- > 0; ) if (objptr(obj)->oname != NULL) break; - ++obj; + if (++obj >= nobjects) + return; while (nobjects > obj) /* free empty end blocks */ if ((--nobjects & (OBJBLKSIZ-1)) == 0) { int i = nobjects >> OBJBLKSHFT; free((void *)objblock[i]); objblock[i] = NULL; } + truncobjndx(); /* truncate modifier look-up */ }