Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't terminate RGBDS strings with a NUL #505

Closed
ISSOtm opened this issue Apr 7, 2020 · 3 comments · Fixed by #1405
Closed

Don't terminate RGBDS strings with a NUL #505

ISSOtm opened this issue Apr 7, 2020 · 3 comments · Fixed by #1405
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Milestone

Comments

@ISSOtm
Copy link
Member

ISSOtm commented Apr 7, 2020

The man page mentions that a NUL truncates a string; this is because RGBDS maps transparently to C strings. People may want to use other terminators (hello Pokémon and its $50, though there 0 is a mostly useless char anyways), or just use 0 in the middle of their strings.
Thus, and especially as fixed-size buffers are mostly being used anyways, RGBDS should use Pascal strings instead.

@ISSOtm ISSOtm added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM labels Apr 7, 2020
@meithecatte
Copy link
Contributor

AFAIK, Pascal strings store their length in a single byte just before the contents. This has the disadvantage of limiting the maximum length of a string. I'd like to suggest Rust-style strings instead, where strings are essentially manipulated as a pair of (pointer to start, length). Apart from removing the string length limit, this also allows to pass substrings around much more efficiently.

@ISSOtm
Copy link
Member Author

ISSOtm commented Apr 7, 2020

Okay, I wasn't intending exactly on using a byte, but the more general idea of storing the length separately. Wasn't aware of Rust's behavior, which is basically what I'm shooting for.

@aaaaaa123456789
Copy link
Member

If you're using C99, you can just use a flexible array member to store the data, which makes the Pascal-like approach a lot simpler:

struct string {
  unsigned length;
  char data[];
};

@Rangi42 Rangi42 added refactoring This PR is intended to clean up code more than change functionality and removed enhancement Typically new features; lesser priority than bugs labels Apr 4, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Apr 29, 2021
Still to port from ISSOtm's strings branch:
- lexer.c
- parser.y
- symbol.c

Fixes gbdev#650
Fixes gbdev#505
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Apr 29, 2021
Still to port from ISSOtm's strings branch:
- lexer.c
- symbol.c

Fixes gbdev#650
Fixes gbdev#505
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Apr 29, 2021
Still to port from ISSOtm's strings branch:
- lexer.c
- symbol.c

Fixes gbdev#650
Fixes gbdev#505
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Apr 29, 2021
Still need to port lexer.c from ISSOtm's strings branch

Fixes gbdev#650
Fixes gbdev#505
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Apr 29, 2021
@Rangi42 Rangi42 added enhancement Typically new features; lesser priority than bugs and removed refactoring This PR is intended to clean up code more than change functionality labels May 2, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jun 21, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jun 21, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jun 21, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jun 24, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jun 27, 2021
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Jul 4, 2021
ISSOtm added a commit to Rangi42/rgbds that referenced this issue Jul 30, 2021
Fixes gbdev#650
Fixes gbdev#505

Co-Authored-By: ISSOtm <eldredhabert0@gmail.com>
@Rangi42 Rangi42 added this to the v0.8.0 milestone Nov 3, 2023
@Rangi42 Rangi42 modified the milestones: v0.9.0, v0.8.0 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Projects
None yet
4 participants