* Makefile: Don't build make-map.exe.
authorJonathan Pryor <jpryor@novell.com>
Tue, 24 Oct 2006 22:37:50 +0000 (22:37 -0000)
committerJonathan Pryor <jpryor@novell.com>
Tue, 24 Oct 2006 22:37:50 +0000 (22:37 -0000)
* Mono.Posix.dll.sources: Move MapAttribute into Mono.Unix.Native; remove
  HeaderAttribute.cs; Add TypeAttributes.cs.
* Mono.Unix/MapAttribute.cs: Moved to ../Mono.Unix.Native/MapAttribute.cs.
* Mono.Unix.Native/HeaderAttribute.cs: Removed.  Use create-native-map
  command-line arguments instead of HeaderAttribute.Includes &
  HeaderAttribute.Defines.
* Mono.Unix.Native/make-map.cs: Moved to
  mono-tools/create-native-map/src/create-native-map.cs.
* Mono.Unix.Native/MapAttribute.cs: Moved from ../Mono.Unix.  Can now be
  specified on Class, Delegeate, Enum, Field, & Struct (instead of just
  Enum).  Add NativeType property.
* Mono.Unix.Native/NativeConvert.generated.cs: Flush (adds new .TryCopy
  methods to copy [Map]'d structures).
* Mono.Unix.Native/NativeConvert.cs: Add .TryCopy methods for Statvfs.
* Mono.Unix.Native/Syscall.cs: Remove HeaderAttribute declaration; Markup
  [Map]'d structure members with [Map] attributes (or MapAttribute
  subclasses) to specify the native types they correspond to (used by
  create-native-map).
* Mono.Unix.Native/TypeAttributes.cs: Added; internal subclasses of
  MapAttribute to help markup structures (e.g. so I can use [blkcnt_t]
  instead of [Map ("blkcnt_t")], thus minimizing the liklihood of a
  spelling error).

svn path=/trunk/mcs/; revision=66947

13 files changed:
mcs/class/Mono.Posix/ChangeLog
mcs/class/Mono.Posix/Makefile
mcs/class/Mono.Posix/Mono.Posix.dll.sources
mcs/class/Mono.Posix/Mono.Unix.Native/ChangeLog
mcs/class/Mono.Posix/Mono.Unix.Native/HeaderAttribute.cs [deleted file]
mcs/class/Mono.Posix/Mono.Unix.Native/MapAttribute.cs [new file with mode: 0644]
mcs/class/Mono.Posix/Mono.Unix.Native/NativeConvert.cs
mcs/class/Mono.Posix/Mono.Unix.Native/NativeConvert.generated.cs
mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
mcs/class/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs [new file with mode: 0644]
mcs/class/Mono.Posix/Mono.Unix.Native/make-map.cs [deleted file]
mcs/class/Mono.Posix/Mono.Unix/ChangeLog
mcs/class/Mono.Posix/Mono.Unix/MapAttribute.cs [deleted file]

index f7b8af0ba10cc52520781d68416538110d97e905..777788bd4431a441bd9f8e9b8e21aad41b754548 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-24  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * Makefile: Don't build make-map.exe.
+       * Mono.Posix.dll.sources: Move MapAttribute into Mono.Unix.Native; remove
+         HeaderAttribute.cs; Add TypeAttributes.cs.
+
 2006-07-02  Jonathan Pryor  <jonpryor@vt.edu>
 
        * Mono.Posix_test.dll.sources: Add Mono.Unix/UnixPathTest.cs.
index 8914d43621c1871859d9815205e3af5d237f543f..2ade729958ce02e4516e77edbbd1a97f8144020b 100644 (file)
@@ -10,16 +10,11 @@ TEST_MCS_FLAGS = /r:Mono.Posix.dll /r:System.dll /nowarn:0219,0618
 
 include ../../build/library.make
 
-EXTRA_DISTFILES = Mono.Unix.Native/make-map.cs
+update-mappings:
+       cp `pkg-config --variable=Sources create-native-map` Mono.Unix.Native
+       cp `pkg-config --variable=Programs create-native-map` Mono.Unix.Native
+       mono --debug Mono.Unix.Native/create-native-map.exe \
+               --library=MonoPosixHelper \
+               --rename-namespace Mono.Unix.Native=Mono.Posix \
+               $(the_lib) Mono.Unix.Native/NativeConvert.generated
 
-all-local: Mono.Unix.Native/make-map.exe 
-
-Mono.Unix.Native/make-map.exe: Mono.Unix.Native/make-map.cs $(the_lib)
-       cp $(the_lib) Mono.Unix.Native/
-ifneq ($(PLATFORM),win32)
-       $(CSCOMPILE) -debug+ -out:Mono.Unix.Native/make-map.exe -r:Mono.Posix.dll Mono.Unix.Native/make-map.cs
-else
-       $(CSCOMPILE) -debug+ -out:Mono.Unix.Native/make-map.exe -r:Mono.Posix.dll Mono.Unix.Native\\make-map.cs
-endif
-
-CLEAN_FILES = Mono.Unix.Native/make-map.exe Mono.Unix.Native/Mono.Posix.dll
index 05f55399ae0b6e047940362479996e897feaa5c8..1d15bc237a86ea382e71139314edf81f5f957961 100644 (file)
@@ -8,7 +8,6 @@
 ./Mono.Unix/FileHandleOperations.cs
 ./Mono.Unix/FileSpecialAttributes.cs
 ./Mono.Unix/FileTypes.cs
-./Mono.Unix/MapAttribute.cs
 ./Mono.Unix/PeerCred.cs
 ./Mono.Unix/StdioFileStream.cs
 ./Mono.Unix/UnixClient.cs
 ./Mono.Unix/UnixUserInfo.cs
 ./Mono.Unix.Native/CdeclFunction.cs
 ./Mono.Unix.Native/FileNameMarshaler.cs
-./Mono.Unix.Native/HeaderAttribute.cs
+./Mono.Unix.Native/MapAttribute.cs
 ./Mono.Unix.Native/NativeConvert.cs
 ./Mono.Unix.Native/NativeConvert.generated.cs
 ./Mono.Unix.Native/Stdlib.cs
 ./Mono.Unix.Native/Syscall.cs
+./Mono.Unix.Native/TypeAttributes.cs
 ./Mono.Posix/Catalog.cs
 ./Mono.Posix/PeerCred.cs
 ./Mono.Posix/Syscall.cs
index 644fcc582f360e8102092fa291f5182975b44716..e9851db764f49b57b4789a0ffa3bc959cb4c61c5 100644 (file)
@@ -1,3 +1,21 @@
+2006-10-24  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * HeaderAttribute.cs: Removed.  Use create-native-map command-line arguments
+         instead of HeaderAttribute.Includes & HeaderAttribute.Defines.
+       * make-map.cs: Moved to mono-tools/create-native-map/src/create-native-map.cs.
+       * MapAttribute.cs: Moved from ../Mono.Unix.  Can now be
+         specified on Class, Delegeate, Enum, Field, & Struct (instead of just
+         Enum).  Add NativeType property.
+       * NativeConvert.generated.cs: Flush (adds new .TryCopy methods to copy [Map]'d
+         structures).
+       * NativeConvert.cs: Add .TryCopy methods for Statvfs.
+       * Syscall.cs: Remove HeaderAttribute declaration; Markup [Map]'d structure 
+         members with [Map] attributes (or MapAttribute subclasses) to specify the 
+         native types they correspond to (used by create-native-map).
+       * TypeAttributes.cs: Added; internal subclasses of MapAttribute to help
+         markup structures (e.g. so I can use [blkcnt_t] instead of 
+         [Map ("blkcnt_t")], thus minimizing the liklihood of a spelling error).
+
 2006-09-15  Jonathan Pryor  <jonpryor@vt.edu>
 
        * Syscall.cs: "Remove" crypt(3), encrypt(3), setkey(3).  These use an
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/HeaderAttribute.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/HeaderAttribute.cs
deleted file mode 100644 (file)
index 50f6ac4..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-// IncludeAttribute.cs
-//
-// Author:
-//   Jonathan Pryor (jonpryor@vt.edu)
-//
-// (C) Novell, Inc.  
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace Mono.Unix.Native {
-
-       [AttributeUsage (AttributeTargets.Assembly)]
-       internal class HeaderAttribute : Attribute {
-               string includes = "";
-               string defines = "";
-               
-               public string Includes {
-                       get {return includes;}
-                       set {includes = value;}
-               }
-
-               public string Defines {
-                       get {return defines;}
-                       set {defines = value;}
-               }
-       }
-}
-
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/MapAttribute.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/MapAttribute.cs
new file mode 100644 (file)
index 0000000..a628a27
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// MapAttribute.cs
+//
+// Author:
+//   Miguel de Icaza (miguel@gnome.org)
+//
+// (C) Novell, Inc.  
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+
+[AttributeUsage (
+               AttributeTargets.Class    |
+               AttributeTargets.Delegate |
+               AttributeTargets.Enum     |
+               AttributeTargets.Field    |
+               AttributeTargets.Struct)]
+internal class MapAttribute : Attribute {
+       private string nativeType;
+
+       public MapAttribute ()
+       {
+       }
+
+       public MapAttribute (string nativeType)
+       {
+               this.nativeType = nativeType;
+       }
+
+       public string NativeType {
+               get {return nativeType;}
+       }
+}
+
index 6dc29ae5cc55d7f189d2cc22010ae30b5b78cad1..617913e48c7528538a6a162b8c67fa9066840093 100644 (file)
@@ -299,6 +299,22 @@ namespace Mono.Unix.Native {
                                throw new ArgumentException (fopen_mode);
                        return fopen_mode;
                }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromStatvfs")]
+               private static extern int FromStatvfs (ref Statvfs source, IntPtr destination);
+
+               public static bool TryCopy (ref Statvfs source, IntPtr destination)
+               {
+                       return FromStatvfs (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToStatvfs")]
+               private static extern int ToStatvfs (IntPtr source, out Statvfs destination);
+
+               public static bool TryCopy (IntPtr source, out Statvfs destination)
+               {
+                       return ToStatvfs (source, out destination) == 0;
+               }
        }
 }
 
index 7fd06c2a3393c1d528f4ab69e2609a6513708682..b22ee2bbed8205a21483f1a51194e1fac6ea2284 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file was automatically generated by make-map from Mono.Posix.dll.
+ * This file was automatically generated by create-native-map from ../../class/lib/default/Mono.Posix.dll.
  *
  * DO NOT MODIFY.
  */
