{"id":63,"date":"2008-02-08T15:37:23","date_gmt":"2008-02-08T15:37:23","guid":{"rendered":"http:\/\/blog.danplanet.com\/wordpress\/?p=63"},"modified":"2008-02-08T15:37:23","modified_gmt":"2008-02-08T15:37:23","slug":"when-is-foo-afoo","status":"publish","type":"post","link":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/","title":{"rendered":"When is foo == &#038;foo?"},"content":{"rendered":"<p>The answer is &#8220;in the CMPI interface specification&#8221;.<\/p>\n<p>So, CMPI defines this massive union of every possible data type, called CMPIValue.&nbsp; It looks something like this (but with many more types):<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>union {<br \/>&nbsp;&nbsp;&nbsp; uint32_t uint32;<br \/>&nbsp;&nbsp;&nbsp; uint64_t uint64;<br \/>&nbsp;&nbsp;&nbsp; char *chars;<br \/>&nbsp;&nbsp;&nbsp; CMPIString *string;<br \/>} CMPIValue;<\/p><\/blockquote>\n<p>This is then thrown around way too much, using an enumeration called CMPIType to indicate which interpretation of CMPIValue you intend to use.&nbsp; For example, to set a property of an instance, you would do something like this for an integer:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>uint32_t myint = 123;<br \/>CMSetProperty(inst, &#8220;MyIntProperty&#8221;, (CMPIValue *)&amp;myint, CMPI_uint32);<\/p><\/blockquote>\n<p>or this for a string:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>const char *mystring = &#8220;We&#8217;re really asking for trouble here&#8230;&#8221;;<br \/>CMSetProperty(inst, &#8220;MyStrProperty&#8221;, (CMPIValue *)mystring, CMPI_chars);<\/p><\/blockquote>\n<p>Makes sense, right?&nbsp; The above usage in the string case is, of course, the scenario intended by the interface designer, and it is (in my experience) almost exclusively used that way.&nbsp; However, assuming you want to do something a little more complicated, such as write a CIMXML instance parser, you might want to pass around their CMPIValue and CMPIType objects.<\/p>\n<p>So, lets say you do something like the following:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>CMPIType parse_integer(char *string, CMPIValue *val) {<br \/>&nbsp;&nbsp;&nbsp; val-&gt;uint32 = 123;<br \/>&nbsp;&nbsp;&nbsp; return CMPI_uint32;<br \/>}<\/p>\n<p>CMPIType parse_string(char *string, CMPIValue *val) {<br \/>&nbsp;&nbsp;&nbsp; val-&gt;chars = strdup(&#8220;Oh, boy, here we go&#8221<img decoding=\"async\" src=\"https:\/\/www.danplanet.com\/blog\/wp-content\/themes\/wordpress-grey-opaque-master\/images\/smilies\/icon_wink.gif\" alt=\"Smilie: ;)\" title=\"Smilie: ;)\" \/>;<br \/>&nbsp;&nbsp;&nbsp; return CMPI_chars;<br \/>}<\/p>\n<p>int set_property(char *string, char *name, CMPIInstance *inst) {<br \/>&nbsp;&nbsp;&nbsp; CMPIValue value;<br \/>&nbsp;&nbsp;&nbsp; CMPIType type;<\/p>\n<p>&nbsp;&nbsp;&nbsp; if (\/* value looks like an integer *\/)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type = parse_integer(string, &amp;value);<br \/>&nbsp;&nbsp;&nbsp; else<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type = parse_string(string, &amp;value);<\/p>\n<p>&nbsp;&nbsp;&nbsp; CMSetProperty(inst, name, &amp;value, type);<br \/>}<\/p><\/blockquote>\n<p>That&#8217;s all fine, right?&nbsp; We set the CMPIValue in our handler functions, and then we pass a pointer to our value to CMSetProperty().&nbsp; Obviously nothing to see here, CMSetProperty() takes a CMPIValue *&#8230;&#8230;doesn&#8217;t it?<\/p>\n<p>The answer is a big fat &#8220;NO, no it doesn&#8217;t&#8221;.&nbsp; If you were paying close attention before, we passed in the pointer to a CMPIValue stack variable in the integer case, but in the string case, we passed in a pointer to an actual string buffer.&nbsp; Thus, if we put that string pointer in the CMPIValue itself, and then pass a pointer to it, you get a double pointer, the equivalent of a char **.&nbsp; Because the type is correct, the compiler doesn&#8217;t complain, but the CIMOM explodes.<\/p>\n<p>I&#8217;m really shocked and horrified that the CMPI interface includes this semantic difference in the setProperty() broker call.&nbsp; To verify that I wasn&#8217;t just hallucinating on a Friday afternoon, I tracked the call down to the following bit of truly spectacular OpenPegasus code:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>CIMValue value2CIMValue(const CMPIValue* data, &#8230<img decoding=\"async\" src=\"https:\/\/www.danplanet.com\/blog\/wp-content\/themes\/wordpress-grey-opaque-master\/images\/smilies\/icon_wink.gif\" alt=\"Smilie: ;)\" title=\"Smilie: ;)\" \/> {<br \/>&nbsp;&nbsp;&nbsp; . . .<br \/>&nbsp;&nbsp;&nbsp; else if (type==CMPI_chars) {<br \/>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (data) v.set(String((char*)data));<br \/>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; else return CIMValue(CIMTYPE_STRING,false);<br \/>&nbsp;&nbsp;&nbsp; }<\/p><\/blockquote>\n<p>Right there, they take the CMPIValue and cast it directly to a char * if you tell them that you&#8217;re passing in CMPI_chars!&nbsp; Just to illustrate how the interpretation of the CMPIValue parameter fundamentally changes depending on the type you passed in, the following appears directly below:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>&nbsp;&nbsp; else if (type==CMPI_charsptr) {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (data &amp;&amp; *(char**)data) v.set(String(*(char**)data));<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else return CIMValue(CIMTYPE_STRING,false);<br \/>&nbsp;&nbsp; }<\/p><\/blockquote>\n<p>So, if you pass in CMPI_chars, then it expects a char*.&nbsp; If you pass in CMPI_charsptr, then it expects a char ** (which would actually cast a the example above to the correct thing).&nbsp; IMHO, it would have been better for them to just call it a void * and be done with it.&nbsp; They think they have made it cleaner, but they&#8217;ve actually made it worse.<\/p>\n<p>What a great way to end a Friday.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The answer is &#8220;in the CMPI interface specification&#8221;. So, CMPI defines this massive union of every possible data type, called CMPIValue.&nbsp; It looks something like this (but with many more types): union {&nbsp;&nbsp;&nbsp; uint32_t uint32;&nbsp;&nbsp;&nbsp; uint64_t uint64;&nbsp;&nbsp;&nbsp; char *chars;&nbsp;&nbsp;&nbsp; CMPIString &hellip; <a href=\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[28],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-codemonkeying","tag-cim"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>When is foo == &amp;foo? - Right Angles<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"When is foo == &amp;foo? - Right Angles\" \/>\n<meta property=\"og:description\" content=\"The answer is &#8220;in the CMPI interface specification&#8221;. So, CMPI defines this massive union of every possible data type, called CMPIValue.&nbsp; It looks something like this (but with many more types): union {&nbsp;&nbsp;&nbsp; uint32_t uint32;&nbsp;&nbsp;&nbsp; uint64_t uint64;&nbsp;&nbsp;&nbsp; char *chars;&nbsp;&nbsp;&nbsp; CMPIString &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\" \/>\n<meta property=\"og:site_name\" content=\"Right Angles\" \/>\n<meta property=\"article:published_time\" content=\"2008-02-08T15:37:23+00:00\" \/>\n<meta name=\"author\" content=\"Dan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\"},\"author\":{\"name\":\"Dan\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"headline\":\"When is foo == &#038;foo?\",\"datePublished\":\"2008-02-08T15:37:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\"},\"wordCount\":703,\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"keywords\":[\"CIM\"],\"articleSection\":[\"Codemonkeying\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\",\"url\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\",\"name\":\"When is foo == &foo? - Right Angles\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\"},\"datePublished\":\"2008-02-08T15:37:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.danplanet.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"When is foo == &#038;foo?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\",\"url\":\"https:\/\/www.danplanet.com\/blog\/\",\"name\":\"Right Angles\",\"description\":\"If they&#039;re not right...they&#039;re wrong\",\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\",\"name\":\"Dan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"caption\":\"Dan\"},\"logo\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.danplanet.com\/blog\/author\/dan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"When is foo == &foo? - Right Angles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/","og_locale":"en_US","og_type":"article","og_title":"When is foo == &foo? - Right Angles","og_description":"The answer is &#8220;in the CMPI interface specification&#8221;. So, CMPI defines this massive union of every possible data type, called CMPIValue.&nbsp; It looks something like this (but with many more types): union {&nbsp;&nbsp;&nbsp; uint32_t uint32;&nbsp;&nbsp;&nbsp; uint64_t uint64;&nbsp;&nbsp;&nbsp; char *chars;&nbsp;&nbsp;&nbsp; CMPIString &hellip; Continue reading &rarr;","og_url":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/","og_site_name":"Right Angles","article_published_time":"2008-02-08T15:37:23+00:00","author":"Dan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#article","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/"},"author":{"name":"Dan","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"headline":"When is foo == &#038;foo?","datePublished":"2008-02-08T15:37:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/"},"wordCount":703,"publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"keywords":["CIM"],"articleSection":["Codemonkeying"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/","url":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/","name":"When is foo == &foo? - Right Angles","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/#website"},"datePublished":"2008-02-08T15:37:23+00:00","breadcrumb":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.danplanet.com\/blog\/2008\/02\/08\/when-is-foo-afoo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.danplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"When is foo == &#038;foo?"}]},{"@type":"WebSite","@id":"https:\/\/www.danplanet.com\/blog\/#website","url":"https:\/\/www.danplanet.com\/blog\/","name":"Right Angles","description":"If they&#039;re not right...they&#039;re wrong","publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c","name":"Dan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","caption":"Dan"},"logo":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.danplanet.com\/blog\/author\/dan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}