You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sizeof() sometimes used as if it would return size in bits and not bytes #1226
sizeof() is sometimes used as if it would return the size in bits instead of bytes. It seems these cases are related to GetHashCode, so it's not a big issue, but still it should probably be fixed.
One example of this would in the PGUtil class: public static int RotateShift(int val, int shift){ return (val << shift) | (val >> (sizeof (int) - shift)); }
I've done a quick pass fixing the sizeof issue (no PR yet).
But a more detailed pass on the hash code generation would probably be better.
This is also related to the other issue #1145
If I might ask:
Is there a specific reason why most Npgsql Types override ==, != and GetHashCode?
Meaning is it needed/essential for something within Npgsql, Entity Framework or NHibernate or is it more or less just a service for the normal user of the library?
Regarding a PR, it's really up to you when you want to submit... If you think you're going to be doing more work in this area then it's better to wait and submit a single PR. However, please separate different changes in different PRs (or at least commits): fixing GetHashCode() is one thing, modifying mutability of Postgis types etc. is another.
Regarding the overriding, it's been there since before I got involved (which is a long time now :)), I 've been wanting to look at this too. None of these types are actually used within Npgsql (and probably aren't really used in EF/NHibernate either, although I'm not sure). So it's a matter of providing high-quality types to users.
Activity
roji commentedon Aug 1, 2016
Thanks for raising this, I noticed this a year ago but forgot about it...
We should probably do a general pass on hash code generation in Npgsql...
roji commentedon Aug 1, 2016
BTW you're welcome to submit a PR if want to.
deng0 commentedon Aug 1, 2016
I've done a quick pass fixing the sizeof issue (no PR yet).
But a more detailed pass on the hash code generation would probably be better.
This is also related to the other issue #1145
Let me know if I should make the PR anyway.
deng0 commentedon Aug 1, 2016
If I might ask:
Is there a specific reason why most Npgsql Types override
==,!=andGetHashCode?Meaning is it needed/essential for something within Npgsql, Entity Framework or NHibernate or is it more or less just a service for the normal user of the library?
roji commentedon Aug 1, 2016
Regarding a PR, it's really up to you when you want to submit... If you think you're going to be doing more work in this area then it's better to wait and submit a single PR. However, please separate different changes in different PRs (or at least commits): fixing GetHashCode() is one thing, modifying mutability of Postgis types etc. is another.
Regarding the overriding, it's been there since before I got involved (which is a long time now :)), I 've been wanting to look at this too. None of these types are actually used within Npgsql (and probably aren't really used in EF/NHibernate either, although I'm not sure). So it's a matter of providing high-quality types to users.
Overriding
==and!=is a good idea when the type is immutable, and a bad idea otherwise (https://msdn.microsoft.com/en-us/library/ms173147(v=vs.90).aspx). It seems that overridingGetHashCode()in general is a good idea rather than leaving the default behavior, especially in structs where the default is reflection based and therefore very slow (the same goes for Equals).A cleanup here may be in order too for 3.2...
roji commentedon Sep 15, 2016
@deng0 just wanted to know whether you think you'll be working on this at some point...
deng0 commentedon Sep 16, 2016
@roji sorry, I'm rather busy atm. I don't think I will work on this anytime soon.
Thanks again for your insights.
roji commentedon Mar 9, 2018
Fixed via 361fbd0 (PR #1741), thanks @YohDeadfall.