Project

General

Profile

Feature #5992 ยป dl-intrinsic-types.diff

nobu (Nobuyoshi Nakada), 02/10/2012 01:50 AM

View differences:

w/ext/dl/dl.c
17 17
ID rbdl_id_cdecl;
18 18
ID rbdl_id_stdcall;
19 19

  
20
#ifndef DLTYPE_SSIZE_T
21
# if SIZEOF_SIZE_T == SIZEOF_INT
22
#   define DLTYPE_SSIZE_T DLTYPE_INT
23
# elif SIZEOF_SIZE_T == SIZEOF_LONG
24
#   define DLTYPE_SSIZE_T DLTYPE_LONG
25
# elif defined HAVE_LONG_LONG && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
26
#   define DLTYPE_SSIZE_T DLTYPE_LONG_LONG
27
# endif
28
#endif
29
#define DLTYPE_SIZE_T (SIGNEDNESS_OF_SIZE_T*DLTYPE_SSIZE_T)
30

  
31
#ifndef DLTYPE_PTRDIFF_T
32
# if SIZEOF_PTRDIFF_T == SIZEOF_INT
33
#   define DLTYPE_PTRDIFF_T DLTYPE_INT
34
# elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
35
#   define DLTYPE_PTRDIFF_T DLTYPE_LONG
36
# elif defined HAVE_LONG_LONG && SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
37
#   define DLTYPE_PTRDIFF_T DLTYPE_LONG_LONG
38
# endif
39
#endif
40

  
41
#ifndef DLTYPE_INTPTR_T
42
# if SIZEOF_INTPTR_T == SIZEOF_INT
43
#   define DLTYPE_INTPTR_T DLTYPE_INT
44
# elif SIZEOF_INTPTR_T == SIZEOF_LONG
45
#   define DLTYPE_INTPTR_T DLTYPE_LONG
46
# elif defined HAVE_LONG_LONG && SIZEOF_INTPTR_T == SIZEOF_LONG_LONG
47
#   define DLTYPE_INTPTR_T DLTYPE_LONG_LONG
48
# endif
49
#endif
50
#define DLTYPE_UINTPTR_T (-DLTYPE_INTPTR_T)
51

  
20 52
VALUE
21 53
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
22 54
{
......
271 303
     */
272 304
    rb_define_const(rb_mDL, "TYPE_DOUBLE",  INT2NUM(DLTYPE_DOUBLE));
273 305

  
306
    /* Document-const: TYPE_SIZE_T
307
     *
308
     * DL::CFunc type - size_t
309
     */
310
    rb_define_const(rb_mDL, "TYPE_SIZE_T",  INT2NUM(DLTYPE_SIZE_T));
311

  
312
    /* Document-const: TYPE_SSIZE_T
313
     *
314
     * DL::CFunc type - ssize_t
315
     */
316
    rb_define_const(rb_mDL, "TYPE_SSIZE_T", INT2NUM(DLTYPE_SSIZE_T));
317

  
318
    /* Document-const: TYPE_PTRDIFF_T
319
     *
320
     * DL::CFunc type - ptrdiff_t
321
     */
322
    rb_define_const(rb_mDL, "TYPE_PTRDIFF_T", INT2NUM(DLTYPE_PTRDIFF_T));
323

  
324
    /* Document-const: TYPE_INTPTR_T
325
     *
326
     * DL::CFunc type - intptr_t
327
     */
328
    rb_define_const(rb_mDL, "TYPE_INTPTR_T", INT2NUM(DLTYPE_INTPTR_T));
329

  
330
    /* Document-const: TYPE_UINTPTR_T
331
     *
332
     * DL::CFunc type - uintptr_t
333
     */
334
    rb_define_const(rb_mDL, "TYPE_UINTPTR_T", INT2NUM(DLTYPE_UINTPTR_T));
335

  
274 336
    /* Document-const: ALIGN_VOIDP
275 337
     *
276 338
     * The alignment size of a void*
......
321 383
     */
322 384
    rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
323 385

  
386
    /* Document-const: ALIGN_SIZE_T
387
     *
388
     * The alignment size of a size_t
389
     */
390
    rb_define_const(rb_mDL, "ALIGN_SIZE_T", INT2NUM(ALIGN_OF(size_t)));
391

  
392
    /* Document-const: ALIGN_SSIZE_T
393
     *
394
     * The alignment size of a ssize_t
395
     */
396
    rb_define_const(rb_mDL, "ALIGN_SSIZE_T", INT2NUM(ALIGN_OF(size_t))); /* same as size_t */
397

  
398
    /* Document-const: ALIGN_PTRDIFF_T
399
     *
400
     * The alignment size of a ptrdiff_t
401
     */
402
    rb_define_const(rb_mDL, "ALIGN_PTRDIFF_T", INT2NUM(ALIGN_OF(ptrdiff_t)));
403

  
404
    /* Document-const: ALIGN_INTPTR_T
405
     *
406
     * The alignment size of a intptr_t
407
     */
408
    rb_define_const(rb_mDL, "ALIGN_INTPTR_T", INT2NUM(ALIGN_OF(intptr_t)));
409

  
410
    /* Document-const: ALIGN_UINTPTR_T
411
     *
412
     * The alignment size of a uintptr_t
413
     */
414
    rb_define_const(rb_mDL, "ALIGN_UINTPTR_T", INT2NUM(ALIGN_OF(uintptr_t)));
415

  
324 416
    /* Document-const: SIZEOF_VOIDP
325 417
     *
326 418
     * size of a void*
......
371 463
     */
372 464
    rb_define_const(rb_mDL, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));
