Hi all, I may have brought this up a long time ago, but I''ve forgotten. Why does PathIsURL(path) fail if ''path'' is frozen? require ''windows/path'' include Windows::Path path = "file://C:\\Documents and Settings\\djberge" PathIsURL(path) # true path.freeze PathIsURL(path) # Boom! TypeError: can''t modify frozen string from (eval):3:in `call'' from (eval):3:in `PathIsURL'' from (irb):9 Any ideas? I realize I can just dup the string, but I thought I''d ask. Thanks, Dan
Hi, ----- Original Message ----- From: "Daniel Berger" <djberg96 at gmail.com> To: "win32utils-devel" <win32utils-devel at rubyforge.org> Sent: Sunday, July 13, 2008 9:37 PM Subject: [Win32utils-devel] PathIsURL and frozen strings> Hi all, > > I may have brought this up a long time ago, but I''ve forgotten. Why does > PathIsURL(path) fail if ''path'' is frozen? > > require ''windows/path'' > include Windows::Path > > path = "file://C:\\Documents and Settings\\djberge" > PathIsURL(path) # true > > path.freeze > PathIsURL(path) # Boom! > > TypeError: can''t modify frozen string > from (eval):3:in `call'' > from (eval):3:in `PathIsURL'' > from (irb):9 > > Any ideas? I realize I can just dup the string, but I thought I''d ask. >In the win32-api, the string type(''P'') denotes both input and output pointer parameter. Thus the string parameter can be modified and must not be frozen. In case of pure input string, you can define another parameter type and skip rb_str_modify(v_arg) (line #584 of win32/api.c) Regards, Park Heesob
Park Heesob wrote:> Hi, > ----- Original Message ----- > From: "Daniel Berger" <djberg96 at gmail.com> > To: "win32utils-devel" <win32utils-devel at rubyforge.org> > Sent: Sunday, July 13, 2008 9:37 PM > Subject: [Win32utils-devel] PathIsURL and frozen strings > > >> Hi all, >> >> I may have brought this up a long time ago, but I''ve forgotten. Why does >> PathIsURL(path) fail if ''path'' is frozen? >> >> require ''windows/path'' >> include Windows::Path >> >> path = "file://C:\\Documents and Settings\\djberge" >> PathIsURL(path) # true >> >> path.freeze >> PathIsURL(path) # Boom! >> >> TypeError: can''t modify frozen string >> from (eval):3:in `call'' >> from (eval):3:in `PathIsURL'' >> from (irb):9 >> >> Any ideas? I realize I can just dup the string, but I thought I''d ask. >> > In the win32-api, the string type(''P'') denotes both input and output pointer > parameter. > Thus the string parameter can be modified and must not be frozen. > In case of pure input string, you can define another parameter type and skip > rb_str_modify(v_arg) (line #584 of win32/api.c)Ah, yes, thanks. I suppose we could add an "S" prototype for pure input strings, but I''m not sure the benefit outweighs the cost of adding yet another prototype. What do you think? Thanks, Dan
Park Heesob wrote:> Hi, > ----- Original Message ----- > From: "Daniel Berger" <djberg96 at gmail.com> > To: "win32utils-devel" <win32utils-devel at rubyforge.org> > Sent: Sunday, July 13, 2008 9:37 PM > Subject: [Win32utils-devel] PathIsURL and frozen strings > > >> Hi all, >> >> I may have brought this up a long time ago, but I''ve forgotten. Why does >> PathIsURL(path) fail if ''path'' is frozen? >> >> require ''windows/path'' >> include Windows::Path >> >> path = "file://C:\\Documents and Settings\\djberge" >> PathIsURL(path) # true >> >> path.freeze >> PathIsURL(path) # Boom! >> >> TypeError: can''t modify frozen string >> from (eval):3:in `call'' >> from (eval):3:in `PathIsURL'' >> from (irb):9 >> >> Any ideas? I realize I can just dup the string, but I thought I''d ask. >> > In the win32-api, the string type(''P'') denotes both input and output pointer > parameter. > Thus the string parameter can be modified and must not be frozen. > In case of pure input string, you can define another parameter type and skip > rb_str_modify(v_arg) (line #584 of win32/api.c)After thinking about it some more I''m going to go ahead and add an ''S'' prototype, which will be for const char* strings. My reasoning is as follows: It''s a bit faster. About 25% in a strcpy benchmark I ran. It means we don''t have to worry about buffers in some cases (or will, once I redefine the prototypes in windows-pr). It eliminates the issue I originally mentioned regarding frozen strings. I think it will simplify certain parts of a port for JRuby or IronRuby. I''ll mark this as a major release, 1.2.0. Regards, Dan