pspsdk strncat broken

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

Moderators: cheriff, TyRaNiD

Post Reply
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

pspsdk strncat broken

Post by danzel »

I've been having some trouble with peldet running out of memory when using newlib, so I decided I'd try the pspsdk libc.
(I seem to recall someone saying that newlib mallocs the largest amount of memory it can and then just assigns from there?)

First thing that hit me was there is no sscanf, that was easy to fix (I wrote some extra code using strtol instead)
This got it compiled and running. It got as far as the first time strncat is called, then the output got a little weird.

Heres strncat from the sdk:
( /trunk/pspsdk/src/libc/string.c - Rev 1486 )

Code: Select all

#ifdef F_strncat
char *strncat(char *s, const char *append, size_t count)
{
        char *pRet = s;

        while(*s)
        {
                s++;
        }

        while((*append) && (count > 0))
        {
                *s++ = *append++;
        }

        *s = 0;

        return pRet;
}
#endif
I think that count needs to be decreased in the while loop.

I'd fix it and test but the toolchain.sh installer doesn't seem to keep a copy of the svn locally and being almost 1am I think its better to leave it in someone elses capable hands while I sleep...
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Yep, decreasing count in that loop gets it working correctly.

Heres a diff:

Code: Select all

--- pspsdk_copy/src/libc/string.c       2005-12-23 10:05:41.000000000 +1300
+++ pspsdk/src/libc/string.c    2005-12-23 10:18:27.000000000 +1300
@@ -79,6 +79,7 @@ char *strncat(char *s, const char *appen
        while((*append) && (count > 0))
        {
                *s++ = *append++;
+               count--;
        }

        *s = 0;
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Re: pspsdk strncat broken

Post by mrbrown »

danzel wrote:I've been having some trouble with peldet running out of memory when using newlib, so I decided I'd try the pspsdk libc.
(I seem to recall someone saying that newlib mallocs the largest amount of memory it can and then just assigns from there?)
For the record, PSPSDK's libc uses the same _sbrk() that newlib does, so they both will try to allocate all of the available system heap unless you instruct them not to.

You can use the PSP_HEAP_SIZE_KB() in pspmoduleinfo.h to explicitly set the heap size.
fl0w
Posts: 5
Joined: Fri Dec 09, 2005 8:41 pm

Re: pspsdk strncat broken

Post by fl0w »

danzel wrote: I'd fix it and test but the toolchain.sh installer doesn't seem to keep a copy of the svn locally and being almost 1am I think its better to leave it in someone elses capable hands while I sleep...
I personnally find it very annoying that the script does a checkout each time and then deletes the sources of the sdk (including the samples). I fond very handy to have the sources. Moreover, doing a checkout each time the sdk is being updated is a waste of bandwidth and compilation time.

I think the script has options to keep the sources of gcc, but not those of pspsdk.

If nobody does it before next year :) I can modify the script (if everyone is OK, of course).
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Re: pspsdk strncat broken

Post by jimparis »

fl0w wrote:I personnally find it very annoying that the script does a checkout each time and then deletes the sources of the sdk
Then check it out yourself and use the --pspsdk-src option to point to it.
fl0w
Posts: 5
Joined: Fri Dec 09, 2005 8:41 pm

Post by fl0w »

Aaaah thanks, jimparis !
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

or just edit the toolchain script to don't delete it :P
fl0w
Posts: 5
Joined: Fri Dec 09, 2005 8:41 pm

Post by fl0w »

weltall wrote:or just edit the toolchain script to don't delete it :P
that's what i've done in the first place, but the toolchain sometimes gets updated so it's not the best solution...
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

As long as you have a svn checkout of pspsdk you should be able to pass the -P parameter to the toolchain script (passing a directory containing the svn'ed pspsdk after it) and the toolchain script should use that instead of downloading it each time.
Post Reply