void *_ion_alloc_owner(SIZE len) { void *owner; ION_ALLOCATION_CHAIN *new_chain; if (g_ion_alloc_page_list.page_size == ION_ALLOC_PAGE_POOL_PAGE_SIZE_NONE) { ion_initialize_page_pool(ION_ALLOC_PAGE_POOL_DEFAULT_PAGE_SIZE, ION_ALLOC_PAGE_POOL_DEFAULT_LIMIT); } new_chain = _ion_alloc_block(len); if (!new_chain) return NULL; owner = _ion_alloc_with_owner_helper(new_chain, len, FALSE); return owner; }
int main(int argc, char **argv) { iENTER; FSTREAM_READER_STATE *preader_state = NULL; FSTREAM_WRITER_STATE *pwriter_state = NULL; ION_STRING temp; char *name = NULL; ION_TYPE t = (ION_TYPE)999; int32_t symbol_table_count = 0; int ii, non_argc = 0; char **non_argv = NULL; ION_STRING_INIT(&temp); // read the command line for any instruction the caller might have non_argv = (char**)malloc(argc * sizeof(char*)); ionizer_process_args(argc, argv, non_argv, &non_argc); if (g_ionizer_print_help) SUCCEED(); // clear the option structs and set them appropriately memset(&g_reader_options, 0, sizeof(g_reader_options)); memset(&g_writer_options, 0, sizeof(g_writer_options)); g_writer_options.pretty_print = g_ionizer_pretty; g_writer_options.output_as_binary = g_ionizer_write_binary; g_writer_options.escape_all_non_ascii = g_ionizer_ascii_only; if (g_ionizer_pool_page_size > 0) { ion_initialize_page_pool(g_ionizer_pool_page_size, 10); } // set up our debug options if (g_ionizer_flush_each) g_writer_options.flush_every_value = TRUE; if (g_ionizer_dump_args) ionizer_dump_arg_globals(); if (g_ion_debug_timer) { ionizer_start_timing(); } // read in the catalog, if there is one if (g_ionizer_catalogs) { CHECK(ionizer_load_catalog_list(&g_hcatalog), "load a catalog file"); g_reader_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - HOW SHOULD WE HANDLE THIS? g_writer_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - HOW SHOULD WE HANDLE THIS? CHECK(ion_catalog_get_symbol_table_count(g_hcatalog, &symbol_table_count), "get the symbol table count from the loaded catalog"); fprintf(stderr, "Catalog loaded %d symbol tables\n", symbol_table_count); } // if there's a "writer symbol table" specified look in the catalog for it if (g_ionizer_writer_symtab && *g_ionizer_writer_symtab) { CHECK(ionizer_load_symbol_table(), "load the symbol table from the catalog or a file"); } // open the output stream writer attached to stdout // TODO: allow caller to specify the output file on the command line CHECK( ionizer_writer_open_fstream(&pwriter_state, stdout, &g_writer_options), "writer open failed"); // now, do we process from stdin or from file names on the command line if (non_argc > 0) { // file names for (ii=0; ii<non_argc; ii++) { // open our input and output streams (reader and writer) CHECK(ionizer_process_filename(non_argv[ii], pwriter_state->hwriter, &g_reader_options), "process filename failed"); } } else { // from stdin // open our input and output streams (reader and writer) CHECK( ionizer_reader_open_fstream(&preader_state, stdin, &g_reader_options), "reader open stdin failed"); CHECKREADER( ionizer_process_input_reader(preader_state->hreader, pwriter_state->hwriter), "process stdin", preader_state->hreader); CHECK( ionizer_reader_close_fstream( preader_state ), "closing the reader"); } // if we're emitting a symbol table we need to actually output the // table now (we only collected the symbols from the input sources // during the pass above if (g_ionizer_write_symtab) { CHECK( ionizer_new_symbol_table_write( pwriter_state->hwriter ), "emit the new symbol table we've built up"); } // if the user wanted us to print out the type counts we do it here if (g_ionizer_include_type_counts) { ionizer_print_count_types(stdout); } // close up CHECK( ionizer_writer_close_fstream( pwriter_state ), "closing the writer"); if (g_hsymtab) CHECK(ion_symbol_table_close(g_hsymtab), "closing the temp symbol table"); if (g_hcatalog) CHECK(ion_catalog_close(g_hcatalog), "closing the catalog"); SUCCEED(); fail:// this is iRETURN expanded so I can set a break point on it if (g_ionizer_debug) { fprintf(stderr, "\nionizer finished, returning err [%d] = \"%s\", %d\n", err, ion_error_to_str(err), (intptr_t)t); } if (g_ion_debug_timer) { ionizer_stop_timing(); } ion_symbol_table_free_system_table(); if (non_argv) free(non_argv); return err; }