clock() doesn't work anymore

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

clock() doesn't work anymore

Post by Shine »

In the program below, with the PSPSDK from SVN repository from yesterday, the displayed clock values look random instead of counting up. The same problem is in Lua Player, where the problem was found. I think in earlier versions of the PSPSDK it worked, but the problem shows only sometimes (looks like it depends on the system time and how long the PSP runs), so I'm not sure. Or is it my fault how I use the clock function?

main.c:

Code: Select all

#include <time.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>

/* Define the module info section */
PSP_MODULE_INFO&#40;"TEST", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

int main&#40;void&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	while &#40;1&#41; &#123;
		SceCtrlData pad;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if &#40;pad.Buttons&#41; break;
		pspDebugScreenClear&#40;&#41;;
		pspDebugScreenPrintf&#40;"clock&#58; %lu\n", clock&#40;&#41;&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
	&#125;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;
Makefile:

Code: Select all

TARGET = test
OBJS = main.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
LIBS = -lpsputility

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

__psp_set_errno should probably be removed from clock() and maybe time() in newlib-psp/newlib/libc/sys/psp/libcglue.c.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Fixed in revision 1489.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

mrbrown wrote:Fixed in revision 1489.
Thanks! This was fast, as always :-)
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

The fix in 1489 is definitely right for clock, but I think time and gettimeofday should keep __psp_set_errno. You could check the return value of time(123) and gettimeofday(123, 456) to see. I can't test it at the moment.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

jimparis wrote:The fix in 1489 is definitely right for clock, but I think time and gettimeofday should keep __psp_set_errno. You could check the return value of time(123) and gettimeofday(123, 456) to see. I can't test it at the moment.
According to some Unix man pages, gettimeofday should return 0. Looks like errno is not set: http://www.opengroup.org/onlinepubs/009 ... ofday.html

Looks like time() has no errors defined, too, so it should be ok: http://www.opengroup.org/onlinepubs/009 ... /time.html
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Fixed again :). Thanks for spotting this. I just looked at the manual pages and those funcs should be setting errno on error.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

mrbrown wrote:Fixed again :). Thanks for spotting this. I just looked at the manual pages and those funcs should be setting errno on error.
According to the ANSI C standard (at least the ISO/IEC 9899:1999, which I have here) the time() function needs not to set errno, but chapter 7.5 says, that it is implementation dependent: A function can set errno, if it is not documented in the standard otherwise. And looks like for gettimeofday some architectures in newlib sets the variable and some not. And the "Single Unix specification" doesn't define that errno is set, but most Unix manual pages does. But this is hairsplitting, I've never seen a program, which checks errno for gettimeofday, so your patch is ok :-)
Post Reply