+static inline ION_COLLECTION *php_ion_catalog_collection(php_ion_catalog *cat)
+{
+ /* do not look too close */
+ struct {
+ void *owner;
+ ION_SYMBOL_TABLE *sys;
+ ION_COLLECTION collection;
+ } *cat_ptr = (void *) cat->cat;
+ return &cat_ptr->collection;
+}
+
+static inline void php_ion_writer_options_init_shared_imports(php_ion_writer_options *opt)
+{
+ php_ion_catalog *cat = php_ion_obj(catalog, opt->cat);
+ OBJ_CHECK(cat);
+
+ ION_CHECK(ion_writer_options_initialize_shared_imports(&opt->opt));
+
+ ION_COLLECTION *col = php_ion_catalog_collection(cat);
+ if (!ION_COLLECTION_IS_EMPTY(col)) {
+ // holy, nah, forget it batman...
+#ifndef IPCN_pNODE_TO_pDATA
+# define IPCN_pNODE_TO_pDATA(x) (&((x)->_data[0]))
+#endif
+ ION_COLLECTION_CURSOR cur;
+ ION_COLLECTION_OPEN(col, cur);
+ while (cur) {
+ ION_SYMBOL_TABLE **ptr;
+ ION_COLLECTION_NEXT(cur, ptr);
+ if (*ptr) {
+ ION_CHECK(ion_writer_options_add_shared_imports_symbol_tables(&opt->opt, ptr, 1));
+ } else {
+ break;
+ }
+ }
+ }
+}
+