lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I have been trying to port lposix to compile and link under MSDev. The problem is that MSDev does not support many of the Posix capabilities. For instance there is no fork() function in Win32 and MSDev has no wrapper for it. This is true for many other Posix functions.

The natural solution is to use Cygwin. I can build lposix with Cygwin just fine. The problem comes in linking. The rest of my app (http://emma3d.org) builds Lua as a dll, so all the various components can share the interpreter. This is important because Emma is an extensible system. You can build an extension dll which can access the interpreter. So the interpreter needs to be a DLL.

The problem is that Cygwin can't link with a DLL produced by MSDev, so I can use GCC to link lposix. And MSDev can't link with an object produced by GCC (or more properly MSDev can't link with the Cygwin libraries that object needs). I can't build liblua.dll using Cygwin because then I would have to build every subsystem that links with that dll in Cygwin, and that is not acceptable for our app.

So I would like to suggest that we go back to the plan to make the 'osex' package small and have it grow. We can still start with lposix, but toss the problematic function calls. To be honest, I'm not sure how practical fork() and some of the permission related calls are in many systems anyway.

Here is what lposix has today:

"access", "chdir", "chmod", "chown", "ctermid", "dir", "errno",
"exec", "files", "fork", "getcwd", "getenv", "getgroup",
"getlogin", "getpasswd", "getprocessid", "kill", "link",
"mkdir", "mkfifo", "pathconf", "putenv", "readlink", "rmdir",
"setgid", "setuid", "sleep", "stat", "symlink", "sysconf",
"times", "ttyname", "umask", "uname", "unlink", "utime", "wait"

Here is what I think we should take from it:

"access", "chdir", "chmod", "errno", "exec", "getcwd",
"getenv", "mkdir", "putenv", "rmdir", "sleep", "stat",
"umask"

Of the things left out, the only thing I think missing is "dir" and "files". These are the directory traversal functions. I left them out because Win32 does this sort of thing very differently. I can implement it pretty easily, but with a totally different stream of code. So I will do it later. I know there are other ideas out there about how to do directory traversal, so we should probably discuss and agree on a design.

I have ported all the above to Win32, using MSDev 7.1. Issues in porting to Win32:

1) Windows has the concept of permissions, but not for user/group/others. So I made it so that setting permissions for any of these sets the Win32 notion of permission. For instance, if you set read permission for user or group or other, I set read permission. (Note: cygwin seems to support full permissions for win32 files, looking at the 'ls -l' command in the cygwin shell. How do they do that?)

2) Windows has no notion of an executable bit, so I just ignore it

3) Windows supports the notion of regular files, directories and character files, but not links, block files, fifos or sockets. So I ignore them.

4) Since Win32 has a Sleep function that takes milliseconds, I decided to change the implementation of sleep to take a double seconds value rather than an integer. On Win32 this means you get resolution down to 1ms. And I used nanosleep() for the Linux implementation which gives resolution down to 1ns (dependent on the machine resolution, of course). If nanosleep does not exist elsewhere, we can always use something else, like sleep(), and just have 1sec resolution.

Comments?

--
chris marrin              ,""$, "As a general rule,don't solve puzzles
chris@marrin.com        b`    $  that open portals to Hell" ,,.
        ,.`           ,b`    ,`                            , 1$'
     ,|`             mP    ,`                              :$$'     ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`