├── .gitignore ├── .gitmodules ├── .rspec ├── .travis.yml ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── ext └── tf │ ├── extconf.rb │ └── tf.cpp ├── generate.sh ├── lib ├── lib │ └── core │ │ └── strings.i ├── platform │ └── base.i ├── tf.rb ├── tf │ └── version.rb └── util │ ├── port.i │ └── rb_checkpoint_reader.i ├── tensorflow.i ├── test ├── test_helper.rb └── tf_test.rb └── tf.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dependencies/tensorflow"] 2 | path = dependencies/tensorflow 3 | url = https://github.com/tensorflow/tensorflow 4 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in tf.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ruby-tensorflow 2 | 3 | [![Build Status](https://travis-ci.org/ankurayadav/ruby-tensorflow.svg?branch=master)](https://travis-ci.org/ankurayadav/ruby-tensorflow) 4 | [![Join the chat at https://gitter.im/ankurayadav/ruby-tensorflow](https://badges.gitter.im/ankurayadav/ruby-tensorflow.svg)](https://gitter.im/ankurayadav/ruby-tensorflow?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | This repository contains Ruby API for utilizing Google's machine learning library TensorFlow. 7 | 8 | ## PREREQUISITES 9 | Install Bazel 10 | 11 | Follow instructions [here](http://bazel.io/docs/install.html) to install the dependencies for bazel. Then download the latest stable bazel version using the [installer for your system](https://github.com/bazelbuild/bazel/releases) and run the installer as mentioned there: 12 | 13 | $ chmod +x PATH_TO_INSTALL.SH 14 | $ ./PATH_TO_INSTALL.SH --user 15 | 16 | Install other dependencies 17 | 18 | $ sudo apt-get install swig 19 | 20 | ## Get Started 21 | 22 | Install gem dependencies: 23 | 24 | $ bundle install 25 | 26 | And then execute: 27 | 28 | $ rake install 29 | 30 | Then test the gem: 31 | 32 | $ rake test 33 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rake/testtask" 3 | 4 | Rake::TestTask.new(:test) do |t| 5 | t.libs << "test" 6 | t.libs << "lib" 7 | t.test_files = FileList['test/**/*_test.rb'] 8 | end 9 | 10 | require "rake/extensiontask" 11 | 12 | task :build => :compile 13 | 14 | Rake::ExtensionTask.new("tf") do |ext| 15 | ext.lib_dir = "lib/tf" 16 | end 17 | 18 | task :default => [:clobber, :compile, :test] 19 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "tf" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /ext/tf/extconf.rb: -------------------------------------------------------------------------------- 1 | require "mkmf" 2 | 3 | $INCFLAGS << " -I$(srcdir)/../../dependencies/tensorflow" 4 | 5 | create_makefile("tf/tf") 6 | -------------------------------------------------------------------------------- /ext/tf/tf.cpp: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.11 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | #define SWIGRUBY 12 | 13 | 14 | #ifdef __cplusplus 15 | /* SwigValueWrapper is described in swig.swg */ 16 | template class SwigValueWrapper { 17 | struct SwigMovePointer { 18 | T *ptr; 19 | SwigMovePointer(T *p) : ptr(p) { } 20 | ~SwigMovePointer() { delete ptr; } 21 | SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } 22 | } pointer; 23 | SwigValueWrapper& operator=(const SwigValueWrapper& rhs); 24 | SwigValueWrapper(const SwigValueWrapper& rhs); 25 | public: 26 | SwigValueWrapper() : pointer(0) { } 27 | SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } 28 | operator T&() const { return *pointer.ptr; } 29 | T *operator&() { return pointer.ptr; } 30 | }; 31 | 32 | template T SwigValueInit() { 33 | return T(); 34 | } 35 | #endif 36 | 37 | /* ----------------------------------------------------------------------------- 38 | * This section contains generic SWIG labels for method/variable 39 | * declarations/attributes, and other compiler dependent labels. 40 | * ----------------------------------------------------------------------------- */ 41 | 42 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 43 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 44 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 45 | # define SWIGTEMPLATEDISAMBIGUATOR template 46 | # elif defined(__HP_aCC) 47 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 48 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 49 | # define SWIGTEMPLATEDISAMBIGUATOR template 50 | # else 51 | # define SWIGTEMPLATEDISAMBIGUATOR 52 | # endif 53 | #endif 54 | 55 | /* inline attribute */ 56 | #ifndef SWIGINLINE 57 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 58 | # define SWIGINLINE inline 59 | # else 60 | # define SWIGINLINE 61 | # endif 62 | #endif 63 | 64 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 65 | #ifndef SWIGUNUSED 66 | # if defined(__GNUC__) 67 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 68 | # define SWIGUNUSED __attribute__ ((__unused__)) 69 | # else 70 | # define SWIGUNUSED 71 | # endif 72 | # elif defined(__ICC) 73 | # define SWIGUNUSED __attribute__ ((__unused__)) 74 | # else 75 | # define SWIGUNUSED 76 | # endif 77 | #endif 78 | 79 | #ifndef SWIG_MSC_UNSUPPRESS_4505 80 | # if defined(_MSC_VER) 81 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 82 | # endif 83 | #endif 84 | 85 | #ifndef SWIGUNUSEDPARM 86 | # ifdef __cplusplus 87 | # define SWIGUNUSEDPARM(p) 88 | # else 89 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 90 | # endif 91 | #endif 92 | 93 | /* internal SWIG method */ 94 | #ifndef SWIGINTERN 95 | # define SWIGINTERN static SWIGUNUSED 96 | #endif 97 | 98 | /* internal inline SWIG method */ 99 | #ifndef SWIGINTERNINLINE 100 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 101 | #endif 102 | 103 | /* exporting methods */ 104 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 105 | # ifndef GCC_HASCLASSVISIBILITY 106 | # define GCC_HASCLASSVISIBILITY 107 | # endif 108 | #endif 109 | 110 | #ifndef SWIGEXPORT 111 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 112 | # if defined(STATIC_LINKED) 113 | # define SWIGEXPORT 114 | # else 115 | # define SWIGEXPORT __declspec(dllexport) 116 | # endif 117 | # else 118 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 119 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 120 | # else 121 | # define SWIGEXPORT 122 | # endif 123 | # endif 124 | #endif 125 | 126 | /* calling conventions for Windows */ 127 | #ifndef SWIGSTDCALL 128 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 129 | # define SWIGSTDCALL __stdcall 130 | # else 131 | # define SWIGSTDCALL 132 | # endif 133 | #endif 134 | 135 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 136 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 137 | # define _CRT_SECURE_NO_DEPRECATE 138 | #endif 139 | 140 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 141 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 142 | # define _SCL_SECURE_NO_DEPRECATE 143 | #endif 144 | 145 | 146 | /* ----------------------------------------------------------------------------- 147 | * This section contains generic SWIG labels for method/variable 148 | * declarations/attributes, and other compiler dependent labels. 149 | * ----------------------------------------------------------------------------- */ 150 | 151 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 152 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 153 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 154 | # define SWIGTEMPLATEDISAMBIGUATOR template 155 | # elif defined(__HP_aCC) 156 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 157 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 158 | # define SWIGTEMPLATEDISAMBIGUATOR template 159 | # else 160 | # define SWIGTEMPLATEDISAMBIGUATOR 161 | # endif 162 | #endif 163 | 164 | /* inline attribute */ 165 | #ifndef SWIGINLINE 166 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 167 | # define SWIGINLINE inline 168 | # else 169 | # define SWIGINLINE 170 | # endif 171 | #endif 172 | 173 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 174 | #ifndef SWIGUNUSED 175 | # if defined(__GNUC__) 176 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 177 | # define SWIGUNUSED __attribute__ ((__unused__)) 178 | # else 179 | # define SWIGUNUSED 180 | # endif 181 | # elif defined(__ICC) 182 | # define SWIGUNUSED __attribute__ ((__unused__)) 183 | # else 184 | # define SWIGUNUSED 185 | # endif 186 | #endif 187 | 188 | #ifndef SWIG_MSC_UNSUPPRESS_4505 189 | # if defined(_MSC_VER) 190 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 191 | # endif 192 | #endif 193 | 194 | #ifndef SWIGUNUSEDPARM 195 | # ifdef __cplusplus 196 | # define SWIGUNUSEDPARM(p) 197 | # else 198 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 199 | # endif 200 | #endif 201 | 202 | /* internal SWIG method */ 203 | #ifndef SWIGINTERN 204 | # define SWIGINTERN static SWIGUNUSED 205 | #endif 206 | 207 | /* internal inline SWIG method */ 208 | #ifndef SWIGINTERNINLINE 209 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 210 | #endif 211 | 212 | /* exporting methods */ 213 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 214 | # ifndef GCC_HASCLASSVISIBILITY 215 | # define GCC_HASCLASSVISIBILITY 216 | # endif 217 | #endif 218 | 219 | #ifndef SWIGEXPORT 220 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 221 | # if defined(STATIC_LINKED) 222 | # define SWIGEXPORT 223 | # else 224 | # define SWIGEXPORT __declspec(dllexport) 225 | # endif 226 | # else 227 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 228 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 229 | # else 230 | # define SWIGEXPORT 231 | # endif 232 | # endif 233 | #endif 234 | 235 | /* calling conventions for Windows */ 236 | #ifndef SWIGSTDCALL 237 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 238 | # define SWIGSTDCALL __stdcall 239 | # else 240 | # define SWIGSTDCALL 241 | # endif 242 | #endif 243 | 244 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 245 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 246 | # define _CRT_SECURE_NO_DEPRECATE 247 | #endif 248 | 249 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 250 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 251 | # define _SCL_SECURE_NO_DEPRECATE 252 | #endif 253 | 254 | 255 | /* ----------------------------------------------------------------------------- 256 | * swigrun.swg 257 | * 258 | * This file contains generic C API SWIG runtime support for pointer 259 | * type checking. 260 | * ----------------------------------------------------------------------------- */ 261 | 262 | /* This should only be incremented when either the layout of swig_type_info changes, 263 | or for whatever reason, the runtime changes incompatibly */ 264 | #define SWIG_RUNTIME_VERSION "4" 265 | 266 | /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ 267 | #ifdef SWIG_TYPE_TABLE 268 | # define SWIG_QUOTE_STRING(x) #x 269 | # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) 270 | # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) 271 | #else 272 | # define SWIG_TYPE_TABLE_NAME 273 | #endif 274 | 275 | /* 276 | You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for 277 | creating a static or dynamic library from the SWIG runtime code. 278 | In 99.9% of the cases, SWIG just needs to declare them as 'static'. 279 | 280 | But only do this if strictly necessary, ie, if you have problems 281 | with your compiler or suchlike. 282 | */ 283 | 284 | #ifndef SWIGRUNTIME 285 | # define SWIGRUNTIME SWIGINTERN 286 | #endif 287 | 288 | #ifndef SWIGRUNTIMEINLINE 289 | # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE 290 | #endif 291 | 292 | /* Generic buffer size */ 293 | #ifndef SWIG_BUFFER_SIZE 294 | # define SWIG_BUFFER_SIZE 1024 295 | #endif 296 | 297 | /* Flags for pointer conversions */ 298 | #define SWIG_POINTER_DISOWN 0x1 299 | #define SWIG_CAST_NEW_MEMORY 0x2 300 | 301 | /* Flags for new pointer objects */ 302 | #define SWIG_POINTER_OWN 0x1 303 | 304 | 305 | /* 306 | Flags/methods for returning states. 307 | 308 | The SWIG conversion methods, as ConvertPtr, return an integer 309 | that tells if the conversion was successful or not. And if not, 310 | an error code can be returned (see swigerrors.swg for the codes). 311 | 312 | Use the following macros/flags to set or process the returning 313 | states. 314 | 315 | In old versions of SWIG, code such as the following was usually written: 316 | 317 | if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { 318 | // success code 319 | } else { 320 | //fail code 321 | } 322 | 323 | Now you can be more explicit: 324 | 325 | int res = SWIG_ConvertPtr(obj,vptr,ty.flags); 326 | if (SWIG_IsOK(res)) { 327 | // success code 328 | } else { 329 | // fail code 330 | } 331 | 332 | which is the same really, but now you can also do 333 | 334 | Type *ptr; 335 | int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); 336 | if (SWIG_IsOK(res)) { 337 | // success code 338 | if (SWIG_IsNewObj(res) { 339 | ... 340 | delete *ptr; 341 | } else { 342 | ... 343 | } 344 | } else { 345 | // fail code 346 | } 347 | 348 | I.e., now SWIG_ConvertPtr can return new objects and you can 349 | identify the case and take care of the deallocation. Of course that 350 | also requires SWIG_ConvertPtr to return new result values, such as 351 | 352 | int SWIG_ConvertPtr(obj, ptr,...) { 353 | if () { 354 | if () { 355 | *ptr = ; 356 | return SWIG_NEWOBJ; 357 | } else { 358 | *ptr = ; 359 | return SWIG_OLDOBJ; 360 | } 361 | } else { 362 | return SWIG_BADOBJ; 363 | } 364 | } 365 | 366 | Of course, returning the plain '0(success)/-1(fail)' still works, but you can be 367 | more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the 368 | SWIG errors code. 369 | 370 | Finally, if the SWIG_CASTRANK_MODE is enabled, the result code 371 | allows to return the 'cast rank', for example, if you have this 372 | 373 | int food(double) 374 | int fooi(int); 375 | 376 | and you call 377 | 378 | food(1) // cast rank '1' (1 -> 1.0) 379 | fooi(1) // cast rank '0' 380 | 381 | just use the SWIG_AddCast()/SWIG_CheckState() 382 | */ 383 | 384 | #define SWIG_OK (0) 385 | #define SWIG_ERROR (-1) 386 | #define SWIG_IsOK(r) (r >= 0) 387 | #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) 388 | 389 | /* The CastRankLimit says how many bits are used for the cast rank */ 390 | #define SWIG_CASTRANKLIMIT (1 << 8) 391 | /* The NewMask denotes the object was created (using new/malloc) */ 392 | #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) 393 | /* The TmpMask is for in/out typemaps that use temporal objects */ 394 | #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) 395 | /* Simple returning values */ 396 | #define SWIG_BADOBJ (SWIG_ERROR) 397 | #define SWIG_OLDOBJ (SWIG_OK) 398 | #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) 399 | #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) 400 | /* Check, add and del mask methods */ 401 | #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) 402 | #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) 403 | #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) 404 | #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) 405 | #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) 406 | #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) 407 | 408 | /* Cast-Rank Mode */ 409 | #if defined(SWIG_CASTRANK_MODE) 410 | # ifndef SWIG_TypeRank 411 | # define SWIG_TypeRank unsigned long 412 | # endif 413 | # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ 414 | # define SWIG_MAXCASTRANK (2) 415 | # endif 416 | # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) 417 | # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) 418 | SWIGINTERNINLINE int SWIG_AddCast(int r) { 419 | return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; 420 | } 421 | SWIGINTERNINLINE int SWIG_CheckState(int r) { 422 | return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; 423 | } 424 | #else /* no cast-rank mode */ 425 | # define SWIG_AddCast(r) (r) 426 | # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) 427 | #endif 428 | 429 | 430 | #include 431 | 432 | #ifdef __cplusplus 433 | extern "C" { 434 | #endif 435 | 436 | typedef void *(*swig_converter_func)(void *, int *); 437 | typedef struct swig_type_info *(*swig_dycast_func)(void **); 438 | 439 | /* Structure to store information on one type */ 440 | typedef struct swig_type_info { 441 | const char *name; /* mangled name of this type */ 442 | const char *str; /* human readable name of this type */ 443 | swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ 444 | struct swig_cast_info *cast; /* linked list of types that can cast into this type */ 445 | void *clientdata; /* language specific type data */ 446 | int owndata; /* flag if the structure owns the clientdata */ 447 | } swig_type_info; 448 | 449 | /* Structure to store a type and conversion function used for casting */ 450 | typedef struct swig_cast_info { 451 | swig_type_info *type; /* pointer to type that is equivalent to this type */ 452 | swig_converter_func converter; /* function to cast the void pointers */ 453 | struct swig_cast_info *next; /* pointer to next cast in linked list */ 454 | struct swig_cast_info *prev; /* pointer to the previous cast */ 455 | } swig_cast_info; 456 | 457 | /* Structure used to store module information 458 | * Each module generates one structure like this, and the runtime collects 459 | * all of these structures and stores them in a circularly linked list.*/ 460 | typedef struct swig_module_info { 461 | swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ 462 | size_t size; /* Number of types in this module */ 463 | struct swig_module_info *next; /* Pointer to next element in circularly linked list */ 464 | swig_type_info **type_initial; /* Array of initially generated type structures */ 465 | swig_cast_info **cast_initial; /* Array of initially generated casting structures */ 466 | void *clientdata; /* Language specific module data */ 467 | } swig_module_info; 468 | 469 | /* 470 | Compare two type names skipping the space characters, therefore 471 | "char*" == "char *" and "Class" == "Class", etc. 472 | 473 | Return 0 when the two name types are equivalent, as in 474 | strncmp, but skipping ' '. 475 | */ 476 | SWIGRUNTIME int 477 | SWIG_TypeNameComp(const char *f1, const char *l1, 478 | const char *f2, const char *l2) { 479 | for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { 480 | while ((*f1 == ' ') && (f1 != l1)) ++f1; 481 | while ((*f2 == ' ') && (f2 != l2)) ++f2; 482 | if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; 483 | } 484 | return (int)((l1 - f1) - (l2 - f2)); 485 | } 486 | 487 | /* 488 | Check type equivalence in a name list like ||... 489 | Return 0 if equal, -1 if nb < tb, 1 if nb > tb 490 | */ 491 | SWIGRUNTIME int 492 | SWIG_TypeCmp(const char *nb, const char *tb) { 493 | int equiv = 1; 494 | const char* te = tb + strlen(tb); 495 | const char* ne = nb; 496 | while (equiv != 0 && *ne) { 497 | for (nb = ne; *ne; ++ne) { 498 | if (*ne == '|') break; 499 | } 500 | equiv = SWIG_TypeNameComp(nb, ne, tb, te); 501 | if (*ne) ++ne; 502 | } 503 | return equiv; 504 | } 505 | 506 | /* 507 | Check type equivalence in a name list like ||... 508 | Return 0 if not equal, 1 if equal 509 | */ 510 | SWIGRUNTIME int 511 | SWIG_TypeEquiv(const char *nb, const char *tb) { 512 | return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; 513 | } 514 | 515 | /* 516 | Check the typename 517 | */ 518 | SWIGRUNTIME swig_cast_info * 519 | SWIG_TypeCheck(const char *c, swig_type_info *ty) { 520 | if (ty) { 521 | swig_cast_info *iter = ty->cast; 522 | while (iter) { 523 | if (strcmp(iter->type->name, c) == 0) { 524 | if (iter == ty->cast) 525 | return iter; 526 | /* Move iter to the top of the linked list */ 527 | iter->prev->next = iter->next; 528 | if (iter->next) 529 | iter->next->prev = iter->prev; 530 | iter->next = ty->cast; 531 | iter->prev = 0; 532 | if (ty->cast) ty->cast->prev = iter; 533 | ty->cast = iter; 534 | return iter; 535 | } 536 | iter = iter->next; 537 | } 538 | } 539 | return 0; 540 | } 541 | 542 | /* 543 | Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison 544 | */ 545 | SWIGRUNTIME swig_cast_info * 546 | SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { 547 | if (ty) { 548 | swig_cast_info *iter = ty->cast; 549 | while (iter) { 550 | if (iter->type == from) { 551 | if (iter == ty->cast) 552 | return iter; 553 | /* Move iter to the top of the linked list */ 554 | iter->prev->next = iter->next; 555 | if (iter->next) 556 | iter->next->prev = iter->prev; 557 | iter->next = ty->cast; 558 | iter->prev = 0; 559 | if (ty->cast) ty->cast->prev = iter; 560 | ty->cast = iter; 561 | return iter; 562 | } 563 | iter = iter->next; 564 | } 565 | } 566 | return 0; 567 | } 568 | 569 | /* 570 | Cast a pointer up an inheritance hierarchy 571 | */ 572 | SWIGRUNTIMEINLINE void * 573 | SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { 574 | return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); 575 | } 576 | 577 | /* 578 | Dynamic pointer casting. Down an inheritance hierarchy 579 | */ 580 | SWIGRUNTIME swig_type_info * 581 | SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { 582 | swig_type_info *lastty = ty; 583 | if (!ty || !ty->dcast) return ty; 584 | while (ty && (ty->dcast)) { 585 | ty = (*ty->dcast)(ptr); 586 | if (ty) lastty = ty; 587 | } 588 | return lastty; 589 | } 590 | 591 | /* 592 | Return the name associated with this type 593 | */ 594 | SWIGRUNTIMEINLINE const char * 595 | SWIG_TypeName(const swig_type_info *ty) { 596 | return ty->name; 597 | } 598 | 599 | /* 600 | Return the pretty name associated with this type, 601 | that is an unmangled type name in a form presentable to the user. 602 | */ 603 | SWIGRUNTIME const char * 604 | SWIG_TypePrettyName(const swig_type_info *type) { 605 | /* The "str" field contains the equivalent pretty names of the 606 | type, separated by vertical-bar characters. We choose 607 | to print the last name, as it is often (?) the most 608 | specific. */ 609 | if (!type) return NULL; 610 | if (type->str != NULL) { 611 | const char *last_name = type->str; 612 | const char *s; 613 | for (s = type->str; *s; s++) 614 | if (*s == '|') last_name = s+1; 615 | return last_name; 616 | } 617 | else 618 | return type->name; 619 | } 620 | 621 | /* 622 | Set the clientdata field for a type 623 | */ 624 | SWIGRUNTIME void 625 | SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { 626 | swig_cast_info *cast = ti->cast; 627 | /* if (ti->clientdata == clientdata) return; */ 628 | ti->clientdata = clientdata; 629 | 630 | while (cast) { 631 | if (!cast->converter) { 632 | swig_type_info *tc = cast->type; 633 | if (!tc->clientdata) { 634 | SWIG_TypeClientData(tc, clientdata); 635 | } 636 | } 637 | cast = cast->next; 638 | } 639 | } 640 | SWIGRUNTIME void 641 | SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { 642 | SWIG_TypeClientData(ti, clientdata); 643 | ti->owndata = 1; 644 | } 645 | 646 | /* 647 | Search for a swig_type_info structure only by mangled name 648 | Search is a O(log #types) 649 | 650 | We start searching at module start, and finish searching when start == end. 651 | Note: if start == end at the beginning of the function, we go all the way around 652 | the circular list. 653 | */ 654 | SWIGRUNTIME swig_type_info * 655 | SWIG_MangledTypeQueryModule(swig_module_info *start, 656 | swig_module_info *end, 657 | const char *name) { 658 | swig_module_info *iter = start; 659 | do { 660 | if (iter->size) { 661 | register size_t l = 0; 662 | register size_t r = iter->size - 1; 663 | do { 664 | /* since l+r >= 0, we can (>> 1) instead (/ 2) */ 665 | register size_t i = (l + r) >> 1; 666 | const char *iname = iter->types[i]->name; 667 | if (iname) { 668 | register int compare = strcmp(name, iname); 669 | if (compare == 0) { 670 | return iter->types[i]; 671 | } else if (compare < 0) { 672 | if (i) { 673 | r = i - 1; 674 | } else { 675 | break; 676 | } 677 | } else if (compare > 0) { 678 | l = i + 1; 679 | } 680 | } else { 681 | break; /* should never happen */ 682 | } 683 | } while (l <= r); 684 | } 685 | iter = iter->next; 686 | } while (iter != end); 687 | return 0; 688 | } 689 | 690 | /* 691 | Search for a swig_type_info structure for either a mangled name or a human readable name. 692 | It first searches the mangled names of the types, which is a O(log #types) 693 | If a type is not found it then searches the human readable names, which is O(#types). 694 | 695 | We start searching at module start, and finish searching when start == end. 696 | Note: if start == end at the beginning of the function, we go all the way around 697 | the circular list. 698 | */ 699 | SWIGRUNTIME swig_type_info * 700 | SWIG_TypeQueryModule(swig_module_info *start, 701 | swig_module_info *end, 702 | const char *name) { 703 | /* STEP 1: Search the name field using binary search */ 704 | swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); 705 | if (ret) { 706 | return ret; 707 | } else { 708 | /* STEP 2: If the type hasn't been found, do a complete search 709 | of the str field (the human readable name) */ 710 | swig_module_info *iter = start; 711 | do { 712 | register size_t i = 0; 713 | for (; i < iter->size; ++i) { 714 | if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) 715 | return iter->types[i]; 716 | } 717 | iter = iter->next; 718 | } while (iter != end); 719 | } 720 | 721 | /* neither found a match */ 722 | return 0; 723 | } 724 | 725 | /* 726 | Pack binary data into a string 727 | */ 728 | SWIGRUNTIME char * 729 | SWIG_PackData(char *c, void *ptr, size_t sz) { 730 | static const char hex[17] = "0123456789abcdef"; 731 | register const unsigned char *u = (unsigned char *) ptr; 732 | register const unsigned char *eu = u + sz; 733 | for (; u != eu; ++u) { 734 | register unsigned char uu = *u; 735 | *(c++) = hex[(uu & 0xf0) >> 4]; 736 | *(c++) = hex[uu & 0xf]; 737 | } 738 | return c; 739 | } 740 | 741 | /* 742 | Unpack binary data from a string 743 | */ 744 | SWIGRUNTIME const char * 745 | SWIG_UnpackData(const char *c, void *ptr, size_t sz) { 746 | register unsigned char *u = (unsigned char *) ptr; 747 | register const unsigned char *eu = u + sz; 748 | for (; u != eu; ++u) { 749 | register char d = *(c++); 750 | register unsigned char uu; 751 | if ((d >= '0') && (d <= '9')) 752 | uu = ((d - '0') << 4); 753 | else if ((d >= 'a') && (d <= 'f')) 754 | uu = ((d - ('a'-10)) << 4); 755 | else 756 | return (char *) 0; 757 | d = *(c++); 758 | if ((d >= '0') && (d <= '9')) 759 | uu |= (d - '0'); 760 | else if ((d >= 'a') && (d <= 'f')) 761 | uu |= (d - ('a'-10)); 762 | else 763 | return (char *) 0; 764 | *u = uu; 765 | } 766 | return c; 767 | } 768 | 769 | /* 770 | Pack 'void *' into a string buffer. 771 | */ 772 | SWIGRUNTIME char * 773 | SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { 774 | char *r = buff; 775 | if ((2*sizeof(void *) + 2) > bsz) return 0; 776 | *(r++) = '_'; 777 | r = SWIG_PackData(r,&ptr,sizeof(void *)); 778 | if (strlen(name) + 1 > (bsz - (r - buff))) return 0; 779 | strcpy(r,name); 780 | return buff; 781 | } 782 | 783 | SWIGRUNTIME const char * 784 | SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { 785 | if (*c != '_') { 786 | if (strcmp(c,"NULL") == 0) { 787 | *ptr = (void *) 0; 788 | return name; 789 | } else { 790 | return 0; 791 | } 792 | } 793 | return SWIG_UnpackData(++c,ptr,sizeof(void *)); 794 | } 795 | 796 | SWIGRUNTIME char * 797 | SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { 798 | char *r = buff; 799 | size_t lname = (name ? strlen(name) : 0); 800 | if ((2*sz + 2 + lname) > bsz) return 0; 801 | *(r++) = '_'; 802 | r = SWIG_PackData(r,ptr,sz); 803 | if (lname) { 804 | strncpy(r,name,lname+1); 805 | } else { 806 | *r = 0; 807 | } 808 | return buff; 809 | } 810 | 811 | SWIGRUNTIME const char * 812 | SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { 813 | if (*c != '_') { 814 | if (strcmp(c,"NULL") == 0) { 815 | memset(ptr,0,sz); 816 | return name; 817 | } else { 818 | return 0; 819 | } 820 | } 821 | return SWIG_UnpackData(++c,ptr,sz); 822 | } 823 | 824 | #ifdef __cplusplus 825 | } 826 | #endif 827 | 828 | /* Errors in SWIG */ 829 | #define SWIG_UnknownError -1 830 | #define SWIG_IOError -2 831 | #define SWIG_RuntimeError -3 832 | #define SWIG_IndexError -4 833 | #define SWIG_TypeError -5 834 | #define SWIG_DivisionByZero -6 835 | #define SWIG_OverflowError -7 836 | #define SWIG_SyntaxError -8 837 | #define SWIG_ValueError -9 838 | #define SWIG_SystemError -10 839 | #define SWIG_AttributeError -11 840 | #define SWIG_MemoryError -12 841 | #define SWIG_NullReferenceError -13 842 | 843 | 844 | 845 | #include 846 | 847 | /* Ruby 1.9.1 has a "memoisation optimisation" when compiling with GCC which 848 | * breaks using rb_intern as an lvalue, as SWIG does. We work around this 849 | * issue for now by disabling this. 850 | * https://sourceforge.net/tracker/?func=detail&aid=2859614&group_id=1645&atid=101645 851 | */ 852 | #ifdef rb_intern 853 | # undef rb_intern 854 | #endif 855 | 856 | /* Remove global macros defined in Ruby's win32.h */ 857 | #ifdef write 858 | # undef write 859 | #endif 860 | #ifdef read 861 | # undef read 862 | #endif 863 | #ifdef bind 864 | # undef bind 865 | #endif 866 | #ifdef close 867 | # undef close 868 | #endif 869 | #ifdef connect 870 | # undef connect 871 | #endif 872 | 873 | 874 | /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */ 875 | #ifndef NUM2LL 876 | #define NUM2LL(x) NUM2LONG((x)) 877 | #endif 878 | #ifndef LL2NUM 879 | #define LL2NUM(x) INT2NUM((long) (x)) 880 | #endif 881 | #ifndef ULL2NUM 882 | #define ULL2NUM(x) UINT2NUM((unsigned long) (x)) 883 | #endif 884 | 885 | /* Ruby 1.7 doesn't (yet) define NUM2ULL() */ 886 | #ifndef NUM2ULL 887 | #ifdef HAVE_LONG_LONG 888 | #define NUM2ULL(x) rb_num2ull((x)) 889 | #else 890 | #define NUM2ULL(x) NUM2ULONG(x) 891 | #endif 892 | #endif 893 | 894 | /* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */ 895 | /* Define these for older versions so we can just write code the new way */ 896 | #ifndef RSTRING_LEN 897 | # define RSTRING_LEN(x) RSTRING(x)->len 898 | #endif 899 | #ifndef RSTRING_PTR 900 | # define RSTRING_PTR(x) RSTRING(x)->ptr 901 | #endif 902 | #ifndef RSTRING_END 903 | # define RSTRING_END(x) (RSTRING_PTR(x) + RSTRING_LEN(x)) 904 | #endif 905 | #ifndef RARRAY_LEN 906 | # define RARRAY_LEN(x) RARRAY(x)->len 907 | #endif 908 | #ifndef RARRAY_PTR 909 | # define RARRAY_PTR(x) RARRAY(x)->ptr 910 | #endif 911 | #ifndef RFLOAT_VALUE 912 | # define RFLOAT_VALUE(x) RFLOAT(x)->value 913 | #endif 914 | #ifndef DOUBLE2NUM 915 | # define DOUBLE2NUM(x) rb_float_new(x) 916 | #endif 917 | #ifndef RHASH_TBL 918 | # define RHASH_TBL(x) (RHASH(x)->tbl) 919 | #endif 920 | #ifndef RHASH_ITER_LEV 921 | # define RHASH_ITER_LEV(x) (RHASH(x)->iter_lev) 922 | #endif 923 | #ifndef RHASH_IFNONE 924 | # define RHASH_IFNONE(x) (RHASH(x)->ifnone) 925 | #endif 926 | #ifndef RHASH_SIZE 927 | # define RHASH_SIZE(x) (RHASH(x)->tbl->num_entries) 928 | #endif 929 | #ifndef RHASH_EMPTY_P 930 | # define RHASH_EMPTY_P(x) (RHASH_SIZE(x) == 0) 931 | #endif 932 | #ifndef RSTRUCT_LEN 933 | # define RSTRUCT_LEN(x) RSTRUCT(x)->len 934 | #endif 935 | #ifndef RSTRUCT_PTR 936 | # define RSTRUCT_PTR(x) RSTRUCT(x)->ptr 937 | #endif 938 | 939 | 940 | 941 | /* 942 | * Need to be very careful about how these macros are defined, especially 943 | * when compiling C++ code or C code with an ANSI C compiler. 944 | * 945 | * VALUEFUNC(f) is a macro used to typecast a C function that implements 946 | * a Ruby method so that it can be passed as an argument to API functions 947 | * like rb_define_method() and rb_define_singleton_method(). 948 | * 949 | * VOIDFUNC(f) is a macro used to typecast a C function that implements 950 | * either the "mark" or "free" stuff for a Ruby Data object, so that it 951 | * can be passed as an argument to API functions like Data_Wrap_Struct() 952 | * and Data_Make_Struct(). 953 | */ 954 | 955 | #ifdef __cplusplus 956 | # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */ 957 | # define PROTECTFUNC(f) ((VALUE (*)()) f) 958 | # define VALUEFUNC(f) ((VALUE (*)()) f) 959 | # define VOIDFUNC(f) ((void (*)()) f) 960 | # else 961 | # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */ 962 | # define PROTECTFUNC(f) ((VALUE (*)()) f) 963 | # define VALUEFUNC(f) ((VALUE (*)()) f) 964 | # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) 965 | # else /* These definitions should work for Ruby 1.7+ */ 966 | # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f) 967 | # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f) 968 | # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) 969 | # endif 970 | # endif 971 | #else 972 | # define VALUEFUNC(f) (f) 973 | # define VOIDFUNC(f) (f) 974 | #endif 975 | 976 | /* Don't use for expressions have side effect */ 977 | #ifndef RB_STRING_VALUE 978 | #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s))) 979 | #endif 980 | #ifndef StringValue 981 | #define StringValue(s) RB_STRING_VALUE(s) 982 | #endif 983 | #ifndef StringValuePtr 984 | #define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s)) 985 | #endif 986 | #ifndef StringValueLen 987 | #define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s)) 988 | #endif 989 | #ifndef SafeStringValue 990 | #define SafeStringValue(v) do {\ 991 | StringValue(v);\ 992 | rb_check_safe_str(v);\ 993 | } while (0) 994 | #endif 995 | 996 | #ifndef HAVE_RB_DEFINE_ALLOC_FUNC 997 | #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1) 998 | #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new") 999 | #endif 1000 | 1001 | static VALUE _mSWIG = Qnil; 1002 | 1003 | /* ----------------------------------------------------------------------------- 1004 | * error manipulation 1005 | * ----------------------------------------------------------------------------- */ 1006 | 1007 | 1008 | /* Define some additional error types */ 1009 | #define SWIG_ObjectPreviouslyDeletedError -100 1010 | 1011 | 1012 | /* Define custom exceptions for errors that do not map to existing Ruby 1013 | exceptions. Note this only works for C++ since a global cannot be 1014 | initialized by a function in C. For C, fallback to rb_eRuntimeError.*/ 1015 | 1016 | SWIGINTERN VALUE 1017 | getNullReferenceError(void) { 1018 | static int init = 0; 1019 | static VALUE rb_eNullReferenceError ; 1020 | if (!init) { 1021 | init = 1; 1022 | rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError); 1023 | } 1024 | return rb_eNullReferenceError; 1025 | } 1026 | 1027 | SWIGINTERN VALUE 1028 | getObjectPreviouslyDeletedError(void) { 1029 | static int init = 0; 1030 | static VALUE rb_eObjectPreviouslyDeleted ; 1031 | if (!init) { 1032 | init = 1; 1033 | rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError); 1034 | } 1035 | return rb_eObjectPreviouslyDeleted; 1036 | } 1037 | 1038 | 1039 | SWIGINTERN VALUE 1040 | SWIG_Ruby_ErrorType(int SWIG_code) { 1041 | VALUE type; 1042 | switch (SWIG_code) { 1043 | case SWIG_MemoryError: 1044 | type = rb_eNoMemError; 1045 | break; 1046 | case SWIG_IOError: 1047 | type = rb_eIOError; 1048 | break; 1049 | case SWIG_RuntimeError: 1050 | type = rb_eRuntimeError; 1051 | break; 1052 | case SWIG_IndexError: 1053 | type = rb_eIndexError; 1054 | break; 1055 | case SWIG_TypeError: 1056 | type = rb_eTypeError; 1057 | break; 1058 | case SWIG_DivisionByZero: 1059 | type = rb_eZeroDivError; 1060 | break; 1061 | case SWIG_OverflowError: 1062 | type = rb_eRangeError; 1063 | break; 1064 | case SWIG_SyntaxError: 1065 | type = rb_eSyntaxError; 1066 | break; 1067 | case SWIG_ValueError: 1068 | type = rb_eArgError; 1069 | break; 1070 | case SWIG_SystemError: 1071 | type = rb_eFatal; 1072 | break; 1073 | case SWIG_AttributeError: 1074 | type = rb_eRuntimeError; 1075 | break; 1076 | case SWIG_NullReferenceError: 1077 | type = getNullReferenceError(); 1078 | break; 1079 | case SWIG_ObjectPreviouslyDeletedError: 1080 | type = getObjectPreviouslyDeletedError(); 1081 | break; 1082 | case SWIG_UnknownError: 1083 | type = rb_eRuntimeError; 1084 | break; 1085 | default: 1086 | type = rb_eRuntimeError; 1087 | } 1088 | return type; 1089 | } 1090 | 1091 | 1092 | /* This function is called when a user inputs a wrong argument to 1093 | a method. 1094 | */ 1095 | SWIGINTERN 1096 | const char* Ruby_Format_TypeError( const char* msg, 1097 | const char* type, 1098 | const char* name, 1099 | const int argn, 1100 | VALUE input ) 1101 | { 1102 | char buf[128]; 1103 | VALUE str; 1104 | VALUE asStr; 1105 | if ( msg && *msg ) 1106 | { 1107 | str = rb_str_new2(msg); 1108 | } 1109 | else 1110 | { 1111 | str = rb_str_new(NULL, 0); 1112 | } 1113 | 1114 | str = rb_str_cat2( str, "Expected argument " ); 1115 | sprintf( buf, "%d of type ", argn-1 ); 1116 | str = rb_str_cat2( str, buf ); 1117 | str = rb_str_cat2( str, type ); 1118 | str = rb_str_cat2( str, ", but got " ); 1119 | str = rb_str_cat2( str, rb_obj_classname(input) ); 1120 | str = rb_str_cat2( str, " " ); 1121 | asStr = rb_inspect(input); 1122 | if ( RSTRING_LEN(asStr) > 30 ) 1123 | { 1124 | str = rb_str_cat( str, StringValuePtr(asStr), 30 ); 1125 | str = rb_str_cat2( str, "..." ); 1126 | } 1127 | else 1128 | { 1129 | str = rb_str_append( str, asStr ); 1130 | } 1131 | 1132 | if ( name ) 1133 | { 1134 | str = rb_str_cat2( str, "\n\tin SWIG method '" ); 1135 | str = rb_str_cat2( str, name ); 1136 | str = rb_str_cat2( str, "'" ); 1137 | } 1138 | 1139 | return StringValuePtr( str ); 1140 | } 1141 | 1142 | /* This function is called when an overloaded method fails */ 1143 | SWIGINTERN 1144 | void Ruby_Format_OverloadedError( 1145 | const int argc, 1146 | const int maxargs, 1147 | const char* method, 1148 | const char* prototypes 1149 | ) 1150 | { 1151 | const char* msg = "Wrong # of arguments"; 1152 | if ( argc <= maxargs ) msg = "Wrong arguments"; 1153 | rb_raise(rb_eArgError,"%s for overloaded method '%s'.\n" 1154 | "Possible C/C++ prototypes are:\n%s", 1155 | msg, method, prototypes); 1156 | } 1157 | 1158 | /* ----------------------------------------------------------------------------- 1159 | * rubytracking.swg 1160 | * 1161 | * This file contains support for tracking mappings from 1162 | * Ruby objects to C++ objects. This functionality is needed 1163 | * to implement mark functions for Ruby's mark and sweep 1164 | * garbage collector. 1165 | * ----------------------------------------------------------------------------- */ 1166 | 1167 | #ifdef __cplusplus 1168 | extern "C" { 1169 | #endif 1170 | 1171 | /* Ruby 1.8 actually assumes the first case. */ 1172 | #if SIZEOF_VOIDP == SIZEOF_LONG 1173 | # define SWIG2NUM(v) LONG2NUM((unsigned long)v) 1174 | # define NUM2SWIG(x) (unsigned long)NUM2LONG(x) 1175 | #elif SIZEOF_VOIDP == SIZEOF_LONG_LONG 1176 | # define SWIG2NUM(v) LL2NUM((unsigned long long)v) 1177 | # define NUM2SWIG(x) (unsigned long long)NUM2LL(x) 1178 | #else 1179 | # error sizeof(void*) is not the same as long or long long 1180 | #endif 1181 | 1182 | 1183 | /* Global Ruby hash table to store Trackings from C/C++ 1184 | structs to Ruby Objects. 1185 | */ 1186 | static VALUE swig_ruby_trackings = Qnil; 1187 | 1188 | /* Global variable that stores a reference to the ruby 1189 | hash table delete function. */ 1190 | static ID swig_ruby_hash_delete; 1191 | 1192 | /* Setup a Ruby hash table to store Trackings */ 1193 | SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { 1194 | /* Create a ruby hash table to store Trackings from C++ 1195 | objects to Ruby objects. */ 1196 | 1197 | /* Try to see if some other .so has already created a 1198 | tracking hash table, which we keep hidden in an instance var 1199 | in the SWIG module. 1200 | This is done to allow multiple DSOs to share the same 1201 | tracking table. 1202 | */ 1203 | ID trackings_id = rb_intern( "@__trackings__" ); 1204 | VALUE verbose = rb_gv_get("VERBOSE"); 1205 | rb_gv_set("VERBOSE", Qfalse); 1206 | swig_ruby_trackings = rb_ivar_get( _mSWIG, trackings_id ); 1207 | rb_gv_set("VERBOSE", verbose); 1208 | 1209 | /* No, it hasn't. Create one ourselves */ 1210 | if ( swig_ruby_trackings == Qnil ) 1211 | { 1212 | swig_ruby_trackings = rb_hash_new(); 1213 | rb_ivar_set( _mSWIG, trackings_id, swig_ruby_trackings ); 1214 | } 1215 | 1216 | /* Now store a reference to the hash table delete function 1217 | so that we only have to look it up once.*/ 1218 | swig_ruby_hash_delete = rb_intern("delete"); 1219 | } 1220 | 1221 | /* Get a Ruby number to reference a pointer */ 1222 | SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) { 1223 | /* We cast the pointer to an unsigned long 1224 | and then store a reference to it using 1225 | a Ruby number object. */ 1226 | 1227 | /* Convert the pointer to a Ruby number */ 1228 | return SWIG2NUM(ptr); 1229 | } 1230 | 1231 | /* Get a Ruby number to reference an object */ 1232 | SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) { 1233 | /* We cast the object to an unsigned long 1234 | and then store a reference to it using 1235 | a Ruby number object. */ 1236 | 1237 | /* Convert the Object to a Ruby number */ 1238 | return SWIG2NUM(object); 1239 | } 1240 | 1241 | /* Get a Ruby object from a previously stored reference */ 1242 | SWIGRUNTIME VALUE SWIG_RubyReferenceToObject(VALUE reference) { 1243 | /* The provided Ruby number object is a reference 1244 | to the Ruby object we want.*/ 1245 | 1246 | /* Convert the Ruby number to a Ruby object */ 1247 | return NUM2SWIG(reference); 1248 | } 1249 | 1250 | /* Add a Tracking from a C/C++ struct to a Ruby object */ 1251 | SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) { 1252 | /* In a Ruby hash table we store the pointer and 1253 | the associated Ruby object. The trick here is 1254 | that we cannot store the Ruby object directly - if 1255 | we do then it cannot be garbage collected. So 1256 | instead we typecast it as a unsigned long and 1257 | convert it to a Ruby number object.*/ 1258 | 1259 | /* Get a reference to the pointer as a Ruby number */ 1260 | VALUE key = SWIG_RubyPtrToReference(ptr); 1261 | 1262 | /* Get a reference to the Ruby object as a Ruby number */ 1263 | VALUE value = SWIG_RubyObjectToReference(object); 1264 | 1265 | /* Store the mapping to the global hash table. */ 1266 | rb_hash_aset(swig_ruby_trackings, key, value); 1267 | } 1268 | 1269 | /* Get the Ruby object that owns the specified C/C++ struct */ 1270 | SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) { 1271 | /* Get a reference to the pointer as a Ruby number */ 1272 | VALUE key = SWIG_RubyPtrToReference(ptr); 1273 | 1274 | /* Now lookup the value stored in the global hash table */ 1275 | VALUE value = rb_hash_aref(swig_ruby_trackings, key); 1276 | 1277 | if (value == Qnil) { 1278 | /* No object exists - return nil. */ 1279 | return Qnil; 1280 | } 1281 | else { 1282 | /* Convert this value to Ruby object */ 1283 | return SWIG_RubyReferenceToObject(value); 1284 | } 1285 | } 1286 | 1287 | /* Remove a Tracking from a C/C++ struct to a Ruby object. It 1288 | is very important to remove objects once they are destroyed 1289 | since the same memory address may be reused later to create 1290 | a new object. */ 1291 | SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) { 1292 | /* Get a reference to the pointer as a Ruby number */ 1293 | VALUE key = SWIG_RubyPtrToReference(ptr); 1294 | 1295 | /* Delete the object from the hash table by calling Ruby's 1296 | do this we need to call the Hash.delete method.*/ 1297 | rb_funcall(swig_ruby_trackings, swig_ruby_hash_delete, 1, key); 1298 | } 1299 | 1300 | /* This is a helper method that unlinks a Ruby object from its 1301 | underlying C++ object. This is needed if the lifetime of the 1302 | Ruby object is longer than the C++ object */ 1303 | SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) { 1304 | VALUE object = SWIG_RubyInstanceFor(ptr); 1305 | 1306 | if (object != Qnil) { 1307 | DATA_PTR(object) = 0; 1308 | } 1309 | } 1310 | 1311 | 1312 | #ifdef __cplusplus 1313 | } 1314 | #endif 1315 | 1316 | /* ----------------------------------------------------------------------------- 1317 | * Ruby API portion that goes into the runtime 1318 | * ----------------------------------------------------------------------------- */ 1319 | 1320 | #ifdef __cplusplus 1321 | extern "C" { 1322 | #endif 1323 | 1324 | SWIGINTERN VALUE 1325 | SWIG_Ruby_AppendOutput(VALUE target, VALUE o) { 1326 | if (NIL_P(target)) { 1327 | target = o; 1328 | } else { 1329 | if (TYPE(target) != T_ARRAY) { 1330 | VALUE o2 = target; 1331 | target = rb_ary_new(); 1332 | rb_ary_push(target, o2); 1333 | } 1334 | rb_ary_push(target, o); 1335 | } 1336 | return target; 1337 | } 1338 | 1339 | /* For ruby1.8.4 and earlier. */ 1340 | #ifndef RUBY_INIT_STACK 1341 | RUBY_EXTERN void Init_stack(VALUE* addr); 1342 | # define RUBY_INIT_STACK \ 1343 | VALUE variable_in_this_stack_frame; \ 1344 | Init_stack(&variable_in_this_stack_frame); 1345 | #endif 1346 | 1347 | 1348 | #ifdef __cplusplus 1349 | } 1350 | #endif 1351 | 1352 | 1353 | /* ----------------------------------------------------------------------------- 1354 | * rubyrun.swg 1355 | * 1356 | * This file contains the runtime support for Ruby modules 1357 | * and includes code for managing global variables and pointer 1358 | * type checking. 1359 | * ----------------------------------------------------------------------------- */ 1360 | 1361 | /* For backward compatibility only */ 1362 | #define SWIG_POINTER_EXCEPTION 0 1363 | 1364 | /* for raw pointers */ 1365 | #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0) 1366 | #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own) 1367 | #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags) 1368 | #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own) 1369 | #define swig_owntype ruby_owntype 1370 | 1371 | /* for raw packed data */ 1372 | #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags) 1373 | #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type) 1374 | 1375 | /* for class or struct pointers */ 1376 | #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) 1377 | #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) 1378 | 1379 | /* for C or C++ function pointers */ 1380 | #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0) 1381 | #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0) 1382 | 1383 | /* for C++ member pointers, ie, member methods */ 1384 | #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty) 1385 | #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type) 1386 | 1387 | 1388 | /* Runtime API */ 1389 | 1390 | #define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule(clientdata) 1391 | #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer) 1392 | 1393 | 1394 | /* Error manipulation */ 1395 | 1396 | #define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code) 1397 | #define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), "%s", msg) 1398 | #define SWIG_fail goto fail 1399 | 1400 | 1401 | /* Ruby-specific SWIG API */ 1402 | 1403 | #define SWIG_InitRuntime() SWIG_Ruby_InitRuntime() 1404 | #define SWIG_define_class(ty) SWIG_Ruby_define_class(ty) 1405 | #define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty) 1406 | #define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value) 1407 | #define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty) 1408 | 1409 | #include "assert.h" 1410 | 1411 | /* ----------------------------------------------------------------------------- 1412 | * pointers/data manipulation 1413 | * ----------------------------------------------------------------------------- */ 1414 | 1415 | #ifdef __cplusplus 1416 | extern "C" { 1417 | #endif 1418 | 1419 | typedef struct { 1420 | VALUE klass; 1421 | VALUE mImpl; 1422 | void (*mark)(void *); 1423 | void (*destroy)(void *); 1424 | int trackObjects; 1425 | } swig_class; 1426 | 1427 | 1428 | /* Global pointer used to keep some internal SWIG stuff */ 1429 | static VALUE _cSWIG_Pointer = Qnil; 1430 | static VALUE swig_runtime_data_type_pointer = Qnil; 1431 | 1432 | /* Global IDs used to keep some internal SWIG stuff */ 1433 | static ID swig_arity_id = 0; 1434 | static ID swig_call_id = 0; 1435 | 1436 | /* 1437 | If your swig extension is to be run within an embedded ruby and has 1438 | director callbacks, you should set -DRUBY_EMBEDDED during compilation. 1439 | This will reset ruby's stack frame on each entry point from the main 1440 | program the first time a virtual director function is invoked (in a 1441 | non-recursive way). 1442 | If this is not done, you run the risk of Ruby trashing the stack. 1443 | */ 1444 | 1445 | #ifdef RUBY_EMBEDDED 1446 | 1447 | # define SWIG_INIT_STACK \ 1448 | if ( !swig_virtual_calls ) { RUBY_INIT_STACK } \ 1449 | ++swig_virtual_calls; 1450 | # define SWIG_RELEASE_STACK --swig_virtual_calls; 1451 | # define Ruby_DirectorTypeMismatchException(x) \ 1452 | rb_raise( rb_eTypeError, "%s", x ); return c_result; 1453 | 1454 | static unsigned int swig_virtual_calls = 0; 1455 | 1456 | #else /* normal non-embedded extension */ 1457 | 1458 | # define SWIG_INIT_STACK 1459 | # define SWIG_RELEASE_STACK 1460 | # define Ruby_DirectorTypeMismatchException(x) \ 1461 | throw Swig::DirectorTypeMismatchException( x ); 1462 | 1463 | #endif /* RUBY_EMBEDDED */ 1464 | 1465 | 1466 | SWIGRUNTIME VALUE 1467 | getExceptionClass(void) { 1468 | static int init = 0; 1469 | static VALUE rubyExceptionClass ; 1470 | if (!init) { 1471 | init = 1; 1472 | rubyExceptionClass = rb_const_get(_mSWIG, rb_intern("Exception")); 1473 | } 1474 | return rubyExceptionClass; 1475 | } 1476 | 1477 | /* This code checks to see if the Ruby object being raised as part 1478 | of an exception inherits from the Ruby class Exception. If so, 1479 | the object is simply returned. If not, then a new Ruby exception 1480 | object is created and that will be returned to Ruby.*/ 1481 | SWIGRUNTIME VALUE 1482 | SWIG_Ruby_ExceptionType(swig_type_info *desc, VALUE obj) { 1483 | VALUE exceptionClass = getExceptionClass(); 1484 | if (rb_obj_is_kind_of(obj, exceptionClass)) { 1485 | return obj; 1486 | } else { 1487 | return rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj)); 1488 | } 1489 | } 1490 | 1491 | /* Initialize Ruby runtime support */ 1492 | SWIGRUNTIME void 1493 | SWIG_Ruby_InitRuntime(void) 1494 | { 1495 | if (_mSWIG == Qnil) { 1496 | _mSWIG = rb_define_module("SWIG"); 1497 | swig_call_id = rb_intern("call"); 1498 | swig_arity_id = rb_intern("arity"); 1499 | } 1500 | } 1501 | 1502 | /* Define Ruby class for C type */ 1503 | SWIGRUNTIME void 1504 | SWIG_Ruby_define_class(swig_type_info *type) 1505 | { 1506 | VALUE klass; 1507 | char *klass_name = (char *) malloc(4 + strlen(type->name) + 1); 1508 | sprintf(klass_name, "TYPE%s", type->name); 1509 | if (NIL_P(_cSWIG_Pointer)) { 1510 | _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject); 1511 | rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new"); 1512 | } 1513 | klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer); 1514 | free((void *) klass_name); 1515 | } 1516 | 1517 | /* Create a new pointer object */ 1518 | SWIGRUNTIME VALUE 1519 | SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags) 1520 | { 1521 | int own = flags & SWIG_POINTER_OWN; 1522 | int track; 1523 | char *klass_name; 1524 | swig_class *sklass; 1525 | VALUE klass; 1526 | VALUE obj; 1527 | 1528 | if (!ptr) 1529 | return Qnil; 1530 | 1531 | if (type->clientdata) { 1532 | sklass = (swig_class *) type->clientdata; 1533 | 1534 | /* Are we tracking this class and have we already returned this Ruby object? */ 1535 | track = sklass->trackObjects; 1536 | if (track) { 1537 | obj = SWIG_RubyInstanceFor(ptr); 1538 | 1539 | /* Check the object's type and make sure it has the correct type. 1540 | It might not in cases where methods do things like 1541 | downcast methods. */ 1542 | if (obj != Qnil) { 1543 | VALUE value = rb_iv_get(obj, "@__swigtype__"); 1544 | const char* type_name = RSTRING_PTR(value); 1545 | 1546 | if (strcmp(type->name, type_name) == 0) { 1547 | return obj; 1548 | } 1549 | } 1550 | } 1551 | 1552 | /* Create a new Ruby object */ 1553 | obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), 1554 | ( own ? VOIDFUNC(sklass->destroy) : 1555 | (track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 ) 1556 | ), ptr); 1557 | 1558 | /* If tracking is on for this class then track this object. */ 1559 | if (track) { 1560 | SWIG_RubyAddTracking(ptr, obj); 1561 | } 1562 | } else { 1563 | klass_name = (char *) malloc(4 + strlen(type->name) + 1); 1564 | sprintf(klass_name, "TYPE%s", type->name); 1565 | klass = rb_const_get(_mSWIG, rb_intern(klass_name)); 1566 | free((void *) klass_name); 1567 | obj = Data_Wrap_Struct(klass, 0, 0, ptr); 1568 | } 1569 | rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); 1570 | 1571 | return obj; 1572 | } 1573 | 1574 | /* Create a new class instance (always owned) */ 1575 | SWIGRUNTIME VALUE 1576 | SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) 1577 | { 1578 | VALUE obj; 1579 | swig_class *sklass = (swig_class *) type->clientdata; 1580 | obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0); 1581 | rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); 1582 | return obj; 1583 | } 1584 | 1585 | /* Get type mangle from class name */ 1586 | SWIGRUNTIMEINLINE char * 1587 | SWIG_Ruby_MangleStr(VALUE obj) 1588 | { 1589 | VALUE stype = rb_iv_get(obj, "@__swigtype__"); 1590 | return StringValuePtr(stype); 1591 | } 1592 | 1593 | /* Acquire a pointer value */ 1594 | typedef void (*ruby_owntype)(void*); 1595 | 1596 | SWIGRUNTIME ruby_owntype 1597 | SWIG_Ruby_AcquirePtr(VALUE obj, ruby_owntype own) { 1598 | if (obj) { 1599 | ruby_owntype oldown = RDATA(obj)->dfree; 1600 | RDATA(obj)->dfree = own; 1601 | return oldown; 1602 | } else { 1603 | return 0; 1604 | } 1605 | } 1606 | 1607 | /* Convert a pointer value */ 1608 | SWIGRUNTIME int 1609 | SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, ruby_owntype *own) 1610 | { 1611 | char *c; 1612 | swig_cast_info *tc; 1613 | void *vptr = 0; 1614 | 1615 | /* Grab the pointer */ 1616 | if (NIL_P(obj)) { 1617 | *ptr = 0; 1618 | return SWIG_OK; 1619 | } else { 1620 | if (TYPE(obj) != T_DATA) { 1621 | return SWIG_ERROR; 1622 | } 1623 | Data_Get_Struct(obj, void, vptr); 1624 | } 1625 | 1626 | if (own) *own = RDATA(obj)->dfree; 1627 | 1628 | /* Check to see if the input object is giving up ownership 1629 | of the underlying C struct or C++ object. If so then we 1630 | need to reset the destructor since the Ruby object no 1631 | longer owns the underlying C++ object.*/ 1632 | if (flags & SWIG_POINTER_DISOWN) { 1633 | /* Is tracking on for this class? */ 1634 | int track = 0; 1635 | if (ty && ty->clientdata) { 1636 | swig_class *sklass = (swig_class *) ty->clientdata; 1637 | track = sklass->trackObjects; 1638 | } 1639 | 1640 | if (track) { 1641 | /* We are tracking objects for this class. Thus we change the destructor 1642 | * to SWIG_RubyRemoveTracking. This allows us to 1643 | * remove the mapping from the C++ to Ruby object 1644 | * when the Ruby object is garbage collected. If we don't 1645 | * do this, then it is possible we will return a reference 1646 | * to a Ruby object that no longer exists thereby crashing Ruby. */ 1647 | RDATA(obj)->dfree = SWIG_RubyRemoveTracking; 1648 | } else { 1649 | RDATA(obj)->dfree = 0; 1650 | } 1651 | } 1652 | 1653 | /* Do type-checking if type info was provided */ 1654 | if (ty) { 1655 | if (ty->clientdata) { 1656 | if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) { 1657 | if (vptr == 0) { 1658 | /* The object has already been deleted */ 1659 | return SWIG_ObjectPreviouslyDeletedError; 1660 | } 1661 | *ptr = vptr; 1662 | return SWIG_OK; 1663 | } 1664 | } 1665 | if ((c = SWIG_MangleStr(obj)) == NULL) { 1666 | return SWIG_ERROR; 1667 | } 1668 | tc = SWIG_TypeCheck(c, ty); 1669 | if (!tc) { 1670 | return SWIG_ERROR; 1671 | } else { 1672 | int newmemory = 0; 1673 | *ptr = SWIG_TypeCast(tc, vptr, &newmemory); 1674 | assert(!newmemory); /* newmemory handling not yet implemented */ 1675 | } 1676 | } else { 1677 | *ptr = vptr; 1678 | } 1679 | 1680 | return SWIG_OK; 1681 | } 1682 | 1683 | /* Check convert */ 1684 | SWIGRUNTIMEINLINE int 1685 | SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty) 1686 | { 1687 | char *c = SWIG_MangleStr(obj); 1688 | if (!c) return 0; 1689 | return SWIG_TypeCheck(c,ty) != 0; 1690 | } 1691 | 1692 | SWIGRUNTIME VALUE 1693 | SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) { 1694 | char result[1024]; 1695 | char *r = result; 1696 | if ((2*sz + 1 + strlen(type->name)) > 1000) return 0; 1697 | *(r++) = '_'; 1698 | r = SWIG_PackData(r, ptr, sz); 1699 | strcpy(r, type->name); 1700 | return rb_str_new2(result); 1701 | } 1702 | 1703 | /* Convert a packed value value */ 1704 | SWIGRUNTIME int 1705 | SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) { 1706 | swig_cast_info *tc; 1707 | const char *c; 1708 | 1709 | if (TYPE(obj) != T_STRING) goto type_error; 1710 | c = StringValuePtr(obj); 1711 | /* Pointer values must start with leading underscore */ 1712 | if (*c != '_') goto type_error; 1713 | c++; 1714 | c = SWIG_UnpackData(c, ptr, sz); 1715 | if (ty) { 1716 | tc = SWIG_TypeCheck(c, ty); 1717 | if (!tc) goto type_error; 1718 | } 1719 | return SWIG_OK; 1720 | 1721 | type_error: 1722 | return SWIG_ERROR; 1723 | } 1724 | 1725 | SWIGRUNTIME swig_module_info * 1726 | SWIG_Ruby_GetModule(void *SWIGUNUSEDPARM(clientdata)) 1727 | { 1728 | VALUE pointer; 1729 | swig_module_info *ret = 0; 1730 | VALUE verbose = rb_gv_get("VERBOSE"); 1731 | 1732 | /* temporarily disable warnings, since the pointer check causes warnings with 'ruby -w' */ 1733 | rb_gv_set("VERBOSE", Qfalse); 1734 | 1735 | /* first check if pointer already created */ 1736 | pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); 1737 | if (pointer != Qnil) { 1738 | Data_Get_Struct(pointer, swig_module_info, ret); 1739 | } 1740 | 1741 | /* reinstate warnings */ 1742 | rb_gv_set("VERBOSE", verbose); 1743 | return ret; 1744 | } 1745 | 1746 | SWIGRUNTIME void 1747 | SWIG_Ruby_SetModule(swig_module_info *pointer) 1748 | { 1749 | /* register a new class */ 1750 | VALUE cl = rb_define_class("swig_runtime_data", rb_cObject); 1751 | /* create and store the structure pointer to a global variable */ 1752 | swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer); 1753 | rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer); 1754 | } 1755 | 1756 | /* This function can be used to check whether a proc or method or similarly 1757 | callable function has been passed. Usually used in a %typecheck, like: 1758 | 1759 | %typecheck(c_callback_t, precedence=SWIG_TYPECHECK_POINTER) { 1760 | $result = SWIG_Ruby_isCallable( $input ); 1761 | } 1762 | */ 1763 | SWIGINTERN 1764 | int SWIG_Ruby_isCallable( VALUE proc ) 1765 | { 1766 | if ( rb_respond_to( proc, swig_call_id ) ) 1767 | return 1; 1768 | return 0; 1769 | } 1770 | 1771 | /* This function can be used to check the arity (number of arguments) 1772 | a proc or method can take. Usually used in a %typecheck. 1773 | Valid arities will be that equal to minimal or those < 0 1774 | which indicate a variable number of parameters at the end. 1775 | */ 1776 | SWIGINTERN 1777 | int SWIG_Ruby_arity( VALUE proc, int minimal ) 1778 | { 1779 | if ( rb_respond_to( proc, swig_arity_id ) ) 1780 | { 1781 | VALUE num = rb_funcall( proc, swig_arity_id, 0 ); 1782 | int arity = NUM2INT(num); 1783 | if ( arity < 0 && (arity+1) < -minimal ) return 1; 1784 | if ( arity == minimal ) return 1; 1785 | return 1; 1786 | } 1787 | return 0; 1788 | } 1789 | 1790 | 1791 | #ifdef __cplusplus 1792 | } 1793 | #endif 1794 | 1795 | 1796 | 1797 | #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) 1798 | 1799 | #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else 1800 | 1801 | 1802 | 1803 | /* -------- TYPES TABLE (BEGIN) -------- */ 1804 | 1805 | #define SWIGTYPE_p_char swig_types[0] 1806 | static swig_type_info *swig_types[2]; 1807 | static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0}; 1808 | #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) 1809 | #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) 1810 | 1811 | /* -------- TYPES TABLE (END) -------- */ 1812 | 1813 | #define SWIG_init Init_tf 1814 | #define SWIG_name "Tf" 1815 | 1816 | static VALUE mTf; 1817 | 1818 | #define SWIG_RUBY_THREAD_BEGIN_BLOCK 1819 | #define SWIG_RUBY_THREAD_END_BLOCK 1820 | 1821 | 1822 | #define SWIGVERSION 0x020011 1823 | #define SWIG_VERSION SWIGVERSION 1824 | 1825 | 1826 | #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) 1827 | #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) 1828 | 1829 | 1830 | #include 1831 | 1832 | 1833 | #include "tensorflow/core/platform/types.h" 1834 | using tensorflow::uint64; 1835 | using tensorflow::string; 1836 | 1837 | 1838 | #include "tensorflow/core/util/port.h" 1839 | 1840 | 1841 | SWIGINTERNINLINE VALUE 1842 | SWIG_From_bool (bool value) 1843 | { 1844 | return value ? Qtrue : Qfalse; 1845 | } 1846 | 1847 | 1848 | #include "tensorflow/core/public/version.h" 1849 | 1850 | extern const char version[] = TF_VERSION_STRING; 1851 | 1852 | 1853 | #include 1854 | #if !defined(SWIG_NO_LLONG_MAX) 1855 | # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) 1856 | # define LLONG_MAX __LONG_LONG_MAX__ 1857 | # define LLONG_MIN (-LLONG_MAX - 1LL) 1858 | # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) 1859 | # endif 1860 | #endif 1861 | 1862 | 1863 | #define SWIG_From_long LONG2NUM 1864 | 1865 | 1866 | SWIGINTERNINLINE VALUE 1867 | SWIG_From_int (int value) 1868 | { 1869 | return SWIG_From_long (value); 1870 | } 1871 | 1872 | 1873 | SWIGINTERN swig_type_info* 1874 | SWIG_pchar_descriptor(void) 1875 | { 1876 | static int init = 0; 1877 | static swig_type_info* info = 0; 1878 | if (!init) { 1879 | info = SWIG_TypeQuery("_p_char"); 1880 | init = 1; 1881 | } 1882 | return info; 1883 | } 1884 | 1885 | 1886 | SWIGINTERNINLINE VALUE 1887 | SWIG_FromCharPtrAndSize(const char* carray, size_t size) 1888 | { 1889 | if (carray) { 1890 | if (size > LONG_MAX) { 1891 | swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); 1892 | return pchar_descriptor ? 1893 | SWIG_NewPointerObj(const_cast< char * >(carray), pchar_descriptor, 0) : Qnil; 1894 | } else { 1895 | return rb_str_new(carray, static_cast< long >(size)); 1896 | } 1897 | } else { 1898 | return Qnil; 1899 | } 1900 | } 1901 | 1902 | 1903 | SWIGINTERNINLINE VALUE 1904 | SWIG_FromCharPtr(const char *cptr) 1905 | { 1906 | return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); 1907 | } 1908 | 1909 | SWIGINTERN VALUE 1910 | _wrap_IsGoogleCudaEnabled(int argc, VALUE *argv, VALUE self) { 1911 | bool result; 1912 | VALUE vresult = Qnil; 1913 | 1914 | if ((argc < 0) || (argc > 0)) { 1915 | rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail; 1916 | } 1917 | result = (bool)tensorflow::IsGoogleCudaEnabled(); 1918 | vresult = SWIG_From_bool(static_cast< bool >(result)); 1919 | return vresult; 1920 | fail: 1921 | return Qnil; 1922 | } 1923 | 1924 | 1925 | SWIGINTERN VALUE 1926 | _wrap_version_get(VALUE self) { 1927 | VALUE _val; 1928 | 1929 | _val = SWIG_FromCharPtr(version); 1930 | return _val; 1931 | } 1932 | 1933 | 1934 | 1935 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ 1936 | 1937 | static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; 1938 | 1939 | static swig_type_info *swig_type_initial[] = { 1940 | &_swigt__p_char, 1941 | }; 1942 | 1943 | static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; 1944 | 1945 | static swig_cast_info *swig_cast_initial[] = { 1946 | _swigc__p_char, 1947 | }; 1948 | 1949 | 1950 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ 1951 | 1952 | /* ----------------------------------------------------------------------------- 1953 | * Type initialization: 1954 | * This problem is tough by the requirement that no dynamic 1955 | * memory is used. Also, since swig_type_info structures store pointers to 1956 | * swig_cast_info structures and swig_cast_info structures store pointers back 1957 | * to swig_type_info structures, we need some lookup code at initialization. 1958 | * The idea is that swig generates all the structures that are needed. 1959 | * The runtime then collects these partially filled structures. 1960 | * The SWIG_InitializeModule function takes these initial arrays out of 1961 | * swig_module, and does all the lookup, filling in the swig_module.types 1962 | * array with the correct data and linking the correct swig_cast_info 1963 | * structures together. 1964 | * 1965 | * The generated swig_type_info structures are assigned staticly to an initial 1966 | * array. We just loop through that array, and handle each type individually. 1967 | * First we lookup if this type has been already loaded, and if so, use the 1968 | * loaded structure instead of the generated one. Then we have to fill in the 1969 | * cast linked list. The cast data is initially stored in something like a 1970 | * two-dimensional array. Each row corresponds to a type (there are the same 1971 | * number of rows as there are in the swig_type_initial array). Each entry in 1972 | * a column is one of the swig_cast_info structures for that type. 1973 | * The cast_initial array is actually an array of arrays, because each row has 1974 | * a variable number of columns. So to actually build the cast linked list, 1975 | * we find the array of casts associated with the type, and loop through it 1976 | * adding the casts to the list. The one last trick we need to do is making 1977 | * sure the type pointer in the swig_cast_info struct is correct. 1978 | * 1979 | * First off, we lookup the cast->type name to see if it is already loaded. 1980 | * There are three cases to handle: 1981 | * 1) If the cast->type has already been loaded AND the type we are adding 1982 | * casting info to has not been loaded (it is in this module), THEN we 1983 | * replace the cast->type pointer with the type pointer that has already 1984 | * been loaded. 1985 | * 2) If BOTH types (the one we are adding casting info to, and the 1986 | * cast->type) are loaded, THEN the cast info has already been loaded by 1987 | * the previous module so we just ignore it. 1988 | * 3) Finally, if cast->type has not already been loaded, then we add that 1989 | * swig_cast_info to the linked list (because the cast->type) pointer will 1990 | * be correct. 1991 | * ----------------------------------------------------------------------------- */ 1992 | 1993 | #ifdef __cplusplus 1994 | extern "C" { 1995 | #if 0 1996 | } /* c-mode */ 1997 | #endif 1998 | #endif 1999 | 2000 | #if 0 2001 | #define SWIGRUNTIME_DEBUG 2002 | #endif 2003 | 2004 | 2005 | SWIGRUNTIME void 2006 | SWIG_InitializeModule(void *clientdata) { 2007 | size_t i; 2008 | swig_module_info *module_head, *iter; 2009 | int found, init; 2010 | 2011 | /* check to see if the circular list has been setup, if not, set it up */ 2012 | if (swig_module.next==0) { 2013 | /* Initialize the swig_module */ 2014 | swig_module.type_initial = swig_type_initial; 2015 | swig_module.cast_initial = swig_cast_initial; 2016 | swig_module.next = &swig_module; 2017 | init = 1; 2018 | } else { 2019 | init = 0; 2020 | } 2021 | 2022 | /* Try and load any already created modules */ 2023 | module_head = SWIG_GetModule(clientdata); 2024 | if (!module_head) { 2025 | /* This is the first module loaded for this interpreter */ 2026 | /* so set the swig module into the interpreter */ 2027 | SWIG_SetModule(clientdata, &swig_module); 2028 | module_head = &swig_module; 2029 | } else { 2030 | /* the interpreter has loaded a SWIG module, but has it loaded this one? */ 2031 | found=0; 2032 | iter=module_head; 2033 | do { 2034 | if (iter==&swig_module) { 2035 | found=1; 2036 | break; 2037 | } 2038 | iter=iter->next; 2039 | } while (iter!= module_head); 2040 | 2041 | /* if the is found in the list, then all is done and we may leave */ 2042 | if (found) return; 2043 | /* otherwise we must add out module into the list */ 2044 | swig_module.next = module_head->next; 2045 | module_head->next = &swig_module; 2046 | } 2047 | 2048 | /* When multiple interpreters are used, a module could have already been initialized in 2049 | a different interpreter, but not yet have a pointer in this interpreter. 2050 | In this case, we do not want to continue adding types... everything should be 2051 | set up already */ 2052 | if (init == 0) return; 2053 | 2054 | /* Now work on filling in swig_module.types */ 2055 | #ifdef SWIGRUNTIME_DEBUG 2056 | printf("SWIG_InitializeModule: size %d\n", swig_module.size); 2057 | #endif 2058 | for (i = 0; i < swig_module.size; ++i) { 2059 | swig_type_info *type = 0; 2060 | swig_type_info *ret; 2061 | swig_cast_info *cast; 2062 | 2063 | #ifdef SWIGRUNTIME_DEBUG 2064 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 2065 | #endif 2066 | 2067 | /* if there is another module already loaded */ 2068 | if (swig_module.next != &swig_module) { 2069 | type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); 2070 | } 2071 | if (type) { 2072 | /* Overwrite clientdata field */ 2073 | #ifdef SWIGRUNTIME_DEBUG 2074 | printf("SWIG_InitializeModule: found type %s\n", type->name); 2075 | #endif 2076 | if (swig_module.type_initial[i]->clientdata) { 2077 | type->clientdata = swig_module.type_initial[i]->clientdata; 2078 | #ifdef SWIGRUNTIME_DEBUG 2079 | printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); 2080 | #endif 2081 | } 2082 | } else { 2083 | type = swig_module.type_initial[i]; 2084 | } 2085 | 2086 | /* Insert casting types */ 2087 | cast = swig_module.cast_initial[i]; 2088 | while (cast->type) { 2089 | 2090 | /* Don't need to add information already in the list */ 2091 | ret = 0; 2092 | #ifdef SWIGRUNTIME_DEBUG 2093 | printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); 2094 | #endif 2095 | if (swig_module.next != &swig_module) { 2096 | ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); 2097 | #ifdef SWIGRUNTIME_DEBUG 2098 | if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); 2099 | #endif 2100 | } 2101 | if (ret) { 2102 | if (type == swig_module.type_initial[i]) { 2103 | #ifdef SWIGRUNTIME_DEBUG 2104 | printf("SWIG_InitializeModule: skip old type %s\n", ret->name); 2105 | #endif 2106 | cast->type = ret; 2107 | ret = 0; 2108 | } else { 2109 | /* Check for casting already in the list */ 2110 | swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); 2111 | #ifdef SWIGRUNTIME_DEBUG 2112 | if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); 2113 | #endif 2114 | if (!ocast) ret = 0; 2115 | } 2116 | } 2117 | 2118 | if (!ret) { 2119 | #ifdef SWIGRUNTIME_DEBUG 2120 | printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); 2121 | #endif 2122 | if (type->cast) { 2123 | type->cast->prev = cast; 2124 | cast->next = type->cast; 2125 | } 2126 | type->cast = cast; 2127 | } 2128 | cast++; 2129 | } 2130 | /* Set entry in modules->types array equal to the type */ 2131 | swig_module.types[i] = type; 2132 | } 2133 | swig_module.types[i] = 0; 2134 | 2135 | #ifdef SWIGRUNTIME_DEBUG 2136 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 2137 | for (i = 0; i < swig_module.size; ++i) { 2138 | int j = 0; 2139 | swig_cast_info *cast = swig_module.cast_initial[i]; 2140 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 2141 | while (cast->type) { 2142 | printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); 2143 | cast++; 2144 | ++j; 2145 | } 2146 | printf("---- Total casts: %d\n",j); 2147 | } 2148 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 2149 | #endif 2150 | } 2151 | 2152 | /* This function will propagate the clientdata field of type to 2153 | * any new swig_type_info structures that have been added into the list 2154 | * of equivalent types. It is like calling 2155 | * SWIG_TypeClientData(type, clientdata) a second time. 2156 | */ 2157 | SWIGRUNTIME void 2158 | SWIG_PropagateClientData(void) { 2159 | size_t i; 2160 | swig_cast_info *equiv; 2161 | static int init_run = 0; 2162 | 2163 | if (init_run) return; 2164 | init_run = 1; 2165 | 2166 | for (i = 0; i < swig_module.size; i++) { 2167 | if (swig_module.types[i]->clientdata) { 2168 | equiv = swig_module.types[i]->cast; 2169 | while (equiv) { 2170 | if (!equiv->converter) { 2171 | if (equiv->type && !equiv->type->clientdata) 2172 | SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); 2173 | } 2174 | equiv = equiv->next; 2175 | } 2176 | } 2177 | } 2178 | } 2179 | 2180 | #ifdef __cplusplus 2181 | #if 0 2182 | { /* c-mode */ 2183 | #endif 2184 | } 2185 | #endif 2186 | 2187 | /* 2188 | 2189 | */ 2190 | #ifdef __cplusplus 2191 | extern "C" 2192 | #endif 2193 | SWIGEXPORT void Init_tf(void) { 2194 | size_t i; 2195 | 2196 | SWIG_InitRuntime(); 2197 | mTf = rb_define_module("Tf"); 2198 | 2199 | SWIG_InitializeModule(0); 2200 | for (i = 0; i < swig_module.size; i++) { 2201 | SWIG_define_class(swig_module.types[i]); 2202 | } 2203 | 2204 | SWIG_RubyInitializeTrackings(); 2205 | rb_define_module_function(mTf, "IsGoogleCudaEnabled", VALUEFUNC(_wrap_IsGoogleCudaEnabled), -1); 2206 | rb_define_const(mTf, "TF_MAJOR_VERSION", SWIG_From_int(static_cast< int >(0))); 2207 | rb_define_const(mTf, "TF_MINOR_VERSION", SWIG_From_int(static_cast< int >(7))); 2208 | rb_define_const(mTf, "TF_PATCH_VERSION", SWIG_From_int(static_cast< int >(1))); 2209 | rb_define_const(mTf, "TF_VERSION_SUFFIX", SWIG_FromCharPtr("")); 2210 | rb_define_const(mTf, "TF_VERSION_STRING", SWIG_FromCharPtr("(0.7.1)")); 2211 | rb_define_const(mTf, "TF_GRAPH_DEF_VERSION_MIN_PRODUCER", SWIG_From_int(static_cast< int >(0))); 2212 | rb_define_const(mTf, "TF_GRAPH_DEF_VERSION_MIN_CONSUMER", SWIG_From_int(static_cast< int >(0))); 2213 | rb_define_const(mTf, "TF_GRAPH_DEF_VERSION", SWIG_From_int(static_cast< int >(9))); 2214 | rb_define_const(mTf, "TF_CHECKPOINT_VERSION_MIN_PRODUCER", SWIG_From_int(static_cast< int >(0))); 2215 | rb_define_const(mTf, "TF_CHECKPOINT_VERSION_MIN_CONSUMER", SWIG_From_int(static_cast< int >(0))); 2216 | rb_define_const(mTf, "TF_CHECKPOINT_VERSION", SWIG_From_int(static_cast< int >(1))); 2217 | rb_define_singleton_method(mTf, "version", VALUEFUNC(_wrap_version_get), 0); 2218 | } 2219 | 2220 | -------------------------------------------------------------------------------- /generate.sh: -------------------------------------------------------------------------------- 1 | swig -ruby -c++ -o ext/tf/tf.cpp -module tf tensorflow.i -------------------------------------------------------------------------------- /lib/lib/core/strings.i: -------------------------------------------------------------------------------- 1 | // Wrapper functions to provide a scripting-language-friendly interface 2 | // to our string libraries. 3 | 4 | %{ 5 | #include "tensorflow/core/lib/core/stringpiece.h" 6 | %} -------------------------------------------------------------------------------- /lib/platform/base.i: -------------------------------------------------------------------------------- 1 | // Helper macros and typemaps for use in Tensorflow swig files. 2 | 3 | %{ 4 | #include "tensorflow/core/platform/types.h" 5 | using tensorflow::uint64; 6 | using tensorflow::string; 7 | %} 8 | 9 | // SWIG macros for explicit API declaration. 10 | // Usage: 11 | // 12 | // %ignoreall 13 | // %unignore SomeName; // namespace / class / method 14 | // %include "somelib.h" 15 | // %unignoreall // mandatory closing "bracket" 16 | %define %ignoreall %ignore ""; %enddef 17 | %define %unignore %rename("%s") %enddef 18 | %define %unignoreall %rename("%s") ""; %enddef -------------------------------------------------------------------------------- /lib/tf.rb: -------------------------------------------------------------------------------- 1 | require "tf/version" 2 | require "tf/tf" 3 | 4 | module Tf 5 | # Your code goes here... 6 | end 7 | -------------------------------------------------------------------------------- /lib/tf/version.rb: -------------------------------------------------------------------------------- 1 | module Tf 2 | VERSION = "0.1.0" 3 | end 4 | -------------------------------------------------------------------------------- /lib/util/port.i: -------------------------------------------------------------------------------- 1 | %include "lib/platform/base.i" 2 | 3 | %{ 4 | #include "tensorflow/core/util/port.h" 5 | %} 6 | 7 | %ignoreall 8 | %unignore tensorflow; 9 | %unignore tensorflow::IsGoogleCudaEnabled; 10 | %unignore tensorflow::CudaSupportsHalfMatMulAndConv; 11 | %include "dependencies/tensorflow/tensorflow/core/util/port.h" 12 | %unignoreall -------------------------------------------------------------------------------- /lib/util/rb_checkpoint_reader.i: -------------------------------------------------------------------------------- 1 | %include "lib/lib/core/strings.i" 2 | %include "lib/platform/base.i" 3 | 4 | %{ 5 | #include "tensorflow/core/lib/core/status.h" 6 | #include "tensorflow/core/util/checkpoint_reader.h" 7 | #include "tensorflow/python/lib/core/py_func.h" 8 | %} 9 | -------------------------------------------------------------------------------- /tensorflow.i: -------------------------------------------------------------------------------- 1 | /* SWIG wrapper for all of TensorFlow native functionality. 2 | * The includes are intentionally not alphabetically sorted, as the order of 3 | * includes follows dependency order */ 4 | 5 | %include "lib/util/port.i" 6 | 7 | %{ 8 | #include "tensorflow/core/public/version.h" 9 | 10 | extern const char version[] = TF_VERSION_STRING; 11 | %} 12 | 13 | %include "dependencies/tensorflow/tensorflow/core/public/version.h" 14 | extern const char version[] = TF_VERSION_STRING; 15 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'tf' 3 | 4 | require 'minitest/autorun' 5 | -------------------------------------------------------------------------------- /test/tf_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TfTest < Minitest::Test 4 | def test_that_it_has_a_proper_tensorflow_version_number 5 | assert_equal( "0.7.1", ::Tf.version) 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /tf.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'tf/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "tf" 8 | spec.version = Tf::VERSION 9 | spec.authors = ["Ankur Yadav"] 10 | spec.email = ["ankurayadav@gmail.com"] 11 | 12 | if spec.respond_to?(:metadata) 13 | spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server." 14 | end 15 | 16 | spec.summary = %q{Write a short summary, because Rubygems requires one.} 17 | spec.description = %q{Write a longer description or delete this line.} 18 | spec.homepage = "http://ankurayadav.in" 19 | spec.license = "Apache License, Version 2.0" 20 | 21 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 22 | 23 | # get an array of submodule dirs by executing 'pwd' inside each submodule 24 | `git submodule --quiet foreach pwd`.split($\).each do |submodule_path| 25 | # for each submodule, change working directory to that submodule 26 | Dir.chdir(submodule_path) do 27 | 28 | # issue git ls-files in submodule's directory 29 | submodule_files = `git ls-files`.split($\) 30 | 31 | # prepend the submodule path to create absolute file paths 32 | submodule_files_fullpaths = submodule_files.map do |filename| 33 | "#{submodule_path}/#{filename}" 34 | end 35 | 36 | # remove leading path parts to get paths relative to the gem's root dir 37 | # (this assumes, that the gemspec resides in the gem's root dir) 38 | submodule_files_paths = submodule_files_fullpaths.map do |filename| 39 | filename.gsub "#{File.dirname(__FILE__)}/", "" 40 | end 41 | 42 | # add relative paths to gem.files 43 | spec.files += submodule_files_paths 44 | end 45 | end 46 | 47 | spec.bindir = "exe" 48 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 49 | spec.require_paths = ["lib"] 50 | spec.extensions = ["ext/tf/extconf.rb"] 51 | 52 | spec.add_development_dependency "bundler", "~> 1.7.9" 53 | spec.add_development_dependency "rake", "~> 10.0" 54 | spec.add_development_dependency "rake-compiler" 55 | spec.add_development_dependency "minitest", "~> 5.0" 56 | end 57 | --------------------------------------------------------------------------------