generateUUID

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Thu May 09, 2013 10:30 am

Well the code for md5 and sha1 uuids is almost identical - you just use a different digest stream (change md5_* to sha1_*) and only use the first 16 bytes of the sha1 digest.

In regards to time/mac based uuids (these are the same thing as far as I can see - type 1) then they could be implemented relatively easily - its just that they need per-platform support routines. However, I might add them too as an example of how to go about handling such cases. The only concern I had was with the sequencing - the RFC suggests that (on any given system) v1 UUIDs should be generated based on state shared amongst all processes and saved/restored between sessions to ensure no two processes generate the same UUID. I'm not sure how important that is although it seems (to me at least) that without that, the chance of generating duplicate v1 UUIDs is much much more likely than duplicate random UUIDs. [ The OSSP code doesn't do state sharing - so the implementation there can guarantee for any one run of a program all v1 UUIDs will be distinct ].

(I fixed my 'not enough randomness' error, btw, I'd missed a 'return true' - doh!)

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: generateUUID

Post by monte » Wed May 15, 2013 9:59 pm

Are you going to merge the uuid function into develop?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Thu May 16, 2013 8:16 am

Well, it would be a shame to leave it as just an example for the conference ;)

So, yes, we'll merge the new function and implementation into develop after the conference :)

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: generateUUID

Post by monte » Sat May 18, 2013 9:19 am

I'd also be keen to see the commit for the map command which will give me everything i need to know for adding a command as we didn't have time to go though it.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Mon May 20, 2013 10:17 am

@monte: you can see the map command branch in runrevmark/livecode as an example of adding a command. I'm slightly reticent to merge it in as a new feature yet as it isn't really complete yet (it only runs on c-strings and would be good to extend it to arrays).

DarScott
Posts: 227
Joined: Fri Jul 28, 2006 12:23 am
Location: Albuquerque
Contact:

Re: generateUUID

Post by DarScott » Tue May 21, 2013 7:10 pm

I'm coming in late in this discussion, so my comments might apply to water under the bridge, and it might be reasonable to skip over them.

What is wrong with LiveCode implementations? Slow? Less trustworthy?

Should there be support functions to go with generation? uuidVersion()? uuidValid()?

(I am intrigued with the notion of indefinite articles as a language feature. My pondering might go way off on some tangent. Maybe functions could be tagged with the allowed or preferred determiner. Suppose those are either the article 'a/a'n or the article 'the'. Maybe pure functions should/must be used with 'the'. Functions with side effects or environmental dependencies, but having some correct answer can be used with either (or some other determiner is brought in). Functions that have no single correct result should/must be used with 'a/an'. Or, if the use of 'the' can be strict and apply only to pure functions, this can help in maintaining code, but unfortunately, the LiveCode compiler cannot enforce that without being somewhat restrictive. These are half-formed notions, but I can see a benefit in not only readability but in software maintenance and development.)

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Tue May 21, 2013 7:15 pm

I've just finished merging in the 'uuid()' function I produced for the engine workshops at the conference into 'develop'. This also goes along with an MCU_random_bytes() abstraction that uses either OpenSSL, or native system support for generating random numbers. The latter is now used by both uuid generation and the randomBytes() function.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: generateUUID

Post by mwieder » Tue May 28, 2013 7:44 pm

@runrevmark- I can't remember the syntax from the engine discussion at the conference, and I don't have my notes with me right now. I experimented with the following:

Code: Select all

put uuid() -- returns a uuid (different every time)
put uuid(1) -- returns a parameter error
put uuid("random") -- appears to be the default
put uuid("sha1") -- returns a "wrong number of parameters" error
put uuid("sha1", 42) -- crashes
put uuid(42, "sha1") -- crashes
I'm fine with all of those except the crashes. I'm not sure what the function is doing with the arguments, but It should fail gracefully.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Wed May 29, 2013 10:03 am

@mwieder:

Looks like you found a couple of bugs :) The 'random' form is the default and takes no extra parameters. Both 'sha1' and 'md5' require two extra parameters - obviously it shouldn't crash when you only pass 1, nor should it crash if you pass it an unrecognised 'type'.

Update: Fixed - I had the logic wrong in the parameter count check.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: generateUUID

Post by mwieder » Wed May 29, 2013 5:34 pm

Cool. Is there a best-practice way to report bugs in dev branches or is this the place?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: generateUUID

Post by mwieder » Wed May 29, 2013 8:30 pm

The uuid() function is getting better. It no longer crashes on wrong parameters. But it could do a better job of reporting wrong-number-of-parameter errors. Here's what I get with the latest commit:

put uuid("sha1") -- Error description: uuid: wrong number of arguments for specified type
put uuid("sha1", 42) -- Error description: Handler: can't find handler
put uuid("sha1", 42, "") -- Error description: uuid: namespace not a uuid
put uuid("sha1", 42, "hello", "bucko") -- Error description: Handler: can't find handler

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Thu May 30, 2013 10:57 am

@mwieder: I think what you are experiencing there is a message box bug...

In recent versions we changed the message box to use an engine function to determine whether the string you type in is an expression or a command. The function that does this tries first to parse as one, then the other - reporting whether either succeeds. In this case, the 2nd and 4th commands will fail to parse as (when parsing the uuid() function) the wrong number of parameters will cause a parse error. This means the message box is likely trying to do something else with it and thus resulting in an error which is not as accurate as it should be.

If you try the same list of commands in the script editor, you should get the correct syntax errors for 2 and 4.

I'll have to ponder the best way to fix the issue exposed by this case.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: generateUUID

Post by mwieder » Thu May 30, 2013 5:30 pm

In recent versions we changed the message box to use an engine function to determine whether the string you type in is an expression or a command.
? The way I determine that is that a command is the first word in a line.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: generateUUID

Post by mwieder » Thu May 30, 2013 5:37 pm

...but otherwise verified. Doing that in a button script I do indeed see the proper error results.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: generateUUID

Post by LCMark » Thu May 30, 2013 6:14 pm

? The way I determine that is that a command is the first word in a line.
Hmmm - my brain is a bit too tired to remember the rationalization... It might be that just doing that could be enough to make the message-box happy - although it does currently do a lot of funky stuff to support some of its features...

Locked

Return to “Engine Contributors”