Ruby/Python - mixed language apps, and garbage collection

  • I couldn't find a more appropriate mailing list. I just have a couple
    of questions:

    1) Can we add Python or Ruby classes to an existing Objective-C
    project? I can't find a sample that mixes languages. I tried adding
    some .rb files to my project, but they don't seem to be loaded at
    runtime. Is there a way to make this work (assuming mixing languages
    is supported at all)?

    2) In the WWDC 2006 or 2007 slides there was a bullet about "Memory
    management does not work" and the vocal comment was that this was
    still being looked into. I didn't grasp the full consequences about
    this - was it saying no garbage collection for Python/Ruby programs at
    all? No garbage collection for mixed-language apps? Or just no GC on
    the Objective-C side of a mixed app? And, what is the current status
    of this rather important bullet?

    Thanks,
    Graham Perks.
    http://www.asinglepixel.com
  • On Nov 18, 2007, at 7:58 AM, Graham Perks wrote:
    > I couldn't find a more appropriate mailing list. I just have a
    > couple of questions:
    >
    > 1) Can we add Python or Ruby classes to an existing Objective-C
    > project? I can't find a sample that mixes languages. I tried adding
    > some .rb files to my project, but they don't seem to be loaded at
    > runtime. Is there a way to make this work (assuming mixing languages
    > is supported at all)?

    You need to add the bootstrap code necessary to bring up the Python or
    Ruby interpreter in your existing application.  The easiest way to do
    this is to create a new Cocoa Python or Cocoa Ruby project, then copy/
    paste out the bits from the main file(s) that are needed.

    Some slight changes will be needed to those files to make it all work
    correctly.  See the "embedding" documentation for your language of
    choice.

    > 2) In the WWDC 2006 or 2007 slides there was a bullet about "Memory
    > management does not work" and the vocal comment was that this was
    > still being looked into. I didn't grasp the full consequences about
    > this - was it saying no garbage collection for Python/Ruby programs
    > at all? No garbage collection for mixed-language apps? Or just no GC
    > on the Objective-C side of a mixed app? And, what is the current
    > status of this rather important bullet?

    Objective-C Garbage Collection cannot be enabled in Ruby/Python based
    Cocoa applications.  Specifically, you can't use Objective-C objects
    on the scripting language side of the bridges.

    If you are embedding Ruby or Python with the purpose of running
    straight ruby/python scripts, with non-object data coming from the
    objective-c side of the world, it isn't an issue.

    (Technically, there really isn't a reason why you couldn't enable GC
    for RubyCocoa and PyObjC.  You would need to recompile the bridges and
    Python/Ruby interpreters with GC enabled.  Once enabled, you "just"
    need to make sure that any reference to an Objective-C object passed
    through to Ruby/Python continues to have a strong reference on the obj-
    c side of the bridge.)

    b.bum
  • Thanks, Bill.

    I looked for "embedding" documentation but all I came up with was
    people embedding the runtime, Tiger-style. Similarly, your comment
    below is implying I'm on Tiger, right? I would be targeting Leopard so
    the Python/Ruby runtime is already compiled and in place, isn't it?

    On Nov 18, 2007, at 11:32 AM, Bill Bumgarner wrote:

    > (Technically, there really isn't a reason why you couldn't enable GC
    > for RubyCocoa and PyObjC.  You would need to recompile the bridges
    > and Python/Ruby interpreters with GC enabled.

    In my head I would like to take an existing Objective-C application,
    and switch over to developing it in Python or Ruby. I'd be subclassing
    ObjC, creating objects on both sides of the bridge - all the stuff you
    do in a regular single-language application. Is this beyond what the
    bridge is intended for? If it is, that's OK, I'd just like to know!

    > Objective-C Garbage Collection cannot be enabled in Ruby/Python
    > based Cocoa applications.  Specifically, you can't use Objective-C
    > objects on the scripting language side of the bridges.

    So I can't pass NSString objects? I am limited to ints & floats and
    the like? GC on the Python/Ruby side is enabled, right - I don't have
    to start managing memory in Python do I?

    Thanks,
    Graham Perks.
  • On Nov 19, 2007, at 5:12 AM, Graham Perks wrote:
    > I looked for "embedding" documentation but all I came up with was
    > people embedding the runtime, Tiger-style. Similarly, your comment
    > below is implying I'm on Tiger, right? I would be targeting Leopard
    > so the Python/Ruby runtime is already compiled and in place, isn't it?

    You still have to link against the appropriate language and bring up
    the interpreter.

    See the result of "new project" and creating a Cocoa / Python or
    Cocoa / Ruby application.  There is no magic;  the main source files
    for both contain everything necessary to bootstrap the interpreters
    for either language, optimized for Leopard.

    > On Nov 18, 2007, at 11:32 AM, Bill Bumgarner wrote:
    >
    >> (Technically, there really isn't a reason why you couldn't enable
    >> GC for RubyCocoa and PyObjC.  You would need to recompile the
    >> bridges and Python/Ruby interpreters with GC enabled.
    >
    > In my head I would like to take an existing Objective-C application,
    > and switch over to developing it in Python or Ruby. I'd be
    > subclassing ObjC, creating objects on both sides of the bridge - all
    > the stuff you do in a regular single-language application. Is this
    > beyond what the bridge is intended for? If it is, that's OK, I'd
    > just like to know!

    That is definitely in scope of the bridges;  exactly what they are
    designed for and exactly what many people are already doing with them.

    >> Objective-C Garbage Collection cannot be enabled in Ruby/Python
    >> based Cocoa applications.  Specifically, you can't use Objective-C
    >> objects on the scripting language side of the bridges.
    >
    > So I can't pass NSString objects? I am limited to ints & floats and
    > the like? GC on the Python/Ruby side is enabled, right - I don't
    > have to start managing memory in Python do I?

    If you have an existing Cocoa application that is non-GC, I would
    leave it non-GC and just use the bridges as is.  If you have a GC'd
    Cocoa app and really want to use the bridges, it might be easier to
    add all the retain/release/autorelease noise back into the code.    Do
    not underestimate the difficulty of enabling GC support for either
    bridge.

    To enable GC with the ruby or python bridge will *require*:

    - recompiling the target language with GC enabled (this can be skipped
    only if there is not a single line of objective-c code in the source
    of ruby or python)

    - recompiling the bridges to be GC enabled

    - dealing with the fallout of bridging between two completely
    different GC subsystems.

    In other words, I wouldn't go there until the bridge developers get
    around to having a look.

    b.bum
  • Hi,

    > 1) Can we add Python or Ruby classes to an existing Objective-C
    > project? I can't find a sample that mixes languages. I tried adding
    > some .rb files to my project, but they don't seem to be loaded at
    > runtime. Is there a way to make this work (assuming mixing languages
    > is supported at all)?

    Sure.  My project, LimeChat could be a sample.

    http://limechat.sourceforge.net/

    It uses RubyCocoa, mainly written in Ruby but contains some ObjC
    classes.  You can download the source code from the site.

    > 2) In the WWDC 2006 or 2007 slides there was a bullet about "Memory
    > management does not work" and the vocal comment was that this was
    > still being looked into. I didn't grasp the full consequences about
    > this - was it saying no garbage collection for Python/Ruby programs
    > at all? No garbage collection for mixed-language apps? Or just no GC
    > on the Objective-C side of a mixed app? And, what is the current
    > status of this rather important bullet?

    Yes.  Because it uses Python's or Ruby's GC.
    About RubyCocoa, I'm not sure that it works well with ObjC 2.0 GC.
    But we don't need ObjC 2.0 GC. Because Ruby's GC takes care of all
    objects, both Ruby objects and Objc objects.

    --
    Satoshi Nakagawa

    On 2007/11/19, at 0:58, Graham Perks wrote:

    > I couldn't find a more appropriate mailing list. I just have a
    > couple of questions:
    >
    > 1) Can we add Python or Ruby classes to an existing Objective-C
    > project? I can't find a sample that mixes languages. I tried adding
    > some .rb files to my project, but they don't seem to be loaded at
    > runtime. Is there a way to make this work (assuming mixing languages
    > is supported at all)?
    >
    > 2) In the WWDC 2006 or 2007 slides there was a bullet about "Memory
    > management does not work" and the vocal comment was that this was
    > still being looked into. I didn't grasp the full consequences about
    > this - was it saying no garbage collection for Python/Ruby programs
    > at all? No garbage collection for mixed-language apps? Or just no GC
    > on the Objective-C side of a mixed app? And, what is the current
    > status of this rather important bullet?
    >
    > Thanks,
    > Graham Perks.
    > http://www.asinglepixel.com
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today