373 465

  
466
    /* Document-const: SIZEOF_SIZE_T
467
     *
468
     * size of a size_t
469
     */
470
    rb_define_const(rb_mDL, "SIZEOF_SIZE_T",  INT2NUM(sizeof(size_t)));
471

  
472
    /* Document-const: SIZEOF_SSIZE_T
473
     *
474
     * size of a ssize_t
475
     */
476
    rb_define_const(rb_mDL, "SIZEOF_SSIZE_T",  INT2NUM(sizeof(size_t))); /* same as size_t */
477

  
478
    /* Document-const: SIZEOF_PTRDIFF_T
479
     *
480
     * size of a ptrdiff_t
481
     */
482
    rb_define_const(rb_mDL, "SIZEOF_PTRDIFF_T",  INT2NUM(sizeof(ptrdiff_t)));
483

  
484
    /* Document-const: SIZEOF_INTPTR_T
485
     *
486
     * size of a intptr_t
487
     */
488
    rb_define_const(rb_mDL, "SIZEOF_INTPTR_T",  INT2NUM(sizeof(intptr_t)));
489

  
490
    /* Document-const: SIZEOF_UINTPTR_T
491
     *
492
     * size of a intptr_t
493
     */
494
    rb_define_const(rb_mDL, "SIZEOF_UINTPTR_T",  INT2NUM(sizeof(uintptr_t)));
495

  
374 496
    rb_define_module_function(rb_mDL, "dlwrap", rb_dl_value2ptr, 1);
375 497
    rb_define_module_function(rb_mDL, "dlunwrap", rb_dl_ptr2value, 1);
376 498

  
w/ext/dl/extconf.rb
25 25
end
26 26

  
27 27
if check
28
  config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h")))
29
  types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil}
30
  types.each do |type, signed|
31
    if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
32
      if size = $2 and size != 'VOIDP'
33
        size = types.fetch(size) {size}
34
        $defs << format("-DDLTYPE_%s=DLTYPE_%s", signed||type, size)
35
      end
36
      if signed
37
        check_signedness(type.downcase, "stddef.h")
38
      end
39
    end
40
  end
28 41
  $defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
29 42
  create_makefile("dl")
30 43
end
w/ext/dl/lib/dl/cparser.rb
95 95
        return TYPE_FLOAT
96 96
      when "double"
97 97
        return TYPE_DOUBLE
98
      when "size_t"
99
        return TYPE_SIZE_T
100
      when "ssize_t"
101
        return TYPE_SSIZE_T
102
      when "ptrdiff_t"
103
        return TYPE_PTRDIFF_T
104
      when "intptr_t"
105
        return TYPE_INTPTR_T
106
      when "uintptr_t"
107
        return TYPE_UINTPTR_T
98 108
      when /\*/, /\[\s*\]/
99 109
        return TYPE_VOIDP
100 110
      else
w/ext/dl/lib/dl/types.rb
40 40
        typealias "UINT", "unsigned int"
41 41
        typealias "ULONG", "unsigned long"
42 42
        typealias "UCHAR", "unsigned char"
43
        if [nil].pack('p').bytesize == 8
44
          typealias "HANDLE", "unsigned long long"
45
        else
