oggy / looksee

Supercharged method introspection in IRB
MIT License
364 stars 14 forks source link

Ruby 2.3 Support #35

Closed janlelis closed 8 years ago

janlelis commented 8 years ago

Hi oggy,

looksee does not work for the new 2.3:

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
$ gem install looksee
Building native extensions.  This could take a while...
ERROR:  Error installing looksee:
    ERROR: Failed to build gem native extension.

    current directory: /home/dan/.rvm/gems/ruby-2.3.0/gems/looksee-3.1.0/ext
/home/dan/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20151230-10586-1sk6yy2.rb extconf.rb
creating Makefile

current directory: /home/dan/.rvm/gems/ruby-2.3.0/gems/looksee-3.1.0/ext
make "DESTDIR=" clean

current directory: /home/dan/.rvm/gems/ruby-2.3.0/gems/looksee-3.1.0/ext
make "DESTDIR="
compiling mri/mri.c
In file included from mri/2.2.0/method.h:14:0,
                 from mri/mri.c:4:
mri/2.2.0/internal.h: In function ‘RCLASS_M_TBL_INIT’:
mri/2.2.0/internal.h:483:43: error: ‘struct RClassDeprecated’ has no member named ‘m_tbl_wrapper’
 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
                                           ^
mri/2.2.0/internal.h:497:5: note: in expansion of macro ‘RCLASS_M_TBL_WRAPPER’
     RCLASS_M_TBL_WRAPPER(c) = wrapper;
     ^
mri/2.2.0/internal.h: In function ‘RCLASS_SUPER’:
mri/2.2.0/internal.h:504:25: error: ‘struct RClassDeprecated’ has no member named ‘super’
     return RCLASS(klass)->super;
                         ^
In file included from /home/dan/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby.h:33:0,
                 from mri/mri.c:1:
mri/2.2.0/internal.h: In function ‘RCLASS_SET_SUPER’:
mri/2.2.0/internal.h:514:39: error: ‘struct RClassDeprecated’ has no member named ‘super’
     RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super);
                                       ^
/home/dan/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/ruby.h:1475:75: note: in definition of macro ‘RB_OBJ_WRITE’
 #define RB_OBJ_WRITE(a, slot, b)       rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)
                                                                           ^
In file included from mri/2.2.0/method.h:14:0,
                 from mri/mri.c:4:
mri/mri.c: In function ‘internal_instance_methods’:
mri/2.2.0/internal.h:483:43: error: ‘struct RClassDeprecated’ has no member named ‘m_tbl_wrapper’
 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
                                           ^
mri/2.2.0/internal.h:484:26: note: in expansion of macro ‘RCLASS_M_TBL_WRAPPER’
 #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
                          ^
mri/mri.c:154:32: note: in expansion of macro ‘RCLASS_M_TBL’
   Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
                                ^
mri/2.2.0/internal.h:483:43: error: ‘struct RClassDeprecated’ has no member named ‘m_tbl_wrapper’
 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
                                           ^
mri/2.2.0/internal.h:484:52: note: in expansion of macro ‘RCLASS_M_TBL_WRAPPER’
 #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
                                                    ^
mri/mri.c:154:32: note: in expansion of macro ‘RCLASS_M_TBL’
   Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
                                ^
mri/mri.c: In function ‘Looksee_internal_undefined_instance_methods’:
mri/2.2.0/internal.h:483:43: error: ‘struct RClassDeprecated’ has no member named ‘m_tbl_wrapper’
 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
                                           ^
mri/2.2.0/internal.h:484:26: note: in expansion of macro ‘RCLASS_M_TBL_WRAPPER’
 #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
                          ^
mri/mri.c:188:32: note: in expansion of macro ‘RCLASS_M_TBL’
   Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
                                ^
mri/2.2.0/internal.h:483:43: error: ‘struct RClassDeprecated’ has no member named ‘m_tbl_wrapper’
 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
                                           ^
mri/2.2.0/internal.h:484:52: note: in expansion of macro ‘RCLASS_M_TBL_WRAPPER’
 #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
                                                    ^
mri/mri.c:188:32: note: in expansion of macro ‘RCLASS_M_TBL’
   Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
                                ^
