ffi 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

data/Rakefile CHANGED
@@ -31,7 +31,7 @@ PROJ.name = 'ffi'
31
31
  PROJ.authors = 'Wayne Meissner'
32
32
  PROJ.email = 'wmeissner@gmail.com'
33
33
  PROJ.url = 'http://kenai.com/projects/ruby-ffi'
34
- PROJ.version = '0.3.2'
34
+ PROJ.version = '0.3.3'
35
35
  PROJ.rubyforge.name = 'ffi'
36
36
  PROJ.readme_file = 'README.rdoc'
37
37
 
@@ -43,7 +43,7 @@ PROJ.ann.email[:server] = 'smtp.gmail.com'
43
43
 
44
44
  # Gem specifications
45
45
  PROJ.gem.need_tar = false
46
- PROJ.gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{ext,lib,nbproject,samples,spec}/**/*")
46
+ PROJ.gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{ext,lib,spec}/**/*")
47
47
  PROJ.gem.platform = Gem::Platform::RUBY
48
48
  PROJ.gem.extensions = %w(ext/ffi_c/extconf.rb gen/Rakefile)
49
49
 
@@ -50,18 +50,17 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
50
50
  {
51
51
  VALUE size = Qnil, count = Qnil, clear = Qnil;
52
52
  Buffer* p;
53
- unsigned long msize;
54
53
  int nargs;
55
-
56
- nargs = rb_scan_args(argc, argv, "12", &size, &count, &clear);
57
- msize = rb_FFI_type_size(size) * (nargs > 1 ? NUM2LONG(count) : 1);
58
54
 
59
55
  Data_Get_Struct(self, Buffer, p);
60
- p->memory.size = msize;
61
56
 
62
- p->storage = malloc(msize + 7);
57
+ nargs = rb_scan_args(argc, argv, "12", &size, &count, &clear);
58
+ p->type_size = rb_FFI_type_size(size);
59
+ p->memory.size = p->type_size * (nargs > 1 ? NUM2LONG(count) : 1);
60
+
61
+ p->storage = malloc(p->memory.size + 7);
63
62
  if (p->storage == NULL) {
64
- rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", msize);
63
+ rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size);
65
64
  }
66
65
 
67
66
  /* ensure the memory is aligned on at least a 8 byte boundary */
@@ -103,6 +102,24 @@ buffer_plus(VALUE self, VALUE offset)
103
102
  return retval;
104
103
  }
105
104
 
105
+ static VALUE
106
+ buffer_aref(VALUE self, VALUE offset)
107
+ {
108
+ Buffer* ptr;
109
+
110
+ Data_Get_Struct(self, Buffer, ptr);
111
+ return buffer_plus(self, INT2FIX(ptr->type_size * NUM2INT(offset)));
112
+ }
113
+
114
+ static VALUE
115
+ buffer_type_size(VALUE self)
116
+ {
117
+ Buffer* ptr;
118
+
119
+ Data_Get_Struct(self, Buffer, ptr);
120
+ return INT2NUM(ptr->type_size);
121
+ }
122
+
106
123
  static VALUE
107
124
  buffer_inspect(VALUE self)
108
125
  {
@@ -149,5 +166,7 @@ rb_FFI_Buffer_Init()
149
166
 
150
167
  rb_define_method(classBuffer, "initialize", buffer_initialize, -1);
151
168
  rb_define_method(classBuffer, "inspect", buffer_inspect, 0);
169
+ rb_define_method(classBuffer, "type_size", buffer_type_size, 0);
170
+ rb_define_method(classBuffer, "[]", buffer_aref, 1);
152
171
  rb_define_method(classBuffer, "+", buffer_plus, 1);
153
172
  }
@@ -40,9 +40,9 @@ rb_FFI_type_size(VALUE type)
40
40
  }
41
41
  }
42
42
  // Not found - call up to the ruby version to resolve
43
- return rb_funcall(moduleFFI, rb_intern("type_size"), 1, &type);
43
+ return NUM2INT(rb_funcall2(moduleFFI, rb_intern("type_size"), 1, &type));
44
44
  } else {
45
- return rb_funcall(type, size_id, 0, NULL);
45
+ return NUM2INT(rb_funcall2(type, size_id, 0, NULL));
46
46
  }
47
47
  }
48
48
 
@@ -451,3 +451,28 @@ describe 'BuggedStruct' do
451
451
  end.should == [[:visible, 0], [:x, 4], [:y, 8], [:rx, 12], [:ry, 14], [:order, 16], [:size, 17]]
452
452
  end
453
453
  end
454
+
455
+ describe "Struct allocation" do
456
+ it "MemoryPointer.new(Struct, 2)" do
457
+ class S < FFI::Struct
458
+ layout :i, :uint
459
+ end
460
+ p = FFI::MemoryPointer.new(S, 2)
461
+ p.total.should == 8
462
+ p.type_size.should == 4
463
+ p.put_uint(4, 0xdeadbeef)
464
+ S.new(p[1])[:i].should == 0xdeadbeef
465
+ p[1].address.should == (p[0].address + 4)
466
+ end
467
+
468
+ it "Buffer.new(Struct, 2)" do
469
+ class S < FFI::Struct
470
+ layout :i, :uint
471
+ end
472
+ p = FFI::Buffer.new(S, 2)
473
+ p.total.should == 8
474
+ p.type_size.should == 4
475
+ p.put_uint(4, 0xdeadbeef)
476
+ S.new(p[1])[:i].should == 0xdeadbeef
477
+ end
478
+ end
metadata CHANGED
@@ -1,34 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
- required_ruby_version: !ruby/object:Gem::Requirement
3
- requirements:
4
- - - '>='
5
- - !ruby/object:Gem::Version
6
- version: "0"
7
- version:
8
- email: wmeissner@gmail.com
2
+ name: ffi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Wayne Meissner
8
+ autorequire:
9
+ bindir: bin
9
10
  cert_chain: []
