[gccsdk] OS_GPBP conundrum
I have some code that uses OS_GPBP 12 to iterate over objects in a directory, returning for each one its name and filetype. It has been working for years in RiscLua, when compiled with Norcroft and Objasm. Now that I am using GCC the filetype is always returned as zero, and I cannot see why. OS_GPBP 12 uses a buffer to return its results, with the object's name as a zero-terminated string at buf+24, and the filetype in the word at buf+20. I declare a buffer with static const int rdir_buf[RDIR_BUFLEN/sizeof(int)]; After the call to OS_GPBP 12 my code grabs the name and filetype with lua_pushstring(L, (char *)(_buf[6])); /* name */ lua_pushinteger(L, rdir_buf[5]); /* file type */ return 2; /* number of returned values */ This stuff is what makes the construction for name, ftype in dir (foo) do end work - well it used to The 'name' part comes out OK, but the 'ftype' is always zero, and I just cannot see why. -- Gavin Wraith (ga...@wra1th.plus.com) Home page: http://www.wra1th.plus.com/ ___ GCCSDK mailing list gcc@gccsdk.riscos.info Bugzilla: http://www.riscos.info/bugzilla/index.cgi List Info: http://www.riscos.info/mailman/listinfo/gcc Main Page: http://www.riscos.info/index.php/GCCSDK
Re: [gccsdk] OS_GPBP conundrum
On 21 September 2015 at 13:31, Gavin Wraithwrote: > I have some code that uses OS_GPBP 12 to iterate > over objects in a directory, returning for each one > its name and filetype. It has been working for years > in RiscLua, when compiled with Norcroft and Objasm. > Now that I am using GCC the filetype is always > returned as zero, and I cannot see why. > > OS_GPBP 12 uses a buffer to return its results, > with the object's name as a zero-terminated > string at buf+24, and the filetype in the word > at buf+20. I declare a buffer with > > static const int rdir_buf[RDIR_BUFLEN/sizeof(int)]; > ^ shouldn't that be static int? Wouldn't the const imply that the buffer never changes and could be liable to some optimisation in the way members are accessed? Nick ___ GCCSDK mailing list gcc@gccsdk.riscos.info Bugzilla: http://www.riscos.info/bugzilla/index.cgi List Info: http://www.riscos.info/mailman/listinfo/gcc Main Page: http://www.riscos.info/index.php/GCCSDK
Re: [gccsdk] OS_GPBP conundrum
Hi Gavin, > static const int rdir_buf[RDIR_BUFLEN/sizeof(int)]; ... > lua_pushstring(L, (char *)(_buf[6])); /* name */ > lua_pushinteger(L, rdir_buf[5]); /* file type */ > return 2; /* number of returned values */ ... > The 'name' part comes out OK, but the 'ftype' is always zero, and I > just cannot see why. Sounds like rdir_buf is being re-used, but only the first 24 bytes of it, trampling the filetype, but not the filename, before the push. Do you see filetype in rdir_buf[5] when you lua_pushinteger() above? If so, what happens between the push of the correct filetype and the pull where it's wrong? If not, show us the OS_GPBP 12 call? Cheers, Ralph. ___ GCCSDK mailing list gcc@gccsdk.riscos.info Bugzilla: http://www.riscos.info/bugzilla/index.cgi List Info: http://www.riscos.info/mailman/listinfo/gcc Main Page: http://www.riscos.info/index.php/GCCSDK