46
          typealias "HANDLE", "unsigned long"
47
        end
43
        typealias "HANDLE", "uintptr_t"
48 44
        typealias "PHANDLE", "void*"
49 45
        typealias "PVOID", "void*"
50 46
        typealias "LPCSTR", "char*"
w/ext/fiddle/extconf.rb
19 19

  
20 20
have_header 'sys/mman.h'
21 21

  
22
config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h")))
23
types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil}
24
types.each do |type, signed|
25
  if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
26
    if size = $2 and size != 'VOIDP'
27
      size = types.fetch(size) {size}
28
      $defs << format("-TYPE_%s=TYPE_%s", signed||type, size)
29
    end
30
    if signed
31
      check_signedness(type.downcase, "stddef.h")
32
    end
33
  end
34
end
35

  
22 36
create_makefile 'fiddle'
23 37

  
24 38
# :startdoc:
w/ext/fiddle/fiddle.c
2 2

  
3 3
VALUE mFiddle;
4 4

  
5
#ifndef TYPE_SSIZE_T
6
# if SIZEOF_SIZE_T == SIZEOF_INT
7
#   define TYPE_SSIZE_T TYPE_INT
8
# elif SIZEOF_SIZE_T == SIZEOF_LONG
9
#   define TYPE_SSIZE_T TYPE_LONG
10
# elif defined HAVE_LONG_LONG && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
11
#   define TYPE_SSIZE_T TYPE_LONG_LONG
12
# endif
13
#endif
14
#define TYPE_SIZE_T (SIGNEDNESS_OF_SIZE_T*TYPE_SSIZE_T)
15

  
16
#ifndef TYPE_PTRDIFF_T
17
# if SIZEOF_PTRDIFF_T == SIZEOF_INT
18
#   define TYPE_PTRDIFF_T TYPE_INT
19
# elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
20
#   define TYPE_PTRDIFF_T TYPE_LONG
21
# elif defined HAVE_LONG_LONG && SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
22
#   define TYPE_PTRDIFF_T TYPE_LONG_LONG
23
# endif
24
#endif
25

  
26
#ifndef TYPE_INTPTR_T
27
# if SIZEOF_INTPTR_T == SIZEOF_INT
28
#   define TYPE_INTPTR_T TYPE_INT
29
# elif SIZEOF_INTPTR_T == SIZEOF_LONG
30
#   define TYPE_INTPTR_T TYPE_LONG
31
# elif defined HAVE_LONG_LONG && SIZEOF_INTPTR_T == SIZEOF_LONG_LONG
32
#   define TYPE_INTPTR_T TYPE_LONG_LONG
33
# endif
34
#endif
35
#define TYPE_UINTPTR_T (-TYPE_INTPTR_T)
36

  
5 37
void
6 38
Init_fiddle(void)
7 39
{
......
71 103
     */
72 104
    rb_define_const(mFiddle, "TYPE_DOUBLE",    INT2NUM(TYPE_DOUBLE));
73 105

  
106
    /* Document-const: TYPE_SSIZE_T
107
     *
108
     * C type - ssize_t
109
     */
110
    rb_define_const(mFiddle, "TYPE_SSIZE_T",   INT2NUM(TYPE_SSIZE_T));
111

  
112
    /* Document-const: TYPE_PTRDIFF_T
113
     *
114
     * C type - ptrdiff_t
115
     */
116
    rb_define_const(mFiddle, "TYPE_PTRDIFF_T", INT2NUM(TYPE_PTRDIFF_T));
117

  
118
    /* Document-const: TYPE_INTPTR_T
119
     *
120
     * C type - intptr_t
121
     */
122
    rb_define_const(mFiddle, "TYPE_INTPTR_T",  INT2NUM(TYPE_INTPTR_T));
123

  
74 124
    /* Document-const: WINDOWS
75 125
     *
76 126
     * Returns a boolean regarding whether the host is WIN32
w/test/ruby/memory_status.rb
22 22
      extend DL::Importer
23 23
      dlload "kernel32.dll", "psapi.dll"
24 24
      include DL::Win32Types
25
      if [nil].pack('p').bytesize == 8
26
        typealias "SIZE_T", "DWORD64"
27
      else
28
        typealias "SIZE_T", "DWORD32"
29
      end
25
      typealias "SIZE_T", "size_t"
30 26

  
31 27
      PROCESS_MEMORY_COUNTERS = struct [
32 28
        "DWORD  cb",