Split a comma-separated argument string at depth 0 (ignoring commas * inside [], (), {}). Returns NULL-terminated arena array of trimmed * substring copies. Caller passes the inside of `[...]`. */
| 3838 | * inside [], (), {}). Returns NULL-terminated arena array of trimmed |
| 3839 | * substring copies. Caller passes the inside of `[...]`. */ |
| 3840 | static const char **py_split_subscript_args(CBMArena *arena, const char *s, int *out_n) { |
| 3841 | if (!s) { |
| 3842 | *out_n = 0; |
| 3843 | return NULL; |
| 3844 | } |
| 3845 | int cap = 8; |
| 3846 | const char **out = |
| 3847 | (const char **)cbm_arena_alloc(arena, (size_t)(cap + 1) * sizeof(const char *)); |
| 3848 | if (!out) { |
| 3849 | *out_n = 0; |
| 3850 | return NULL; |
| 3851 | } |
| 3852 | int n = 0; |
| 3853 | int depth = 0; |
| 3854 | size_t len = strlen(s); |
| 3855 | size_t start = 0; |
| 3856 | for (size_t i = 0; i <= len; i++) { |
| 3857 | char c = (i < len) ? s[i] : ','; |
| 3858 | if (c == '[' || c == '(' || c == '{') |
| 3859 | depth++; |
| 3860 | else if (c == ']' || c == ')' || c == '}') |
| 3861 | depth--; |
| 3862 | else if (c == ',' && depth == 0) { |
| 3863 | char *part = py_trim_ws(arena, s + start, i - start); |
| 3864 | if (part && part[0]) { |
| 3865 | if (n >= cap) { |
| 3866 | int new_cap = cap * 2; |
| 3867 | const char **grown = (const char **)cbm_arena_alloc( |
| 3868 | arena, (size_t)(new_cap + 1) * sizeof(const char *)); |
| 3869 | if (grown) { |
| 3870 | for (int q = 0; q < n; q++) |
| 3871 | grown[q] = out[q]; |
| 3872 | out = grown; |
| 3873 | cap = new_cap; |
| 3874 | } |
| 3875 | } |
| 3876 | if (n < cap) |
| 3877 | out[n++] = part; |
| 3878 | } |
| 3879 | start = i + 1; |
| 3880 | } |
| 3881 | } |
| 3882 | out[n] = NULL; |
| 3883 | *out_n = n; |
| 3884 | return out; |
| 3885 | } |
| 3886 | |
| 3887 | static const CBMType *py_parse_type_text_qn(CBMArena *arena, const char *ann, |
| 3888 | const char *module_qn) { |
no test coverage detected