Closed Bug 245927 Opened 21 years ago Closed 21 years ago

nsUint64 would be nice

Categories

(Core :: XPCOM, enhancement)

x86
Linux
enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.8alpha2

People

(Reporter: Biesinger, Assigned: Biesinger)

References

()

Details

Attachments

(1 file, 2 obsolete files)

similar to nsInt64, a class for unsigned integers would be nice, for places where the value is conceptually unsigned.
Attached patch patch (obsolete) — Splinter Review
Assignee: dougt → cbiesinger
Status: NEW → ASSIGNED
Attachment #151250 - Flags: superreview?(dougt)
Attachment #151250 - Flags: review?(bsmedberg)
Target Milestone: --- → mozilla1.8alpha2
Comment on attachment 151250 [details] [diff] [review] patch Isn't _t suffix reserved by POSIX? (Though I've seen tons of code that uses _t.) Also, we already have a convention that is to prefix with nsT for such template classes. I don't see _t used anywhere else. Maybe better not to start a new convention? See for example nsTHashtable.
ok, good idea, so I'll probably make that nsTInt64. I'll attach a new patch after bsmedberg's review...
Comment on attachment 151250 [details] [diff] [review] patch >@@ -136,248 +139,267 @@ public: > * Convert a 64-bit integer to a native 64-bit integer. > */ > operator PRInt64(void) const { > return mValue; > } > >+ operator PRUint64(void) const { >+ return mValue; >+ } >+ This doesn't look good to me, why not just do: operator T(void) const { return mValue; } (and I agree with the nsTInt64 naming convention).
Attachment #151250 - Flags: review?(bsmedberg) → review+
Comment on attachment 151250 [details] [diff] [review] patch going to attach a new patch
Attachment #151250 - Flags: superreview?(dougt)
(In reply to comment #4) > This doesn't look good to me, why not just do: > > operator T(void) const { > return mValue; > } some code wants to implicitly convert nsUint64 to a PRInt64, to pass to a function that wants this (nsISeekableStream) -> build would break
Attached patch patch v2 (obsolete) — Splinter Review
Attachment #151250 - Attachment is obsolete: true
Attachment #151706 - Flags: superreview?(darin)
Comment on attachment 151706 [details] [diff] [review] patch v2 >Index: xpcom/ds/nsInt64.h >+ nsTInt64(const PRInt64 aInt64) : mValue(aInt64) { >+ } >+ nsTInt64(const PRUint64 aInt64) : mValue(aInt64) { > } ok, what's this about. why not have a single constructor that takes a |const T| or (even better perhaps) |const T&| parameter? > operator PRInt64(void) const { > return mValue; > } > >+ operator PRUint64(void) const { >+ return mValue; >+ } Why allow automatic casting from signed to unsigned and vice versa? That seems like it would be a recipe for disaster. I don't want the compiler switching from signed to unsigned arithmetic on me unless I purposely make that change. These casts should not be automatic unless they are really necessary. Are they? We didn't have them before, so I think they must not be necessary. I'm going to minus this because I think it's wrong. I'll give sr+ if you can convince me otherwise or if you change the patch ;-)
Attachment #151706 - Flags: superreview?(darin) → superreview-
hmm. bug 247715's patch uses nsUint64 in nsInputStreamPump. now, that file interfaces with nsISeekableStream in some places. nsISeekableStream uses signed integers. (even for tell... I'm not sure why. Seek of course needs a signed integer, for SEEK_CUR/SEEK_END support) so there needs to be _some_ way to convert an nsUint64 to a signed PRInt64. and also the other way round, since we want to be able to assign the result of Tell() to an nsUint64... maybe that file should keep using nsInt64... hm...
hm actually.... an PRUint64 can be implicitly converted to an PRInt64... even when that uses a non-native type, since in those cases PRInt64 is identical to PRUint64
Attached patch patch v3Splinter Review
ok. use operator T, and nsTInt64(T), and cast at the callers as needed.
Attachment #151706 - Attachment is obsolete: true
Attachment #151758 - Flags: superreview?(darin)
Comment on attachment 151758 [details] [diff] [review] patch v3 sr=darin
Attachment #151758 - Flags: superreview?(darin) → superreview+
Checking in nsInt64.h; /cvsroot/mozilla/xpcom/ds/nsInt64.h,v <-- nsInt64.h new revision: 3.11; previous revision: 3.10 done
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: