Functions attached with FFI::Struct.by_value as a return value are returning 
null pointers
------------------------------------------------------------------------------------------

                 Key: JRUBY-4769
                 URL: http://jira.codehaus.org/browse/JRUBY-4769
             Project: JRuby
          Issue Type: Bug
          Components: Extensions
    Affects Versions: JRuby 1.5.0.RC2
         Environment: Linux i386
            Reporter: Justin Collins


Thought I'd test my [FFI gdbm|http://github.com/presidentbeef/ffi-gdbm] library 
against 1.5.0rc2.

This is the struct class I use:

{noformat} class Datum < FFI::Struct
    layout :dptr, :pointer, :dsize, :int

    #Expects either a MemoryPointer or a String as an argument.
    #If it is given a String, it will initialize the fields, including
    #setting dsize.
    def initialize(*args)
      if args.length == 0 or (args.length == 1 and args[0].is_a? 
FFI::MemoryPointer)
        super
      elsif args.length == 1 and args[0].is_a? String
        super()
        self.dptr = args[0]
        self[:dsize] = args[0].length
      end
    end

    def value
      if self[:dptr].nil? or self[:dptr].null?
        nil
      else
        self[:dptr].read_string(self.size)
      end
    end

    def dptr=(str)
      @dptr = FFI::MemoryPointer.from_string(str)
      self[:dptr] = @dptr
    end

    def size
      self[:dsize]
    end
  end
{noformat}

And these are the functions which are returning structs with null pointers for 
:dptr

{noformat}  attach_function :gdbm_fetch, [ :pointer, Datum.by_value ], 
Datum.by_value
  attach_function :gdbm_firstkey, [ :pointer ], Datum.by_value
  attach_function :gdbm_nextkey, [ :pointer, Datum.by_value ], Datum.by_value
{noformat} 


These functions work properly with 1.4.0, as well as MRI 1.8.7p72 and 1.9.1p243 
with FFI 0.6.3.

Please let me know what further info I can provide to narrow down this issue.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to