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

introduce csize_t instead of fixing csize #12497

Merged
merged 2 commits into from
Oct 31, 2019
Merged

introduce csize_t instead of fixing csize #12497

merged 2 commits into from
Oct 31, 2019

Conversation

krux02
Copy link
Contributor

@krux02 krux02 commented Oct 23, 2019

Implement the proposal by @Araq in #12447 (comment)_

It is actually harder to maintain backwards compatibility with this change instead of #12321. Explicit conversions like csize(x) or cast[csize](x) would work no matter if csize is defined as int or uint. The new type csize_t and deprecating csize forces user of csize into one of these options:

  • Ignore deprecation warnings
  • Drop support for Nim versions that don't provide csize_t
  • Copy the definition of csize_t into the project with some when declared condition.
  • Avoid using csize/csize_t all together and use int/uint directly.

This still does break backwards compatibility, since I did change functions that return csize to return csize_t now. The alternative would be to introduce new names, for example: proc c_strlen*(a: cstring): csize and proc c_strlen2*(a: cstring): csize_t. I also didn't introduce a new type Glob2 next to Glob where the members gl_pathc and gl_offs stay cint, because then I would also need to duplicate posix.glob and posix.globfree. This basically means that every module that uses csize anywhere in the exposed symbols needs to duplicate those symbols now with another version that uses csize_t instead of csize to fix the deprecationd and also stay backwards compatible.

The alternative is to remerge #12321, but with a switch that allows csize to stay the old way.

@Araq
Copy link
Member

Araq commented Oct 24, 2019

This still does break backwards compatibility, since I did change functions that return csize to return csize_t now.

Yeah but the idea was not to break code. I personally would replace csize with int everywhere it comes up. No code breakage, fixes C's mistake of using wrap around arithmetic for sizes. Yeah, yeah, yeah in some alternative universe where you use 4GB sized buffers on a 32 bit system (how can you you do that? who knows) it will be "wrong" but then so is the wrap-around arithmetic.

@krux02
Copy link
Contributor Author

krux02 commented Oct 24, 2019

Yeah, yeah, yeah in some alternative universe where you use 4GB sized buffers on a 32 bit system (how can you you do that? who knows) it will be "wrong" but then so is the wrap-around arithmetic.

Can you please stop bringing this up again and again. The c++ committee even agreen on this, happy about that? But that is totally not the point here. The issue here that I try to solve is csize type definition in Nim is an incorrect type definiton that causes incorrect behavior in Nim. I don't know what all can go wrong, but here is something that certainly goes wrong.

I personally would replace csize with int everywhere it comes up.

Does that mean that you will do it? Or is that your review advice for this PR?

@Araq
Copy link
Member

Araq commented Oct 28, 2019

After a long discussion, here is what we agreed on:

The changes to ansi_c.nim are too much, not required becaues it's an internal API.

@mrgaturus
Copy link

mrgaturus commented Oct 29, 2019

Is a bit weird how you want avoid a direct usage of unsigned types, another example is the Natural type, has a range from 0 to the maximum positive of a int instead using an unsigned int for that

@Araq
Copy link
Member

Araq commented Oct 30, 2019

Maybe it's because I know the semantic implications.

@Araq Araq merged commit 99078d8 into nim-lang:devel Oct 31, 2019
kiyolee pushed a commit to kiyolee/nim that referenced this pull request Nov 7, 2019
mratsim added a commit to mratsim/weave that referenced this pull request Nov 24, 2019
Rename to WV_CacheLinePadding

Unfortunately nim-lang/Nim#12722 broke Nim devel in the past 3 days, commit nim-lang/Nim@1b2c1bc is good.

Also C proc signatures changed to csize_t nim-lang/Nim#12497
alehander92 pushed a commit to alehander92/Nim that referenced this pull request Dec 2, 2019
@ringabout
Copy link
Member

csize_t is unsigned type and it should be named as cusize_t to be consistent with cint and cuint.
Because there is also ssize_t in c which is a signed type.

@krux02
Copy link
Contributor Author

krux02 commented Jan 24, 2021

@xflywind the names are directly from C. And in C the type definition is called size_t and not unsigned size_t. Therefore the name is correct. Regarding ssize_t. I was thinking about exporting that one as well, but sadly, that type definiton is not ANSI C, it is POSIX and therefore not something to generally available in a C environment.

https://stackoverflow.com/questions/55190317/where-is-ssize-t-defined-in-linux

@ringabout
Copy link
Member

@krux02
I see. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants