* [ruby-core:120448] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name
@ 2024-12-30 21:11 cfis (Charlie Savage) via ruby-core
2024-12-30 21:13 ` [ruby-core:120449] " cfis (Charlie Savage) via ruby-core
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2024-12-30 21:11 UTC (permalink / raw)
To: ruby-core; +Cc: cfis (Charlie Savage)
Issue #20994 has been reported by cfis (Charlie Savage).
----------------------------------------
Bug #20994: C API - How to Create Classes with Non-ASCII characters in Name
https://bugs.ruby-lang.org/issues/20994
* Author: cfis (Charlie Savage)
* Status: Open
* ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x64-mswin64_140]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
As part of Rice (Ruby C++ bindings), I am experimenting with using unicode characters to make more readable class names (see https://ruby-rice.github.io/4.x/stl/stl.html#automatically-generated-ruby-classes).
I am experimenting with class names like this:
```
Map≺string≺char≻٬vector≺complex≺double≻≻≻`
```
Where < and > are actually Unicode characters precede (\u227A) and succeed (\u227B).
In Ruby this works fine:
``` ruby
irb(main):01> class Map≺string≺char≻٬vector≺complex≺double≻≻≻
irb(main):02> end
=> nil
irb(main):013> Map≺string≺char≻٬vector≺complex≺double≻≻≻.new
=> #<Map≺string≺char≻٬vector≺complex≺double≻≻≻:0x0000021114674c98>
```
However, this fails using the Ruby C API `define_method`. Passing a `char*` that is utf8 encoded fails because `define_method` calls `rb_intern` which calls `rb_intern2` which forces the use of ascii encoding (see https://github.com/ruby/ruby/blob/5fec9308320e8b377681ef19b0cd46d53f94e8ac/symbol.c#L818).
I thought I might be able to define the class using ascii characters, and then call `rb_define_const` to add in a utf8 encoded name, but that also has the same problem.
My question - how does one create class names that have non ascii characters in them via the C API?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120449] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name
2024-12-30 21:11 [ruby-core:120448] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name cfis (Charlie Savage) via ruby-core
@ 2024-12-30 21:13 ` cfis (Charlie Savage) via ruby-core
2024-12-30 21:24 ` [ruby-core:120450] " cfis (Charlie Savage) via ruby-core
2024-12-31 4:28 ` [ruby-core:120454] [Ruby master Misc#20994] " nobu (Nobuyoshi Nakada) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2024-12-30 21:13 UTC (permalink / raw)
To: ruby-core; +Cc: cfis (Charlie Savage)
Issue #20994 has been updated by cfis (Charlie Savage).
Sorry, above where I wrote `define_method` I of course meant `rb_define_class`.
----------------------------------------
Bug #20994: C API - How to Create Classes with Non-ASCII characters in Name
https://bugs.ruby-lang.org/issues/20994#change-111228
* Author: cfis (Charlie Savage)
* Status: Open
* ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x64-mswin64_140]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
As part of Rice (Ruby C++ bindings), I am experimenting with using unicode characters to make more readable class names (see https://ruby-rice.github.io/4.x/stl/stl.html#automatically-generated-ruby-classes).
I am experimenting with class names like this:
```
Map≺string≺char≻٬vector≺complex≺double≻≻≻`
```
Where < and > are actually Unicode characters precede (\u227A) and succeed (\u227B).
In Ruby this works fine:
``` ruby
irb(main):01> class Map≺string≺char≻٬vector≺complex≺double≻≻≻
irb(main):02> end
=> nil
irb(main):013> Map≺string≺char≻٬vector≺complex≺double≻≻≻.new
=> #<Map≺string≺char≻٬vector≺complex≺double≻≻≻:0x0000021114674c98>
```
However, this fails using the Ruby C API `define_method`. Passing a `char*` that is utf8 encoded fails because `define_method` calls `rb_intern` which calls `rb_intern2` which forces the use of ascii encoding (see https://github.com/ruby/ruby/blob/5fec9308320e8b377681ef19b0cd46d53f94e8ac/symbol.c#L818).
I thought I might be able to define the class using ascii characters, and then call `rb_define_const` to add in a utf8 encoded name, but that also has the same problem.
My question - how does one create class names that have non ascii characters in them via the C API?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120450] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name
2024-12-30 21:11 [ruby-core:120448] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name cfis (Charlie Savage) via ruby-core
2024-12-30 21:13 ` [ruby-core:120449] " cfis (Charlie Savage) via ruby-core
@ 2024-12-30 21:24 ` cfis (Charlie Savage) via ruby-core
2024-12-31 4:28 ` [ruby-core:120454] [Ruby master Misc#20994] " nobu (Nobuyoshi Nakada) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: cfis (Charlie Savage) via ruby-core @ 2024-12-30 21:24 UTC (permalink / raw)
To: ruby-core; +Cc: cfis (Charlie Savage)
Issue #20994 has been updated by cfis (Charlie Savage).
Ah - I found `rb_define_class_id_under` which works.
----------------------------------------
Bug #20994: C API - How to Create Classes with Non-ASCII characters in Name
https://bugs.ruby-lang.org/issues/20994#change-111231
* Author: cfis (Charlie Savage)
* Status: Open
* ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x64-mswin64_140]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
As part of Rice (Ruby C++ bindings), I am experimenting with using unicode characters to make more readable class names (see https://ruby-rice.github.io/4.x/stl/stl.html#automatically-generated-ruby-classes).
I am experimenting with class names like this:
```
Map≺string≺char≻٬vector≺complex≺double≻≻≻`
```
Where < and > are actually Unicode characters precede (\u227A) and succeed (\u227B).
In Ruby this works fine:
``` ruby
irb(main):01> class Map≺string≺char≻٬vector≺complex≺double≻≻≻
irb(main):02> end
=> nil
irb(main):013> Map≺string≺char≻٬vector≺complex≺double≻≻≻.new
=> #<Map≺string≺char≻٬vector≺complex≺double≻≻≻:0x0000021114674c98>
```
However, this fails using the Ruby C API `rb_define_class`. Passing a `char*` that is utf8 encoded fails because `rb_define_class` calls `rb_intern` which calls `rb_intern2` which forces the use of ascii encoding (see https://github.com/ruby/ruby/blob/5fec9308320e8b377681ef19b0cd46d53f94e8ac/symbol.c#L818).
I thought I might be able to define the class using ascii characters, and then call `rb_define_const` to add in a utf8 encoded name, but that also has the same problem.
My question - how does one create classes that have non ascii characters in their names them via the C API?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120454] [Ruby master Misc#20994] C API - How to Create Classes with Non-ASCII characters in Name
2024-12-30 21:11 [ruby-core:120448] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name cfis (Charlie Savage) via ruby-core
2024-12-30 21:13 ` [ruby-core:120449] " cfis (Charlie Savage) via ruby-core
2024-12-30 21:24 ` [ruby-core:120450] " cfis (Charlie Savage) via ruby-core
@ 2024-12-31 4:28 ` nobu (Nobuyoshi Nakada) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-31 4:28 UTC (permalink / raw)
To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)
Issue #20994 has been updated by nobu (Nobuyoshi Nakada).
Tracker changed from Bug to Misc
Status changed from Open to Closed
ruby -v deleted (ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x64-mswin64_140])
Backport deleted (3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN)
Or you can assign an anonymous class to that constant.
----------------------------------------
Misc #20994: C API - How to Create Classes with Non-ASCII characters in Name
https://bugs.ruby-lang.org/issues/20994#change-111235
* Author: cfis (Charlie Savage)
* Status: Closed
----------------------------------------
As part of Rice (Ruby C++ bindings), I am experimenting with using unicode characters to make more readable class names (see https://ruby-rice.github.io/4.x/stl/stl.html#automatically-generated-ruby-classes).
I am experimenting with class names like this:
```
Map≺string≺char≻٬vector≺complex≺double≻≻≻`
```
Where < and > are actually Unicode characters precede (\u227A) and succeed (\u227B).
In Ruby this works fine:
``` ruby
irb(main):01> class Map≺string≺char≻٬vector≺complex≺double≻≻≻
irb(main):02> end
=> nil
irb(main):013> Map≺string≺char≻٬vector≺complex≺double≻≻≻.new
=> #<Map≺string≺char≻٬vector≺complex≺double≻≻≻:0x0000021114674c98>
```
However, this fails using the Ruby C API `rb_define_class`. Passing a `char*` that is utf8 encoded fails because `rb_define_class` calls `rb_intern` which calls `rb_intern2` which forces the use of ascii encoding (see https://github.com/ruby/ruby/blob/5fec9308320e8b377681ef19b0cd46d53f94e8ac/symbol.c#L818).
I thought I might be able to define the class using ascii characters, and then call `rb_define_const` to add in a utf8 encoded name, but that also has the same problem.
My question - how does one create classes that have non ascii characters in their names them via the C API?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-31 4:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-30 21:11 [ruby-core:120448] [Ruby master Bug#20994] C API - How to Create Classes with Non-ASCII characters in Name cfis (Charlie Savage) via ruby-core
2024-12-30 21:13 ` [ruby-core:120449] " cfis (Charlie Savage) via ruby-core
2024-12-30 21:24 ` [ruby-core:120450] " cfis (Charlie Savage) via ruby-core
2024-12-31 4:28 ` [ruby-core:120454] [Ruby master Misc#20994] " nobu (Nobuyoshi Nakada) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).