mri/mri.c: In function ‘Looksee_singleton_instance’:
mri/2.2.0/internal.h:480:33: error: ‘struct RClassDeprecated’ has no member named ‘ptr’
 #define RCLASS_EXT(c) (RCLASS(c)->ptr)
                                 ^
mri/2.2.0/internal.h:481:27: note: in expansion of macro ‘RCLASS_EXT’
 #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
                           ^
mri/mri.c:208:38: note: in expansion of macro ‘RCLASS_IV_TBL’
     if (!Looksee_method_table_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
                                      ^
mri/2.2.0/internal.h: In function ‘RCLASS_SUPER’:
mri/2.2.0/internal.h:505:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
Makefile:238: recipe for target 'mri.o' failed
make: *** [mri.o] Error 1

make failed, exit code 2
zw963 commented 8 years ago

Need help too, looksee is the best gem I ever seen, no the one. Thanks.

zw963 commented 8 years ago

Still not update, I still use Ruby 2.2.3, hope can use Ruby 2.3 serious soon.

Thanks.

mathieujobin commented 8 years ago

just mentioning, same issue on ruby-head 2.4.0dev

thank you very much for your excellent gem !

I am definitely not going to upgrade my ruby until looksee works

sorry Matz ;)

viktorchukhantsev commented 8 years ago

+1

zw963 commented 8 years ago

I have use Ruby 2.3 servel days, But, my Project still keep 2.2.3 ...

oggy commented 8 years ago

Thanks for the report & encouragement, and sorry for the slow response.

Unfortunately it seems the changes in ruby 2.3 have made the current implementation impossible. I'll need to decide on a path forward, but it probably won't be all that quick. In the meantime I can recommend pry’s ls command, which isn’t quite as complete or accurate as Looksee, but hopefully good enough 99% of the time.

zw963 commented 8 years ago

Cool, hope can patch Ruby 2.3 as quickly as possible.

janlelis commented 8 years ago

Thank you for all your hard work creating the gem!

Maybe it is possible to involve Ruby core and ask them to provide the necessary reflection capabilities directly. What exactly would be needed?

mathieujobin commented 8 years ago

doing a little bit of digging...

anyone looked at this commit ? https://github.com/ruby/ruby/commit/8f88ff4e37a5374e49025076905c57941379336a

it seems RCLASS_M_TBL_WRAPPER just becomes RCLASS_M_TBL

this is just a partial hint so far as I keep digging, but I thought of sharing it early... in case someone else knows more already on this?

looksee's usage of RClassDeprecated clearly shows that it is using some deprecated feature of ruby. one would hope there is some documentation on what is has been deprecated by?

another related commit https://github.com/ruby/ruby/commit/084b602d9a52b62a04d17f65ba1a9b8a767d1e3e

mathieujobin commented 8 years ago

https://github.com/ruby/ruby/commit/1f2255604087e9a7d7efcb2df61b5ca0e2daa200 this commit clearly shows how the few attributes became internal...

mathieujobin commented 8 years ago

right now, all MRI share the same ext/mri/mri.c but it feels like we are going to need a different one for both 2.3 and 2.4 I am testing with both 2.3.1 and ruby-head because internal.h and method.h changed between 2.3 and head

this commit 18bbd05 explains what I am seeing on this travis build https://travis-ci.org/mathieujobin/looksee/jobs/126929337

mathieujobin commented 8 years ago

it is of interested that rwx had a similar issue http://osdir.com/ml/ruby-core/2015-08/msg00201.html and they have now fixed the issue for both 2.3 and 2.4 https://travis-ci.org/Hanmac/rwx/builds/122278873

forget about the above... their issue was no where like this one ...

mathieujobin commented 8 years ago

maybe i am dreaming,,, but I think I am making progress

2.3 https://travis-ci.org/mathieujobin/looksee/jobs/126960065 2.4 https://travis-ci.org/mathieujobin/looksee/jobs/126960201

mathieujobin commented 8 years ago

latest piece of hint....

git log -p -S rb_method_entry_t --since 2015-03-01

5e8a147480f87f19a8b96ad3fb33a25fb4bb19b9
could be a rename to rb_callable_method_entry_t
rb_method_entry_struct

c19d37375074987b36413af6bf83df7262ce227d
-           me->def->flags.visi = visi;
+           METHOD_ENTRY_VISI(me) = visi;

57b817f4c550e54ff57642b50723cc7c92bdd2fe

      * rb_method_entry_t::flag is move to rb_method_definition_t::flag.
mathieujobin commented 8 years ago

i made some good progress... missing a tiny something,... anyone willing to help on this ?

please have a look

https://github.com/oggy/looksee/pull/36

mathieujobin commented 8 years ago

@oggy

Unfortunately it seems the changes in ruby 2.3 have made the current implementation impossible. I'll need to decide on a path forward, but it probably won't be all that quick. In the meantime I can recommend pry’s ls command, which isn’t quite as complete or accurate as Looksee, but hopefully good enough 99% of the time.

the changes were not that bad finally... most of the current code still works... I think I only have one tiny issue left...

pry is no where close what looksee does. I tried it, and it's not a very good replacement IMO

I talked with koichi and we should have all the necessary public methods for ruby 2.4

zw963 commented 8 years ago

Don't Follow ...

Anyway, I am saw hope ...

mathieujobin commented 8 years ago

anyone good at troubleshooting this kind of C compile error dereferencing pointer to incomplete type please try my fork on either 2.3.0 or 2.3.1

thank you

mathieujobin commented 8 years ago

@oggy whenever you have a minute, if you could take look. I think there is only one small compile issue left. hopefully this will be easy for you...

mathieujobin commented 8 years ago

I meant to post my last comment on PR #36

zw963 commented 8 years ago

Ruby 2.3.1 still not get support?

mathieujobin commented 8 years ago

@zw963 I could be mistaken, but I think the branch I have open in #36 is not far from completion. I just don't understand why a type present a few lines above is not being found by the compiler/linker. anyone that would like to look into this one might be solving it for good.

I have not heard back from @oggy he must be busy on other things

zw963 commented 8 years ago

I send a mail to ruby-talk maillist for this issue.

@mathieujobin, I still not get the key idea about your branch, I does not understood Linux C. what you mean is 2.3.0 is worked in your branch? if i fork your branch, looksee is work for me?

mathieujobin commented 8 years ago

after talking with @ko1, opened this issue on ruby https://bugs.ruby-lang.org/issues/12655

hopefully there won't be a need for a C extension for ruby 2.4

zw963 commented 8 years ago

thanks all。 2016年8月4日 下午10:52,Mathieu Jobin notifications@github.com写道:after talking with @ko1, opened this issue on ruby https://bugs.ruby-lang.org/issues/12655

hopefully there won't be a need for a C extension for ruby 2.4

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.

oggy commented 8 years ago

Thanks for the push all!

I've pushed some "best effort" support for ruby 2.3 to master. This means it doesn't render undef'd methods, but it should do everything else. I'll be using this over the next day or two and if things seem good I'll push it to rubygems. Until then you can install this from the repo with:

bundle
bundle exec rake gem:build
gem install looksee-3.1.1.gem

(It'll be v4.0.0 once it goes to rubygems.)

I also replied to @mathieujobin 's redmine ticket (thanks for setting that up!). The version in master shrinks the extension down to just the two functions requested there. If we can get those into core we'll be extension free from that version onwards.

mathieujobin commented 8 years ago

looks to be working fine, even the protected visibility shows as yellow now

i don't know what feature you removed but looks alright to me

thanks a lot for taking the time to work on it

oggy commented 8 years ago

I pushed 4.0.0 earlier today, so closing this at long last. Thanks for hanging in there.

@mathieujobin the feature removed was undefined methods (using undef_method). You sometimes see this with proxy objects that delegate almost everything to another object. They use undef_method rather than remove_method so it forces most of the built-in methods to hit method_missing.

It's a little less important as more projects move to supporting only ruby version that have BasicObject, but it would still be nice to more accurately depict the method tables.

zw963 commented 8 years ago

Cool.

Thanks all !!

Will try it right now.