10
11
 
11
- summary: A Ruby foreign function interface
12
- post_install_message:
12
+ date: 2009-04-27 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bones
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.4.2
24
+ version:
25
+ description: A Ruby foreign function interface
26
+ email: wmeissner@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/ffi_c/extconf.rb
13
31
  extra_rdoc_files:
14
32
  - README.rdoc
15
33
  - lib/ffi
16
34
  - lib/ffi/tools
17
- homepage: http://kenai.com/projects/ruby-ffi
18
- signing_key:
19
- name: ffi
20
- rdoc_options:
21
- - -x
22
- - ext
23
- - --main
24
- - README.rdoc
25
- autorequire:
26
- rubyforge_project: ffi
27
- executables: []
28
-
29
- description: A Ruby foreign function interface
30
- specification_version: 2
31
- default_executable:
32
35
  files:
33
36
  - LICENSE
34
37
  - README.rdoc
@@ -341,23 +344,6 @@ files:
341
344
  - lib/ffi/types.rb
342
345
  - lib/ffi/union.rb
343
346
  - lib/ffi/variadic.rb
344
- - nbproject/Makefile-Default.mk
345
- - nbproject/Makefile-impl.mk
346
- - nbproject/Package-Default.bash
347
- - nbproject/configurations.xml
348
- - nbproject/private
349
- - nbproject/private/configurations.xml
350
- - nbproject/private/private.xml
351
- - nbproject/project.properties
352
- - nbproject/project.xml
353
- - samples/getlogin.rb
354
- - samples/getpid.rb
355
- - samples/gettimeofday.rb
356
- - samples/hello.rb
357
- - samples/inotify.rb
358
- - samples/pty.rb
359
- - samples/qsort.rb
360
- - samples/sample_helper.rb
361
347
  - spec/ffi
362
348
  - spec/ffi/buffer_spec.rb
363
349
  - spec/ffi/callback_spec.rb
@@ -378,38 +364,35 @@ files:
378
364
  - spec/ffi/union_spec.rb
379
365
  - spec/ffi/variadic_spec.rb
380
366
  - spec/spec.opts
367
+ has_rdoc: true
368
+ homepage: http://kenai.com/projects/ruby-ffi
369
+ post_install_message:
370
+ rdoc_options:
371
+ - -x
372
+ - ext
373
+ - --main
374
+ - README.rdoc
375
+ require_paths:
376
+ - lib
377
+ - ext
378
+ required_ruby_version: !ruby/object:Gem::Requirement
379
+ requirements:
380
+ - - ">="
381
+ - !ruby/object:Gem::Version
382
+ version: "0"
383
+ version:
381
384
  required_rubygems_version: !ruby/object:Gem::Requirement
382
385
  requirements:
383
- - - '>='
386
+ - - ">="
384
387
  - !ruby/object:Gem::Version
385
388
  version: "0"
386
389
  version:
387
- extensions:
388
- - ext/ffi_c/extconf.rb
389
- rubygems_version: 1.3.1
390
390
  requirements: []
391
391
 
392
- authors:
393
- - Wayne Meissner
394
- date: 2009-03-24 14:00:00 +00:00
395
- platform: ruby
392
+ rubyforge_project: ffi
393
+ rubygems_version: 1.3.1
394
+ signing_key:
395
+ specification_version: 2
396
+ summary: A Ruby foreign function interface
396
397
  test_files: []
397
398
 
