User Tag List

Results 1 to 6 of 6

Thread: Returning and Using Strings

  1. #1
    Clicker Multimedia Fusion 2 Developer
    Matt's Avatar
    Join Date
    Jun 2006
    Location
    Connecticut
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Returning and Using Strings

    Since all extensions will have to be recompiled anyway, I was wondering if any had given any thought to conventions regarding strings. Here are a few questions I'd like to have answered:

    -Is null an acceptable return value? Will an extension ever be passed null? (I'm guessing the answer to the first question will answer the second.)
    -If a string is passed to a function, can that function modify it? I would imagine that this would be a bad thing to do but that really depends on the answer to my next question.
    -If a function is returning a string, should it ever return a pointer to one of its internal strings? SHould it always return a copy?


    These are a few things that bothered me in previous extensions. I know that MMF never used null strings, but I know that a few 3EE extensions did return them, which could cause other extensions (that were not expecting nulls) to crash.

    I also saw another scenario where the Associative Array object would return a pointer to one of its interanl strings and then a function in another object (String Manipulator maybe) would modify that string directly, causing AssArray to exhibit odd behavior.

    I would just like to avoid these scenarios in MMF2 if at all possible. Conventions on these sorts of things would be nice.

  2. #2
    Clicker Multimedia Fusion 2 Developer
    Matt's Avatar
    Join Date
    Jun 2006
    Location
    Connecticut
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Returning and Using Strings

    Since all extensions will have to be recompiled anyway, I was wondering if any had given any thought to conventions regarding strings. Here are a few questions I'd like to have answered:

    -Is null an acceptable return value? Will an extension ever be passed null? (I'm guessing the answer to the first question will answer the second.)
    -If a string is passed to a function, can that function modify it? I would imagine that this would be a bad thing to do but that really depends on the answer to my next question.
    -If a function is returning a string, should it ever return a pointer to one of its internal strings? SHould it always return a copy?


    These are a few things that bothered me in previous extensions. I know that MMF never used null strings, but I know that a few 3EE extensions did return them, which could cause other extensions (that were not expecting nulls) to crash.

    I also saw another scenario where the Associative Array object would return a pointer to one of its interanl strings and then a function in another object (String Manipulator maybe) would modify that string directly, causing AssArray to exhibit odd behavior.

    I would just like to avoid these scenarios in MMF2 if at all possible. Conventions on these sorts of things would be nice.

  3. #3
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    13,857
    Mentioned
    262 Post(s)
    Tagged
    3 Thread(s)

    Re: Returning and Using Strings

    >> -Is null an acceptable return value?

    No, you must not return NULL. Return an empty string if necessary.

    >> Will an extension ever be passed null?

    Theoretically no, but practically yes : there might be bugs or another extension could return NULL and MMF2 could pass it to your function directly without processing it

    => you should always test if a string parameter is NULL.

    >> If a string is passed to a function, can that function modify it?

    No, you must not modify it.

    >> If a function is returning a string, should it ever return a pointer to one of its internal strings?

    It can return a pointer to an internal string. MMF2 will make a copy if necessary.

    >> Should it always return a copy?

    No.

    Note: if you want to allocate memory for returning a string, use a callRuntimeFunction ( ... RFUNCTION_GETSTRINGSPACE_EX ... ). MMF2 frees strings allocated with this function when it no longer needs them.

    >> I know that a few 3EE extensions did return them, which could cause other extensions (that were not expecting nulls) to crash.

    Yes, that's what I said above.

    >> the Associative Array object would return a pointer to one of its interanl strings
    >> and then a function in another object (String Manipulator maybe) would modify that string directly

    Bad practice, you must not modify strings passed as parameters.

    Yves.

  4. #4
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    13,857
    Mentioned
    262 Post(s)
    Tagged
    3 Thread(s)

    Re: Returning and Using Strings

    >> -Is null an acceptable return value?

    No, you must not return NULL. Return an empty string if necessary.

    >> Will an extension ever be passed null?

    Theoretically no, but practically yes : there might be bugs or another extension could return NULL and MMF2 could pass it to your function directly without processing it

    => you should always test if a string parameter is NULL.

    >> If a string is passed to a function, can that function modify it?

    No, you must not modify it.

    >> If a function is returning a string, should it ever return a pointer to one of its internal strings?

    It can return a pointer to an internal string. MMF2 will make a copy if necessary.

    >> Should it always return a copy?

    No.

    Note: if you want to allocate memory for returning a string, use a callRuntimeFunction ( ... RFUNCTION_GETSTRINGSPACE_EX ... ). MMF2 frees strings allocated with this function when it no longer needs them.

    >> I know that a few 3EE extensions did return them, which could cause other extensions (that were not expecting nulls) to crash.

    Yes, that's what I said above.

    >> the Associative Array object would return a pointer to one of its interanl strings
    >> and then a function in another object (String Manipulator maybe) would modify that string directly

    Bad practice, you must not modify strings passed as parameters.

    Yves.

  5. #5
    Clicker Multimedia Fusion 2 Developer
    Matt's Avatar
    Join Date
    Jun 2006
    Location
    Connecticut
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Returning and Using Strings

    Thanks, Yves.

    These were the answers I was hpoing for. It might be worth noting the caveat about not modifying passed strings in the EXPPARAM_STRING and PARAM_EXPSTRING sections of the SDK help and noting the warning not to return NULL in the EXPFLAG_STRING section.

    Thanks,
    -Matt

  6. #6
    Clicker Multimedia Fusion 2 Developer
    Matt's Avatar
    Join Date
    Jun 2006
    Location
    Connecticut
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Returning and Using Strings

    Thanks, Yves.

    These were the answers I was hpoing for. It might be worth noting the caveat about not modifying passed strings in the EXPPARAM_STRING and PARAM_EXPSTRING sections of the SDK help and noting the warning not to return NULL in the EXPFLAG_STRING section.

    Thanks,
    -Matt

Similar Threads

  1. Scan Global Strings and Other strings
    By Ausomeman in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 19th May 2010, 05:01 PM
  2. returning to frame one
    By willow in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 18th November 2009, 06:49 PM
  3. FastFunction not returning strings in expressions
    By jdv in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 9th April 2009, 03:42 PM
  4. Returning __int64 ?
    By Cocodrilo in forum Extension Development
    Replies: 5
    Last Post: 18th July 2008, 01:57 PM
  5. Using Global Strings embedded in larger strings
    By Mudstick in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 12th May 2008, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •