Re: [MacRuby-devel] [MacRuby] #339: YAML error with UTF-16 string
#339: YAML error with UTF-16 string
---+
Reporter: d...@… |Owner: lsansone...@…
Type: defect | Status: closed
Priority: critical |Milestone: MacRuby 0.5
Component: MacRuby| Resolution: fixed
Keywords: YAML encoding |
---+
Comment(by jazz...@…):
{{{
$ macruby -e 'require "yaml"; puts "Rübe".to_yaml'
--- "R\xFCbe"
$ ruby1.9 -e 'require "yaml"; puts "Rübe".to_yaml'
--- "R\xC3\xBCbe"
}}}
seems to work now! Macruby escpapes to UTF-16 and Ruby1.9 escapes to
UTF-8. I didn't find anything in YAML docs that describes that behaviour,
both methods seem to be correct. But ruby 1.8 fails to load the UTF-16
YAML. That is not astonishing because IMHO there is now way to guess what
is the correct escaping mode.
I think escaping is not necessary here because the encoding of input and
output is the same. This can easly be tested by
{{{
$ macruby -e 'require "yaml"; puts YAML::load "--- Rübe"'
Rübe
}}}
--
Ticket URL:
MacRuby
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] [MacRuby] #339: YAML error with UTF-16 string
On Nov 14, 2009, at 15:44 , MacRuby wrote:
> #339: YAML error with UTF-16 string
> ---+
> Reporter: d...@… |Owner: lsansone...@…
> Type: defect | Status: closed
> Priority: critical |Milestone: MacRuby 0.5
> Component: MacRuby| Resolution: fixed
> Keywords: YAML encoding |
> ---+
>
> Comment(by jazz...@…):
>
> {{{
> $ macruby -e 'require "yaml"; puts "Rübe".to_yaml'
> --- "R\xFCbe"
> $ ruby1.9 -e 'require "yaml"; puts "Rübe".to_yaml'
> --- "R\xC3\xBCbe"
> }}}
>
> seems to work now! Macruby escpapes to UTF-16 and Ruby1.9 escapes to
> UTF-8.
Actually, it seems to me (though I'm willing to be corrected on this), that the
ruby1.9 encoding is simply wrong: It translates the accented character into
UTF-8, and then escapes the two UTF-8 characters separately. What this ends up
encoding is "Rübe", which is not what you want.
> I didn't find anything in YAML docs that describes that behaviour, both
> methods seem to be correct.
They can't possibly be BOTH correct, as interpreting the output of one
according to the theory of the other would give a different result. If you look
at the section in the YAML spec:
, you will see
[57] "Escaped 8-bit Unicode character."
This is NOT an UTF-8 character.
> But ruby 1.8 fails to load the UTF-16 YAML. That is not astonishing because
> IMHO there is now way to guess what is the correct escaping mode.
It's not astonishing because (a) 1.8 has very poor Unicode support anyway and
(b) this would hardly be the only bug in syck.
> I think escaping is not necessary here because the encoding of input and
> output is the same. This can easly be tested by
>
> {{{
> $ macruby -e 'require "yaml"; puts YAML::load "--- Rübe"'
> Rübe
> }}}
That's an interesting point. I think you're right that the YAML spec does not
require escaping of printable characters >\u007F. However, non-printable
characters DO have to be escaped, and for the printable ones, it could be
argued that erring on the side of escaping helps readability if the OS does not
have font coverage for some printable characters. In any case, the current
implementation tries to be conservative in what it generates and liberal in
what it accepts. I'm open to persuasion that we should avoid escaping
characters, provided there is a low-cost test for printability of general
Unicode characters (I have not yet checked whether one of the built-in
CFCharacterSets can give that; the descriptions were inconclusive).
Matthias
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Quicklook plugin, Spotlight importer
Hi, I'm afraid I don't totally understand the question. If the class is written in Ruby using MacRuby, it can't be used in a non-GC environment. If the class is written in Objective-C but used in a MacRuby app, it can be used in a RR environment, assuming that it's correctly implemented to handle both environments. Laurent On Nov 12, 2009, at 6:18 AM, B. Ohr wrote: Hi, I have written a MacRuby class that reads binary data (a special format) from a file. Is there a chance that I can use this class in a Quicklook plugin or a spotlight importer? Both targets don't support GC-memory, but all object instances are created in one procedure with autorelease (NSAutoreleasePool ). So this is a very special case of GC Bernd ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] MacRuby 0.5b1: Reloading classes at runtime
Hi Frank,
Sorry for the late response. It seems to work here. Following is a
small test that loads a class from a Ruby file, calls +new on it, then
changes the code, re-loads it again.
Could you try to reduce your problem to a small test like this one and
let us know?
Thanks,
Laurent
$ pwd
/tmp/test
$ cat t.m
#import
#import
int main(void)
{
MacRuby *runtime = [MacRuby sharedRuntime];
[@"class Foo; def initialize; p 123; end; end" writeToFile:@"/tmp/
test/test.rb" atomically:YES encoding:NSUTF8StringEncoding error:nil];
[runtime evaluateString:[NSString stringWithFormat:@"load \"/tmp/
test/test.rb\""]];
[NSClassFromString(@"Foo") new];
[@"class Foo; def initialize; p 456; end; end" writeToFile:@"/tmp/
test/test.rb" atomically:YES encoding:NSUTF8StringEncoding error:nil];
[runtime evaluateString:[NSString stringWithFormat:@"load \"/tmp/
test/test.rb\""]];
[NSClassFromString(@"Foo") new];
return 0;
}
$ gcc t.m -o t -fobjc-gc -framework MacRuby -framework Foundation
$ ./t
123
456
On Nov 12, 2009, at 4:03 PM, Frank Illenberger wrote:
Thanks for your quick answer. But sadly, it does not seem to work.
My application is a regular Objective-C application and uses MacRuby
to load plug-in ruby classes which reside in their own .rb file.
First I implemented the loading like this:
NSString* path = @"/path/to/MyPlugInClass.rb";
[[MacRuby sharedRuntime] evaluateFileAtPath: path]
id plugInInstance = [[NSClassFromString(@"MyPlugInClass") alloc]
init];
This is working fine when the class is loaded for the first time.
Reloading the class while the app keeps running after the .rb has
been edited however does not refresh the class.
Then I tried to use the "load" command as you suggested:
NSString* path = @"/path/to/MyPlugInClass.rb";
NSString* command = [NSString stringWithFormat:@"load '%@'", path];
[[MacRuby sharedRuntime] evaluateString: command]
id plugInInstance = [[NSClassFromString(@"MyPlugInClass") alloc]
init];
But it shows the same behavior as the first case.
Am I doing something wrong here?
Cheers
Frank
Am 12.11.2009 um 20:40 schrieb Matt Aimonetti:
This is the right place to ask this kind of questions and welcome
to the list :)
What kind of file are you loading? If you are reloading a ruby, you
might want to try to use load instead of require.
http://www.fromjavatoruby.com/2008/10/require-vs-load.html
- Matt
On Thu, Nov 12, 2009 at 11:11 AM, Frank Illenberger > wrote:
Hello folks,
please excuse me if this is not the right mailing list to post this
question:
I am currently porting an application from PyObjC to MacRuby. Under
PyObjC it is possible to reload a .py file containing a class
definition at runtime. -[MacRuby evaluateFileAtPath:] works fine
for me loading a class for the first time. But after is loaded, it
is not updated when called again. Does anybody know if there is a
way to make this work with MacRuby?
Thanks and cheers
Frank
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] MacRuby 0.5b1: Tinkering with -[NSObject hash]
Hi Frank, Thanks for the report, it looks like a critical bug in MacRuby. Could you file a bug report on Trac? This way we won't forget it for the upcoming release. Laurent On Nov 13, 2009, at 6:16 AM, Frank Illenberger wrote: Hi everybody, I just found out the hard way, that initializing the MacRuby runtime seems to alter the values returned by -[NSObject hash] even for objects of non-ruby classes. In my Objective-C application, I am loading the MacRuby runtime lazily once the user needs to load a Ruby plug-in. This immediately destroys all NSDictionaries/ NSMapTables/NSSets that have been filled with objects before the loading. The only workaround I have found so far, is to call -[MacRuby sharedRuntime] early at the start of the application, but this results in an unnecessarily slower startup time and a larger memory footprint. Is the change in the hash values meant by design or might it be a bug in MacRuby? Cheers Frank ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
