Skip to content

size_t vs usize #1671

@elichai

Description

@elichai
Contributor

Input C/C++ Header

#include <stddef.h>
static size_t A = 5;

bindgen converts size_t to `usize. but I'm not sure that's correct. the unsafe guidelines(https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html) say that usize==uintptr_t. but the C standard doesn't define that uintptr_t==size_t therefore usize != size_t.

Am I missing something?

Activity

highfive

highfive commented on Nov 9, 2019

@highfive

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

emilio

emilio commented on Nov 9, 2019

@emilio
Contributor

You're technically correct, I think (which is the best kind of correct ;)).

In practice, in all platforms that I know of sizeof(size_t) == sizeof(uintptr_t). See https://stackoverflow.com/questions/1464174/size-t-vs-uintptr-t.

But we should probably avoid doing this transformation, should be straight-forward.

cmcavity

cmcavity commented on Nov 13, 2019

@cmcavity
Contributor

Hi I'd like to work on this. Should the ssize_t to isize transformation be removed as well?
@highfive: assign me

highfive

highfive commented on Nov 13, 2019

@highfive

Hey @cmcavity! Thanks for your interest in working on this issue. It's now assigned to you!

cmcavity

cmcavity commented on Jan 22, 2020

@cmcavity
Contributor

@emilio This issue should be closed after pull request #1688.

emilio

emilio commented on Feb 2, 2020

@emilio
Contributor

Fixed by the above PR.

quidity

quidity commented on Feb 5, 2020

@quidity

For posterity, a flag was added to revert to previous behavior: --size_t-is-usize

f96dcf9

29 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dkg@geofft@vext01@quidity@emilio

        Issue actions

          size_t vs usize · Issue #1671 · rust-lang/rust-bindgen