1create-native-map(1)        General Commands Manual       create-native-map(1)
2
3
4

NAME

6       create-native-map - C/C# Mapping Creator
7

SYNOPSIS

9       create-native-map [OPTIONS]* ASSEMBLY-FILE-NAME OUPUT-PREFIX
10

OPTIONS

12       --autoconf-header=HEADER
13              HEADER  is  a header file name in the syntax typically used with
14              the C #include statement, e.g.  #include <stdio.h>  or  #include
15              "local.h" .
16
17              An  Autoconf-formatted macro is generated from the include name,
18              and a #include directive is wrapped within a  #ifdef  block  for
19              the Autoconf macro within the generated .c file.
20
21              For  example,  --autoconf-header=<stdio.h>  would  generate  the
22              code:
23
24                   #ifndef HAVE_STDIO_H
25                   #include <stdio.h>
26                   #endif /* ndef HAVE_STDIO_H */
27
28
29       --autoconf-member=MEMBER
30              Specify that any access to MEMBER should  be  wrapped  within  a
31              #ifdef  HAVE_MEMBER block.  MEMBER can be either a field-name or
32              a class-name .  field-name combination.
33
34              For example, given the C# declaration:
35
36                   [Mono.Unix.Native.Map ("struct dirent")]
37                   struct Dirent {
38                        public long d_off;
39                   }
40
41              then --autoconf-member=d_off would generate the code similar to:
42
43                   int
44                   ToDirent (struct dirent *from, struct Dirent *to)
45                   {
46                   #ifdef HAVE_STRUCT_DIRENT_D_OFF
47                        to->d_off = from->d_off;
48                   #endif /* ndef HAVE_STRUCT_DIRENT_D_OFF */
49                   }
50
51
52       --exclude-native-symbol=SYMBOL
53              SYMBOL is a [DllImport] -marked method that should  not  have  a
54              prototype generated for it.
55
56       --impl-header=HEADER
57              Insert  a  #include  statement  within the generated .c file for
58              HEADER .
59
60              For example, --impl-header=<stdlib.h> generates
61
62                   #include <stdlib.h>
63
64
65       --impl-macro=MACRO
66              Insert a #define statement within the generated .c file.   MACRO
67              can contain a = to separate the macro name from the macro value.
68
69              For example, --impl-macro=FOO=42 generates
70
71                   #define FOO 42
72
73
74       --library=LIBRARY
75              Create  prototypes  for [DllImport] -marked methods which refer‐
76              ence the native library LIBRARY into the generated .h file.
77
78       --public-header=HEADER
79              Insert a #include statement within the  generated  .h  file  for
80              HEADER .
81
82              For example, --public-header=<stdlib.h> generates
83
84                   #include <stdlib.h>
85
86
87       --public-macro=MACRO
88              Insert  a #define statement within the generated .h file.  MACRO
89              can contain a = to separate the macro name from the macro value.
90
91              For example, --public-macro=FOO=42 generates
92
93                   #define FOO 42
94
95
96       --rename-member=FROM=TO
97              This is used when FROM is a C macro, and thus must be altered in
98              order  to  be used sanely.  All generated references to the man‐
99              aged representation will use TO instead of FROM .
100
101              For example, given the C# declaration:
102
103                   [Mono.Unix.Native.Map ("struct stat")]
104                   struct Stat {
105                        public long st_atime;
106                   }
107
108              and the argument --rename-member=st_atime=st_atime_ , the gener‐
109              ated .h file would contain:
110
111                   struct Stat {
112                        gint64 st_atime_;
113                   };
114
115              (note the altered field name), while the generated .c file would
116              contain:
117
118                   ToStat (struct stat *from, struct Stat *to)
119                   {
120                        to->st_atime_ = from->st_atime;
121                   }
122
123
124       --rename-namespace=FROM=TO
125              By default, the C "namespace" (symbol prefix) is the  C#  names‐
126              pace; types within the C# namespace Mono.Unix.Native would be in
127              the C "namespace" Mono_Unix_Native .  Use --rename-namespace  to
128              modify       the       default,       e.g.       --rename-names‐
129              pace=Mono.Unix.Native=Mono_Posix .
130

