Skip to content

Conversation

alexrp
Copy link
Contributor

@alexrp alexrp commented May 15, 2012

First commit deprecates the crc32 module and copies it into std/crc32.d. Second commit updates the API to be slightly more sane and conforming to Phobos standards. I don't know how we should go about deprecating the old module, but for now, I've just added a pragma(msg, ...); in there.

@@ -14,6 +14,8 @@
// CRC-32 calculation
module crc32;

pragma(msg, "The 'crc32' module has been deprecated. Please use 'std.crc32' instead.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "scheduled for deprecation" rather than "deprecated." Also, if we're just moving the module, it should be more like std.contracts was before we removed it - that is, it should publicly import std.crc32, and have its documentation (and the pragma) telling users that it has been scheduled for deprecation and that they should use std.crc32. There's no need to have any implementation in crc32 if none of the implementation is changing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in my second commit, I actually changed the API of std.crc32 to sanitize it somewhat, so I'm not sure that's really worth the effort. If users switch to std.crc32, they should just use the new API right away. At least that seems like a more sensible approach, if users are switching away from a deprecated module anyway.

Fixed the message and rebased.

@jmdavis
Copy link
Member

jmdavis commented May 15, 2012

Also, you're going to have to merge in the latest HEAD for this to be mergeable.

@jmdavis
Copy link
Member

jmdavis commented May 15, 2012

Well, if you changed the API, then that's different. But if it's a straight move, then there's no need for twice the implementation.

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

See 61a23808161bcd84c585cc46515767b4a576a106 specifically; I made the API less backwards, fixed the naming, applied some code style, and added pure, nothrow, @safe.

}

uint arrayToCRC32(T)(in T[] arr) pure nothrow
if (is(T == ubyte) || is(T == byte) || is(T == char))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's ugly (if not outright evil) that this accepts char. It's not a string. But the original did, so I don't know... I'd still be tempted to disallow it though. People can cast if they really want to pass in a char[].

Regardless, I would point out that if you're going to rewrite it like this, why not just make it take a range?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make it take a range. Removing the ability to pass char arrays probably won't cause too much grief to anyone.

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

Added docs (added myself as author since I may as well take maintainership of this).

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

Now works on forward ranges and doesn't allow char. Also added unit test to ensure that it's callable with forward ranges.

@kyllingstad
Copy link
Contributor

See also pull request 221. Should we perhaps move crc32 into the std.crypt package too?

@jmdavis
Copy link
Member

jmdavis commented May 15, 2012

Yeah. Good point. std.crypt.crc32 makes more sense than std.crc32 - particularly since it seems likely that pull request #221 (or something very similar) is going to get merged in.

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

I think any cryptologist would like to have a word with you if you moved a CRC32 implementation into a cryptography package. ;)

I do agree that just flat std.crc32 is a bit undesirable, though.

@jmdavis
Copy link
Member

jmdavis commented May 15, 2012

It's a hashing function just like md5 or sha1 are (and they're slated to go in std.crypt). It's just a sucky one.

@kyllingstad
Copy link
Contributor

jmdavis:

It's a hashing function just like md5 or sha1 are [...]

It's not a cryptographic hash, though. There were other suggestions for pull#221 as well, such as std.hash and std.digest. I don't have any particular preference for std.crypt (in fact, I agree it would be a bad fit for a crc32 module), I just think pull#221 should be taken into account before anything is dumped straight into std.

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

Wouldn't std.hash be a better, more general term for all kinds of hashes (including this one)?

Also, interestingly, there's a Digest::CRC32 in CPAN...

@kyllingstad
Copy link
Contributor

I think so. std.crypt was @andralex 's suggestion. He wants to expand it with stream encryption at some point in the future. I don't see anything wrong with putting hashes, including cryptographic ones, into std.hash, and other crypto stuff in std.crypt.

@jmdavis
Copy link
Member

jmdavis commented May 15, 2012

Sounds good to me, but the other pull request will need to be changed then. I just think that they should go in the same package. I don't care all that much about the name as long as it's reasonable.

@alexrp
Copy link
Contributor Author

alexrp commented May 15, 2012

Done. Also made std.stream use the new std.hash.crc32.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 1, 2012

This now seems to be passing the auto tester, except on FreeBSD_32: http://d.puremagic.com/test-results/pull.ghtml?runid=183981

The failure is completely unrelated though. I suspect the machine might be so stressed it literally couldn't allocate a semaphore...

@jmdavis
Copy link
Member

jmdavis commented Jun 1, 2012

I believe that that's a recurring, intermitent failure. It certainly has nothing to do with this (especially, since these changes are in Phobos, no druntime). I'd merge this in, but I was hoping for some sort of response on pull# 221 about using std.hash rather than std.crypt before we did that.

@jmdavis
Copy link
Member

jmdavis commented Jun 4, 2012

Needs to be rebased due to changes to win32.mak.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 5, 2012

I've rebased this into a single commit and also rebased on top of current Phobos. Let's see what the auto tester says.

redstar added a commit to redstar/phobos that referenced this pull request Jun 5, 2012
@alexrp
Copy link
Contributor Author

alexrp commented Jun 5, 2012

This is now green in the auto tester. Can someone re-review?

