Issue #14722 has been updated by mrkn (Kenta Murata).


I have a similar problem.  I want to share raw memory among the different C extension libraries, such as numo-narray, red-arrow, numpy.rb, and pandas.rb.

I intended to implement [PEP-3118](https://www.python.org/dev/peps/pep-3118/) like feature in Fiddle (See [ruby/fiddle#17](https://github.com/ruby/fiddle/issues/17) and [ruby/fiddle#18](https://github.com/ruby/fiddle/issues/18)), but it has not been done, yet. This feature is just related to C extension library layer, so Fiddle should be a suitable place to implement it. But it could not be done because we encountered the difficult issue: referring symbols in a C extension library from the other C extension library.

We need to introduce functions like `PyObject_CheckBuffer` and `PyObject_GetBuffer` for realizing buffer protocol. If we introduce `rb_fiddle_check_buffer` and `rb_fiddle_get_buffer` in fiddle.so, there is no portable and legal way to refer them from the other C extension libraries.

There are two ways to avoid this issue.

1. Introducing [libruby-fiddle.so](http://libfiddle.so) in Fiddle. This provides functions for C extension libraries. It is installed in the directory where [libruby.so](http://libruby.so) is located.
2. Implement buffer protocol features in Ruby's core.

I guess the former way is very difficult because we let `gem install` put `libruby-fiddle.so` in the appropriate place. So it is better to provide buffer protocol in Ruby's core if possible.

----------------------------------------
Feature #14722: python's buffer protocol clone
https://bugs.ruby-lang.org/issues/14722#change-86199

* Author: jsaak (jsaak jsaak)
* Status: Open
* Priority: Normal
----------------------------------------
Is there a way to implement, or even copy Python's buffer protocol in ruby?

There is an article that describes the benefits quite well:
https://jeffknupp.com/blog/2017/09/15/python-is-the-fastest-growing-programming-language-due-to-a-feature-youve-never-heard-of/

I did some work with machine vision, and the ability to manipulate images fast was also not realistic with ruby today.
This could be another area where ruby could shine.

Maybe this idea is worth a comment.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>