DESCRIPTION

132       create-native-map is a program for a specific  scenario:  keeping  code
133       which  is  tightly  coupled  between  C and C# in sync with each other,
134       based upon the C# types.
135
136       Platform Invoke is only useful if the  managed  code  knows  the  exact
137       types  and layout of all unmanaged structures it uses.  This is usually
138       the case on Windows, but it is not the  case  on  Unix.   For  example,
139       struct  stat makes use of types with sizes that will vary from platform
140       to platform (or even based on the compiler macros defined!).  For exam‐
141       ple,  off_t  is usually a signed 32-bit integer on ILP32 platforms, but
142       may be a signed 64-bit integer on LP64 platforms, but  may  also  be  a
143       64-bit signed integer on ILP32 platforms if the _FILE_OFFSET_BITS macro
144       has the value 64.  In short, everything is flexible  within  Unix,  and
145       managed code can't deal with such flexibility.
146
147       Thus, the niche for create-native-map : assume a fixed ABI that managed
148       code can target, and generate code to "thunk" the  managed  representa‐
149       tions  to  the  corresponding native representations.  This needs to be
150       done for everything that can vary between platforms and compiler flags,
151       from  enumeration  values ( SIGBUS has the value 10 on FreeBSD but 7 on
152       Linux) to structure members (how big is off_t ?).
153
154       create-native-map will inspect ASSEMBLY-FILE-NAME and output  the  fol‐
155       lowing files:
156
157              OUTPUT-PREFIX.h
158                     Contains enumeration values, class and structure declara‐
159                     tions, delegate  declarations,  and  [DllImport]  -marked
160                     methods (from the library specified by --library ) within
161                     the assembly ASSEMBLY-FILE-NAME .
162
163              OUTPUT-PREFIX.c
164                     Contains the implementation of enumeration and  structure
165                     conversion functions.
166
167              OUTPUT-PREFIX.cs
168                     Contains a partial class NativeConvert containing enumer‐
169                     ation translation methods.
170
171              OUTPUT-PREFIX.xml
172                     Generates ECMA XML documentation stubs for  the  enumera‐
173                     tion translation methods in OUTPUT-PREFIX.cs .
174
175       create-native-map  primarily  looks  for MapAttribute -decorated types,
176       and makes use of two MapAttribute properties:
177
178              NativeType
179                     Contains  the  corresponding  C  type.   Only  useful  if
180                     applied to classes, structures, and fields.
181
182              SuppressFlags
183                     When  specified  on  an  enumeration  member of a [Flags]
184                     -decorated enumeration type,  disables  the  normal  code
185                     generator support for bit-masking enumeration types.
186
187                     This  is  useful when bitmask and non-bitmask information
188                     is stored within the  same  type,  and  bitmask  checking
189                     shouldn't  be  used for the non-bitmask values.  Example:
190                     Mono.Unix.Native.FilePermissions.S_IFREG , which is not a
191                     bitmask  value, while most of FilePermissions consists of
192                     bitmask values (  FilePermissions.S_IRUSR  ,  FilePermis‐
193                     sions.S_IWUSR , etc.).
194
195       The  MapAttribute  attribute  can  be specified on classes, structures,
196       delegates, fields, and enumerations.
197
198       Delegates
199              Code   generation   for    delegates    ignores    the    MapAt‐
200              tribute.NativeType  property,  and  generates a function pointer
201              typedef that best matches the delegate declaration into  the  .h
202              file.
203
204              For example,
205
206                   namespace Foo {
207                        [Map]
208                        delegate string MyCallback (string s);
209                   }
210
211              generates the typedef :
212
213                   typedef char* (*Foo_MyCallback) (const char *s);
214
215
216       Classes and Structures
217              A  [Map]  -decorated  class  or structure will get a C structure
218              declaration within the .h file:
219
220                   [Map]
221                   struct Foo {
222                        public int i;
223                   }
224
225              becomes
226
227                   struct Foo {
228                        public int i;
229                   };
230
231              If the MapAttribute.NativeType property is set, then  conversion
232              functions will be declared within the .h file and created within
233              the .c file:
234
235                   namespace Foo {
236                        [Map ("struct stat")]
237                        struct Stat {
238                             public uint st_uid;
239                        }
240                   }
241
242              becomes
243
244                   /* The .h file */
245                   struct Foo_Stat {
246                        unsigned int st_uid;
247                   };
248                   int
249                   Foo_FromStat (struct Foo_Stat *from, struct stat *to);
250                   int
251                   Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to);
252
253                   /* The .c file */
254                   int
255                   Foo_FromStat (struct Foo_Stat *from, struct stat *to)
256                   {
257                        memset (to, 0, sizeof(*to);
258                        to->st_uid = from->st_uid;
259                        return 0;
260                   }
261
262                   int
263                   Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to)
264                   {
265                        memset (to, 0, sizeof(*to);
266                        to->st_uid = from->st_uid;
267                        return 0;
268                   }
269
270
271       Fields If a field (1) has the MapAttribute attribute, and (2)  has  the
272              MapAttribute.NativeType  property set, then the specified native
273              type will be used for overflow checking.  For example:
274
275                   namespace Foo {
276                        [Map ("struct stat")]
277                        struct Stat {
278                             [Map ("off_t")] public long st_size;
279                        }
280                   }
281
282              generates
283
284                   /* The .h file */
285                   struct Foo_Stat {
286                        gint64 st_size;
287                   };
288                   int
289                   Foo_FromStat (struct Foo_Stat *from, struct stat *to);
290                   int
291                   Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to);
292
293                   /* The .c file */
294                   int
295                   Foo_FromStat (struct Foo_Stat *from, struct stat *to)
296                   {
297                        _cnm_return_val_if_overflow (off_t, from->st_size, -1);
298
299                        memset (to, 0, sizeof(*to);
300                        to->st_size = from->st_size;
301                        return 0;
302                   }
303
304                   int
305                   Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to)
306                   {
307                        _cnm_return_val_if_overflow (gint64, from->st_size, -1);
308
309                        memset (to, 0, sizeof(*to);
310                        to->st_size = from->st_size;
311                        return 0;
312                   }
313
314              This is useful for better error checking within  the  conversion
315              functions.   MapAttribute.NativeType  is  required  for  this as
316              there is no other way to know what the native type  is  (without
317              parsing the system header files...).
318
319       Enumerations
320              Generates  a  C  enumeration  and macros for each of the members
321              within the enumeration.  To and From functions are also declared
322              in the .h file and implemented in the .c file.
323
324              For example,
325
326                   namespace Foo {
327                        [Map]
328                        enum Errno {
329                             EINVAL
330                        }
331                   }
332
333              would generate the following in the .h file:
334
335                   enum Foo_Errno {
336                        Foo_Errno_EINVAL          = 0,
337                        #define Foo_Errno_EINVAL    Foo_Errno_EINVAL
338                   };
339                   int Foo_FromErrno (int from, int *to);
340                   int Foo_ToErrno (int from, int *to);
341
342              and generates the following in the the .c file:
343
344                   int
345                   Foo_FromErrno (int from, int *to)
346                   {
347                        *to = 0;
348                        if (from == Foo_Errno_EPERM)
349                   #ifdef EINVAL
350                             {*to = EINVAL;}
351                   #else
352                             {errno = EINVAL; return -1;}
353                   #endif
354                        return 0;
355                   }
356
357                   int
358                   Foo_ToErrno (int from, int *to)
359                   {
360                        *to = 0;
361                   #ifdef EINVAL
362                        if (from == EINVAL)
363                             {*to = Foo_Errno_EPERM; return 0;}
364                   #endif
365                        return -1;
366                   }
367
368              Different  code  will  be  generated  if  the  managed enum is a
369              [Flags] -decorated enumeration (to account for  bitwise  flags),
370              but this is the basic idea.
371

MAILING LISTS

373       Visit    http://lists.ximian.com/mailman/listinfo/mono-devel-list   for
374       details.
375

WEB SITE

377       Visit http://www.mono-project.com for details
378
379
380
381                                                          create-native-map(1)
Impressum