This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Michael.Felt
Recipients David.Edelsohn, Michael.Felt, lys.nikolaou, pablogsal, skrah
Date 2020-07-06.14:30:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <b1dfca66-fbde-fa6a-ebfe-b998d69d46eb@felt.demon.nl>
In-reply-to <1594039040.95.0.662013019583.issue41215@roundup.psfhosted.org>
Content
Glad you figured it out!

I doubt I would have. Thx!!

On 06/07/2020 14:37, Pablo Galindo Salgado wrote:
> Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:
>
> This is enough to reproduce the problem:
>
> #include <stdio.h>
>
> typedef struct {
>     char *str;
>     int type;
> } KeywordToken;
>
> static KeywordToken *the_array[] = {
>    NULL,
>    NULL,
>    (KeywordToken[]) {
>         {"if", 510},
>         {"in", 518},
>         {"as", 520},
>         {"is", 527},
>         {"or", 532},
>         {NULL, -1},
>    },
>    NULL,
>    NULL,
>     (KeywordToken[]) {
>         {"del11", 503},
>         {"try22", 511},
>         {NULL, -1},
>     },
>     NULL
> };
>
>
> int main() {
>    for (int s=0; s<7;s++) {
>       KeywordToken *tok = the_array[s];
>       printf("--> %i\n",s);
>       if (tok == NULL) {
>          continue;
>       }
>       printf("--> %i %.*s\n", s,s, tok->str);
>    }
>    return 0;
> }
>
> [cpython (3.9)]$ xlc check_bad.c -o check_bad
> [cpython (3.9)]$ ./check_bad
> --> 0
> --> 1
> --> 2
> Segmentation fault (core dumped)
>
>
> But if you change it to:
>
> #include <stdio.h>
>
> typedef struct {
>     char *str;
>     int type;
> } KeywordToken;
>
> static KeywordToken *the_array[] = {
>      (KeywordToken[]) {{NULL, -1}},
>      (KeywordToken[]) {{NULL, -1}},
>     (KeywordToken[]) {
>         {"if", 510},
>         {"in", 518},
>         {"as", 520},
>         {"is", 527},
>         {"or", 532},
>         {NULL, -1},
>     },
>     (KeywordToken[]) {{NULL, -1}},
>     (KeywordToken[]) {{NULL, -1}},
>     (KeywordToken[]) {
>         {"del11", 503},
>         {"try22", 511},
>         {NULL, -1},
>     },
>     (KeywordToken[]) {{NULL, -1}},
> };
>
>
> int main() {
>    for (int s=0; s<7;s++) {
>       KeywordToken *tok = the_array[s];
>       if (tok == NULL) {
>          continue;
>       }
>       printf("--> %i %.*s\n", s,s, tok->str);
>    }
>    return 0;
> }
>
> [cpython (3.9)]$ xlc check.c -o check
> [cpython (3.9)]$ ./check
> --> 0
> --> 1
> --> 2 if
> --> 3
> --> 4
> --> 5 del11
> --> 6
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue41215>
> _______________________________________
>
History
Date User Action Args
2020-07-06 14:30:15Michael.Feltsetrecipients: + Michael.Felt, skrah, David.Edelsohn, lys.nikolaou, pablogsal
2020-07-06 14:30:15Michael.Feltlinkissue41215 messages
2020-07-06 14:30:15Michael.Feltcreate