[#23457] [Bug #1471] "Mutual join" deadlock detection faulty in 1.8.6 and 1.8.7 — John Carter <redmine@...>

Bug #1471: "Mutual join" deadlock detection faulty in 1.8.6 and 1.8.7

17 messages 2009/05/15

[#23483] [Bug #1478] Ruby archive — Oleg Puchinin <redmine@...>

Bug #1478: Ruby archive

29 messages 2009/05/16
[#29225] [Feature #1478] Ruby archive — Luis Lavena <redmine@...> 2010/04/02

Issue #1478 has been updated by Luis Lavena.

[#30345] Re: [Feature #1478] Ruby archive — "NAKAMURA, Hiroshi" <nakahiro@...> 2010/05/21

On Fri, Apr 2, 2010 at 17:13, Luis Lavena <redmine@ruby-lang.org> wrote:

[#30346] Re: [Feature #1478] Ruby archive — Jonathan Nielsen <jonathan@...> 2010/05/21

> Thanks for your comment.

[#30347] Re: [Feature #1478] Ruby archive — Jonathan Nielsen <jonathan@...> 2010/05/21

OK Hiroshi, I read some of the comments earlier in the thread that I

[#30355] Re: [Feature #1478] Ruby archive — Caleb Clausen <vikkous@...> 2010/05/21

On 5/20/10, Jonathan Nielsen <jonathan@jmnet.us> wrote:

[#30364] Re: [Feature #1478] Ruby archive — Benoit Daloze <eregontp@...> 2010/05/22

Hi,

[#23505] [Bug #1494] tempfile#unlink may silently fail on windows — Nicholas Manning <redmine@...>

Bug #1494: tempfile#unlink may silently fail on windows

19 messages 2009/05/19

[#23572] [Bug #1525] Deadlock in Ruby 1.9's VM caused by ConditionVariable.wait and fork? — Hongli Lai <redmine@...>

Bug #1525: Deadlock in Ruby 1.9's VM caused by ConditionVariable.wait and fork?

27 messages 2009/05/27

[#23595] Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...>

The RUBY_PLATFORM constant is documented in the latest Pickaxe as "The

17 messages 2009/05/28
[#23596] Re: Meaning of RUBY_PLATFORM — Luis Lavena <luislavena@...> 2009/05/28

On Thu, May 28, 2009 at 3:41 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#23602] Re: Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...> 2009/05/28

On Thu, May 28, 2009 at 2:52 PM, Luis Lavena <luislavena@gmail.com> wrote:

[#23608] Re: Meaning of RUBY_PLATFORM — Luis Lavena <luislavena@...> 2009/05/28

On Thu, May 28, 2009 at 7:08 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#23609] Re: Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...> 2009/05/29

On Thu, May 28, 2009 at 7:22 PM, Luis Lavena <luislavena@gmail.com> wrote:

[ruby-core:23407] ruby-ffi problem

From: Aston <blackapache512-ticket@...>
Date: 2009-05-09 09:48:33 UTC
List: ruby-core #23407
Hello,

I am trying to learn ruby-ffi now (after sadly leaving dl library), I have some trouble here too

I will present a simple example where I want to pass a struct between ruby and C
I am facing problems while setting fields of struct if that field is of type string(char*, not char[])
I understand we have to allocate the char* field of struct first than assign some literal srting

consider the C file

********************** C FILE**********************
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct
{
    char *name;
    double val;
} INFO, *INFO_PTR;

INFO_PTR create( char* name, double val)
{
    INFO_PTR p = (INFO_PTR)malloc( sizeof(INFO));
    p->val = val;
    p->name = (char*)malloc( strlen(name) + 1);
    strcpy( p->name, name);
    return p;
}

int show( INFO_PTR pInfo)
{
    return printf( "%s - %f\n", pInfo->name, pInfo->val);
}

********************** END C FILE**********************

********************** RUBY FILE**********************
require 'ffi'

module LibTest
  class Info < FFI::Struct
    layout :name, :string,
           :val, :double
  end

  extend FFI::Library
  ffi_lib "./libtest.so"
  attach_function :create, [:string, :double], :pointer
  attach_function :show, [:pointer], :int
end

include FFI

ptr = LibTest.create( "test string", 11.27)
obj = LibTest::Info.new(ptr)
LibTest.show(ptr)
obj[:val] = 27.11 # this works
# obj[:name] = "new string" # this gives error, `[]=': Cannot set :string fields (ArgumentError)
LibTest.show(ptr)
********************** END RUBY FILE**********************

how can I set string values from ruby ?
If I refuse to declare name field as type char[] from char* then I have to allocate before I can assign
then my approach below core dumps :(

1 str = "test string"
2 p = MemoryPointer.new( str.size)
3 p.write_string(str)
4 puts p.read_string # "test string"
5 obj[:name].write_pointer(p) # core dumps here!

line # 5 core dumps everytime one tries to write anything there, since pointer is invalid I guess
how do I allocate memory there ? once allocated can i treat that allocated memory as ruby string ?

Goal I want to achieve is I shall allocate in ruby, assign in ruby and pass in to C code only for modification or read only purpose
how do I go from here ? can you comment on this ?

Aston


      Cricket on your mind? Visit the ultimate cricket website. Enter http://beta.cricket.yahoo.com

In This Thread

Prev Next