Code Monkey home page Code Monkey logo

ruby-deepclone's Introduction

Deep Clone

This repository is no longer maintained and it's looking for a new owner :) If you'd like to take over please file an issue.

Status

System Status
Travis Travis Build Status
Gem Version Gem Version
Code Climante Code Climate

Description

This gem provides a native implementation to deep clone Ruby objects. It supports Ruby 1.9.3, 2.2.x, 2.3.x and 2.4.x.

Installation

gem install ruby_deep_clone

or add it to your Gemfile

gem 'ruby_deep_clone'

and run bundle install

Usage

Can be used as follows:

require 'deep_clone'

object = Object.new
clone_object = DeepClone.clone obj

ruby-deepclone's People

Contributors

adisos avatar antw avatar balmma avatar gmodarelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ruby-deepclone's Issues

Fails to build for Ruby 2.3.0.

Installing ruby_deep_clone 0.6.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/jpickwell/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/ruby_deep_clone-0.6.0/ext/deep_clone
/Users/jpickwell/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160323-10809-qgkgsa.rb extconf.rb
creating Makefile

current directory: /Users/jpickwell/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/ruby_deep_clone-0.6.0/ext/deep_clone
make "DESTDIR=" clean

current directory: /Users/jpickwell/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/ruby_deep_clone-0.6.0/ext/deep_clone
make "DESTDIR="
compiling deep_clone.c
deep_clone.c:116:27: error: no member named 'ptr' in 'struct RClassDeprecated'
          st_table *tbl = DC_ROBJECT_IV_INDEX_TBL(object);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./deep_clone.h:55:6: note: expanded from macro 'DC_ROBJECT_IV_INDEX_TBL'
     DC_RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./deep_clone.h:46:36: note: expanded from macro 'DC_RCLASS_IV_INDEX_TBL'
#define DC_RCLASS_IV_INDEX_TBL(c) (DC_RCLASS_EXT(c)->iv_index_tbl)
                                   ^~~~~~~~~~~~~~~~
./deep_clone.h:45:71: note: expanded from macro 'DC_RCLASS_EXT'
#define DC_RCLASS_EXT(c)          ((dc_iv_tbl_classext_t *)RCLASS(c)->ptr)
                                                           ~~~~~~~~~  ^
deep_clone.c:116:27: warning: 'RClassDeprecated' is deprecated: RClass is internal use only [-Wdeprecated-declarations]
./deep_clone.h:55:6: note: expanded from macro 'DC_ROBJECT_IV_INDEX_TBL'
     DC_RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
     ^
./deep_clone.h:46:36: note: expanded from macro 'DC_RCLASS_IV_INDEX_TBL'
#define DC_RCLASS_IV_INDEX_TBL(c) (DC_RCLASS_EXT(c)->iv_index_tbl)
                                   ^
./deep_clone.h:45:60: note: expanded from macro 'DC_RCLASS_EXT'
#define DC_RCLASS_EXT(c)          ((dc_iv_tbl_classext_t *)RCLASS(c)->ptr)
                                                           ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:1243:30: note: expanded from macro 'RCLASS'
#define RCLASS(obj)  (R_CAST(RClass)(obj))
                             ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:924:16: note: expanded from macro 'RClass'
#define RClass RClassDeprecated
               ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:1240:30: note: expanded from macro 'R_CAST'
#define R_CAST(st)   (struct st*)
                             ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:927:8: note: 'RClassDeprecated' has been explicitly marked deprecated here
