sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Building C extension compatibility

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 2 Posters 748 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tt_suT Offline
      tt_su
      last edited by

      Was rb_hash_lookup the only function it was missing? Sounds like there should be a function like that - might be under a different name. On the olden days they where quite found of naming functions post_fixed with 1,2,3 etc instead of proper names.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Anton_S
        last edited by

        @tt_su said:

        Was rb_hash_lookup the only function it was missing? Sounds like there should be a function like that - might be under a different name.

        Aha!!! rb_hash_lookup is very similar to rb_hash_aref. rb_hash_aref is in both 1.8.6 and 1.8.7. πŸ‘ The difference between is that one's default return value is 0 and the other's default return value is nil. I will replace rb_hash_lookup with rb_hash_aref and try compile.


        Edit: Yes, to compile FFI for ruby 1.8.6 you only had to replace the rb_hash_lookup. I tested and it works well! Now, FFI will work in Ruby 1.8.6+, which means I can use it in SU8 or later; however, SU6 and SU7 uses Ruby 1.8.0, I will have to find what its missing...


        Edit: Is there a windows installer for Ruby 1.8.0? Can you help me find it?


        Edit: Actually I think there shouldn't be support for SU7 or below. I will simply ask them to update their Ruby core to 1.8.6 or 1.8.7 if for some reason they are willing to use the plugin in SU7 or below.

        1 Reply Last reply Reply Quote 0
        • tt_suT Offline
          tt_su
          last edited by

          You might not need to recompile for 1.8.0. I think in large part 1.8.0-1.8.6 Ruby will run 1.8.6 binaries. It's first at 1.8.7 they made notable change.
          If anyone hook 1.8.7 into SketchUp that might break other extensions.

          Vertex Tools contained a C Extension, and it ran all the way down to SU6 - no need to recompile. Though I don't recall which Ruby version I used then - it was written in pure C. But I think it was a newer 1.8.x version.

          1 Reply Last reply Reply Quote 0
          • A Offline
            Anton_S
            last edited by

            The reason I asked about 1.8.0 because the recompiled ams_ffi_c.so works on 1.8.6 or 1.8.7, but raises an error in 1.8.0.

            If not much changes were made between 1.8.0 and 1.8.6, can you give me a link to windows installer for 1.8.0? I wanna find a ruby function which made ffi incompatible.

            Also, Thomthom, I'm wondering on what Ruby version did you compile your C extension? Was it on 1.8.7, 1.8.6 or 1.8.0? Is it supposed to be compiled on the least available Ruby version in 1.8.x categories in order to have it work on all 1.8 versions?

            1 Reply Last reply Reply Quote 0
            • A Offline
              Anton_S
              last edited by

              Ok, I found a link to old Ruby versions: https://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/
              I will investigate.

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @anton_s said:

                Also, Thomthom, I'm wondering on what Ruby version did you compile your C extension? Was it on 1.8.7, 1.8.6 or 1.8.0? Is it supposed to be compiled on the least available Ruby version in 1.8.x categories in order to have it work on all 1.8 versions?

                I have moved away from doing pure C extensions using Ruby's own build tools. C++ is so much nicer to work with and having multiple versions of Ruby under OSX is a pain - even with RVM. The old 1.8 32bit Ruby versions really has reached their end of days and getting it to compile under Maverics etc just thins out your hair... :s

                I now recommend anyone to use the C++ example we have at GitHub. It has the libraries and headers that SketchUp uses: https://github.com/SketchUp/ruby-c-extension-examples
                All though, not the 1.8.0 ones - they are just too old to keep support for.

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  To clarify, I currently compile 1.8.6 and 2.0.0 for my extensions. (PC)

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Anton_S
                    last edited by

                    Unfortunately, I couldn't compile ffi on 1.8.0.
                    First I added devkit to 1.8.0

                    I had to do a few things to make it compatible:

                    1. Add to rbconfig.rb: RbConfig = Config # compatibility for ruby-1.9
                    2. Modify LongDouble.c in ffi: Replace RSTRING_PTR(s) with (RSTRING(s)->ptr) in line 44
                    3. Add find_header method to mkfk.rb; copied it from Ruby 1.8.6 mkfk.rb

                    Then I called ruby extconf.rb once again to ensure I have no errors.
                    Then I called make and got the missing separator error at line 138 in makefile.
                    So, I replaced

                    LIBFFI_HOST=--host=i686-mswin32
                    !include $(srcdir)/libffi.vc.mk
                    

                    with

                    LIBFFI_HOST=--host=
                    include ${srcdir}/libffi.mk
                    

                    I copied the code from Makefile created in Ruby 1.8.6.

                    After that everything started compiling, until it got to AbstractMemory.obj:
                    ffi compile error 1.8.0.png
                    Google search tells me I have to include cl.exe, but I haven't figured out how, even after looking in from stack overflow: http://stackoverflow.com/questions/7865432/command-line-compile-using-cl-exe

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Anton_S
                      last edited by

                      @tt_su said:

                      I now recommend anyone to use the C++ example we have at GitHub. It has the libraries and headers that SketchUp uses: https://github.com/SketchUp/ruby-c-extension-examples

                      Thanks for mentioning. πŸ‘

                      @tt_su said:

                      If anyone hook 1.8.7 into SketchUp that might break other extensions.

                      Thanks for mentioning that too. I once came up with an error when copied the latest 1.8.7 core to SU8, but can't recall which plugin raised it. Though, there is a stable release which Dan Rathbun provided. It didn't raise any errors.

                      @tt_su said:

                      To clarify, I currently compile 1.8.6 and 2.0.0 for my extensions. (PC)

                      Right... Compiled ams__api (win32-api) on Ruby 1.8.7 and it works on all ruby 1.8.x versions.

                      1 Reply Last reply Reply Quote 0
                      • tt_suT Offline
                        tt_su
                        last edited by

                        @anton_s said:

                        [*]Modify LongDouble.c in ffi: Replace RSTRING_PTR(s) with (RSTRING(s)->ptr) in line

                        Easier and more maintainable to add the macros if they are undefined:
                        https://bitbucket.org/thomthom/tt-library-2/src/be17bac137aa5421323733cc206d80b9ff885dc4/Ruby%20C%20Extensions/win32-api/ext/tt_api.c?at=Version%202.9#cl-5

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement