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

Is a godot_uint (not) needed ? #38923

Open
touilleMan opened this issue May 21, 2020 · 1 comment
Open

Is a godot_uint (not) needed ? #38923

touilleMan opened this issue May 21, 2020 · 1 comment

Comments

@touilleMan
Copy link
Member

PR #36163 has made godot_int an alias to int64_t, this pretty good for GDnative (before that calling methods returning uint64_t/int64_t could lead to segfault, see #34254)

However I wonder from a documentation point of view this is not perfect given the methods returning uint64_t are presented to GDnative users as returning godot_int (hence 64bits signed number)

I see currently three usecases for those signed values:

  1. uint64_t GDAPI godot_color_to_abgr64(const godot_color *p_self) (see Fix return type for GDNative's godot_color_to_XXX64 #35795)
  2. uint64_t OS::get_static_memory_usage() const;
  3. uint64_t OS::get_unix_time () const & uint64_t OS::get_system_time_msecs()

In case 1 here we return an array of 4 a/b/g/r bytes, so it's meaningless to use the return value as a number. Hence there is no trouble ;-)

In case 2&3 we are actually providing a number (and a negative value is meaningless in those contexts). However we will hit a trouble if the returned value is bigger than 2⁶³ - 1.. which is really huge ! (get_system_time_msecs will start to have issue in year 29227899, get_static_memory_usage needs more than 8 Exaoctet of used RAM...)

So my guess is we don't need a godot_uint type (it would add complexity for a small documentation benefit), but I think it's good to have this choice documented (at least by this issue ^^).

@aaronfranke
Copy link
Member

aaronfranke commented May 22, 2020

In case 3, a negative value is not necessarily meaningless. Negative values represent times before the year 1970. While negative values may not be returned by these specific methods, int64_t (or one day int128_t) should be used to store time in case you need to store times before 1970.

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

No branches or pull requests

3 participants