[MacRuby-devel] Using 'Pointer.new_with_type'

Michael Winterstein parzival at mindspring.com
Mon Feb 9 20:20:25 PST 2009


This is useful to know this in case I really need another stdlib.c  
function.  For some reason I thought they were included (probably  
they're included in the C/Obj-C files, which I should have realized  
isn't the same as being available in MacRuby.)

I'm already using NSTemporaryDirectory as a start.  If it'd worked  
mkstemp would be even more secure (but it only adds protection against  
a very small number of cases).

For my purposes, mkstemp is overkill, so I won't bother with the effort.

Michael

On Feb 9, 2009, at 11:30 AM, Laurent Sansonetti wrote:

> Indeed (and sorry for the late reply), mkstemp is not covered by the  
> BridgeSupport mechanism yet, which is why it is not available from  
> MacRuby.
>
> As a workaround I would recommend too to wrap the call inside an  
> Objective-C class.  You don't have to build a framework, just a  
> shared library (.dylib) with an empty Init_XXX function (where XXX  
> is the name of the library file) can be loaded using #require.
>
> But first I would try to see if there is no alternative in the Cocoa  
> APIs. The NSTemporaryDirectory() function for instance returns you a  
> secure temporary directory for your process. You can then create a  
> file there based on a unique pattern.
>
> $ macirb
> >> framework 'Cocoa'
> => true
> >> NSTemporaryDirectory()
> => "/var/folders/v1/v1Iq1tXOEMuSDv5AyY7i2k+++TI/-Tmp-/"
> [...]
>
> Laurent
>
> On Feb 9, 2009, at 11:06 AM, Brian Chapados wrote:
>
>> mkstemp is defined in the standard C library.  To use it, you would
>> need to define a new bridged function in MacRuby on the fly. I don't
>> think there is a way to do this right now.
>>
>> As a work-around, you could wrap the C function calls in methods
>> defined in an Obj-C class and build a framework.  Then you would be
>> able to load the framework in MacRuby and call those methods.
>>
>> On Fri, Feb 6, 2009 at 12:24 AM, Michael Winterstein
>> <parzival at mindspring.com> wrote:
>>>
>>> On Feb 5, 2009, at 10:53 AM, Michael Winterstein wrote:
>>>
>>>> Hi all,
>>>>
>>>> Is there a particular framework that's required in order to use
>>>> 'Pointer.new_with_type'?
>>>>
>>>> I'm using the trunk (build 809) and it's apparently not available  
>>>> in
>>>> either my Xcode project or in macirb.
>>>>
>>>> Is there an alternative method for working with pointers?
>>>>
>>>>
>>>>
>>>> My specific case is that I want to call the C function mkstemp.
>>>> Is this what I should be doing? :
>>>>
>>>> @tmpfInfo += "/"+"resynch.fileinfo.XXXXXX"
>>>> tmptr = Pointer.new_with_type('*')
>>>> tmptr.assign(@tmpfInfo)
>>>> fd_tmpInfo = mkstemp(tmptr)
>>>> tmpInfoFileHandle =  
>>>> NSFileHandle.initWithFileDescriptor(@fd_tmpInfo)
>>>>
>>>> Michael_______________________________________________
>>>> MacRuby-devel mailing list
>>>> MacRuby-devel at lists.macosforge.org
>>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>>> Scratch some of that ... I didn't have the right file and now I do  
>>> have
>>> Pointer.new_with_type.
>>>
>>> But I'm still wondering what's the correct approach.  This code  
>>> still gives
>>> me "undefined method" errors on mkstemp.
>>>
>>> Michael
>>>
>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list