Fiddle + CoreMIDI + Segmentation fault

Hello people,

I’m playing around with Fiddle and CoreMIDI on OSX.

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]

require ‘fiddle’
require ‘fiddle/import’

module CoreMIDI
extend Fiddle::Importer
dlload
‘/System/Library/Frameworks/CoreMIDI.framework/Versions/Current/CoreMIDI’

#from MIDIServices.h
#extern MIDIEndpointRef MIDIGetSource(  ItemCount sourceIndex0 )
extern "int MIDIGetSource(int)"

# from MIDIServices.h
# extern OSStatus MIDIObjectGetStringProperty(MIDIObjectRef obj,

CFStringRef propertyID, CFStringRef *str);
extern “int MIDIObjectGetStringProperty(int, char *, char *)”

end

from MIDIServices.h

extern const CFStringRef kMIDIPropertyOffline

irb(main)> m = CoreMIDI.MIDIGetSource(0)
=> 273731602
irb(main)> str = “”
irb(main)> CoreMIDI.MIDIObjectGetStringProperty(m,"",str)
=> -10835 #kMIDIUnknownProperty = -10835

from MIDIServices.h

extern const CFStringRef kMIDIPropertyOffline

irb(main)>
CoreMIDI.MIDIObjectGetStringProperty(m,‘kMIDIPropertyOffline’,str)
[BUG] Segmentation fault at 0x00000000000000

#file ruby_2015-05-03-150759_nautilus.crash
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT

The first try

CoreMIDI.MIDIObjectGetStringProperty(m,"",str)

returns -10835 which is kMIDIUnknownProperty. Looks ok for a response.
But then:

CoreMIDI.MIDIObjectGetStringProperty(m,‘kMIDIPropertyOffline’,str)

Exit with a Segmentation fault.

This function MIDIObjectGetStringProperty has an argument “CFStringRef
*str” which I understand is a reference. But how can I give that
reference from ruby. Is it possible?

Should I provide the BUG report. I’m not sure this is a BUG but me not
passing the right parameters type or references.

Many thanks in advance!
Matias Repetti.

Hello Juan M.,

I do not understand the subject matter, but from a formal point of view,
given that the last two arguments of the original function declaration
are
CFStringRef propertyID
and
CFStringRef *str
(one without an asterisk and one with an asterisk),
then it seems odd to me, that in your “extern” statement
they are both getting the same type, namely “char *”.

Would it not be more logical to add one astersk more
to the last argument, ie “char **”?

So long
Sven

Juan M. wrote in post #1172996:

Hello people,

I’m playing around with Fiddle and CoreMIDI on OSX.

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]

require ‘fiddle’
require ‘fiddle/import’

module CoreMIDI
extend Fiddle::Importer
dlload
‘/System/Library/Frameworks/CoreMIDI.framework/Versions/Current/CoreMIDI’

#from MIDIServices.h
#extern MIDIEndpointRef MIDIGetSource(  ItemCount sourceIndex0 )
extern "int MIDIGetSource(int)"

# from MIDIServices.h
# extern OSStatus MIDIObjectGetStringProperty(MIDIObjectRef obj,

CFStringRef propertyID, CFStringRef *str);
extern “int MIDIObjectGetStringProperty(int, char *, char *)”

end

from MIDIServices.h

extern const CFStringRef kMIDIPropertyOffline

irb(main)> m = CoreMIDI.MIDIGetSource(0)
=> 273731602
irb(main)> str = “”
irb(main)> CoreMIDI.MIDIObjectGetStringProperty(m,"",str)
=> -10835 #kMIDIUnknownProperty = -10835

from MIDIServices.h

extern const CFStringRef kMIDIPropertyOffline

irb(main)>
CoreMIDI.MIDIObjectGetStringProperty(m,‘kMIDIPropertyOffline’,str)
[BUG] Segmentation fault at 0x00000000000000

#file ruby_2015-05-03-150759_nautilus.crash
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT

The first try

CoreMIDI.MIDIObjectGetStringProperty(m,"",str)

returns -10835 which is kMIDIUnknownProperty. Looks ok for a response.
But then:

CoreMIDI.MIDIObjectGetStringProperty(m,‘kMIDIPropertyOffline’,str)

Exit with a Segmentation fault.

This function MIDIObjectGetStringProperty has an argument “CFStringRef
*str” which I understand is a reference. But how can I give that
reference from ruby. Is it possible?

Should I provide the BUG report. I’m not sure this is a BUG but me not
passing the right parameters type or references.

Many thanks in advance!
Matias Repetti.

Thanks Sven for your answer.

Apologies, I wrote this post in a hurry.

I’ll rewrite my question again when I’m back.

In short, I don’t know how to cast the types to be parsed by Fiddle and
also, how to pass variables as a reference.

This is the header on from MIDIServices.h file shows:

extern OSStatus MIDIObjectGetStringProperty(MIDIObjectRef obj,

CFStringRef propertyID, CFStringRef *str);

I tried to import the above function in ruby using Fiddle, to be honest,
I tried different types, I don’t know which types should I use on the
ruby side. For example OSStatus is a SInt32 then I though that using int
will be ok, MIDIObjectRef is a UInt32, then also int. But with
CFStringRef I have no idea.

I couldn’t find many examples on the topic, then I’m trying to guess.

Now I found some examples using DL:Import from the book: Practical Ruby
Projects: Ideas for the Eclectic Programmer(Topher Cyll) he is using
(void *) for the CFStringRef types. I’ll try that.

Another thing is, the function MIDIObjectGetStringProperty is setting
the result in: CFStringRef *str.
From ruby, I should provide a variable to receive the result, but I
don’t know how.

For example from Ruby:

str = “”
m = CoreMIDI.MIDIGetSource(0)
CoreMIDI.MIDIObjectGetStringProperty(m,<property_to_get>,str)

I expect “str” to contain the result of MIDIObjectGetStringProperty
call. But doesn’t happen.
If someone have some advice on this, I’ll appreciate.

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs