c_from_ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 859fc74c07e4d30f69400e1dff5905f3a321bb2106338c5b9426130e18cee91a
4
+ data.tar.gz: 87824591f256fa4f5243faca96722c0ea7385d020389d75335c095713ad5dd2e
5
+ SHA512:
6
+ metadata.gz: 1ef299e170732d8932de968327748e9cf07e3602af8428de87ecea15862641c7478ebfad058ec6fbed1d4842ca0b2ef84b056fb953013c5930a294acb11d10da
7
+ data.tar.gz: ae38cfc78ff8755aef2cf9ea09a321503ac77ff73b729ada1f379b7fb39b5fed2c95bfa4a37fe016851d827b16503581f3d23169b9c99f61b17b406bc8bb9152
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.1.1
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Gemspec/RequireMFA:
20
+ Enabled: false
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-31
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at chiranjeevi.kodati@ridecell.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in c_from_ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ c_from_ruby (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ parallel (1.22.1)
12
+ parser (3.1.1.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.1.1)
15
+ rake (13.0.6)
16
+ regexp_parser (2.2.1)
17
+ rexml (3.2.5)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ rubocop (1.26.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.1.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.16.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.16.0)
41
+ parser (>= 3.1.1.0)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.1.0)
44
+
45
+ PLATFORMS
46
+ arm64-darwin-21
47
+ x86_64-linux
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 2.3.10)
51
+ c_from_ruby!
52
+ rake (~> 13.0)
53
+ rspec (~> 3.0)
54
+ rubocop (~> 1.21)
55
+
56
+ BUNDLED WITH
57
+ 2.3.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Chiranjeevi Kodati
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # CFromRuby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/c_from_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add c_from_ruby
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install c_from_ruby
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ $ bin/setup
21
+ $ bundler exec rake compile
22
+ $ bin/console
23
+ $ bundler exec rake
24
+ ```
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/c_from_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/c_from_ruby/blob/master/CODE_OF_CONDUCT.md).
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the CFromRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/c_from_ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ task :compile do
7
+ puts "Compiling extension"
8
+ `cd ext && make clean`
9
+ `cd ext && ruby extconf.rb`
10
+ `cd ext && make`
11
+ puts "Done"
12
+ end
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ require "rubocop/rake_task"
17
+
18
+ RuboCop::RakeTask.new
19
+
20
+ task default: %i[spec rubocop]
data/ext/Makefile ADDED
@@ -0,0 +1,268 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ V0 = $(V:0=)
7
+ Q1 = $(V:1=)
8
+ Q = $(Q1:0=@)
9
+ ECHO1 = $(V:1=@ :)
10
+ ECHO = $(ECHO1:0=@ echo)
11
+ NULLCMD = :
12
+
13
+ #### Start of system configuration section. ####
14
+
15
+ srcdir = .
16
+ topdir = /Users/chiranjeevikodati/.rbenv/versions/3.1.1/include/ruby-3.1.0
17
+ hdrdir = $(topdir)
18
+ arch_hdrdir = /Users/chiranjeevikodati/.rbenv/versions/3.1.1/include/ruby-3.1.0/arm64-darwin21
19
+ PATH_SEPARATOR = :
20
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
21
+ prefix = $(DESTDIR)/Users/chiranjeevikodati/.rbenv/versions/3.1.1
22
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
23
+ rubyarchprefix = $(rubylibprefix)/$(arch)
24
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
25
+ exec_prefix = $(prefix)
26
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
27
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
28
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
29
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
30
+ sitehdrdir = $(rubyhdrdir)/site_ruby
31
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
32
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
33
+ vendorlibdir = $(vendordir)/$(ruby_version)
34
+ vendordir = $(rubylibprefix)/vendor_ruby
35
+ sitearchdir = $(sitelibdir)/$(sitearch)
36
+ sitelibdir = $(sitedir)/$(ruby_version)
37
+ sitedir = $(rubylibprefix)/site_ruby
38
+ rubyarchdir = $(rubylibdir)/$(arch)
39
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
40
+ sitearchincludedir = $(includedir)/$(sitearch)
41
+ archincludedir = $(includedir)/$(arch)
42
+ sitearchlibdir = $(libdir)/$(sitearch)
43
+ archlibdir = $(libdir)/$(arch)
44
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
45
+ mandir = $(datarootdir)/man
46
+ localedir = $(datarootdir)/locale
47
+ libdir = $(exec_prefix)/lib
48
+ psdir = $(docdir)
49
+ pdfdir = $(docdir)
50
+ dvidir = $(docdir)
51
+ htmldir = $(docdir)
52
+ infodir = $(datarootdir)/info
53
+ docdir = $(datarootdir)/doc/$(PACKAGE)
54
+ oldincludedir = $(DESTDIR)/usr/include
55
+ includedir = $(SDKROOT)$(prefix)/include
56
+ runstatedir = $(localstatedir)/run
57
+ localstatedir = $(prefix)/var
58
+ sharedstatedir = $(prefix)/com
59
+ sysconfdir = $(prefix)/etc
60
+ datadir = $(datarootdir)
61
+ datarootdir = $(prefix)/share
62
+ libexecdir = $(exec_prefix)/libexec
63
+ sbindir = $(exec_prefix)/sbin
64
+ bindir = $(exec_prefix)/bin
65
+ archdir = $(rubyarchdir)
66
+
67
+
68
+ CC_WRAPPER =
69
+ CC = clang
70
+ CXX = clang++
71
+ LIBRUBY = $(LIBRUBY_SO)
72
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
73
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
74
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation $(MAINLIBS)
75
+ empty =
76
+ OUTFLAG = -o $(empty)
77
+ COUTFLAG = -o $(empty)
78
+ CSRCFLAG = $(empty)
79
+
80
+ RUBY_EXTCONF_H =
81
+ cflags = -fdeclspec $(optflags) $(debugflags) $(warnflags)
82
+ cxxflags =
83
+ optflags = -O3 -fno-fast-math
84
+ debugflags = -ggdb3
85
+ warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef
86
+ cppflags =
87
+ CCDLFLAGS = -fno-common
88
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe $(ARCH_FLAG)
89
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
90
+ DEFS =
91
+ CPPFLAGS = -I/Users/chiranjeevikodati/.rbenv/versions/3.1.1/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
92
+ CXXFLAGS = $(CCDLFLAGS) -fdeclspec $(ARCH_FLAG)
93
+ ldflags = -L. -L/Users/chiranjeevikodati/.rbenv/versions/3.1.1/lib -L/usr/local/opt/python@3.10/lib -fstack-protector-strong -L/usr/local/lib
94
+ dldflags = -L/Users/chiranjeevikodati/.rbenv/versions/3.1.1/lib -L/usr/local/opt/python@3.10/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
95
+ ARCH_FLAG =
96
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
97
+ LDSHARED = $(CC) -dynamic -bundle
98
+ LDSHAREDXX = $(CXX) -dynamic -bundle
99
+ AR = ar
100
+ EXEEXT =
101
+
102
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
103
+ RUBY_SO_NAME = ruby.3.1
104
+ RUBYW_INSTALL_NAME =
105
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
106
+ RUBYW_BASE_NAME = rubyw
107
+ RUBY_BASE_NAME = ruby
108
+
109
+ arch = arm64-darwin21
110
+ sitearch = $(arch)
111
+ ruby_version = 3.1.0
112
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
113
+ RUBY = $(ruby)
114
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
115
+
116
+ RM = rm -f
117
+ RM_RF = rm -fr
118
+ RMDIRS = rmdir -p
119
+ MAKEDIRS = mkdir -p
120
+ INSTALL = /usr/bin/install -c
121
+ INSTALL_PROG = $(INSTALL) -m 0755
122
+ INSTALL_DATA = $(INSTALL) -m 644
123
+ COPY = cp
124
+ TOUCH = exit >
125
+
126
+ #### End of system configuration section. ####
127
+
128
+ preload =
129
+ libpath = . $(libdir)
130
+ LIBPATH = -L. -L$(libdir)
131
+ DEFFILE =
132
+
133
+ CLEANFILES = mkmf.log
134
+ DISTCLEANFILES =
135
+ DISTCLEANDIRS =
136
+
137
+ extout =
138
+ extout_prefix =
139
+ target_prefix =
140
+ LOCAL_LIBS =
141
+ LIBS = $(LIBRUBYARG_SHARED)
142
+ ORIG_SRCS = extension.c library.c
143
+ SRCS = $(ORIG_SRCS)
144
+ OBJS = extension.o library.o
145
+ HDRS = $(srcdir)/library.h
146
+ LOCAL_HDRS =
147
+ TARGET = extension
148
+ TARGET_NAME = extension
149
+ TARGET_ENTRY = Init_$(TARGET_NAME)
150
+ DLLIB = $(TARGET).bundle
151
+ EXTSTATIC =
152
+ STATIC_LIB =
153
+
154
+ TIMESTAMP_DIR = .
155
+ BINDIR = $(bindir)
156
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
157
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
158
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
159
+ HDRDIR = $(sitehdrdir)$(target_prefix)
160
+ ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
161
+ TARGET_SO_DIR =
162
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
163
+ CLEANLIBS = $(TARGET_SO) $(TARGET_SO).dSYM
164
+ CLEANOBJS = *.o *.bak
165
+
166
+ all: $(DLLIB)
167
+ static: $(STATIC_LIB)
168
+ .PHONY: all install static install-so install-rb
169
+ .PHONY: clean clean-so clean-static clean-rb
170
+
171
+ clean-static::
172
+ clean-rb-default::
173
+ clean-rb::
174
+ clean-so::
175
+ clean: clean-so clean-static clean-rb-default clean-rb
176
+ -$(Q)$(RM_RF) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
177
+
178
+ distclean-rb-default::
179
+ distclean-rb::
180
+ distclean-so::
181
+ distclean-static::
182
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
183
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
184
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
185
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
186
+
187
+ realclean: distclean
188
+ install: install-so install-rb
189
+
190
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.time
191
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
192
+ clean-static::
193
+ -$(Q)$(RM) $(STATIC_LIB)
194
+ install-rb: pre-install-rb do-install-rb install-rb-default
195
+ install-rb-default: pre-install-rb-default do-install-rb-default
196
+ pre-install-rb: Makefile
197
+ pre-install-rb-default: Makefile
198
+ do-install-rb:
199
+ do-install-rb-default:
200
+ pre-install-rb-default:
201
+ @$(NULLCMD)
202
+ $(TIMESTAMP_DIR)/.sitearchdir.time:
203
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
204
+ $(Q) $(TOUCH) $@
205
+
206
+ site-install: site-install-so site-install-rb
207
+ site-install-so: install-so
208
+ site-install-rb: install-rb
209
+
210
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
211
+
212
+ .cc.o:
213
+ $(ECHO) compiling $(<)
214
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
215
+
216
+ .cc.S:
217
+ $(ECHO) translating $(<)
218
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
219
+
220
+ .mm.o:
221
+ $(ECHO) compiling $(<)
222
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
223
+
224
+ .mm.S:
225
+ $(ECHO) translating $(<)
226
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
227
+
228
+ .cxx.o:
229
+ $(ECHO) compiling $(<)
230
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
231
+
232
+ .cxx.S:
233
+ $(ECHO) translating $(<)
234
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
235
+
236
+ .cpp.o:
237
+ $(ECHO) compiling $(<)
238
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
239
+
240
+ .cpp.S:
241
+ $(ECHO) translating $(<)
242
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
243
+
244
+ .c.o:
245
+ $(ECHO) compiling $(<)
246
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
247
+
248
+ .c.S:
249
+ $(ECHO) translating $(<)
250
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
251
+
252
+ .m.o:
253
+ $(ECHO) compiling $(<)
254
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
255
+
256
+ .m.S:
257
+ $(ECHO) translating $(<)
258
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
259
+
260
+ $(TARGET_SO): $(OBJS) Makefile
261
+ $(ECHO) linking shared-object $(DLLIB)
262
+ -$(Q)$(RM) $(@)
263
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
264
+ $(Q) $(POSTLINK)
265
+
266
+
267
+
268
+ $(OBJS): $(HDRS) $(ruby_headers)
data/ext/extconf.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile "extension"
Binary file
data/ext/extension.c ADDED
@@ -0,0 +1,38 @@
1
+ #include "ruby/ruby.h"
2
+ #include "ruby/encoding.h"
3
+ #include "library.h"
4
+
5
+ static VALUE string(VALUE self, VALUE value) {
6
+ Check_Type(value, T_STRING);
7
+
8
+ char* pointer_in = RSTRING_PTR(value);
9
+ char* pointer_out = string_from_library(pointer_in);
10
+ return rb_str_new2(pointer_out);
11
+ }
12
+
13
+ static VALUE number(VALUE self, VALUE value) {
14
+ Check_Type(value, T_FIXNUM);
15
+
16
+ int number_in = NUM2INT(value);
17
+ int number_out = number_from_library(number_in);
18
+ return INT2NUM(number_out);
19
+ }
20
+
21
+ static VALUE boolean(VALUE self, VALUE value) {
22
+ int boolean_in = RTEST(value);
23
+ int boolean_out = boolean_from_library(boolean_in);
24
+ if (boolean_out == 1) {
25
+ return Qtrue;
26
+ } else {
27
+ return Qfalse;
28
+ }
29
+ }
30
+
31
+ void Init_extension(void) {
32
+ VALUE CFromRuby = rb_define_module("CFromRuby");
33
+ VALUE NativeHelpers = rb_define_class_under(CFromRuby, "NativeHelpers", rb_cObject);
34
+
35
+ rb_define_singleton_method(NativeHelpers, "string", string, 1);
36
+ rb_define_singleton_method(NativeHelpers, "number", number, 1);
37
+ rb_define_singleton_method(NativeHelpers, "boolean", boolean, 1);
38
+ }
data/ext/extension.o ADDED
Binary file
data/ext/library.c ADDED
@@ -0,0 +1,12 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+
4
+ char *string_from_library(char *val) {
5
+ char *out = (char *)malloc(256*sizeof(char));
6
+ sprintf(out, "String from C: '%s'", val);
7
+ return out;
8
+ }
9
+
10
+ int number_from_library(int val) { return val+1; }
11
+
12
+ int boolean_from_library(int val) { return !val; }
data/ext/library.h ADDED
@@ -0,0 +1,3 @@
1
+ char *string_from_library(char *);
2
+ int number_from_library(int);
3
+ int boolean_from_library(int);
data/ext/library.o ADDED
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CFromRuby
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "extension"
4
+ require_relative "c_from_ruby/version"
5
+
6
+ module CFromRuby
7
+ class Helpers
8
+ def self.string(value)
9
+ "String from Ruby: '#{value}'"
10
+ end
11
+
12
+ def self.number(value)
13
+ value + 1
14
+ end
15
+
16
+ def self.boolean(value)
17
+ !value
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module CFromRuby
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: c_from_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chiranjeevi Kodati
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.11.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.11.0
55
+ description: This gem is used to call functions written in C
56
+ email:
57
+ - chiru6753@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - ext/Makefile
72
+ - ext/extconf.rb
73
+ - ext/extension.bundle
74
+ - ext/extension.c
75
+ - ext/extension.o
76
+ - ext/library.c
77
+ - ext/library.h
78
+ - ext/library.o
79
+ - lib/c_from_ruby.rb
80
+ - lib/c_from_ruby/version.rb
81
+ - sig/c_from_ruby.rbs
82
+ homepage: https://rubygems.org
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ homepage_uri: https://rubygems.org
88
+ source_code_uri: https://github.com/kratos6753/c_from_ruby
89
+ changelog_uri: https://github.com/kratos6753/c_from_ruby/CHANGELOG.md
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ - ext
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.1.1
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.3.7
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: This gem is used to call functions written in C
110
+ test_files: []