@@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
 using Mono.Unix.Native;
 
 namespace Mono.Unix.Native {
+
        public sealed /* static */ partial class NativeConvert
        {
                private NativeConvert () {}
@@ -565,6 +566,22 @@ namespace Mono.Unix.Native {
                        return rval;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromPollfd")]
+               private static extern int FromPollfd (ref Pollfd source, IntPtr destination);
+
+               public static bool TryCopy (ref Pollfd source, IntPtr destination)
+               {
+                       return FromPollfd (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToPollfd")]
+               private static extern int ToPollfd (IntPtr source, out Pollfd destination);
+
+               public static bool TryCopy (IntPtr source, out Pollfd destination)
+               {
+                       return ToPollfd (source, out destination) == 0;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromPosixFadviseAdvice")]
                private static extern int FromPosixFadviseAdvice (PosixFadviseAdvice value, out Int32 rval);
 
@@ -693,6 +710,22 @@ namespace Mono.Unix.Native {
                        return rval;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromStat")]
+               private static extern int FromStat (ref Stat source, IntPtr destination);
+
+               public static bool TryCopy (ref Stat source, IntPtr destination)
+               {
+                       return FromStat (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToStat")]
+               private static extern int ToStat (IntPtr source, out Stat destination);
+
+               public static bool TryCopy (IntPtr source, out Stat destination)
+               {
+                       return ToStat (source, out destination) == 0;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromSysconfName")]
                private static extern int FromSysconfName (SysconfName value, out Int32 rval);
 
@@ -821,6 +854,38 @@ namespace Mono.Unix.Native {
                        return rval;
                }
 
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromTimeval")]
+               private static extern int FromTimeval (ref Timeval source, IntPtr destination);
+
+               public static bool TryCopy (ref Timeval source, IntPtr destination)
+               {
+                       return FromTimeval (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToTimeval")]
+               private static extern int ToTimeval (IntPtr source, out Timeval destination);
+
+               public static bool TryCopy (IntPtr source, out Timeval destination)
+               {
+                       return ToTimeval (source, out destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_FromTimezone")]
+               private static extern int FromTimezone (ref Timezone source, IntPtr destination);
+
+               public static bool TryCopy (ref Timezone source, IntPtr destination)
+               {
+                       return FromTimezone (ref source, destination) == 0;
+               }
+
+               [DllImport (LIB, EntryPoint="Mono_Posix_ToTimezone")]
+               private static extern int ToTimezone (IntPtr source, out Timezone destination);
+
+               public static bool TryCopy (IntPtr source, out Timezone destination)
+               {
+                       return ToTimezone (source, out destination) == 0;
+               }
+
                [DllImport (LIB, EntryPoint="Mono_Posix_FromWaitOptions")]
                private static extern int FromWaitOptions (WaitOptions value, out Int32 rval);
 
index 6d8dd0def0895c6bcd17885b125be1e35f639241..c8cc4ce82a3ff30bc50eea08b65ed54623af6093 100644 (file)
@@ -6,7 +6,7 @@
 //   Jonathan Pryor (jonpryor@vt.edu)
 //
 // (C) 2003 Novell, Inc.
-// (C) 2004-2005 Jonathan Pryor
+// (C) 2004-2006 Jonathan Pryor
 //
 // This file implements the low-level syscall interface to the POSIX
 // subsystem.
@@ -60,27 +60,6 @@ using System.Security;
 using System.Text;
 using Mono.Unix.Native;
 
-[assembly:Mono.Unix.Native.HeaderAttribute (
-       Includes=
-               "sys/types.h," + 
-               "sys/stat.h," + 
-               "ah:sys/poll.h," + 
-               "ah:sys/wait.h," +
-               "ah:sys/statvfs.h," +
-               "ah:sys/xattr.h," +
-               "ah:sys/mman.h," +
-               "unistd.h," + 
-               "fcntl.h," + 
-               "signal.h," + 
-               "ah:poll.h," + 
-               "ah:grp.h," + 
-               "errno.h," + 
-               "ah:syslog.h",
-       Defines=
-               "_GNU_SOURCE," +
-               "_XOPEN_SOURCE"
-)]
-
 namespace Mono.Unix.Native {
 
        #region Enumerations
@@ -737,9 +716,9 @@ namespace Mono.Unix.Native {
                public LockType         l_type;    // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
                [CLSCompliant (false)]
                public SeekFlags        l_whence;  // How to interpret l_start
-               public /* off_t */ long l_start;   // Starting offset for lock
-               public /* off_t */ long l_len;     // Number of bytes to lock
-               public /* pid_t */ int  l_pid;     // PID of process blocking our lock (F_GETLK only)
+               [off_t] public long     l_start;   // Starting offset for lock
+               [off_t] public long     l_len;     // Number of bytes to lock
+               [pid_t] public int      l_pid;     // PID of process blocking our lock (F_GETLK only)
 
                public override int GetHashCode ()
                {
@@ -776,6 +755,7 @@ namespace Mono.Unix.Native {
                }
        }
 
+       [Map ("struct pollfd")]
        public struct Pollfd
 #if NET_2_0
                : IEquatable <Pollfd>
@@ -816,33 +796,35 @@ namespace Mono.Unix.Native {
                }
        }
 
+       [Map ("struct stat")]
        public struct Stat
 #if NET_2_0
                : IEquatable <Stat>
 #endif
        {
                [CLSCompliant (false)]
-               public  /* dev_t */     ulong   st_dev;     // device
+               [dev_t]     public ulong    st_dev;     // device
                [CLSCompliant (false)]
-               public  /* ino_t */     ulong   st_ino;     // inode
+               [ino_t]     public  ulong   st_ino;     // inode
                [CLSCompliant (false)]
-               public  FilePermissions         st_mode;    // protection
+               public  FilePermissions     st_mode;    // protection
                [CLSCompliant (false)]
-               private uint                    _padding_;  // padding for structure alignment
+               [NonSerialized]
+               private uint                _padding_;  // padding for structure alignment
                [CLSCompliant (false)]
-               public  /* nlink_t */   ulong   st_nlink;   // number of hard links
+               [nlink_t]   public  ulong   st_nlink;   // number of hard links
                [CLSCompliant (false)]
-               public  /* uid_t */     uint    st_uid;     // user ID of owner
+               [uid_t]     public  uint    st_uid;     // user ID of owner
                [CLSCompliant (false)]
-               public  /* gid_t */     uint    st_gid;     // group ID of owner
+               [gid_t]     public  uint    st_gid;     // group ID of owner
                [CLSCompliant (false)]
-               public  /* dev_t */     ulong   st_rdev;    // device type (if inode device)
-               public  /* off_t */     long    st_size;    // total size, in bytes
-               public  /* blksize_t */ long    st_blksize; // blocksize for filesystem I/O
-               public  /* blkcnt_t */  long    st_blocks;  // number of blocks allocated
-               public  /* time_t */    long    st_atime;   // time of last access
-               public  /* time_t */    long    st_mtime;   // time of last modification
-               public  /* time_t */    long    st_ctime;   // time of last status change
+               [dev_t]     public  ulong   st_rdev;    // device type (if inode device)
+               [off_t]     public  long    st_size;    // total size, in bytes
+               [blksize_t] public  long    st_blksize; // blocksize for filesystem I/O
+               [blkcnt_t]  public  long    st_blocks;  // number of blocks allocated
+               [time_t]    public  long    st_atime;   // time of last access
+               [time_t]    public  long    st_mtime;   // time of last modification
+               [time_t]    public  long    st_ctime;   // time of last status change
 
                public override int GetHashCode ()
                {
@@ -909,6 +891,8 @@ namespace Mono.Unix.Native {
                }
        }
 
+       // `struct statvfs' isn't portable, so don't generate To/From methods.
+       [Map]
        [CLSCompliant (false)]
        public struct Statvfs
 #if NET_2_0
@@ -917,12 +901,12 @@ namespace Mono.Unix.Native {
        {
                public                  ulong f_bsize;    // file system block size
                public                  ulong f_frsize;   // fragment size
-               public /* fsblkcnt_t */ ulong f_blocks;   // size of fs in f_frsize units
-               public /* fsblkcnt_t */ ulong f_bfree;    // # free blocks
-               public /* fsblkcnt_t */ ulong f_bavail;   // # free blocks for non-root
-               public /* fsfilcnt_t */ ulong f_files;    // # inodes
-               public /* fsfilcnt_t */ ulong f_ffree;    // # free inodes
-               public /* fsfilcnt_t */ ulong f_favail;   // # free inodes for non-root
+               [fsblkcnt_t] public     ulong f_blocks;   // size of fs in f_frsize units
+               [fsblkcnt_t] public     ulong f_bfree;    // # free blocks
+               [fsblkcnt_t] public     ulong f_bavail;   // # free blocks for non-root
+               [fsfilcnt_t] public     ulong f_files;    // # inodes
+               [fsfilcnt_t] public     ulong f_ffree;    // # free inodes
+               [fsfilcnt_t] public     ulong f_favail;   // # free inodes for non-root
                public                  ulong f_fsid;     // file system id
                public MountFlags             f_flag;     // mount flags
                public                  ulong f_namemax;  // maximum filename length
@@ -986,13 +970,14 @@ namespace Mono.Unix.Native {
                }
        }
 
+       [Map ("struct timeval")]
        public struct Timeval
 #if NET_2_0
                : IEquatable <Timeval>
 #endif
        {
-               public  /* time_t */      long    tv_sec;   // seconds
-               public  /* suseconds_t */ long    tv_usec;  // microseconds
+               [time_t]      public long tv_sec;   // seconds
+               [suseconds_t] public long tv_usec;  // microseconds
 
                public override int GetHashCode ()
                {
@@ -1023,6 +1008,7 @@ namespace Mono.Unix.Native {
                }
        }
 
+       [Map ("struct timezone")]
        public struct Timezone
 #if NET_2_0
                : IEquatable <Timezone>
@@ -1065,8 +1051,8 @@ namespace Mono.Unix.Native {
                : IEquatable <Utimbuf>
 #endif
        {
-               public  /* time_t */      long    actime;   // access time
-               public  /* time_t */      long    modtime;  // modification time
+               [time_t] public long    actime;   // access time
+               [time_t] public long    modtime;  // modification time
 
                public override int GetHashCode ()
                {
@@ -1803,8 +1789,8 @@ namespace Mono.Unix.Native {
                public static extern int rewinddir (IntPtr dir);
 
                private struct _Dirent {
-                       public /* ino_t */ ulong  d_ino;
-                       public /* off_t */ long   d_off;
+                       [ino_t] public ulong      d_ino;
+                       [off_t] public long       d_off;
                        public ushort             d_reclen;
                        public byte               d_type;
                        public IntPtr             d_name;
@@ -1938,6 +1924,7 @@ namespace Mono.Unix.Native {
                //
                // <fstab.h>  -- COMPLETE
                //
+               [Map]
                private struct _Fstab {
                        public IntPtr fs_spec;
                        public IntPtr fs_file;
@@ -2067,11 +2054,12 @@ namespace Mono.Unix.Native {
                        return setgroups ((ulong) list.Length, list);
                }
 
+               [Map]
                private struct _Group
                {
                        public IntPtr           gr_name;
                        public IntPtr           gr_passwd;
-                       public /* gid_t */ uint gr_gid;
+                       [gid_t] public uint     gr_gid;
                        public int              _gr_nmem_;
                        public IntPtr           gr_mem;
                        public IntPtr           _gr_buf_;
@@ -2239,12 +2227,13 @@ namespace Mono.Unix.Native {
                //
                // SKIPPING: getpw(3): it's dangerous.  Use getpwuid(3) instead.
 
+               [Map]
                private struct _Passwd
                {
                        public IntPtr           pw_name;
                        public IntPtr           pw_passwd;
-                       public /* uid_t */ uint pw_uid;
-                       public /* gid_t */ uint pw_gid;
+                       [uid_t] public uint     pw_uid;
+                       [gid_t] public uint     pw_gid;
                        public IntPtr           pw_gecos;
                        public IntPtr           pw_dir;
                        public IntPtr           pw_shell;
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/TypeAttributes.cs
new file mode 100644 (file)
index 0000000..2fadc9a
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// TypeAttributes.cs
+//
+// Author:
+//   Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2006 Jonathan Pryor
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+
+namespace Mono.Unix.Native {
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class blkcnt_tAttribute : MapAttribute {
+               
+               public blkcnt_tAttribute () : base ("blkcnt_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class blksize_tAttribute : MapAttribute {
+               
+               public blksize_tAttribute () : base ("blksize_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class dev_tAttribute : MapAttribute {
+               
+               public dev_tAttribute () : base ("dev_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class gid_tAttribute : MapAttribute {
+               
+               public gid_tAttribute () : base ("gid_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class fsblkcnt_tAttribute : MapAttribute {
+               
+               public fsblkcnt_tAttribute () : base ("fsblkcnt_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class fsfilcnt_tAttribute : MapAttribute {
+               
+               public fsfilcnt_tAttribute () : base ("fsfilcnt_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class ino_tAttribute : MapAttribute {
+               
+               public ino_tAttribute () : base ("ino_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class nlink_tAttribute : MapAttribute {
+               
+               public nlink_tAttribute () : base ("nlink_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class off_tAttribute : MapAttribute {
+               
+               public off_tAttribute () : base ("off_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class pid_tAttribute : MapAttribute {
+               
+               public pid_tAttribute () : base ("pid_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class suseconds_tAttribute : MapAttribute {
+               
+               public suseconds_tAttribute () : base ("suseconds_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class uid_tAttribute : MapAttribute {
+               
+               public uid_tAttribute () : base ("uid_t")
+               {
+               }
+       }
+
+       [AttributeUsage (AttributeTargets.Field)]
+       internal class time_tAttribute : MapAttribute {
+               
+               public time_tAttribute () : base ("time_t")
+               {
+               }
+       }
+}
+
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/make-map.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/make-map.cs
deleted file mode 100644 (file)
index 39f8b03..0000000
+++ /dev/null
@@ -1,893 +0,0 @@
-//
-// MakeMap.cs: Builds a C map of constants defined on C# land
-//
-// Authors:
-//  Miguel de Icaza (miguel@novell.com)
-//  Jonathan Pryor (jonpryor@vt.edu)
-//
-// (C) 2003 Novell, Inc.
-// (C) 2004-2005 Jonathan Pryor
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-using System.IO;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-delegate void CreateFileHandler (string assembly_name, string file_prefix);
-delegate void AssemblyAttributesHandler (Assembly assembly);
-delegate void TypeHandler (Type t, string ns, string fn);
-delegate void CloseFileHandler (string file_prefix);
-
-class MakeMap {
-
-       public static int Main (string [] args)
-       {
-               FileGenerator[] generators = new FileGenerator[]{
-                       new HeaderFileGenerator (),
-                       new SourceFileGenerator (),
-                       new ConvertFileGenerator (),
-                       new ConvertDocFileGenerator (),
-                       new MphPrototypeFileGenerator (),
-               };
-
-               MakeMap composite = new MakeMap ();
-               foreach (FileGenerator g in generators) {
-                       composite.FileCreators += new CreateFileHandler (g.CreateFile);
-                       composite.AssemblyAttributesHandler += 
-                               new AssemblyAttributesHandler (g.WriteAssemblyAttributes);
-                       composite.TypeHandler += new TypeHandler (g.WriteType);
-                       composite.FileClosers += new CloseFileHandler (g.CloseFile);
-               }
-
-               return composite.Run (args);
-       }
-
-       event CreateFileHandler FileCreators;
-       event AssemblyAttributesHandler AssemblyAttributesHandler;
-       event TypeHandler TypeHandler;
-       event CloseFileHandler FileClosers;
-
-       int Run (string[] args)
-       {
-               if (args.Length != 2){
-                       Console.WriteLine ("Usage is: make-map assembly output");
-                       return 1;
-               }
-               
-               string assembly_name = args[0];
-               string output = args[1];
-
-               FileCreators (assembly_name, output);
-
-               Assembly assembly = Assembly.LoadFrom (assembly_name);
-               AssemblyAttributesHandler (assembly);
-               
-               Type [] exported_types = assembly.GetTypes ();
-               Array.Sort (exported_types, new TypeFullNameComparer ());
-                       
-               foreach (Type t in exported_types) {
-                       string ns = t.Namespace;
-                       if (ns == null || !ns.StartsWith ("Mono"))
-                               continue;
-                       string fn = GetNativeName (t.FullName);
-                       ns = GetNativeName (ns);
-
-                       TypeHandler (t, ns, fn);
-               }
-               FileClosers (output);
-
-               return 0;
-       }
-
-       private class TypeFullNameComparer : IComparer {
-               public int Compare (object o1, object o2)
-               {
-                       Type t1 = o1 as Type;
-                       Type t2 = o2 as Type;
-                       if (t1 == t2)
-                               return 0;
-                       if (t1 == null)
-                               return 1;
-                       if (t2 == null)
-                               return -1;
-                       return CultureInfo.InvariantCulture.CompareInfo.Compare (
-                                       t1.FullName, t2.FullName, CompareOptions.Ordinal);
-               }
-       }
-
-       private class _MemberNameComparer : IComparer {
-               public int Compare (object o1, object o2)
-               {
-                       MemberInfo m1 = o1 as MemberInfo;
-                       MemberInfo m2 = o2 as MemberInfo;
-                       if (m1 == m2)
-                               return 0;
-                       if (m1 == null)
-                               return 1;
-                       if (m2 == null)
-                               return -1;
-                       return CultureInfo.InvariantCulture.CompareInfo.Compare (
-                                       m1.Name, m2.Name, CompareOptions.Ordinal);
-               }
-       }
-
-       private class _OrdinalStringComparer : IComparer {
-               public int Compare (object o1, object o2)
-               {
-                       string s1 = o1 as string;
-                       string s2 = o2 as string;
-                       if (object.ReferenceEquals (s1, s2))
-                               return 0;
-                       if (s1 == null)
-                               return 1;
-                       if (s2 == null)
-                               return -1;
-                       return CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s2, 
-                                       CompareOptions.Ordinal);
-               }
-       }
-
-       internal static IComparer MemberNameComparer = new _MemberNameComparer ();
-       internal static IComparer OrdinalStringComparer = new _OrdinalStringComparer ();
-
-       internal static string GetNativeName (string fn)
-       {
-               fn = fn.Replace ('.', '_');
-               if (fn.StartsWith ("Mono_Unix_Native"))
-                       return fn.Replace ("Mono_Unix_Native", "Mono_Posix");
-               return fn.Replace ("Mono_Unix", "Mono_Posix");
-       }
-}
-
-abstract class FileGenerator {
-       public abstract void CreateFile (string assembly_name, string file_prefix);
-
-       public virtual void WriteAssemblyAttributes (Assembly assembly)
-       {
-       }
-
-       public abstract void WriteType (Type t, string ns, string fn);
-       public abstract void CloseFile (string file_prefix);
-
-       protected static void WriteHeader (StreamWriter s, string assembly)
-       {
-               WriteHeader (s, assembly, false);
-       }
-
-       protected static void WriteHeader (StreamWriter s, string assembly, bool noConfig)
-       {
-               s.WriteLine (
-                       "/*\n" +
-                       " * This file was automatically generated by make-map from {0}.\n" +
-                       " *\n" +
-                       " * DO NOT MODIFY.\n" +
-                       " */",
-                       assembly);
-               if (!noConfig) {
-                       s.WriteLine ("#include <config.h>");
-               }
-               s.WriteLine ();
-       }
-
-       protected static bool CanMapType (Type t, out bool bits)
-       {
-               object [] attributes = t.GetCustomAttributes (false);
-               bool map = false;
-               bits = false;
-               
-               foreach (object attr in attributes) {
-                       if (attr.GetType ().Name == "MapAttribute")
-                               map = true;
-                       if (attr.GetType ().Name == "FlagsAttribute")
-                               bits = true;
-               }
-               return map;
-       }
-
-       protected static string GetNativeType (Type t)
-       {
-               string ut = t.Name;
-               if (t.IsEnum)
-                       ut = Enum.GetUnderlyingType (t).Name;
-               Type et = t.GetElementType ();
-               if (et != null && et.IsEnum)
-                       ut = Enum.GetUnderlyingType (et).Name;
-
-               string type = null;
-
-               switch (ut) {
-                       case "Boolean":       type = "int";             break;
-                       case "Byte":          type = "unsigned char";   break;
-                       case "SByte":         type = "signed char";     break;
-                       case "Int16":         type = "short";           break;
-                       case "UInt16":        type = "unsigned short";  break;
-                       case "Int32":         type = "int";             break;
-                       case "UInt32":        type = "unsigned int";    break;
-                       case "UInt32[]":      type = "unsigned int*";   break;
-                       case "Int64":         type = "gint64";          break;
-                       case "UInt64":        type = "guint64";         break;
-                       case "IntPtr":        type = "void*";           break;
-                       case "Byte[]":        type = "void*";           break;
-                       case "String":        type = "const char*";     break;
-                       case "StringBuilder": type = "char*";           break;
-                       case "Void":          type = "void";            break;
-                       case "HandleRef":     type = "void*";           break;
-               }
-               if (type != null)
-                       return string.Format ("{0}{1}", type,
-                                       t.IsByRef ? "*" : "");
-               return GetTypeName (t);
-       }
-
-       private static string GetTypeName (Type t)
-       {
-               if (t.Namespace.StartsWith ("System"))
-                       return "int /* warning: unknown mapping for type: " + t.Name + " */";
-               string ts = "struct " +
-                       MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*")
-                               .Replace ("[]", "*");
-               return ts;
-       }
-}
-
-class HeaderFileGenerator : FileGenerator {
-       StreamWriter sh;
-
-       public override void CreateFile (string assembly_name, string file_prefix)
-       {
-               sh = File.CreateText (file_prefix + ".h");
-               WriteHeader (sh, assembly_name);
-               sh.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_H");
-               sh.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_H\n");
-               sh.WriteLine ("#include <glib.h>\n");
-               sh.WriteLine ("G_BEGIN_DECLS\n");
-       }
-
-       public override void WriteType (Type t, string ns, string fn)
-       {
-               bool bits;
-               if (!CanMapType (t, out bits))
-                       return;
-               string etype = GetNativeType (t);
-
-               WriteLiteralValues (sh, t, fn);
-               sh.WriteLine ("int {1}_From{2} ({0} x, {0} *r);", etype, ns, t.Name);
-               sh.WriteLine ("int {1}_To{2} ({0} x, {0} *r);", etype, ns, t.Name);
-               sh.WriteLine ();
-       }
-
-       static void WriteLiteralValues (StreamWriter sh, Type t, string n)
-       {
-               object inst = Activator.CreateInstance (t);
-               FieldInfo[] fields = t.GetFields ();
-               Array.Sort (fields, MakeMap.MemberNameComparer);
-               foreach (FieldInfo fi in fields) {
-                       if (!fi.IsLiteral)
-                               continue;
-                       sh.WriteLine ("#define {0}_{1} 0x{2:x}", n, fi.Name, fi.GetValue (inst));
-               }
-       }
-
-       public override void CloseFile (string file_prefix)
-       {
-               sh.WriteLine ("G_END_DECLS\n");
-               sh.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_H */\n");
-               sh.Close ();
-       }
-}
-
-class SourceFileGenerator : FileGenerator {
-       StreamWriter sc;
-
-       public override void CreateFile (string assembly_name, string file_prefix)
-       {
-               sc = File.CreateText (file_prefix + ".c");
-               WriteHeader (sc, assembly_name);
-
-               if (file_prefix.IndexOf ("/") != -1)
-                       file_prefix = file_prefix.Substring (file_prefix.IndexOf ("/") + 1);
-               sc.WriteLine ("#include \"{0}.h\"", file_prefix);
-               sc.WriteLine ();
-       }
-
-       public override void WriteAssemblyAttributes (Assembly assembly)
-       {
-               object [] x = assembly.GetCustomAttributes (false);
-               Console.WriteLine ("Got: " + x.Length);
-               foreach (object aattr in assembly.GetCustomAttributes (false)) {
-                       Console.WriteLine ("Got: " + aattr.GetType ().Name);
-                       if (aattr.GetType ().Name == "HeaderAttribute"){
-                               WriteDefines (sc, aattr);
-                               WriteIncludes (sc, aattr);
-                       }
-               }
-       }
-
-       static void WriteDefines (TextWriter writer, object o)
-       {
-               PropertyInfo prop = o.GetType ().GetProperty ("Defines");
-               if (prop == null)
-                       throw new Exception ("Cannot find 'Defines' property");
-
-               MethodInfo method = prop.GetGetMethod ();
-               string [] defines = method.Invoke (o, null).ToString ().Split (',');
-               foreach (string def in defines) {
-                       writer.WriteLine ("#ifndef {0}", def);
-                       writer.WriteLine ("#define {0}", def);
-                       writer.WriteLine ("#endif /* ndef {0} */", def);
-               }
-       }
-
-       static void WriteIncludes (TextWriter writer, object o)
-       {
-               PropertyInfo prop = o.GetType ().GetProperty ("Includes");
-               if (prop == null)
-                       throw new Exception ("Cannot find 'Includes' property");
-
-               MethodInfo method = prop.GetGetMethod ();
-               string [] includes = method.Invoke (o, null).ToString ().Split (',');;
-               foreach (string inc in includes){
-                       if (inc.Length > 3 && 
-                                       string.CompareOrdinal (inc, 0, "ah:", 0, 3) == 0) {
-                               string i = inc.Substring (3);
-                               writer.WriteLine ("#ifdef HAVE_" + (i.ToUpper ().Replace ("/", "_").Replace (".", "_")));
-                               writer.WriteLine ("#include <{0}>", i);
-                               writer.WriteLine ("#endif");
-                       } else 
-                               writer.WriteLine ("#include <{0}>", inc);
-               }
-               writer.WriteLine ();
-       }
-
-       public override void WriteType (Type t, string ns, string fn)
-       {
-               bool bits;
-               if (!CanMapType (t, out bits))
-                       return;
-               string etype = GetNativeType (t);
-
-               WriteFromManagedType (t, ns, fn, etype, bits);
-               WriteToManagedType (t, ns, fn, etype, bits);
-       }
-
-       private void WriteFromManagedType (Type t, string ns, string fn, string etype, bool bits)
-       {
-               sc.WriteLine ("int {1}_From{2} ({0} x, {0} *r)", etype, ns, t.Name);
-               sc.WriteLine ("{");
-               sc.WriteLine ("\t*r = 0;");
-               // For many values, 0 is a valid value, but doesn't have it's own symbol.
-               // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
-               // Make 0 valid for all conversions.
-               sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
-               FieldInfo[] fields = t.GetFields ();
-               Array.Sort (fields, MakeMap.MemberNameComparer);
-               foreach (FieldInfo fi in fields) {
-                       if (!fi.IsLiteral)
-                               continue;
-                       if (Attribute.GetCustomAttribute (fi, 
-                               typeof(ObsoleteAttribute), false) != null) {
-                               sc.WriteLine ("\t/* {0}_{1} is obsolete; ignoring */", fn, fi.Name);
-                               continue;
-                       }
-                       if (bits)
-                               // properly handle case where [Flags] enumeration has helper
-                               // synonyms.  e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
-                               sc.WriteLine ("\tif ((x & {0}_{1}) == {0}_{1})", fn, fi.Name);
-                       else
-                               sc.WriteLine ("\tif (x == {0}_{1})", fn, fi.Name);
-                       sc.WriteLine ("#ifdef {0}", fi.Name);
-                       if (bits)
-                               sc.WriteLine ("\t\t*r |= {1};", fn, fi.Name);
-                       else
-                               sc.WriteLine ("\t\t{{*r = {1}; return 0;}}", fn, fi.Name);
-                       sc.WriteLine ("#else /* def {0} */\n\t\t{{errno = EINVAL; return -1;}}", fi.Name);
-                       sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
-               }
-               if (bits)
-                       sc.WriteLine ("\treturn 0;");
-               else
-                       sc.WriteLine ("\terrno = EINVAL; return -1;"); // return error if not matched
-               sc.WriteLine ("}\n");
-       }
-
-       private void WriteToManagedType (Type t, string ns, string fn, string etype, bool bits)
-       {
-               sc.WriteLine ("int {1}_To{2} ({0} x, {0} *r)", etype, ns, t.Name);
-               sc.WriteLine ("{");
-               sc.WriteLine ("\t*r = 0;", etype);
-               // For many values, 0 is a valid value, but doesn't have it's own symbol.
-               // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
-               // Make 0 valid for all conversions.
-               sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
-               FieldInfo[] fields = t.GetFields ();
-               Array.Sort (fields, MakeMap.MemberNameComparer);
-               foreach (FieldInfo fi in fields) {
-                       if (!fi.IsLiteral)
-                               continue;
-                       sc.WriteLine ("#ifdef {0}", fi.Name);
-                       if (bits)
-                               // properly handle case where [Flags] enumeration has helper
-                               // synonyms.  e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
-                               sc.WriteLine ("\tif ((x & {1}) == {1})\n\t\t*r |= {0}_{1};", fn, fi.Name);
-                       else
-                               sc.WriteLine ("\tif (x == {1})\n\t\t{{*r = {0}_{1}; return 0;}}", fn, fi.Name);
-                       sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
-               }
-               if (bits)
-                       sc.WriteLine ("\treturn 0;");
-               else
-                       sc.WriteLine ("\terrno = EINVAL; return -1;");
-               sc.WriteLine ("}\n");
-       }
-
-       public override void CloseFile (string file_prefix)
-       {
-               sc.Close ();
-       }
-}
-
-class ConvertFileGenerator : FileGenerator {
-       StreamWriter scs;
-
-       public override void CreateFile (string assembly_name, string file_prefix)
-       {
-               scs = File.CreateText (file_prefix + ".cs");
-               WriteHeader (scs, assembly_name, true);
-               scs.WriteLine ("using System;");
-               scs.WriteLine ("using System.Runtime.InteropServices;");
-               scs.WriteLine ("using Mono.Unix.Native;\n");
-               scs.WriteLine ("namespace Mono.Unix.Native {\n");
-               scs.WriteLine ("\t[CLSCompliant (false)]");
-               scs.WriteLine ("\tpublic sealed /* static */ partial class NativeConvert");
-               scs.WriteLine ("\t{");
-               scs.WriteLine ("\t\tprivate NativeConvert () {}\n");
-               scs.WriteLine ("\t\tprivate const string LIB = \"MonoPosixHelper\";\n");
-               scs.WriteLine ("\t\tprivate static void ThrowArgumentException (object value)");
-               scs.WriteLine ("\t\t{");
-               scs.WriteLine ("\t\t\tthrow new ArgumentOutOfRangeException (\"value\", value,");
-               scs.WriteLine ("\t\t\t\tLocale.GetText (\"Current platform doesn't support this value.\"));");
-               scs.WriteLine ("\t\t}\n");
-       }
-
-       public override void WriteType (Type t, string ns, string fn)
-       {
-               bool bits;
-               if (!CanMapType (t, out bits))
-                       return;
-
-               string mtype = Enum.GetUnderlyingType(t).Name;
-               ObsoleteAttribute oa = (ObsoleteAttribute) Attribute.GetCustomAttribute (t, 
-                                       typeof(ObsoleteAttribute), false);
-               string obsolete = "";
-               if (oa != null) {
-                       obsolete = string.Format ("[Obsolete (\"{0}\", {1})]\n\t\t",
-                                       oa.Message, oa.IsError ? "true" : "false");
-               }
-               scs.WriteLine ("\t\t{3}[DllImport (LIB, " + 
-                       "EntryPoint=\"{0}_From{1}\")]\n" +
-                       "\t\tprivate static extern int From{1} ({1} value, out {2} rval);\n",
-                       ns, t.Name, mtype, obsolete);
-               scs.WriteLine ("\t\t{3}public static bool TryFrom{1} ({1} value, out {2} rval)\n" +
-                       "\t\t{{\n" +
-                       "\t\t\treturn From{1} (value, out rval) == 0;\n" +
-                       "\t\t}}\n", ns, t.Name, mtype, obsolete);
-               scs.WriteLine ("\t\t{2}public static {0} From{1} ({1} value)", mtype, t.Name, obsolete);
-               scs.WriteLine ("\t\t{");
-               scs.WriteLine ("\t\t\t{0} rval;", mtype);
-               scs.WriteLine ("\t\t\tif (From{0} (value, out rval) == -1)\n" + 
-                               "\t\t\t\tThrowArgumentException (value);", t.Name);
-               scs.WriteLine ("\t\t\treturn rval;");
-               scs.WriteLine ("\t\t}\n");
-               scs.WriteLine ("\t\t{3}[DllImport (LIB, " + 
-                       "EntryPoint=\"{0}_To{1}\")]\n" +
-                       "\t\tprivate static extern int To{1} ({2} value, out {1} rval);\n",
-                       ns, t.Name, mtype, obsolete);
-               scs.WriteLine ("\t\t{2}public static bool TryTo{1} ({0} value, out {1} rval)\n" +
-                       "\t\t{{\n" +
-                       "\t\t\treturn To{1} (value, out rval) == 0;\n" +
-                       "\t\t}}\n", mtype, t.Name, obsolete);
-               scs.WriteLine ("\t\t{2}public static {1} To{1} ({0} value)", mtype, t.Name, obsolete);
-               scs.WriteLine ("\t\t{");
-               scs.WriteLine ("\t\t\t{0} rval;", t.Name);
-               scs.WriteLine ("\t\t\tif (To{0} (value, out rval) == -1)\n" + 
-                               "\t\t\t\tThrowArgumentException (value);", t.Name);
-               scs.WriteLine ("\t\t\treturn rval;");
-               scs.WriteLine ("\t\t}\n");
-       }
-
-       public override void CloseFile (string file_prefix)
-       {
-               scs.WriteLine ("\t}");
-               scs.WriteLine ("}\n");
-               scs.Close ();
-       }
-}
-
-class ConvertDocFileGenerator : FileGenerator {
-       StreamWriter scs;
-
-       public override void CreateFile (string assembly_name, string file_prefix)
-       {
-               scs = File.CreateText (file_prefix + ".xml");
-               scs.WriteLine ("    <!-- BEGIN GENERATED CONTENT");
-               WriteHeader (scs, assembly_name, true);
-               scs.WriteLine ("      -->");
-       }
-
-       public override void WriteType (Type t, string ns, string fn)
-       {
-               bool bits;
-               if (!CanMapType (t, out bits))
-                       return;
-
-               string type = GetCSharpType (t);
-               string mtype = Enum.GetUnderlyingType(t).FullName;
-               string member = t.Name;
-               string ftype = t.FullName;
-
-               string to_returns = "";
-               string to_remarks = "";
-               string to_exception = "";
-
-               if (bits) {
-                       to_returns = "<returns>An approximation of the equivalent managed value.</returns>";
-                       to_remarks = @"<para>The current conversion functions are unable to determine
-        if a value in a <c>[Flags]</c>-marked enumeration <i>does not</i> 
-        exist on the current platform.  As such, if <paramref name=""value"" /> 
-        contains a flag value which the current platform doesn't support, it 
-        will not be present in the managed value returned.</para>
-        <para>This should only be a problem if <paramref name=""value"" /> 
-        <i>was not</i> previously returned by 
-        <see cref=""M:Mono.Unix.Native.NativeConvert.From" + member + "\" />.</para>\n";
-               }
-               else {
-                       to_returns = "<returns>The equivalent managed value.</returns>";
-                       to_exception = @"
-        <exception cref=""T:System.ArgumentOutOfRangeException"">
-          <paramref name=""value"" /> has no equivalent managed value.
-        </exception>
-";
-               }
-               scs.WriteLine (@"
-    <Member MemberName=""TryFrom{1}"">
-      <MemberSignature Language=""C#"" Value=""public static bool TryFrom{1} ({0} value, out {2} rval);"" />
-      <MemberType>Method</MemberType>
-      <ReturnValue>
-        <ReturnType>System.Boolean</ReturnType>
-      </ReturnValue>
-      <Parameters>
-        <Parameter Name=""value"" Type=""{0}"" />
-        <Parameter Name=""rval"" Type=""{3}&amp;"" RefType=""out"" />
-      </Parameters>
-      <Docs>
-        <param name=""value"">The managed value to convert.</param>
-        <param name=""rval"">The OS-specific equivalent value.</param>
-        <summary>Converts a <see cref=""T:{0}"" /> 
-          enumeration value to an OS-specific value.</summary>
-        <returns><see langword=""true"" /> if the conversion was successful; 
-        otherwise, <see langword=""false"" />.</returns>
-        <remarks><para>This is an exception-safe alternative to 
-        <see cref=""M:Mono.Unix.Native.NativeConvert.From{1}"" />.</para>
-        <para>If successful, this method stores the OS-specific equivalent
-        value of <paramref name=""value"" /> into <paramref name=""rval"" />.
-        Otherwise, <paramref name=""rval"" /> will contain <c>0</c>.</para>
-        </remarks>
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.From{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.To{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryTo{1}"" />
-      </Docs>
-    </Member>
-    <Member MemberName=""From{1}"">
-      <MemberSignature Language=""C#"" Value=""public static {2} From{1} ({0} value);"" />
-      <MemberType>Method</MemberType>
-      <ReturnValue>
-        <ReturnType>{3}</ReturnType>
-      </ReturnValue>
-      <Parameters>
-        <Parameter Name=""value"" Type=""{0}"" />
-      </Parameters>
-      <Docs>
-        <param name=""value"">The managed value to convert.</param>
-        <summary>Converts a <see cref=""T:{0}"" /> 
-          to an OS-specific value.</summary>
-        <returns>The equivalent OS-specific value.</returns>
-        <exception cref=""T:System.ArgumentOutOfRangeException"">
-          <paramref name=""value"" /> has no equivalent OS-specific value.
-        </exception>
-        <remarks></remarks>
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.To{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryFrom{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryTo{1}"" />
-      </Docs>
-    </Member>
-    <Member MemberName=""TryTo{1}"">
-      <MemberSignature Language=""C#"" Value=""public static bool TryTo{1} ({2} value, out {0} rval);"" />
-      <MemberType>Method</MemberType>
-      <ReturnValue>
-        <ReturnType>System.Boolean</ReturnType>
-      </ReturnValue>
-      <Parameters>
-        <Parameter Name=""value"" Type=""{3}"" />
-        <Parameter Name=""rval"" Type=""{0}&amp;"" RefType=""out"" />
-      </Parameters>
-      <Docs>
-        <param name=""value"">The OS-specific value to convert.</param>
-        <param name=""rval"">The managed equivalent value</param>
-        <summary>Converts an OS-specific value to a 
-          <see cref=""T:{0}"" />.</summary>
-        <returns><see langword=""true"" /> if the conversion was successful; 
-        otherwise, <see langword=""false"" />.</returns>
-        <remarks><para>This is an exception-safe alternative to 
-        <see cref=""M:Mono.Unix.Native.NativeConvert.To{1}"" />.</para>
-        <para>If successful, this method stores the managed equivalent
-        value of <paramref name=""value"" /> into <paramref name=""rval"" />.
-        Otherwise, <paramref name=""rval"" /> will contain a <c>0</c>
-        cast to a <see cref=""T:{0}"" />.</para>
-        " + to_remarks + 
-@"        </remarks>
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.From{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.To{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryFrom{1}"" />
-      </Docs>
-    </Member>
-    <Member MemberName=""To{1}"">
-      <MemberSignature Language=""C#"" Value=""public static {0} To{1} ({2} value);"" />
-      <MemberType>Method</MemberType>
-      <ReturnValue>
-        <ReturnType>{0}</ReturnType>
-      </ReturnValue>
-      <Parameters>
-        <Parameter Name=""value"" Type=""{3}"" />
-      </Parameters>
-      <Docs>
-        <param name=""value"">The OS-specific value to convert.</param>
-        <summary>Converts an OS-specific value to a 
-          <see cref=""T:{0}"" />.</summary>
-                                       " + to_returns + "\n" + 
-                       to_exception + 
-@"        <remarks>
-        " + to_remarks + @"
-        </remarks>
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.From{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryFrom{1}"" />
-        <altmember cref=""M:Mono.Unix.Native.NativeConvert.TryTo{1}"" />
-      </Docs>
-    </Member>
-", ftype, member, type, mtype
-               );
-       }
-
-       private string GetCSharpType (Type t)
-       {
-               string ut = t.Name;
-               if (t.IsEnum)
-                       ut = Enum.GetUnderlyingType (t).Name;
-               Type et = t.GetElementType ();
-               if (et != null && et.IsEnum)
-                       ut = Enum.GetUnderlyingType (et).Name;
-
-               string type = null;
-
-               switch (ut) {
-                       case "Boolean":       type = "bool";    break;
-                       case "Byte":          type = "byte";    break;
-                       case "SByte":         type = "sbyte";   break;
-                       case "Int16":         type = "short";   break;
-                       case "UInt16":        type = "ushort";  break;
-                       case "Int32":         type = "int";     break;
-                       case "UInt32":        type = "uint";    break;
-                       case "Int64":         type = "long";    break;
-                       case "UInt64":        type = "ulong";   break;
-               }
-
-               return type;
-       }
-
-       public override void CloseFile (string file_prefix)
-       {
-               scs.WriteLine ("    <!-- END GENERATED CONTENT -->");
-               scs.Close ();
-       }
-}
-
-class MphPrototypeFileGenerator : FileGenerator {
-       StreamWriter icall;
-       Hashtable methods = new Hashtable ();
-       Hashtable structs = new Hashtable ();
-
-       public override void CreateFile (string assembly_name, string file_prefix)
-       {
-               icall = File.CreateText (file_prefix + "-icalls.h");
-               WriteHeader (icall, assembly_name);
-               icall.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H");
-               icall.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_ICALLS_H\n");
-               icall.WriteLine ("#include <glib.h>\n");
-               icall.WriteLine ("G_BEGIN_DECLS\n");
-
-               // Kill warning about unused method
-               DumpTypeInfo (null);
-       }
-
-       public override void WriteType (Type t, string ns, string fn)
-       {
-               BindingFlags bf = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
-               foreach (MethodInfo m in t.GetMethods (bf)) {
-                       if ((m.Attributes & MethodAttributes.PinvokeImpl) == 0)
-                               continue;
-                       DllImportAttribute dia = GetDllImportInfo (m);
-                       if (dia == null) {
-                               Console.WriteLine ("Unable to emit native prototype for P/Invoke " + 
-                                               "method: {0}", m);
-                               continue;
-                       }
-                       // we shouldn't declare prototypes for POSIX, etc. functions.
-                       if (dia.Value != "MonoPosixHelper" || IsOnExcludeList (dia.EntryPoint))
-                               continue;
-                       methods [dia.EntryPoint] = m;
-                       RecordStructs (m);
-               }
-       }
-
-       private static DllImportAttribute GetDllImportInfo (MethodInfo method)
-       {
-               // .NET 2.0 synthesizes pseudo-attributes such as DllImport
-               DllImportAttribute dia = (DllImportAttribute) Attribute.GetCustomAttribute (method, 
-                                       typeof(DllImportAttribute), false);
-               if (dia != null)
-                       return dia;
-
-               // We're not on .NET 2.0; assume we're on Mono and use some internal
-               // methods...
-               Type MonoMethod = Type.GetType ("System.Reflection.MonoMethod", false);
-               if (MonoMethod == null) {
-                       Console.WriteLine ("cannot find MonoMethod");
-                       return null;
-               }
-               MethodInfo GetDllImportAttribute = 
-                       MonoMethod.GetMethod ("GetDllImportAttribute", 
-                                       BindingFlags.Static | BindingFlags.NonPublic);
-               if (GetDllImportAttribute == null) {
-                       Console.WriteLine ("cannot find GetDllImportAttribute");
-                       return null;
-               }
-               IntPtr mhandle = method.MethodHandle.Value;
-               return (DllImportAttribute) GetDllImportAttribute.Invoke (null, 
-                               new object[]{mhandle});
-       }
-
-       private static string[] ExcludeList = new string[]{
-               "Mono_Posix_Stdlib_snprintf",
-       };
-
-       private bool IsOnExcludeList (string method)
-       {
-               int idx = Array.BinarySearch (ExcludeList, method);
-               return (idx >= 0 && idx < ExcludeList.Length) ? true : false;
-       }
-
-       private void RecordStructs (MethodInfo method)
-       {
-               ParameterInfo[] parameters = method.GetParameters ();
-               foreach (ParameterInfo pi in parameters) {
-                       string s = GetNativeType (pi.ParameterType);
-                       if (s.StartsWith ("struct"))
-                               structs [s] = s;
-               }
-       }
-
-       public override void CloseFile (string file_prefix)
-       {
-               icall.WriteLine ("/*\n * Structure Declarations\n */");
-               foreach (string s in Sort (structs.Keys))
-                       icall.WriteLine ("{0};", s.Replace ("*", ""));
-
-               icall.WriteLine ();
-
-               icall.WriteLine ("/*\n * Function Declarations\n */");
-               foreach (string method in Sort (methods.Keys)) {
-                       WriteMethodDeclaration ((MethodInfo) methods [method], method);
-               }
-
-               icall.WriteLine ("\nG_END_DECLS\n");
-               icall.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H */\n");
-               icall.Close ();
-       }
-
-       private static IEnumerable Sort (ICollection c)
-       {
-               ArrayList al = new ArrayList (c);
-               al.Sort (MakeMap.OrdinalStringComparer);
-               return al;
-       }
-
-       private void WriteMethodDeclaration (MethodInfo method, string entryPoint)
-       {
-               icall.Write ("{0} ", GetNativeType (method.ReturnType));
-               icall.Write ("{0} ", entryPoint);
-               ParameterInfo[] parameters = method.GetParameters();
-               if (parameters.Length == 0) {
-                       icall.WriteLine ("(void);");
-                       return;
-               }
-               if (parameters.Length > 0) {
-                       icall.Write ("(");
-                       WriteParameterDeclaration (parameters [0]);
-               }
-               for (int i = 1; i < parameters.Length; ++i) {
-                       icall.Write (", ");
-                       WriteParameterDeclaration (parameters [i]);
-               }
-               icall.WriteLine (");");
-       }
-
-       private void DumpTypeInfo (Type t)
-       {
-               if (t == null)
-                       return;
-
-               icall.WriteLine ("\t\t/* Type Info for " + t.FullName + ":");
-               foreach (MemberInfo mi in typeof(Type).GetMembers()) {
-                       icall.WriteLine ("\t\t\t{0}={1}", mi.Name, GetMemberValue (mi, t));
-               }
-               icall.WriteLine ("\t\t */");
-       }
-
-       private static string GetMemberValue (MemberInfo mi, Type t)
-       {
-               try {
-               switch (mi.MemberType) {
-                       case MemberTypes.Constructor:
-                       case MemberTypes.Method: {
-                               MethodBase b = (MethodBase) mi;
-                               if (b.GetParameters().Length == 0)
-                                       return b.Invoke (t, new object[]{}).ToString();
-                               return "<<cannot invoke>>";
-                       }
-                       case MemberTypes.Field:
-                               return ((FieldInfo) mi).GetValue (t).ToString ();
-                       case MemberTypes.Property: {
-                               PropertyInfo pi = (PropertyInfo) mi;
-                               if (!pi.CanRead)
-                                       return "<<cannot read>>";
-                               return pi.GetValue (t, null).ToString ();
-                       }
-                       default:
-                               return "<<unknown value>>";
-               }
-               }
-               catch (Exception e) {
-                       return "<<exception reading member: " + e.Message + ">>";
-               }
-       }
-
-       private void WriteParameterDeclaration (ParameterInfo pi)
-       {
-               // DumpTypeInfo (pi.ParameterType);
-               icall.Write ("{0} {1}", GetNativeType (pi.ParameterType), pi.Name);
-       }
-}
-
-// vim: noexpandtab
index 7c51ee6daac1ce2c0f92cf706ea8b4c7f37dda1c..1b60fc20990cb601b66e5215642d1b6f6fd26e0d 100644 (file)
@@ -1,3 +1,7 @@
+2006-10-24  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * MapAttribute.cs: Moved to ../Mono.Unix.Native/MapAttribute.cs.
+
 2006-08-21  Jonathan Pryor  <jonpryor@vt.edu>
 
        * UnixStream.cs: .Close() shouldn't close(2) the fd unless owner==true;
diff --git a/mcs/class/Mono.Posix/Mono.Unix/MapAttribute.cs b/mcs/class/Mono.Posix/Mono.Unix/MapAttribute.cs
deleted file mode 100644 (file)
index 623ffc7..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// MapAttribute.cs
-//
-// Author:
-//   Miguel de Icaza (miguel@gnome.org)
-//
-// (C) Novell, Inc.  
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-namespace Mono.Unix {
-
-       [AttributeUsage (AttributeTargets.Enum)]
-       internal class MapAttribute : Attribute {
-       }
-}