Struct needs to be a constant?

Actually, it looks like either a bug or a behaviorial change in 1.7.2. I
don’t get this error with 1.6.7.

I’ll grab the nightly build and see if that changes anything.

Regards,

Dan

···

-----Original Message-----
From: GOTO Kentaro [mailto:gotoken@notwork.org]
At Thu, 8 Aug 2002 05:27:27 +0900, > Daniel Berger wrote:

test.rb:3:in `require’: identifier Proto::ProtoStruct needs
to be constant (NameError) from
test.rb:3

void Init_proto()
{
VALUE np_mNet;
np_mNet = rb_define_module(“Net”);
cNetProto = rb_define_class_under(np_mNet,“Proto”,rb_cObject);

sProto =
rb_struct_define(“Proto::ProtoStruct”,“name”,“aliases”,“number”,0);
rb_global_variable(&sProto);

try replacing the last two lines by

sProto =
rb_struct_define(“ProtoStruct”,“name”,“aliases”,“number”,0);
rb_define_const(cNetProto, “ProtoStruct”, sProto);

rb_struct_define("Proto::ProtoStruct","name","aliases","number",0);

                    ^^^^^^^^^^^^^^^^^^^^
                          ^^
                          ^^

This is this that 1.7 don't like, and I understand it.

> void Init_proto()

               ^^^^^
               ^^^^^

Now nobody can write an extension with the name `proto', even if your
extension is called via 'require "net/proto"' :frowning:

Guy Decoux

Hi,

sProto =
rb_struct_define(“ProtoStruct”,“name”,“aliases”,“number”,0);
rb_define_const(cNetProto, “ProtoStruct”, sProto);

Actually, it looks like either a bug or a behaviorial change in 1.7.2. I
don’t get this error with 1.6.7.

You have to supply a constant name for the first argument, so that
"Proto::ProtoStruct" is not a sufficient name for the struct. 1.7 has
stricter check for names.

If you don’t want define class under Struct
(i.e. Struct::ProtoStruct), you don’t have to give it a name:

sProto = rb_struct_define(0,"name","aliases","number",0);
rb_define_const(cNetProto, "ProtoStruct", sProto);

						matz.
···

In message “RE: struct needs to be a constant?” on 02/08/08, “Berger, Daniel” djberge@qwest.com writes: