Closed suicvne closed 1 year ago
NOTE: It's also worth noting you can test this by setting --enable-newlib-io-c99-formats
in the environment variable TARG_XTRA_OPTS
before running the general pspdev/build-all.sh script.
cd ~/git/pspdev
TARG_XTRA_OPTS=--enable-newlib-io-c99-formats ./build-all.sh
I tested it with my psp using this code and it worked perfectly!👍🏼
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define TEST_LOG(...) \
{\
pspDebugScreenPrintf(__VA_ARGS__);\
printf(__VA_ARGS__);\
}\
PSP_MODULE_INFO("C99-formatters", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
int done = 0;
int exit_callback(int arg1, int arg2, void *common)
{
done = 1;
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(void)
{
pspDebugScreenInit();
SetupCallbacks();
while(!done){
pspDebugScreenSetXY(0, 2);
TEST_LOG("Characters: %c %c \n", 'a', 65);
TEST_LOG("Decimals: %d %ld\n", 1977, 650000L);
TEST_LOG("Preceding with blanks: %10d \n", 1977);
TEST_LOG("Preceding with zeros: %010d \n", 1977);
TEST_LOG("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
TEST_LOG("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
TEST_LOG("Width trick: %*d \n", 5, 10);
TEST_LOG("%s \n", "A string");
TEST_LOG("Formatter: %zu\n", (size_t)42069);
TEST_LOG("Formatter: %p\n", (uintptr_t)0xdeadbeef);
}
sceKernelExitGame();
return 0;
}
Thanks, this seems like a cool addition! I'll let the automated builds run and merge it after.
Submitting this PR to add
--enable-newlib-io-c99-formats
to the default list of configure options, which adds support for C99 formatters such as %zu. This eases the burden of homebrew developers working on ports as they no longer need to change or write special cases to remove %zu formatters from their code.Consider the following sample program:
Compiling the toolchain normally will produce the following output from PPSSPP and from a real PSP:
Compiling the toolchain WITH the flag will result in the following correct behavior:
Recently, we also needed to patch this configure flag into the Dreamcast toolchain compilation options, as it's not enabled there either.