398
- version: !ruby/object:Gem::Version
399
- version: 0.3.2
400
- require_paths:
401
- - lib
402
- - ext
403
- dependencies:
404
- - !ruby/object:Gem::Dependency
405
- version_requirements: !ruby/object:Gem::Requirement
406
- requirements:
407
- - - '>='
408
- - !ruby/object:Gem::Version
409
- version: 2.4.2
410
- version:
411
- type: :development
412
- version_requirement:
413
- name: bones
414
- bindir: bin
415
- has_rdoc: true
@@ -1,57 +0,0 @@
1
- #
2
- # Generated Makefile - do not edit!
3
- #
4
- # Edit the Makefile in the project folder instead (../Makefile). Each target
5
- # has a -pre and a -post target defined where you can add customized code.
6
- #
7
- # This makefile implements configuration specific macros and targets.
8
-
9
-
10
- # Environment
11
- MKDIR=mkdir
12
- CP=cp
13
- CCADMIN=CCadmin
14
- RANLIB=ranlib
15
- CC=gcc
16
- CCC=g++
17
- CXX=g++
18
- FC=
19
-
20
- # Macros
21
- PLATFORM=GNU-MacOSX
22
-
23
- # Include project Makefile
24
- include ruby-ffi-Makefile.mk
25
-
26
- # Object Directory
27
- OBJECTDIR=build/Default/${PLATFORM}
28
-
29
- # Object Files
30
- OBJECTFILES=
31
-
32
- # C Compiler Flags
33
- CFLAGS=
34
-
35
- # CC Compiler Flags
36
- CCFLAGS=
37
- CXXFLAGS=
38
-
39
- # Fortran Compiler Flags
40
- FFLAGS=
41
-
42
- # Link Libraries and Options
43
- LDLIBSOPTIONS=
44
-
45
- # Build Targets
46
- .build-conf: ${BUILD_SUBPROJECTS}
47
- cd . && rake compile
48
-
49
- # Subprojects
50
- .build-subprojects:
51
-
52
- # Clean Targets
53
- .clean-conf:
54
- cd . && rake clean
55
-
56
- # Subprojects
57
- .clean-subprojects:
@@ -1,123 +0,0 @@
1
- #
2
- # Generated Makefile - do not edit!
3
- #
4
- # Edit the Makefile in the project folder instead (../Makefile). Each target
5
- # has a pre- and a post- target defined where you can add customization code.
6
- #
7
- # This makefile implements macros and targets common to all configurations.
8
- #
9
- # NOCDDL
10
-
11
-
12
- # Building and Cleaning subprojects are done by default, but can be controlled with the SUB
13
- # macro. If SUB=no, subprojects will not be built or cleaned. The following macro
14
- # statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
15
- # and .clean-reqprojects-conf unless SUB has the value 'no'
16
- SUB_no=NO
17
- SUBPROJECTS=${SUB_${SUB}}
18
- BUILD_SUBPROJECTS_=.build-subprojects
19
- BUILD_SUBPROJECTS_NO=
20
- BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
21
- CLEAN_SUBPROJECTS_=.clean-subprojects
22
- CLEAN_SUBPROJECTS_NO=
23
- CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
24
-
25
-
26
- # Project Name
27
- PROJECTNAME=ruby-ffi
28
-
29
- # Active Configuration
30
- DEFAULTCONF=Default
31
- CONF=${DEFAULTCONF}
32
-
33
- # All Configurations
34
- ALLCONFS=Default
35
-
36
-
37
- # build
38
- .build-impl: .build-pre .validate-impl .depcheck-impl
39
- @#echo "=> Running $@... Configuration=$(CONF)"
40
- ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
41
-
42
-
43
- # clean
44
- .clean-impl: .clean-pre .validate-impl .depcheck-impl
45
- @#echo "=> Running $@... Configuration=$(CONF)"
46
- ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
47
-
48
-
49
- # clobber
50
- .clobber-impl: .clobber-pre .depcheck-impl
51
- @#echo "=> Running $@..."
52
- for CONF in ${ALLCONFS}; \
53
- do \
54
- ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
55
- done
56
-
57
- # all
58
- .all-impl: .all-pre .depcheck-impl
59
- @#echo "=> Running $@..."
60
- for CONF in ${ALLCONFS}; \
61
- do \
62
- ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \
63
- done
64
-
65
- # dependency checking support
66
- .depcheck-impl:
67
- @echo "# This code depends on make tool being used" >.dep.inc
68
- @if [ -n "${MAKE_VERSION}" ]; then \
69
- echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
70
- echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
71
- echo "include \$${DEPFILES}" >>.dep.inc; \
72
- echo "endif" >>.dep.inc; \
73
- else \
74
- echo ".KEEP_STATE:" >>.dep.inc; \
75
- echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
76
- fi
77
-
78
- # configuration validation
79
- .validate-impl:
80
- @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
81
- then \
82
- echo ""; \
83
- echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
84
- echo "See 'make help' for details."; \
85
- echo "Current directory: " `pwd`; \
86
- echo ""; \
87
- fi
88
- @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
89
- then \
90
- exit 1; \
91
- fi
92
-
93
-
94
- # help
95
- .help-impl: .help-pre
96
- @echo "This makefile supports the following configurations:"
97
- @echo " ${ALLCONFS}"
98
- @echo ""
99
- @echo "and the following targets:"
100
- @echo " build (default target)"
101
- @echo " clean"
102
- @echo " clobber"
103
- @echo " all"
104
- @echo " help"
105
- @echo ""
106
- @echo "Makefile Usage:"
107
- @echo " make [CONF=<CONFIGURATION>] [SUB=no] build"
108
- @echo " make [CONF=<CONFIGURATION>] [SUB=no] clean"
109
- @echo " make [SUB=no] clobber"
110
- @echo " make [SUB=no] all"
111
- @echo " make help"
112
- @echo ""
113
- @echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
114
- @echo " also build subprojects."
115
- @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
116
- @echo " also clean subprojects."
117
- @echo "Target 'clobber' will remove all built files from all configurations and,"
118
- @echo " unless 'SUB=no', also from subprojects."
119
- @echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
120
- @echo " also build subprojects."
121
- @echo "Target 'help' prints this message."
122
- @echo ""
123
-
@@ -1,72 +0,0 @@
1
- #!/bin/bash -x
2
-
3
- #
4
- # Generated - do not edit!
5
- #
6
-
7
- # Macros
8
- TOP=`pwd`
9
- PLATFORM=GNU-MacOSX
10
- TMPDIR=build/Default/${PLATFORM}/tmp-packaging
11
- TMPDIRNAME=tmp-packaging
12
- OUTPUT_PATH=MissingOutputInProject
13
- OUTPUT_BASENAME=MissingOutputInProject
14
- PACKAGE_TOP_DIR=ruby-ffi/
15
-
16
- # Functions
17
- function checkReturnCode
18
- {
19
- rc=$?
20
- if [ $rc != 0 ]
21
- then
22
- exit $rc
23
- fi
24
- }
25
- function makeDirectory
26
- # $1 directory path
27
- # $2 permission (optional)
28
- {
29
- mkdir -p "$1"
30
- checkReturnCode
31
- if [ "$2" != "" ]
32
- then
33
- chmod $2 "$1"
34
- checkReturnCode
35
- fi
36
- }
37
- function copyFileToTmpDir
38
- # $1 from-file path
39
- # $2 to-file path
40
- # $3 permission
41
- {
42
- cp "$1" "$2"
43
- checkReturnCode
44
- if [ "$3" != "" ]
45
- then
46
- chmod $3 "$2"
47
- checkReturnCode
48
- fi
49
- }
50
-
51
- # Setup
52
- cd "${TOP}"
53
- mkdir -p dist/Default/${PLATFORM}/package
54
- rm -rf ${TMPDIR}
55
- mkdir -p ${TMPDIR}
56
-
57
- # Copy files and create directories and links
58
- cd "${TOP}"
59
- makeDirectory ${TMPDIR}/ruby-ffi/bin
60
- copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
61
-
62
-
63
- # Generate tar file
64
- cd "${TOP}"
65
- rm -f dist/Default/${PLATFORM}/package/ruby-ffi.tar
66
- cd ${TMPDIR}
67
- tar -vcf ../../../../dist/Default/${PLATFORM}/package/ruby-ffi.tar *
68
- checkReturnCode
69
-
70
- # Cleanup
71
- cd "${TOP}"
72
- rm -rf ${TMPDIR}
@@ -1,293 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <configurationDescriptor version="51">
3
- <logicalFolder name="root" displayName="root" projectFiles="true">
4
- <logicalFolder name="ruby-ffi" displayName="ruby-ffi" projectFiles="true">
5
- <logicalFolder name="ext" displayName="ext" projectFiles="true">
6
- <itemPath>ext/ffi_c/AbstractMemory.c</itemPath>
7
- <itemPath>ext/ffi_c/AbstractMemory.h</itemPath>
8
- <itemPath>ext/ffi_c/AutoPointer.c</itemPath>
9
- <itemPath>ext/ffi_c/AutoPointer.h</itemPath>
10
- <itemPath>ext/ffi_c/Buffer.c</itemPath>
11
- <itemPath>ext/ffi_c/Callback.c</itemPath>
12
- <itemPath>ext/ffi_c/Callback.h</itemPath>
13
- <itemPath>ext/ffi_c/compat.h</itemPath>
14
- <itemPath>ext/ffi_c/extconf.rb</itemPath>
15
- <itemPath>ext/ffi_c/ffi.c</itemPath>
16
- <itemPath>ext/ffi_c/Invoker.c</itemPath>
17
- <itemPath>ext/ffi_c/MemoryPointer.c</itemPath>
18
- <itemPath>ext/ffi_c/MemoryPointer.h</itemPath>
19
- <itemPath>ext/ffi_c/NativeLibrary.c</itemPath>
20
- <itemPath>ext/ffi_c/NativeLibrary.h</itemPath>
21
- <itemPath>ext/ffi_c/NullPointer.c</itemPath>
22
- <itemPath>ext/ffi_c/Platform.c</itemPath>
23
- <itemPath>ext/ffi_c/Platform.h</itemPath>
24
- <itemPath>ext/ffi_c/Pointer.c</itemPath>
25
- <itemPath>ext/ffi_c/Pointer.h</itemPath>
26
- <itemPath>ext/ffi_c/rbffi.h</itemPath>
27
- <itemPath>ext/ffi_c/Struct.c</itemPath>
28
- <itemPath>ext/ffi_c/Struct.h</itemPath>
29
- <itemPath>ext/ffi_c/Types.c</itemPath>
30
- <itemPath>ext/ffi_c/Types.h</itemPath>
31
- </logicalFolder>
32
- <logicalFolder name="f1" displayName="lib" projectFiles="true">
33
- <logicalFolder name="ffi" displayName="ffi" projectFiles="true">
34
- <itemPath>lib/ffi/autopointer.rb</itemPath>
35
- <itemPath>lib/ffi/callback.rb</itemPath>
36
- <itemPath>lib/ffi/ffi.rb</itemPath>
37
- <itemPath>lib/ffi/io.rb</itemPath>
38
- <itemPath>lib/ffi/library.rb</itemPath>
39
- <itemPath>lib/ffi/memorypointer.rb</itemPath>
40
- <itemPath>lib/ffi/platform.rb</itemPath>
41
- <itemPath>lib/ffi/pointer.rb</itemPath>
42
- <itemPath>lib/ffi/struct.rb</itemPath>
43
- <itemPath>lib/ffi/types.rb</itemPath>
44
- <itemPath>lib/ffi/variadic.rb</itemPath>
45
- </logicalFolder>
46
- <itemPath>lib/ffi.rb</itemPath>
47
- </logicalFolder>
48
- <logicalFolder name="libtest" displayName="libtest" projectFiles="true">
49
- <itemPath>libtest/Benchmark.c</itemPath>
50
- <itemPath>libtest/BufferTest.c</itemPath>
51
- <itemPath>libtest/ClosureTest.c</itemPath>
52
- <itemPath>libtest/GlobalVariable.c</itemPath>
53
- <itemPath>libtest/LastErrorTest.c</itemPath>
54
- <itemPath>libtest/NumberTest.c</itemPath>
55
- <itemPath>libtest/PointerTest.c</itemPath>
56
- <itemPath>libtest/ReferenceTest.c</itemPath>
57
- <itemPath>libtest/StringTest.c</itemPath>
58
- <itemPath>libtest/StructTest.c</itemPath>
59
- <itemPath>libtest/VariadicTest.c</itemPath>
60
- </logicalFolder>
61
- <logicalFolder name="f2" displayName="spec" projectFiles="true">
62
- <itemPath>spec/ffi/buffer_spec.rb</itemPath>
63
- <itemPath>spec/ffi/callback_spec.rb</itemPath>
64
- <itemPath>spec/ffi/errno_spec.rb</itemPath>
65
- <itemPath>spec/ffi/library_spec.rb</itemPath>
66
- <itemPath>spec/ffi/managed_struct_spec.rb</itemPath>
67
- <itemPath>spec/ffi/number_spec.rb</itemPath>
68
- <itemPath>spec/ffi/pointer_spec.rb</itemPath>
69
- <itemPath>spec/ffi/spec_helper.rb</itemPath>
70
- <itemPath>spec/ffi/string_spec.rb</itemPath>
71
- <itemPath>spec/ffi/struct_spec.rb</itemPath>
72
- <itemPath>spec/ffi/typedef_spec.rb</itemPath>
73
- <itemPath>spec/ffi/union_spec.rb</itemPath>
74
- <itemPath>spec/ffi/variadic_spec.rb</itemPath>
75
- </logicalFolder>
76
- </logicalFolder>
77
- <logicalFolder name="ExternalFiles"
78
- displayName="Important Files"
79
- projectFiles="false">
80
- <itemPath>Makefile</itemPath>
81
- <itemPath>Rakefile</itemPath>
82
- <itemPath>ruby-ffi-Makefile.mk</itemPath>
83
- </logicalFolder>
84
- </logicalFolder>
85
- <projectmakefile>ruby-ffi-Makefile.mk</projectmakefile>
86
- <confs>
87
- <conf name="Default" type="0">
88
- <toolsSet>
89
- <developmentServer>localhost</developmentServer>
90
- <compilerSet>GNU|GNU</compilerSet>
91
- <platform>4</platform>
92
- </toolsSet>
93
- <makefileType>
94
- <makeTool>
95
- <buildCommandWorkingDir>.</buildCommandWorkingDir>
96
- <buildCommand>rake compile</buildCommand>
97
- <cleanCommand>rake clean</cleanCommand>
98
- <executablePath></executablePath>
99
- <cCompilerTool>
100
- <includeDirectories>
101
- <directoryPath>/opt/local/include</directoryPath>
102
- </includeDirectories>
103
- </cCompilerTool>
104
- </makeTool>
105
- <requiredProjects>
106
- </requiredProjects>
107
- </makefileType>
108
- <item path="ext/ffi_c/AbstractMemory.c">
109
- <itemTool>0</itemTool>
110
- </item>
111
- <item path="ext/ffi_c/AbstractMemory.h">
112
- <itemTool>3</itemTool>
113
- </item>
114
- <item path="ext/ffi_c/AutoPointer.c">
115
- <itemTool>0</itemTool>
116
- </item>
117
- <item path="ext/ffi_c/AutoPointer.h">
118
- <itemTool>3</itemTool>
119
- </item>
120
- <item path="ext/ffi_c/Buffer.c">
121
- <itemTool>0</itemTool>
122
- </item>
123
- <item path="ext/ffi_c/Callback.c">
124
- <itemTool>0</itemTool>
125
- </item>
126
- <item path="ext/ffi_c/Callback.h">
127
- <itemTool>3</itemTool>
128
- </item>
129
- <item path="ext/ffi_c/Invoker.c">
130
- <itemTool>0</itemTool>
131
- </item>
132
- <item path="ext/ffi_c/MemoryPointer.c">
133
- <itemTool>0</itemTool>
134
- </item>
135
- <item path="ext/ffi_c/MemoryPointer.h">
136
- <itemTool>3</itemTool>
137
- </item>
138
- <item path="ext/ffi_c/NativeLibrary.c">
139
- <itemTool>0</itemTool>
140
- </item>
141
- <item path="ext/ffi_c/NativeLibrary.h">
142
- <itemTool>3</itemTool>
143
- </item>
144
- <item path="ext/ffi_c/NullPointer.c">
145
- <itemTool>0</itemTool>
146
- </item>
147
- <item path="ext/ffi_c/Platform.c">
148
- <itemTool>0</itemTool>
149
- </item>
150
- <item path="ext/ffi_c/Platform.h">
151
- <itemTool>3</itemTool>
152
- </item>
153
- <item path="ext/ffi_c/Pointer.c">
154
- <itemTool>0</itemTool>
155
- </item>
156
- <item path="ext/ffi_c/Pointer.h">
157
- <itemTool>3</itemTool>
158
- </item>
159
- <item path="ext/ffi_c/Struct.c">
160
- <itemTool>0</itemTool>
161
- </item>
162
- <item path="ext/ffi_c/Struct.h">
163
- <itemTool>3</itemTool>
164
- </item>
165
- <item path="ext/ffi_c/Types.c">
166
- <itemTool>0</itemTool>
167
- </item>
168
- <item path="ext/ffi_c/Types.h">
169
- <itemTool>3</itemTool>
170
- </item>
171
- <item path="ext/ffi_c/compat.h">
172
- <itemTool>3</itemTool>
173
- </item>
174
- <item path="ext/ffi_c/extconf.rb">
175
- <itemTool>3</itemTool>
176
- </item>
177
- <item path="ext/ffi_c/ffi.c">
178
- <itemTool>0</itemTool>
179
- </item>
180
- <item path="ext/ffi_c/rbffi.h">
181
- <itemTool>3</itemTool>
182
- </item>
183
- <item path="lib/ffi.rb">
184
- <itemTool>3</itemTool>
185
- </item>
186
- <item path="lib/ffi/autopointer.rb">
187
- <itemTool>3</itemTool>
188
- </item>
189
- <item path="lib/ffi/callback.rb">
190
- <itemTool>3</itemTool>
191
- </item>
192
- <item path="lib/ffi/ffi.rb">
193
- <itemTool>3</itemTool>
194
- </item>
195
- <item path="lib/ffi/io.rb">
196
- <itemTool>3</itemTool>
197
- </item>
198
- <item path="lib/ffi/library.rb">
199
- <itemTool>3</itemTool>
200
- </item>
201
- <item path="lib/ffi/memorypointer.rb">
202
- <itemTool>3</itemTool>
203
- </item>
204
- <item path="lib/ffi/platform.rb">
205
- <itemTool>3</itemTool>
206
- </item>
207
- <item path="lib/ffi/pointer.rb">
208
- <itemTool>3</itemTool>
209
- </item>
210
- <item path="lib/ffi/struct.rb">
211
- <itemTool>3</itemTool>
212
- </item>
213
- <item path="lib/ffi/types.rb">
214
- <itemTool>3</itemTool>
215
- </item>
216
- <item path="lib/ffi/variadic.rb">
217
- <itemTool>3</itemTool>
218
- </item>
219
- <item path="libtest/Benchmark.c">
220
- <itemTool>0</itemTool>
221
- </item>
222
- <item path="libtest/BufferTest.c">
223
- <itemTool>0</itemTool>
224
- </item>
225
- <item path="libtest/ClosureTest.c">
226
- <itemTool>0</itemTool>
227
- </item>
228
- <item path="libtest/GlobalVariable.c">
229
- <itemTool>0</itemTool>
230
- </item>
231
- <item path="libtest/LastErrorTest.c">
232
- <itemTool>0</itemTool>
233
- </item>
234
- <item path="libtest/NumberTest.c">
235
- <itemTool>0</itemTool>
236
- </item>
237
- <item path="libtest/PointerTest.c">
238
- <itemTool>0</itemTool>
239
- </item>
240
- <item path="libtest/ReferenceTest.c">
241
- <itemTool>0</itemTool>
242
- </item>
243
- <item path="libtest/StringTest.c">
244
- <itemTool>0</itemTool>
245
- </item>
246
- <item path="libtest/StructTest.c">
247
- <itemTool>0</itemTool>
248
- </item>
249
- <item path="libtest/VariadicTest.c">
250
- <itemTool>0</itemTool>
251
- </item>
252
- <item path="spec/ffi/buffer_spec.rb">
253
- <itemTool>3</itemTool>
254
- </item>
255
- <item path="spec/ffi/callback_spec.rb">
256
- <itemTool>3</itemTool>
257
- </item>
258
- <item path="spec/ffi/errno_spec.rb">
259
- <itemTool>3</itemTool>
260
- </item>
261
- <item path="spec/ffi/library_spec.rb">
262
- <itemTool>3</itemTool>
263
- </item>
264
- <item path="spec/ffi/managed_struct_spec.rb">
265
- <itemTool>3</itemTool>
266
- </item>
267
- <item path="spec/ffi/number_spec.rb">
268
- <itemTool>3</itemTool>
269
- </item>
270
- <item path="spec/ffi/pointer_spec.rb">
271
- <itemTool>3</itemTool>
272
- </item>
273
- <item path="spec/ffi/spec_helper.rb">
274
- <itemTool>3</itemTool>
275
- </item>
276
- <item path="spec/ffi/string_spec.rb">
277
- <itemTool>3</itemTool>
278
- </item>
279
- <item path="spec/ffi/struct_spec.rb">
280
- <itemTool>3</itemTool>
281
- </item>
282
- <item path="spec/ffi/typedef_spec.rb">
283
- <itemTool>3</itemTool>
284
- </item>
285
- <item path="spec/ffi/union_spec.rb">
286
- <itemTool>3</itemTool>
287
- </item>
288
- <item path="spec/ffi/variadic_spec.rb">
289
- <itemTool>3</itemTool>
290
- </item>
291
- </conf>
292
- </confs>
293
- </configurationDescriptor>
@@ -1,22 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <configurationDescriptor version="51">
3
- <projectmakefile>ruby-ffi-Makefile.mk</projectmakefile>
4
- <defaultConf>0</defaultConf>
5
- <confs>
6
- <conf name="Default" type="0">
7
- <gdbdebugger version="2">
8
- <gdb_command>gdb</gdb_command>
9
- <array_repeat_threshold>10</array_repeat_threshold>
10
- </gdbdebugger>
11
- <runprofile version="5">
12
- <args></args>
13
- <rundir></rundir>
14
- <buildfirst>true</buildfirst>
15
- <console-type>0</console-type>
16
- <terminal-type>0</terminal-type>
17
- <environment>
18
- </environment>
19
- </runprofile>
20
- </conf>
21
- </confs>
22
- </configurationDescriptor>
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3
- <code-assistance-data xmlns="http://www.netbeans.org/ns/make-project-private/1">
4
- <code-model-enabled>false</code-model-enabled>
5
- </code-assistance-data>
6
- <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
7
- </project-private>
File without changes
@@ -1,15 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project xmlns="http://www.netbeans.org/ns/project/1">
3
- <type>org.netbeans.modules.cnd.makeproject</type>
4
- <configuration>
5
- <data xmlns="http://www.netbeans.org/ns/make-project/1">
6
- <name>ruby-ffi</name>
7
- <make-project-type>0</make-project-type>
8
- <c-extensions>c</c-extensions>
9
- <cpp-extensions/>
10
- <header-extensions>h</header-extensions>
11
- <sourceEncoding>UTF-8</sourceEncoding>
12
- <make-dep-projects/>
13
- </data>
14
- </configuration>
15
- </project>
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'ffi'
3
- module Foo
4
- extend FFI::Library
5
- attach_function :getlogin, [ ], :string
6
- end
7
- puts "getlogin=#{Foo.getlogin}"
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'ffi'
3
- module Foo
4
- extend FFI::Library
5
- attach_function :getpid, [ ], :int
6
- end
7
- puts "My pid=#{Foo.getpid}"
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'ffi'
3
- class Timeval < FFI::Struct
4
- rb_maj, rb_min, rb_micro = RUBY_VERSION.split('.')
5
- if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/
6
- layout :tv_sec => :ulong, :tv_usec => :ulong
7
- else
8
- layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
9
- end
10
- end
11
- module LibC
12
- extend FFI::Library
13
- attach_function :gettimeofday, [ :pointer, :pointer ], :int
14
- end
15
- t = Timeval.new
16
- LibC.gettimeofday(t.pointer, nil)
17
- puts "t.tv_sec=#{t[:tv_sec]} t.tv_usec=#{t[:tv_usec]}"
@@ -1,6 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "sample_helper"))
2
- module Foo
3
- extend FFI::Library
4
- attach_function("cputs", "puts", [ :string ], :int)
5
- end
6
- Foo.cputs("Hello, World via libc puts using FFI on MRI ruby")
@@ -1,59 +0,0 @@
1
- require 'rubygems'
2
- require 'ffi'
3
- module Inotify
4
- extend FFI::Library
5
- class Event < FFI::Struct
6
- layout \
7
- :wd, :int,
8
- :mask, :uint,
9
- :cookie, :uint,
10
- :len, :uint
11
- end
12
- attach_function :init, :inotify_init, [ ], :int
13
- attach_function :add_watch, :inotify_add_watch, [ :int, :string, :uint ], :int
14
- attach_function :rm_watch, :inotify_rm_watch, [ :int, :uint ], :int
15
- attach_function :read, [ :int, :buffer_out, :uint ], :int
16
- IN_ACCESS=0x00000001
17
- IN_MODIFY=0x00000002
18
- IN_ATTRIB=0x00000004
19
- IN_CLOSE_WRITE=0x00000008
20
- IN_CLOSE_NOWRITE=0x00000010
21
- IN_CLOSE=(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
22
- IN_OPEN=0x00000020
23
- IN_MOVED_FROM=0x00000040
24
- IN_MOVED_TO=0x00000080
25
- IN_MOVE= (IN_MOVED_FROM | IN_MOVED_TO)
26
- IN_CREATE=0x00000100
27
- IN_DELETE=0x00000200
28
- IN_DELETE_SELF=0x00000400
29
- IN_MOVE_SELF=0x00000800
30
- # Events sent by the kernel.
31
- IN_UNMOUNT=0x00002000
32
- IN_Q_OVERFLOW=0x00004000
33
- IN_IGNORED=0x00008000
34
- IN_ONLYDIR=0x01000000
35
- IN_DONT_FOLLOW=0x02000000
36
- IN_MASK_ADD=0x20000000
37
- IN_ISDIR=0x40000000
38
- IN_ONESHOT=0x80000000
39
- IN_ALL_EVENTS=(IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE \
40
- | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM \
41
- | IN_MOVED_TO | IN_CREATE | IN_DELETE \
42
- | IN_DELETE_SELF | IN_MOVE_SELF)
43
-
44
- end
45
- if $0 == __FILE__
46
- fd = Inotify.init
47
- puts "fd=#{fd}"
48
- wd = Inotify.add_watch(fd, "/tmp/", Inotify::IN_ALL_EVENTS)
49
- fp = FFI::IO.for_fd(fd)
50
- puts "wfp=#{fp}"
51
- while true
52
- buf = FFI::Buffer.alloc_out(Inotify::Event.size + 4096, 1, false)
53
- ev = Inotify::Event.new buf
54
- ready = IO.select([ fp ], nil, nil, nil)
55
- n = Inotify.read(fd, buf, buf.total)
56
- puts "Read #{n} bytes from inotify fd"
57
- puts "event.wd=#{ev[:wd]} mask=#{ev[:mask]} len=#{ev[:len]} name=#{ev[:len] > 0 ? buf.get_string(16) : 'unknown'}"
58
- end
59
- end
@@ -1,75 +0,0 @@
1
- require 'ffi'
2
-
3
-
4
- module PTY
5
- private
6
- module LibC
7
- extend FFI::Library
8
- attach_function :forkpty, [ :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
9
- attach_function :openpty, [ :buffer_out, :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
10
- attach_function :login_tty, [ :int ], :int
11
- attach_function :close, [ :int ], :int
12
- attach_function :strerror, [ :int ], :string
13
- attach_function :fork, [], :int
14
- attach_function :execv, [ :string, :buffer_in ], :int
15
- attach_function :execvp, [ :string, :buffer_in ], :int
16
- attach_function :dup2, [ :int, :int ], :int
17
- attach_function :dup, [ :int ], :int
18
- end
19
- Buffer = FFI::Buffer
20
- def self.build_args(args)
21
- cmd = args.shift
22
- cmd_args = args.map do |arg|
23
- MemoryPointer.from_string(arg)
24
- end
25
- exec_args = MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)
26
- exec_cmd = MemoryPointer.from_string(cmd)
27
- exec_args[0].put_pointer(0, exec_cmd)
28
- cmd_args.each_with_index do |arg, i|
29
- exec_args[i + 1].put_pointer(0, arg)
30
- end
31
- [ cmd, exec_args ]
32
- end
33
- public
34
- def self.getpty(*args)
35
- mfdp = Buffer.new :int
36
- name = Buffer.new 1024
37
- #
38
- # All the execv setup is done in the parent, since doing anything other than
39
- # execv in the child after fork is really flakey
40
- #
41
- exec_cmd, exec_args = build_args(args)
42
- pid = LibC.forkpty(mfdp, name, nil, nil)
43
- raise "forkpty failed: #{LibC.strerror(FFI.errno)}" if pid < 0
44
- if pid == 0
45
- LibC.execvp(exec_cmd, exec_args)
46
- exit 1
47
- end
48
- masterfd = mfdp.get_int(0)
49
- rfp = FFI::IO.for_fd(masterfd, "r")
50
- wfp = FFI::IO.for_fd(LibC.dup(masterfd), "w")
51
- if block_given?
52
- yield rfp, wfp, pid
53
- rfp.close unless rfp.closed?
54
- wfp.close unless wfp.closed?
55
- else
56
- [ rfp, wfp, pid ]
57
- end
58
- end
59
- def self.spawn(*args, &block)
60
- self.getpty("/bin/sh", "-c", args[0], &block)
61
- end
62
- end
63
- module LibC
64
- extend FFI::Library
65
- attach_function :close, [ :int ], :int
66
- attach_function :write, [ :int, :buffer_in, :ulong ], :long
67
- attach_function :read, [ :int, :buffer_out, :ulong ], :long
68
- end
69
- PTY.getpty("/bin/ls", "-alR", "/") { |rfd, wfd, pid|
70
- #PTY.spawn("ls -laR /") { |rfd, wfd, pid|
71
- puts "child pid=#{pid}"
72
- while !rfd.eof? && (buf = rfd.gets)
73
- puts "child: '#{buf.strip}'"
74
- end
75
- }
@@ -1,20 +0,0 @@
1
- require 'rubygems'
2
- require 'ffi'
3
-
4
- module LibC
5
- extend FFI::Library
6
- callback :qsort_cmp, [ :pointer, :pointer ], :int
7
- attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int
8
- end
9
-
10
- p = MemoryPointer.new(:int, 2)
11
- p.put_array_of_int32(0, [ 2, 1 ])
12
- puts "ptr=#{p.inspect}"
13
- puts "Before qsort #{p.get_array_of_int32(0, 2).join(', ')}"
14
- LibC.qsort(p, 2, 4) do |p1, p2|
15
- i1 = p1.get_int32(0)
16
- i2 = p2.get_int32(0)
17
- puts "In block: comparing #{i1} and #{i2}"
18
- i1 < i2 ? -1 : i1 > i2 ? 1 : 0
19
- end
20
- puts "After qsort #{p.get_array_of_int32(0, 2).join(', ')}"
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
-
4
- $:.unshift File.join(File.dirname(__FILE__), "..", "lib"), File.join(File.dirname(__FILE__), "..", "build", RUBY_VERSION) unless RUBY_PLATFORM =~ /java/
5
- require "ffi"
6
-