NCDVal.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /**
  2. * @file NCDVal.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef BADVPN_NCDVAL_H
  30. #define BADVPN_NCDVAL_H
  31. #include <stddef.h>
  32. #include <stdint.h>
  33. #include <misc/debug.h>
  34. #include <structure/CAvl.h>
  35. #include <ncd/NCDStringIndex.h>
  36. // these are implementation details. The interface is defined below.
  37. #define NCDVAL_FASTBUF_SIZE 64
  38. #define NCDVAL_FIRST_SIZE 256
  39. #define NCDVAL_MAXIDX INT_MAX
  40. #define NCDVAL_MINIDX INT_MIN
  41. typedef int NCDVal__idx;
  42. typedef struct {
  43. char *buf;
  44. NCDVal__idx size;
  45. NCDVal__idx used;
  46. char fastbuf[NCDVAL_FASTBUF_SIZE];
  47. } NCDValMem;
  48. typedef struct {
  49. NCDValMem *mem;
  50. NCDVal__idx idx;
  51. } NCDValRef;
  52. typedef struct {
  53. NCDVal__idx idx;
  54. } NCDValSafeRef;
  55. struct NCDVal__string {
  56. int type;
  57. NCDVal__idx length;
  58. char data[];
  59. };
  60. struct NCDVal__list {
  61. int type;
  62. NCDVal__idx maxcount;
  63. NCDVal__idx count;
  64. NCDVal__idx elem_indices[];
  65. };
  66. struct NCDVal__mapelem {
  67. NCDVal__idx key_idx;
  68. NCDVal__idx val_idx;
  69. NCDVal__idx tree_child[2];
  70. NCDVal__idx tree_parent;
  71. int8_t tree_balance;
  72. };
  73. struct NCDVal__idstring {
  74. int type;
  75. NCD_string_id_t string_id;
  76. NCDStringIndex *string_index;
  77. };
  78. typedef struct NCDVal__mapelem NCDVal__maptree_entry;
  79. typedef NCDValMem *NCDVal__maptree_arg;
  80. #include "NCDVal_maptree.h"
  81. #include <structure/CAvl_decl.h>
  82. struct NCDVal__map {
  83. int type;
  84. NCDVal__idx maxcount;
  85. NCDVal__idx count;
  86. NCDVal__MapTree tree;
  87. struct NCDVal__mapelem elems[];
  88. };
  89. typedef struct {
  90. NCDVal__idx elemidx;
  91. } NCDValMapElem;
  92. #define NCDVAL_INSTR_PLACEHOLDER 0
  93. #define NCDVAL_INSTR_REINSERT 1
  94. struct NCDVal__instr {
  95. int type;
  96. union {
  97. struct {
  98. NCDVal__idx plid;
  99. NCDVal__idx plidx;
  100. } placeholder;
  101. struct {
  102. NCDVal__idx mapidx;
  103. NCDVal__idx elempos;
  104. } reinsert;
  105. };
  106. };
  107. typedef struct {
  108. struct NCDVal__instr *instrs;
  109. size_t num_instrs;
  110. } NCDValReplaceProg;
  111. //
  112. #define NCDVAL_STRING 1
  113. #define NCDVAL_LIST 2
  114. #define NCDVAL_MAP 3
  115. #define NCDVAL_PLACEHOLDER 4
  116. /**
  117. * Initializes a value memory object.
  118. * A value memory object holds memory for value structures. Values within
  119. * the memory are referenced using {@link NCDValRef} objects, which point
  120. * to values within memory objects.
  121. *
  122. * Values may be added to a memory object using functions such as
  123. * {@link NCDVal_NewString}, {@link NCDVal_NewList} and {@link NCDVal_NewMap},
  124. * and {@link NCDVal_NewCopy}, which return references to the new values within
  125. * the memory object.
  126. *
  127. * It is not possible to remove values from the memory object, or modify existing
  128. * values other than adding elements to pre-allocated slots in lists and maps.
  129. * Once a value is added, it will consume memory as long as its memory object
  130. * exists. This is by design - this code is intended and optimized for constructing
  131. * and passing around values, not for operating on them in place. In fact, al
  132. * values within a memory object are stored in a single memory buffer, as an
  133. * embedded data structure with relativepointers. For example, map values use an
  134. * embedded AVL tree.
  135. */
  136. void NCDValMem_Init (NCDValMem *o);
  137. /**
  138. * Frees a value memory object.
  139. * All values within the memory object cease to exist, and any {@link NCDValRef}
  140. * object pointing to them must no longer be used.
  141. */
  142. void NCDValMem_Free (NCDValMem *o);
  143. /**
  144. * Attempts to free the value memory object, exporting its data to an external
  145. * memory block.
  146. * On success, 1 is returned, and *out_data and *out_len are set; *out_data
  147. * receives a memory block which should be freed using {@link BFree}.
  148. * After the memory object is exported, copies can be created using
  149. * {@link NCDValMem_InitImport}. Any value references needed from the original
  150. * should be turned to safe references using {@link NCDVal_ToSafe} before
  151. * exporting the block, and imported to copies using {@link NCDVal_FromSafe}.
  152. * On failure, 0 is returned, and the memory object is unchanged (it should
  153. * still be freed using {@link NCDValMem_Free}.
  154. */
  155. int NCDValMem_FreeExport (NCDValMem *o, char **out_data, size_t *out_len) WARN_UNUSED;
  156. /**
  157. * Initializes the value memory object as a copy of an external memory block,
  158. * which was obtained using {@link NCDValMem_FreeExport}.
  159. * The memory block provided is only read, and is copied into this memory object.
  160. * Returns 1 on success, 0 on failure.
  161. */
  162. int NCDValMem_InitImport (NCDValMem *o, const char *data, size_t len) WARN_UNUSED;
  163. /**
  164. * Does nothing.
  165. * The value reference object must either point to a valid value within a valid
  166. * memory object, or must be an invalid reference (most functions operating on
  167. * {@link NCDValRef} implicitly require that).
  168. */
  169. void NCDVal_Assert (NCDValRef val);
  170. /**
  171. * Determines if a value reference is invalid.
  172. */
  173. int NCDVal_IsInvalid (NCDValRef val);
  174. /**
  175. * Determines if a value is a placeholder value.
  176. * The value reference must not be an invalid reference.
  177. */
  178. int NCDVal_IsPlaceholder (NCDValRef val);
  179. /**
  180. * Returns the type of the value reference, which must not be an invalid reference.
  181. * Possible values are NCDVAL_STRING, NCDVAL_LIST, NCDVAL_MAP and NCDVAL_PLACEHOLDER.
  182. * The placeholder type is only used internally in the interpreter for argument
  183. * resolution, and is never seen by modules; see {@link NCDVal_NewPlaceholder}.
  184. */
  185. int NCDVal_Type (NCDValRef val);
  186. /**
  187. * Returns an invalid reference.
  188. * An invalid reference must not be passed to any function here, except:
  189. * {@link NCDVal_Assert}, {@link NCDVal_IsInvalid}, {@link NCDVal_ToSafe},
  190. * {@link NCDVal_FromSafe}, {@link NCDVal_Moved}.
  191. */
  192. NCDValRef NCDVal_NewInvalid (void);
  193. /**
  194. * Returns a new placeholder value reference. A placeholder value is a valid value
  195. * containing an integer placeholder identifier.
  196. * This always succeeds; however, the caller must ensure the identifier is
  197. * non-negative and satisfies (NCDVAL_MINIDX + plid < -1).
  198. *
  199. * The placeholder type is only used internally in the interpreter for argument
  200. * resolution, and is never seen by modules. Also see {@link NCDPlaceholderDb}.
  201. */
  202. NCDValRef NCDVal_NewPlaceholder (NCDValMem *mem, int plid);
  203. /**
  204. * Returns the indentifier of a placeholder value.
  205. * The value reference must point to a placeholder value.
  206. */
  207. int NCDVal_PlaceholderId (NCDValRef val);
  208. /**
  209. * Copies a value into the specified memory object. The source
  210. * must not be an invalid reference, however it may reside in any memory
  211. * object (including 'mem').
  212. * Returns a reference to the copied value. On out of memory, returns
  213. * an invalid reference.
  214. */
  215. NCDValRef NCDVal_NewCopy (NCDValMem *mem, NCDValRef val);
  216. /**
  217. * Compares two values, both of which must not be invalid references.
  218. * Returns -1, 0 or 1.
  219. */
  220. int NCDVal_Compare (NCDValRef val1, NCDValRef val2);
  221. /**
  222. * Converts a value reference to a safe referece format, which remains valid
  223. * if the memory object is moved (safe references do not contain a pointer
  224. * to the memory object, unlike {@link NCDValRef} references).
  225. */
  226. NCDValSafeRef NCDVal_ToSafe (NCDValRef val);
  227. /**
  228. * Converts a safe value reference to a normal value reference.
  229. * This should be used to recover references from safe references
  230. * after the memory object is moved.
  231. */
  232. NCDValRef NCDVal_FromSafe (NCDValMem *mem, NCDValSafeRef sval);
  233. /**
  234. * Fixes a value reference after its memory object was moved.
  235. */
  236. NCDValRef NCDVal_Moved (NCDValMem *mem, NCDValRef val);
  237. /**
  238. * Determines if a value is a string value.
  239. * The value reference must not be an invalid reference.
  240. */
  241. int NCDVal_IsString (NCDValRef val);
  242. /**
  243. * Determines if a value is an ID-string value. See {@link NCDVal_NewIdString}
  244. * for an explanation of ID-string values.
  245. * The value reference must not be an invalid reference.
  246. */
  247. int NCDVal_IsIdString (NCDValRef val);
  248. /**
  249. * Determines if a value is a string value which has no null bytes.
  250. * The value reference must not be an invalid reference.
  251. */
  252. int NCDVal_IsStringNoNulls (NCDValRef val);
  253. /**
  254. * Builds a new string value from a null-terminated array of bytes.
  255. * Equivalent to NCDVal_NewStringBin(mem, data, strlen(data)).
  256. * Returns a reference to the new value, or an invalid reference
  257. * on out of memory.
  258. * WARNING: The buffer passed must NOT be part of any value in the
  259. * memory object specified. In particular, you may NOT use this
  260. * function to copy a string that resides in the same memory object.
  261. */
  262. NCDValRef NCDVal_NewString (NCDValMem *mem, const char *data);
  263. /**
  264. * Builds a new string value.
  265. * Returns a reference to the new value, or an invalid reference
  266. * on out of memory.
  267. * WARNING: The buffer passed must NOT be part of any value in the
  268. * memory object specified. In particular, you may NOT use this
  269. * function to copy a string that resides in the same memory object.
  270. */
  271. NCDValRef NCDVal_NewStringBin (NCDValMem *mem, const uint8_t *data, size_t len);
  272. /**
  273. * Builds a new string value of the given length with undefined contents.
  274. * You can define the contents of the string later by copying to the address
  275. * returned by {@link NCDVal_StringValue}. The terminating null byte is
  276. * however automatically written.
  277. */
  278. NCDValRef NCDVal_NewStringUninitialized (NCDValMem *mem, size_t len);
  279. /**
  280. * Builds a new ID-string value.
  281. * Returns a reference to the new value, or an invalid reference
  282. * on out of memory.
  283. *
  284. * An ID-string value is a special kind of string value which is represented
  285. * efficiently as a string identifier via {@link NCDStringIndex}. An ID-string
  286. * is also a string and is transparent for use. For example, for an ID-string,
  287. * {@link NCDVal_Type} still returns NCDVAL_STRING, {@link NCDVal_IsString}
  288. * returns 1, and {@link NCDVal_StringValue} and {@link NCDVal_StringLength}
  289. * both work. The only way to distinguish an ID-string from a non-ID string is
  290. * by calling {@link NCDVal_IsIdString}.
  291. */
  292. NCDValRef NCDVal_NewIdString (NCDValMem *mem, NCD_string_id_t string_id,
  293. NCDStringIndex *string_index);
  294. /**
  295. * Returns a pointer to the data of a string value. An extra null byte
  296. * is always appended to the actual contents of the string.
  297. * The value reference must point to a string value.
  298. */
  299. const char * NCDVal_StringValue (NCDValRef string);
  300. /**
  301. * Returns the length of the string value, excluding the automatically
  302. * appended null byte.
  303. * The value reference must point to a string value.
  304. */
  305. size_t NCDVal_StringLength (NCDValRef string);
  306. /**
  307. * Returns the string ID and the string index of an ID-string.
  308. * The value given must be an ID-string value (which can be determined via
  309. * {@link NCDVal_IsIdString}). Both the \a out_string_id and \a out_string_index
  310. * pointers must be non-NULL.
  311. */
  312. void NCDVal_IdStringGet (NCDValRef idstring, NCD_string_id_t *out_string_id,
  313. NCDStringIndex **out_string_index);
  314. /**
  315. * Determines if the string value has any null bytes in its contents,
  316. * i.e. that length > strlen().
  317. * The value reference must point to a string value.
  318. */
  319. int NCDVal_StringHasNulls (NCDValRef string);
  320. /**
  321. * Determines if the string value is equal to the given null-terminated
  322. * string.
  323. * The value reference must point to a string value.
  324. */
  325. int NCDVal_StringEquals (NCDValRef string, const char *data);
  326. /**
  327. * Determines if a value is a list value.
  328. * The value reference must not be an invalid reference.
  329. */
  330. int NCDVal_IsList (NCDValRef val);
  331. /**
  332. * Builds a new list value. The 'maxcount' argument specifies how
  333. * many element slots to preallocate. Not more than that many
  334. * elements may be appended to the list using {@link NCDVal_ListAppend}.
  335. * Returns a reference to the new value, or an invalid reference
  336. * on out of memory.
  337. */
  338. NCDValRef NCDVal_NewList (NCDValMem *mem, size_t maxcount);
  339. /**
  340. * Appends a value to to the list value.
  341. * The 'list' reference must point to a list value, and the
  342. * 'elem' reference must be non-invalid and point to a value within
  343. * the same memory object as the list.
  344. * Inserting a value into a list does not in any way change it;
  345. * internally, the list only points to it.
  346. */
  347. void NCDVal_ListAppend (NCDValRef list, NCDValRef elem);
  348. /**
  349. * Returns the number of elements in a list value, i.e. the number
  350. * of times {@link NCDVal_ListAppend} was called.
  351. * The 'list' reference must point to a list value.
  352. */
  353. size_t NCDVal_ListCount (NCDValRef list);
  354. /**
  355. * Returns the maximum number of elements a list value may contain,
  356. * i.e. the 'maxcount' argument to {@link NCDVal_NewList}.
  357. * The 'list' reference must point to a list value.
  358. */
  359. size_t NCDVal_ListMaxCount (NCDValRef list);
  360. /**
  361. * Returns a reference to the value at the given position 'pos' in a list,
  362. * starting with zero.
  363. * The 'list' reference must point to a list value.
  364. * The position 'pos' must refer to an existing element, i.e.
  365. * pos < NCDVal_ListCount().
  366. */
  367. NCDValRef NCDVal_ListGet (NCDValRef list, size_t pos);
  368. /**
  369. * Returns references to elements within a list by writing them
  370. * via (NCDValRef *) variable arguments.
  371. * If 'num' == NCDVal_ListCount(), succeeds, returing 1 and writing 'num'
  372. * references, as mentioned.
  373. * If 'num' != NCDVal_ListCount(), fails, returning 0, without writing any
  374. * references
  375. */
  376. int NCDVal_ListRead (NCDValRef list, int num, ...);
  377. /**
  378. * Like {@link NCDVal_ListRead}, but the list can contain more than 'num'
  379. * elements.
  380. */
  381. int NCDVal_ListReadHead (NCDValRef list, int num, ...);
  382. /**
  383. * Determines if a value is a map value.
  384. * The value reference must not be an invalid reference.
  385. */
  386. int NCDVal_IsMap (NCDValRef val);
  387. /**
  388. * Builds a new map value. The 'maxcount' argument specifies how
  389. * many entry slots to preallocate. Not more than that many
  390. * entries may be inserted to the map using {@link NCDVal_MapInsert}.
  391. * Returns a reference to the new value, or an invalid reference
  392. * on out of memory.
  393. */
  394. NCDValRef NCDVal_NewMap (NCDValMem *mem, size_t maxcount);
  395. /**
  396. * Inserts an entry to the map value.
  397. * The 'map' reference must point to a map value, and the
  398. * 'key' and 'val' references must be non-invalid and point to values within
  399. * the same memory object as the map.
  400. * Inserting an entry does not in any way change the 'key'and 'val';
  401. * internally, the map only points to it.
  402. * You must not modify the key after inserting it into a map. This is because
  403. * the map builds an embedded AVL tree of entries indexed by keys.
  404. * If 'key' does not exist in the map, succeeds, returning 1.
  405. * If 'key' already exists in the map, fails, returning 0.
  406. */
  407. int NCDVal_MapInsert (NCDValRef map, NCDValRef key, NCDValRef val);
  408. /**
  409. * Returns the number of entries in a map value, i.e. the number
  410. * of times {@link NCDVal_MapInsert} was called successfully.
  411. * The 'map' reference must point to a map value.
  412. */
  413. size_t NCDVal_MapCount (NCDValRef map);
  414. /**
  415. * Returns the maximum number of entries a map value may contain,
  416. * i.e. the 'maxcount' argument to {@link NCDVal_NewMap}.
  417. * The 'map' reference must point to a map value.
  418. */
  419. size_t NCDVal_MapMaxCount (NCDValRef map);
  420. /**
  421. * Determines if a map entry reference is invalid. This is used in combination
  422. * with the map iteration functions to detect the end of iteration.
  423. */
  424. int NCDVal_MapElemInvalid (NCDValMapElem me);
  425. /**
  426. * Returns a reference to the first entry in a map, with respect to some
  427. * arbitrary order.
  428. * If the map is empty, returns an invalid map entry reference.
  429. */
  430. NCDValMapElem NCDVal_MapFirst (NCDValRef map);
  431. /**
  432. * Returns a reference to the entry in a map that follows the entry referenced
  433. * by 'me', with respect to some arbitrary order.
  434. * The 'me' argument must be a non-invalid reference to an entry in the map.
  435. * If 'me' is the last entry, returns an invalid map entry reference.
  436. */
  437. NCDValMapElem NCDVal_MapNext (NCDValRef map, NCDValMapElem me);
  438. /**
  439. * Like {@link NCDVal_MapFirst}, but with respect to the order defined by
  440. * {@link NCDVal_Compare}.
  441. * Ordered iteration is slower and should only be used when needed.
  442. */
  443. NCDValMapElem NCDVal_MapOrderedFirst (NCDValRef map);
  444. /**
  445. * Like {@link NCDVal_MapNext}, but with respect to the order defined by
  446. * {@link NCDVal_Compare}.
  447. * Ordered iteration is slower and should only be used when needed.
  448. */
  449. NCDValMapElem NCDVal_MapOrderedNext (NCDValRef map, NCDValMapElem me);
  450. /**
  451. * Returns a reference to the key of the map entry referenced by 'me'.
  452. * The 'me' argument must be a non-invalid reference to an entry in the map.
  453. */
  454. NCDValRef NCDVal_MapElemKey (NCDValRef map, NCDValMapElem me);
  455. /**
  456. * Returns a reference to the value of the map entry referenced by 'me'.
  457. * The 'me' argument must be a non-invalid reference to an entry in the map.
  458. */
  459. NCDValRef NCDVal_MapElemVal (NCDValRef map, NCDValMapElem me);
  460. /**
  461. * Looks for a key in the map. The 'key' reference must be a non-invalid
  462. * value reference, and may point to a value in a different memory object
  463. * than the map.
  464. * If the key exists in the map, returns a reference to the corresponding
  465. * map entry.
  466. * If the key does not exist, returns an invalid map entry reference.
  467. */
  468. NCDValMapElem NCDVal_MapFindKey (NCDValRef map, NCDValRef key);
  469. /**
  470. * Builds a placeholder replacement program, which is a list of instructions for
  471. * efficiently replacing placeholders in identical values in identical memory
  472. * objects.
  473. * To actually perform replacements, make copies of the memory object of this value
  474. * using {@link NCDValMem_FreeExport} and {@link NCDValMem_InitImport}, then call
  475. * {@link NCDValReplaceProg_Execute} on the copies.
  476. * The value passed must be a valid value, and not a placeholder.
  477. * Returns 1 on success, 0 on failure.
  478. */
  479. int NCDValReplaceProg_Init (NCDValReplaceProg *o, NCDValRef val);
  480. /**
  481. * Frees the placeholder replacement program.
  482. */
  483. void NCDValReplaceProg_Free (NCDValReplaceProg *o);
  484. /**
  485. * Callback used by {@link NCDValReplaceProg_Execute} to allow the caller to produce
  486. * values of placeholders.
  487. * This function should build a new value within the memory object 'mem' (which is
  488. * the same as of the memory object where placeholders are being replaced).
  489. * On success, it should return 1, writing a valid value reference to *out.
  490. * On failure, it can either return 0, or return 1 but write an invalid value reference.
  491. * This callback must not access the memory object in any other way than building
  492. * new values in it; it must not modify any values that were already present at the
  493. * point it was called.
  494. */
  495. typedef int (*NCDVal_replace_func) (void *arg, int plid, NCDValMem *mem, NCDValRef *out);
  496. /**
  497. * Executes the replacement program, replacing placeholders in a value.
  498. * The memory object must given be identical to the memory object which was used in
  499. * {@link NCDValReplaceProg_Init}; see {@link NCDValMem_FreeExport} and
  500. * {@link NCDValMem_InitImport}.
  501. * This will call the callback 'replace', which should build the values to replace
  502. * the placeholders.
  503. * Returns 1 on success and 0 on failure. On failure, the entire memory object enters
  504. * and inconsistent state and must be freed using {@link NCDValMem_Free} before
  505. * performing any other operation on it.
  506. * The program is passed by value instead of pointer because this appears to be faster.
  507. * Is is not modified in any way.
  508. */
  509. int NCDValReplaceProg_Execute (NCDValReplaceProg prog, NCDValMem *mem, NCDVal_replace_func replace, void *arg);
  510. #endif