[MacRuby] #691: Runtime should allow pointer types for C-string arguments
#691: Runtime should allow pointer types for C-string arguments --------------------------------+------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- The MacRuby runtime does not allow calls to C functions that take a string buffer using Pointer types. So, any C functions that need to fill a string buffer cannot be called. For example, I'm trying to do some GLSL shaders with MacRuby. I cannot call glGetShaderInfoLog if the shader compilation fails. The C function's prototype is: void glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei * length, GLchar * infoLog); I couldn't find any docs on how Pointer.new_with_type, so I tried a few things, such as: log_info = Pointer.new_with_type('c', 4096) length = Pointer.new_with_type('i') glGetShaderInfoLog(@shader_id, 4096, length, log_info) However, I get the error: TypeError: can't convert Pointer into String It seems that the bridge wants log_info to be a String object. But, using a String causes a bus error. I'm expecting that the bridge isn't expecting the string to be mutated. -- Ticket URL: <http://www.macruby.org/trac/ticket/691> MacRuby <http://macruby.org/>
#691: Runtime should allow pointer types for C-string arguments --------------------------------+------------------------------------------- Reporter: mike@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: major | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: fixed Keywords: | --------------------------------+------------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.7 Comment: Should be fixed in r4034. I haven't tried this specific OpenGL function but the following snippet works: {{{ $ cat t.rb framework 'Foundation' s = NSString.stringWithString('foo') ptr = Pointer.new(:char, 4) p s.getCString(ptr, maxLength: 4, encoding: NSASCIIStringEncoding) 4.times { |i| p ptr[i].chr } $ ./miniruby t.rb true "f" "o" "o" "\x00" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/691#comment:1> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby