-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix #56, undo RepyV1 uniqueid patch #194
Open
aaaaalbert
wants to merge
1
commit into
SeattleTestbed:master
Choose a base branch
from
aaaaalbert:fix-#56-unique-uniqueids
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Check that uniqueid returns unique ids, also if imported multiple times, | ||
and across multiple threads. | ||
""" | ||
#pragma repy restrictions.default dylink.r2py | ||
|
||
uniqueid = dy_import_module("uniqueid.r2py") | ||
|
||
|
||
# Test 1: Get a couple of IDs and see if they are indeed unique. | ||
|
||
oldids = [] | ||
|
||
for i in range(100): | ||
newid = uniqueid.uniqueid_getid() | ||
assert newid not in oldids, "Saw the same ID twice: " + str(oldid) | ||
oldids.append(newid) | ||
|
||
|
||
|
||
# Test 2: "Reimport" the library. (Dylink should yield the existing instance.) | ||
|
||
uniqueid2 = dy_import_module("uniqueid.r2py") | ||
|
||
assert uniqueid2.uniqueid_getid() != uniqueid.uniqueid_getid(), "Got the same ID twice after pseudo-reimporting!" | ||
|
||
|
||
|
||
# Test 3: Get IDs in threads | ||
|
||
idlist = [] | ||
|
||
def get_an_id(): | ||
idlist.append(uniqueid.uniqueid_getid()) | ||
|
||
for i in range(10): | ||
createthread(get_an_id) | ||
|
||
# Give the threads some time to spawn and finish | ||
sleep(5) | ||
|
||
for anid in idlist: | ||
assert idlist.count(anid)==1, "Duplicate ID: " + str(anid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,20 +7,12 @@ Start date: November 11th, 2008 | |
|
||
This is a really, really simple module, only broken out to avoid duplicating | ||
functionality. | ||
|
||
NOTE: This will give unique ids PER FILE. If you have multiple python | ||
modules that include this, they will have the potential to generate the | ||
same ID. | ||
|
||
""" | ||
|
||
# This is a list to prevent using part of the user's mycontext dict | ||
# We use getruntime() instead of a list starting with 0, as this | ||
# library may get imported multiple times. | ||
# See ticket #1319 and #1318 for more details. | ||
# Use this list as module-level storage. (This avoids cluttering the | ||
# programmer's `mycontext` dict.) | ||
|
||
current_time = getruntime() | ||
uniqueid_idlist = [int((current_time - int(current_time)) * 2**32)] | ||
uniqueid_idlist = [0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why exactly does this have to be a list? It will always only hold one element, right? |
||
|
||
uniqueid_idlock = createlock() | ||
|
||
|
@@ -44,8 +36,6 @@ def uniqueid_getid(): | |
|
||
uniqueid_idlock.acquire(True) | ||
|
||
# I'm using a list because I need a global, but don't want to use the | ||
# programmer's dict | ||
myid = uniqueid_idlist[0] | ||
uniqueid_idlist[0] = uniqueid_idlist[0] + 1 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also verify that
uniqueid2
does not return an id that was already returned byuniqueid
, i.e.assert uniqueid2.uniqueid_getid() not in oldids
to catch the case that the new import resets the module store.