Ruby DL::Importable struct issue

Hi,

The ruby182-14RC9.exe (one click installer) version of Ruby breaks some DL
code in a gem of mine (tidy on rubyforge). The problem is with the first
struct item which defines "byte* bp". I get the following error when I run
the script at the bottom. If "byte*" is deliberately no longer supported,
what would be a valid equivalent?

(eval):2 in '[]': unsupported type 'p' (DL::DLTypeError)
  from (eval):2:in 'bp'

···

#-------
require 'dl/import'
require 'dl/struct'

extend DL::Importable

# http://tidy.sourceforge.net/docs/api/struct__TidyBuffer.html
TidyBuffer = struct [
  "byte* bp",
  "uint size",
  "uint allocated",
  "uint next"
]

struct = TidyBuffer.malloc
puts struct.bp
#-------

Try "char* bp" or "unsigned char* bp".

···

In article <EYCdnZRN0fuN6z7cRVn-3g@rogers.com>, Kevin Howe wrote:

Hi,

The ruby182-14RC9.exe (one click installer) version of Ruby breaks some DL
code in a gem of mine (tidy on rubyforge). The problem is with the first
struct item which defines "byte* bp". I get the following error when I run
the script at the bottom. If "byte*" is deliberately no longer supported,
what would be a valid equivalent?

(eval):2 in '': unsupported type 'p' (DL::DLTypeError)
from (eval):2:in 'bp'

#-------
require 'dl/import'
require 'dl/struct'

extend DL::Importable

# http://tidy.sourceforge.net/docs/api/struct__TidyBuffer.html
TidyBuffer = struct [
"byte* bp",
"uint size",
"uint allocated",
"uint next"
]

struct = TidyBuffer.malloc
puts struct.bp
#-------

Kevin,

Hi, nice to see you here again :wink:

I looked in the diffs at
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/dl/lib/dl/types.rb.diff?r1=1.7;r2=1.8;f=h
and based on that, I changed the 'p' back into 'P' in dl/types.rb, as it was
in version 1.7. Now your usage.rb passes gloriously...!

Of course I don't know what I'm doing...

Luc

"Kevin Howe" <khowe@perfnet.ca> wrote in message
news:EYCdnZRN0fuN6z7cRVn-3g@rogers.com...

···

Hi,

The ruby182-14RC9.exe (one click installer) version of Ruby breaks some DL
code in a gem of mine (tidy on rubyforge). The problem is with the first
struct item which defines "byte* bp". I get the following error when I run
the script at the bottom. If "byte*" is deliberately no longer supported,
what would be a valid equivalent?

(eval):2 in '': unsupported type 'p' (DL::DLTypeError)
from (eval):2:in 'bp'

#-------
require 'dl/import'
require 'dl/struct'

extend DL::Importable

# http://tidy.sourceforge.net/docs/api/struct__TidyBuffer.html
TidyBuffer = struct [
"byte* bp",
"uint size",
"uint allocated",
"uint next"
]

struct = TidyBuffer.malloc
puts struct.bp
#-------

I get the following error
(eval):2 in '': unsupported type 'p' (DL::DLTypeError)
from (eval):2:in 'bp'

Try "char* bp" or "unsigned char* bp".

"char* bp" produces the same error, but with type 's' instead of type 'p'.
"unsigned char*" produces an "invalid element" error. I also tried "uint*
bp" and "int* bp", but they give the same original error.

Okay, this is a bug in newer versions of the dl extension.

e.g. current CVS ruby/ext/dl/sample/libc.rb fails with
10
true
false
"ab"
(eval):5:in `call': unsupported type `p' (DL::DLTypeError)
        from (eval):5:in `qsort'
        from libc.rb:62

$ ruby -v
ruby 1.9.0 (2004-11-24) [i686-linux]

There are a couple of places in ptr.c which do a `switch' on the type ('I',
'S' etc.) but only handle upper-case types like 'P' and not lower-case like
'p' (the latter are the pointer versions).

`rb_dlptr_aref' and `cary2ary' in particular.

···

In article <Vv-dnXwGIanSqTncRVn-sQ@rogers.com>, Kevin Howe wrote:

I get the following error
(eval):2 in '': unsupported type 'p' (DL::DLTypeError)
from (eval):2:in 'bp'

Try "char* bp" or "unsigned char* bp".

"char* bp" produces the same error, but with type 's' instead of type 'p'.
"unsigned char*" produces an "invalid element" error. I also tried "uint*
bp" and "int* bp", but they give the same original error.

Tim Sutherland said:

I get the following error
(eval):2 in '': unsupported type 'p' (DL::DLTypeError)
from (eval):2:in 'bp'

Okay, this is a bug in newer versions of the dl extension.

I fixed that.
Please replace import.rb, types.rb and struct.rb in lib/ruby/dl
with files shown at the following URL.
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/dl/lib/dl/

Regards,

···

--
Takaaki Tateishi <ttate@ttsky.net>

> Okay, this is a bug in newer versions of the dl extension.

I fixed that.
Please replace import.rb, types.rb and struct.rb in lib/ruby/dl
with files shown at the following URL.
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/dl/lib/dl/

When I use these files I get the following error:

types.rb:236:in 'encode_type': unknown type: uint (TypeError)

Kevin Howe said:

When I use these files I get the following error:
types.rb:236:in 'encode_type': unknown type: uint (TypeError)

Could you try again?

Thanks,

···

--
Takaaki Tateishi <ttate@ttsky.net>

Could you try again?

That seems to have done it, thanks!

- Kevin