struct RClass {
       ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/ruby/ruby.h:924:16: note: expanded from macro 'RClass'
#define RClass RClassDeprecated
               ^
/Users/jpickwell/.rbenv/versions/2.3.0/include/ruby-2.3.0/x86_64-darwin15/ruby/config.h:123:33: note: expanded from macro 'DEPRECATED_TYPE'
#define DEPRECATED_TYPE(mesg,x) x __attribute__ ((deprecated mesg))
                                ^
1 warning and 1 error generated.
make: *** [deep_clone.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/jpickwell/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/ruby_deep_clone-0.6.0 for inspection.
Results logged to /Users/jpickwell/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/ruby_deep_clone-0.6.0/gem_make.out

TypeError: allocator undefined for Proc

Does not support Procs:

[8] pry(Morrow::Console)> h = { proc: proc{} }
=> {:proc=>#<Proc:0x00007f9549c47698@(pry):8>}
[9] pry(Morrow::Console)> DeepClone.clone(h)
TypeError: allocator undefined for Proc
from (pry):9:in `clone'

However, Proc#clone should work:

[11] pry(Morrow::Console)> p = proc {}
=> #<Proc:0x00007f954d225a58@(pry):11>
[12] pry(Morrow::Console)> p.clone
=> #<Proc:0x00007f954d254ce0@(pry):11>

Cloning Struct

I am trying to deep clone a Struct element, but DeepClone does not seem to work as expected.

2.3.1 :001 > require "deep_clone"
 => true 
2.3.1 :002 > AStruct = Struct.new(:test)
 => AStruct 
2.3.1 :003 > a = AStruct.new("ciao")
 => #<struct AStruct test="ciao"> 
2.3.1 :004 > b = a.clone
 => #<struct AStruct test="ciao"> 
2.3.1 :005 > c = DeepClone.clone(a)
 => #<struct AStruct test="ciao"> 
2.3.1 :006 > a.test = "hello"
 => "hello" 
2.3.1 :007 > a
 => #<struct AStruct test="hello"> 
2.3.1 :008 > b
 => #<struct AStruct test="ciao"> 
2.3.1 :009 > c
 => #<struct AStruct test="hello">

Not working in Ruby 2.2.0 and 2.3.1

irb

2.2.0 :001 > require "deep_clone"
=> true
2.2.0 :002 > o1 = Object.new
=> #Object:0x0000000097c2c8
2.2.0 :003 > o2 = DeepClone.clone o1
ArgumentError: wrong number of arguments (1 for 0)
from (irb):3:in clone
from (irb):3
from /usr/local/rvm/rubies/ruby-2.2.0/bin/irb:11:in

with 1.9.3 it works OK. With 2.3.* it doesn't too.

Support for other Ruby implementations

Deep Clone seems to heavily depend on internals that MRI itself does not expose.

I think the best way to support other Ruby implementations such as TruffleRuby and JRuby would be to use a pure-Ruby fallback using Marshal.load Marshal.dump(obj) on any implementation where RUBY_ENGINE != "ruby".
Do you think this could be done in this gem?
Then it would work transparently on other Ruby implementations.

From oracle/truffleruby#2073

TypeError (can't copy BigDecimal)

Hi! I need to make a depth copy of objects with BigDecimal values.
When a try, I get this error. TypeError (can't copy BigDecimal)

Thanks.

Gem fails to install

First off, thanks for sharing your code. I'm new to ruby, so if this is something simple please forgive my ignorance. I tried installing your gem today and was met with this error:
gem install -n . ruby_deep_clone
Building native extensions. This could take a while...
ERROR: Error installing ruby_deep_clone:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
creating Makefile

make
gcc -I. -I/usr/lib/ruby/1.8/x86_64-linux -I/usr/lib/ruby/1.8/x86_64-linux -I. -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -c deep_clone.c
In file included from deep_clone.c:1:
deep_clone.h:5:21: error: ruby/st.h: No such file or directory
deep_clone.h:6:26: error: ruby/version.h: No such file or directory
In file included from deep_clone.c:1:
deep_clone.h:61: error: expected ‘)’ before ‘key’
deep_clone.c:34: error: expected ‘)’ before ‘key’
deep_clone.c: In function ‘hash_each’:
deep_clone.c:47: error: ‘ST_CONTINUE’ undeclared (first use in this function)
deep_clone.c:47: error: (Each undeclared identifier is reported only once
deep_clone.c:47: error: for each function it appears in.)
deep_clone.c: In function ‘clone_object’:
deep_clone.c:80: error: ‘st_data_t’ undeclared (first use in this function)
deep_clone.c:116: error: ‘st_table’ undeclared (first use in this function)
deep_clone.c:116: error: ‘tbl’ undeclared (first use in this function)
deep_clone.c:116: error: ‘ROBJECT_EMBED’ undeclared (first use in this function)
deep_clone.c:116: error: ‘struct RClass’ has no member named ‘iv_index_tbl’
deep_clone.c:116: error: ‘struct RObject’ has no member named ‘as’
deep_clone.c:120: error: ‘clone_variable’ undeclared (first use in this function)
make: *** [deep_clone.o] Error 1

I'm running ruby 1.8.7 (I know, upgrade but work just hasn't given me time yet) on Debian squeeze 6.0.8 x64
Thanks for your time.

Prebuilts for windows

For now ruby_deep_clone forces windows users to install RIDK on to be able to install this gem (to compile native extension).

It's totally ok for developers but sometimes RIDK installation create difficulties for those users who don't familiar with programming but wanna use some tool written in ruby

So it will be nice if you will provide prebuilt of native extension for your ruby gem

Thanks

ruby_deep_clone 0.7.1 on rubygems does not contain header file

The currently released gem for 0.7.1 on rubygems.org (https://rubygems.org/gems/ruby_deep_clone/) does not include the header file (ext/deep_clone/deep_clone.h) needed to compile the gem. When compiling, you get:

gem install ruby_deep_clone -v '0.7.1'
Building native extensions.  This could take a while...
ERROR:  Error installing ruby_deep_clone:
ERROR: Failed to build gem native extension.

current directory: /Users/name/.rvm/gems/ruby-1.9.3-p551/gems/ruby_deep_clone-0.7.1/ext/deep_clone
/Users/name/.rvm/rubies/ruby-1.9.3-p551/bin/ruby -r ./siteconf20160420-49369-1uvptbx.rb extconf.rb
creating Makefile

current directory: /Users/name/.rvm/gems/ruby-1.9.3-p551/gems/ruby_deep_clone-0.7.1/ext/deep_clone
make  clean

current directory: /Users/name/.rvm/gems/ruby-1.9.3-p551/gems/ruby_deep_clone-0.7.1/ext/deep_clone
make
compiling deep_clone.c
deep_clone.c:1:24: fatal error: deep_clone.h: No such file or directory
#include "deep_clone.h"
                    ^
compilation terminated.
make: *** [deep_clone.o] Error 1

make failed, exit code 2

This was fixed in the commit 1c154c4. Can you please reupload the gem to rubygems?

Impossible to install the gem under Ruby 2.1

It is impossible to install the gem under Ruby 2.1 The error is bellow:

gem install ruby_deep_clone -v '0.3.0' 
Building native extensions.  This could take a while...
ERROR:  Error installing ruby_deep_clone:
    ERROR: Failed to build gem native extension.

    /Users/romikoops/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
/Users/romikoops/.rvm/rubies/ruby-2.1.0/bin/ruby: warning: RUBY_FREE_MIN is obsolete. Use RUBY_GC_HEAP_FREE_SLOTS instead.
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling deep_clone.c
deep_clone.c:106:25: error: no member named 'iv_index_tbl' in 'struct RClass'
        st_table *tbl = ROBJECT_IV_INDEX_TBL(object);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/romikoops/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/ruby/ruby.h:784:6: note: expanded from macro 'ROBJECT_IV_INDEX_TBL'
     RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./deep_clone.h:33:44: note: expanded from macro 'RCLASS_IV_INDEX_TBL'
#define RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
                                ~~~~~~~~~  ^
1 error generated.
make: *** [deep_clone.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/romikoops/.rvm/gems/ruby-2.1.0@calc-service/gems/ruby_deep_clone-0.3.0 for inspection.
Results logged to /Users/romikoops/.rvm/gems/ruby-2.1.0@calc-service/extensions/x86_64-darwin-12/2.1.0-static/ruby_deep_clone-0.3.0/gem_make.out

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.