| View previous topic :: View next topic |
| Author |
Message |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Nov 27, 2005 4:11 am Post subject: clock() doesn't work anymore |
|
|
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: |
#include <time.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
/* Define the module info section */
PSP_MODULE_INFO("TEST", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int main(void)
{
pspDebugScreenInit();
while (1) {
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons) break;
pspDebugScreenClear();
pspDebugScreenPrintf("clock: %lu\n", clock());
sceDisplayWaitVblankStart();
sceDisplayWaitVblankStart();
}
sceKernelExitGame();
return 0;
}
|
Makefile:
| Code: |
TARGET = test
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpsputility
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
|
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Sun Nov 27, 2005 4:54 am Post subject: |
|
|
| __psp_set_errno should probably be removed from clock() and maybe time() in newlib-psp/newlib/libc/sys/psp/libcglue.c. |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Sun Nov 27, 2005 5:05 am Post subject: |
|
|
| Fixed in revision 1489. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Nov 27, 2005 5:11 am Post subject: |
|
|
| mrbrown wrote: | | Fixed in revision 1489. |
Thanks! This was fast, as always :-) |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Sun Nov 27, 2005 5:19 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Sun Nov 27, 2005 5:32 am Post subject: |
|
|
| Fixed again :). Thanks for spotting this. I just looked at the manual pages and those funcs should be setting errno on error. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Nov 27, 2005 7:00 am Post subject: |
|
|
| 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 :-) |
|
| Back to top |
|
 |
|