Results 1 to 5 of 5

Thread: PARAM_ENUM_NAMES length

  1. #1
    Junior Member
    Join Date
    Mar 2005


    The spec, and the implementation, says that the length of the PARAM_ENUM_NAMES parameter capability is the number of enums.

    However, the example code (nullxcode, v4l, winaudio) sets the length to the length of the concatenated enum name string.

    This could cause problems when attempting to get the name of an invalid enum as the search of the enum name string falls off the end.


  2. #2

    Re: PARAM_ENUM_NAMES length

    I haven't taked a look at the examples. As you said, the lengh of the string is set to the concatenated enum strings. However, each enum strings are separated by NULL characters. If you want to search an enum in the string, you should use from these NULL characters.
    Here's a function that you can accomplish this task:

    bool searchString( char* searchAnString, char* allStrings )
    char* endOfString; //pointer to the last string element
    int index = 0; //index for spaces
    endOfString = allStrins + strlen( allStrings );

    //loop while we haven't reached the end of the string
    while( allStrings < endOfString )
    /*returns an integer value specifying the length of the initial segment of *Allstrings* that consists entirely of characters not in NULL character*/
    index = strcspn( allStrings, "\0" );

    //we found searchStr
    if( (strlen( searchAnString ) == index ) && (strncmp( searchAnString, allStrings, index ) == 0 ) )
    return true;

    /*we didn't find searchAnString, move pointer to the next string to search*/
    allStrings += ( index + 2 );

    return false;

    Now we can get the enum strings and find a string in the enum strings.
    Here's a code that shows this task:

    MLpv* parameterCap;
    mlPvGetCapabilities( someObjectId, someParameterId, & parameterCap );

    MLpv* enumNames = mlPvFind( parameterCap, ML_PARAM_ENUM_NAMES_BYTE_ARRAY );

    //ensure that this feature is supported
    if( enumNames )
    if( enumNames->lenght )
    char* enumNamesString = (char*)enumNames->value.pByte;
    char* searchAnString;
    //searchAnString = string that you want to search
    bool returnValue= false;
    returnValue = searchString( searchAnString, enumNamesStrings );

    Now if an invalid enum isn't in the string, the funcion searchString returns false.There's no problem here...

    If you found an error in the codes, let me know.
    1.OpenML specification
    2.OpenML programmers guide
    3.OpenGL game programming
    4.MSDN january 2001


    [ April 26, 2005: Message edited by: Ehsan Kamrani ]

  3. #3
    Junior Member
    Join Date
    Mar 2005

    Re: PARAM_ENUM_NAMES length

    I'm quite capable of searching an array of double nul terminated strings thank you. Besides, there is code in mlpublic.c to do just that already (_valueInt32ToString() for example).

    I wasn't asking about how to do it. I was pointing out that the length of the parameter is set incorrectly in the example devices, and that this could lead to mysterious crashes.


  4. #4

    Re: PARAM_ENUM_NAMES length

    I thought that you are corresponding the lenght component to searching the invalid enumeration.I only claimed that there's no correspondence between the lenght component and searching the enum--And also searching the invalid enum didn't produce an error.
    In the above code, if enumeNames->lenght is valid(exept zero, there's no difference between the other values), then the searchString searches the enum values(valid or invalid values) and returns a value.No error is generated...
    <BLOCKQUOTE><font size="1" face="Arial, Verdana, Helvetica, sans-serif">quote:</font><HR>Originally posted by Jarno van der Linden:
    This could cause problems when attempting to get the name of an invalid enum as the search of the enum name string falls off the end.
    Maybe i can't understand your meaning of that quote or maybe i'm completely incorrect

    But,I didn't say anything about the first and second paragraphs of your message.
    Like always,Fabrice can check the codes and replyes to you

    [ April 27, 2005: Message edited by: Ehsan Kamrani ]

  5. #5
    Join Date
    Jul 2003

    Re: PARAM_ENUM_NAMES length

    Indeed, this is an inconsistency between the spec and the current sample implementations. I'll check to see which we should be fixing.

    Thank you for pointing this out.

Similar Threads

  1. Minimal kernel name length
    By PhilTillet in forum OpenCL
    Replies: 4
    Last Post: 12-31-2012, 10:12 PM
  2. Arrays of Variable Length
    By toneburst in forum OpenCL
    Replies: 1
    Last Post: 01-11-2010, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean