Skip to content

[Feature Request] Convert the stdlib bytes from List[Int8] to List[UInt8] #2317

Closed
@gabrieldemarmiesse

Description

@gabrieldemarmiesse

Review Mojo's priorities

What is your request?

This issue is a follow up to track the progress on the implementation of the proposal #2099 . @JoeLoser mentioned that Modular doesn't have the bandwidth internally to make the change in the stdlib, it's up to the community to do it. See #2099 (comment)

We should convert all bytes usage from Int8 to UInt8. Here is some reference:

git grep 'List\[Int8\]' | cat - 
stdlib/src/base64/base64.mojo:    var out = List[Int8](capacity=length + 1)
stdlib/src/builtin/file.mojo:    fn read_bytes(self, size: Int64 = -1) raises -> List[Int8]:
stdlib/src/builtin/file.mojo:        var list = List[Int8](capacity=int(size_copy))
stdlib/src/builtin/hex.mojo:    var buf = List[Int8]()
stdlib/src/builtin/hex.mojo:    inout fmt: List[Int8],
stdlib/src/builtin/string.mojo:    alias _buffer_type = List[Int8]
stdlib/src/builtin/string.mojo:        var buf = List[Int8]()
stdlib/src/builtin/string.mojo:    fn as_bytes(self) -> List[Int8]:
stdlib/src/builtin/string.mojo:        var res = List[Int8]()
stdlib/src/builtin/string.mojo:        var res = List[Int8]()
stdlib/src/pathlib/path.mojo:    fn read_bytes(self) raises -> List[Int8]:
stdlib/src/utils/inlined_string.mojo:            var buffer = List[Int8](capacity=total_len)
stdlib/test/collections/test_list.mojo:    var some_list = List[Int8](new_pointer, size=3, capacity=5)
stdlib/test/collections/test_list.mojo:    initial_list = List[Int8](0, 1, 2)
stdlib/test/collections/test_list.mojo:    var some_list = List[Int8](
stdlib/test/utils/issue_13632.mojo:fn sum_items(data: List[Int8]) -> Int:
stdlib/test/utils/issue_13632.mojo:fn make_abcd_vector() -> List[Int8]:
stdlib/test/utils/issue_13632.mojo:    return List[Int8](97, 98, 99, 100)

It's possible that some of those usages don't need to be converted or that there are more, but it gives an overview of what to do. Don't hesitate to add unit tests if you're scared of breaking something.

What is your motivation for this change?

The proposal was accepted.

Any other details?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmojoIssues that are related to mojomojo-repoTag all issues with this label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions