News for hackers. Stuff that matters.
Re:Never create Ruby strings longer than 23 characters by anon4 on Wednesday December 11, 2013 @12:12PM (#6888868)
Wouldn't it be better to use this declaration though:

    struct RString {

      struct RBasic basic;

      union {
        struct {
          long len;
          char *ptr;
          union {
            long capa;
            VALUE shared;
          } aux;
        } heap;
    
        char ary[];
      } as;
    };

    /* apologies if I messed up the syntax here */
    #define RSTRING_EMBED_LEN_MAX (sizeof(((RString*)(0))->as) - 1)
Then you can even use the padding the compiler added, if any, plus you can add more things to heap and the embed length will grow automatically.

There are no comments on this comment yet.