* Params:
* range = The range to compute a CRC32 value for.
*/
uint rangeToCRC32(R)(in R range) pure nothrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe CRC of Range? I'm not native speaker but 'to' somehow implies nondestructive conversion to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. How is this destructive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It consumes the range if it's an input range rather than a forward range, but that's normal. I believe that even std.conv.to will do that, so I see no problem with the name. "To" implies a conversion, but it doesn't say anything about what happens to the original. Personally, I'd probably have picked something more like genCRC32, but rangeToCRC32 works just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to only abbreviate words/terms when identifiers get overly long (I'm looking at you, largestPartialIntersectionWeighted ;)), and rangeToCRC32 is pretty bearable IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen is a very common and rather obvious abbreviation, and I'd personally be against using the word generate, because gen is plenty clear and much shorter, but rangeToCRC32 works just fine. It's just not what I would have picked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not length but somehow it seems illogical to me. Anyway I agreee with Jonathan.

@DmitryOlshansky
Copy link
Member

I think there is not much to review, but here you go ;)

/**
* Initializes a CRC32 value.
*/
uint initCRC32() pure nothrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have noticed this before, but shouldn't this be a property, or even simply an enum? I'd have expected this to be simply

enum initCRC32 = uint.max;

Or even better,

enum crc32Init = uint.max;

(since initCRC32 is more of a function name, whereas crc32Init looks more like the init property). It seems really odd to make this a function when all it does is return uint.max. I assume that that's what the original did, but if we're improving upon it, it seems rather silly to leave it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. This was indeed how the original code looked, and I hadn't really thought of removing some of the pointless abstraction.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 6, 2012

So is this good to go?

@jmdavis
Copy link
Member

jmdavis commented Jun 6, 2012

So is this good to go?

Please fix initCRC32 as a commented a few minutes ago (sorry that I didn't notice it earlier - I should have). Once that's done, I see no reason not to merge it.

@jmdavis
Copy link
Member

jmdavis commented Jun 6, 2012

Don't forget to push your changes.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 6, 2012

It should all be pushed...

@jmdavis
Copy link
Member

jmdavis commented Jun 6, 2012

It should all be pushed...

It looks like it is now, but it wasn't when I checked a few minutes ago.

jmdavis added a commit that referenced this pull request Jun 6, 2012
Deprecate crc32 and move it into std.crc32 (with new interface).
@jmdavis jmdavis merged commit e9cf468 into dlang:master Jun 6, 2012
@jmdavis
Copy link
Member

jmdavis commented Jun 6, 2012

Merged.

@jpf91
Copy link
Contributor

jpf91 commented Jun 21, 2012

Sorry to resurrect this discussion, but shoudn't we use some sort of common interface for all hashes? In pull request #221 both the sha-1 and md5 implementations have a *_CTX struct (btw, couldn't we just use MD5Hash as a name, or just MD5? imho MD5_CTX sounds strange), but this crc32 implementation has nothing similar.

I think we need a common interface + some template helpers (isHash, hashType, ...) and we should merge convenience functions like mdFile, SHA1File, etc into new templates which work with every hash.

Or are different hashes really so different that they need different interfaces?

@jmdavis
Copy link
Member

jmdavis commented Jun 21, 2012

MD5's situation is being cleaned up somewhat, since as part of the move to std.hash, its names are being made to match Phobos' current naming conventions - though maybe some additional changes are needed to make the names themselves more appropriate rather than simply following the correct casing. And the SHA-1 stuff was specifically made to look like the MD5 stuff, so there was some attempt to make things the same there, but I'm not sure that it was enough to make hashes intertangeable via templates or not, even for those two. Certainly, you bring up a good point that std.hash.crc32 does not follow the same conventions at all, and that's probably something that we should look at doing (and preferably soon, so that it can be done prior to the next release so that we don't have to tell people to change which functions they're using yet again after we sort that out).

@jpf91
Copy link
Contributor

jpf91 commented Jun 22, 2012

Probably we should revert this pull request for now. I could post a message to the newsgroup regarding the basic design of std.hash and some details (does it really make sense to pass ubyte[16] by ref, do we want classes + interfaces or structs + templates, should finish really reset state, ...) and then adapt crc32 md5 and sha-1 to this new interface next week.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 22, 2012

I don't see why you would revert this; that seems very drastic. You can simply alter std.hash.crc32 as required since it hasn't shipped in a release yet.

@jpf91
Copy link
Contributor

jpf91 commented Jun 22, 2012

Yes, but we don't know when 2.060 will be released (it's been more than 2 months since 2.059) and I don't know how long the refactoring will take (I can promise it would definitely be ready for 2.061). So reverting seems to be the best way to make sure we really won't ship this change in a public release.

@jmdavis
Copy link
Member

jmdavis commented Jun 22, 2012

We'll have plenty of warning prior to a release to revert the changes to crc32 if we need to do that. I see no reason to go through the trouble of reverting them if we don't have to. But we do need to sort out the std.hash situation fairly promptly if we want it done prior to the next release, since it probably won't be all that long before Walter starts on the beta process for it.

@alexrp
Copy link
Contributor Author

alexrp commented Jun 22, 2012

We can simply comment out the parts of the makefiles that put the module into a release, if need be. I really think reverting all of this pull request is unnecessary.

@jpf91
Copy link
Contributor

jpf91 commented Jun 22, 2012

OK, so we can leave it as is till the beta proccess is started. I just posted a message to the D newsgroup regarding the design of std.hash.

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.

5 participants