diff --git a/direct/src/plugin/binaryXml.cxx b/direct/src/plugin/binaryXml.cxx index d0dbcb0747..e46abd54ea 100644 --- a/direct/src/plugin/binaryXml.cxx +++ b/direct/src/plugin/binaryXml.cxx @@ -104,7 +104,7 @@ write_xml_node(ostream &out, TiXmlNode *xnode) { // return value. Returns NULL on error. //////////////////////////////////////////////////////////////////// static TiXmlNode * -read_xml_node(istream &in) { +read_xml_node(istream &in, char *&buffer, size_t &buffer_length) { NodeType type = (NodeType)in.get(); if (type == NT_unknown) { return NULL; @@ -116,10 +116,14 @@ read_xml_node(istream &in) { return NULL; } - char *buffer = new char[value_length]; + if (value_length > buffer_length) { + delete[] buffer; + buffer_length = value_length; + buffer = new char[buffer_length]; + } + in.read(buffer, value_length); string value(buffer, value_length); - delete[] buffer; TiXmlNode *xnode = NULL; if (type == NT_element) { @@ -147,10 +151,14 @@ read_xml_node(istream &in) { return NULL; } - buffer = new char[name_length]; + if (name_length > buffer_length) { + delete[] buffer; + buffer_length = name_length; + buffer = new char[buffer_length]; + } + in.read(buffer, name_length); string name(buffer, name_length); - delete[] buffer; size_t value_length; in.read((char *)&value_length, sizeof(value_length)); @@ -159,10 +167,14 @@ read_xml_node(istream &in) { return NULL; } - buffer = new char[value_length]; + if (value_length > buffer_length) { + delete[] buffer; + buffer_length = value_length; + buffer = new char[buffer_length]; + } + in.read(buffer, value_length); string value(buffer, value_length); - delete[] buffer; xelement->SetAttribute(name, value); @@ -175,7 +187,7 @@ read_xml_node(istream &in) { while (got_child && in && !in.eof()) { // We have a child. - TiXmlNode *xchild = read_xml_node(in); + TiXmlNode *xchild = read_xml_node(in, buffer, buffer_length); if (xchild != NULL) { xnode->LinkEndChild(xchild); } @@ -201,6 +213,11 @@ write_xml(ostream &out, TiXmlDocument *doc, ostream &logfile) { #else // Formatted ASCII write. + + // We need a declaration to write it safely. + TiXmlDeclaration decl("1.0", "utf-8", ""); + doc->InsertBeforeChild(doc->FirstChild(), decl); + out << *doc; #endif @@ -232,7 +249,10 @@ TiXmlDocument * read_xml(istream &in, ostream &logfile) { #if DO_BINARY_XML // binary read. - TiXmlNode *xnode = read_xml_node(in); + size_t buffer_length = 128; + char *buffer = new char[buffer_length]; + TiXmlNode *xnode = read_xml_node(in, buffer, buffer_length); + delete[] buffer; if (xnode == NULL) { return NULL; } diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 6b682d3ac2..6e858cd26f 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -94,7 +94,7 @@ P3DInstance:: P3D_OBJECT_XDECREF(_browser_script_object); nout << "panda_script_object ref = " - << _panda_script_object->_ref_count << "\n" << flush; + << _panda_script_object->_ref_count << "\n"; P3D_OBJECT_DECREF(_panda_script_object); // Tell all of the packages that we're no longer in business for @@ -208,7 +208,6 @@ set_wparams(const P3DWindowParams &wparams) { // Update the instance in the sub-process. if (_session != NULL) { TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "setup_window"); xcommand->SetAttribute("instance_id", get_instance_id()); @@ -247,7 +246,6 @@ set_wparams(const P3DWindowParams &wparams) { } #endif // __APPLE__ - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); xcommand->LinkEndChild(xwparams); @@ -466,8 +464,7 @@ feed_url_stream(int unique_id, size_t this_data_size) { Downloads::iterator di = _downloads.find(unique_id); if (di == _downloads.end()) { - nout << "Unexpected feed_url_stream for " << unique_id << "\n" - << flush; + nout << "Unexpected feed_url_stream for " << unique_id << "\n"; // Don't know this request. return false; } @@ -696,7 +693,6 @@ make_xml() { void P3DInstance:: send_browser_script_object() { TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "pyobj"); xcommand->SetAttribute("op", "set_browser_script_object"); @@ -704,7 +700,6 @@ send_browser_script_object() { xcommand->LinkEndChild(_session->p3dobj_to_xml(_browser_script_object)); } - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); _session->send_command(doc); @@ -793,17 +788,15 @@ void P3DInstance:: handle_notify_request(const string &message) { // We look for certain notify events that have particular meaning // to this instance. - nout << "Got notify: " << message << "\n" << flush; + nout << "Got notify: " << message << "\n"; if (message == "onpythonload") { // Once Python is up and running, we can get the actual toplevel // object from the Python side, and merge it with our own. TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "pyobj"); xcommand->SetAttribute("op", "get_panda_script_object"); - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); TiXmlDocument *response = _session->command_and_response(doc); @@ -859,12 +852,10 @@ handle_script_request(const string &operation, P3D_object *object, bool needs_response, int unique_id) { TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "script_response"); xcommand->SetAttribute("unique_id", unique_id); - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); if (operation == "get_property") { diff --git a/direct/src/plugin/p3dInstanceManager.cxx b/direct/src/plugin/p3dInstanceManager.cxx index 5143fcb921..4ba7e08e0a 100644 --- a/direct/src/plugin/p3dInstanceManager.cxx +++ b/direct/src/plugin/p3dInstanceManager.cxx @@ -85,7 +85,7 @@ P3DInstanceManager:: << " " << _none_object->_ref_count << " " << _true_object->_ref_count << " " << _false_object->_ref_count - << "\n" << flush; + << "\n"; /* assert(_undefined_object->_ref_count == 1); @@ -119,10 +119,10 @@ initialize() { _platform = P3D_PLUGIN_PLATFORM; nout << "_root_dir = " << _root_dir << ", download = " - << _download_url << "\n" << flush; + << _download_url << "\n"; if (_root_dir.empty()) { - nout << "Could not find root directory.\n" << flush; + nout << "Could not find root directory.\n"; return false; } @@ -158,7 +158,7 @@ bool P3DInstanceManager:: start_instance(P3DInstance *inst, const string &p3d_filename, const P3D_token tokens[], size_t num_tokens) { if (inst->is_started()) { - nout << "Instance started twice: " << inst << "\n" << flush; + nout << "Instance started twice: " << inst << "\n"; return false; } inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens)); diff --git a/direct/src/plugin/p3dObject.cxx b/direct/src/plugin/p3dObject.cxx index a6b2fa645c..c151daad84 100644 --- a/direct/src/plugin/p3dObject.cxx +++ b/direct/src/plugin/p3dObject.cxx @@ -112,7 +112,7 @@ static void generic_finish(P3D_object *object) { // You must override finish(), though, otherwise it's a leak. The // core API has no idea how to delete your object. - nout << "Warning! default object_finish() method does nothing; object will leak.\n" << flush; + nout << "Warning! default object_finish() method does nothing; object will leak.\n"; } static P3D_object_type diff --git a/direct/src/plugin/p3dOsxSplashWindow.cxx b/direct/src/plugin/p3dOsxSplashWindow.cxx index 207af6e700..4a87e33360 100644 --- a/direct/src/plugin/p3dOsxSplashWindow.cxx +++ b/direct/src/plugin/p3dOsxSplashWindow.cxx @@ -257,31 +257,33 @@ paint_window() { PaintRect(&rdone); EraseRect(&rneed); - RGBColor black = { 0, 0, 0 }; - RGBForeColor(&black); + if (!_install_label.empty()) { + RGBColor black = { 0, 0, 0 }; + RGBForeColor(&black); + + TextFont(0); + TextFace(bold); + TextMode(srcOr); + TextSize(0); + + Point numer = { 1, 1 }; + Point denom = { 1, 1 }; + FontInfo font_info; + StdTxMeas(_install_label.size(), _install_label.data(), &numer, &denom, &font_info); + int ascent = font_info.ascent * numer.v / denom.v; + int descent = font_info.descent * numer.v / denom.v; - TextFont(0); - TextFace(bold); - TextMode(srcOr); - TextSize(0); + int text_width = TextWidth(_install_label.data(), 0, _install_label.size()); + int text_x = (win_width - text_width) / 2; + int text_y = bar_y - descent - 8; + + Rect rtext = { text_y - ascent - 2, text_x - 2, + text_y + descent + 2, text_x + text_width + 2 }; + EraseRect(&rtext); - Point numer = { 1, 1 }; - Point denom = { 1, 1 }; - FontInfo font_info; - StdTxMeas(_install_label.size(), _install_label.data(), &numer, &denom, &font_info); - int ascent = font_info.ascent * numer.v / denom.v; - int descent = font_info.descent * numer.v / denom.v; - - int text_width = TextWidth(_install_label.data(), 0, _install_label.size()); - int text_x = (win_width - text_width) / 2; - int text_y = bar_y - descent - 8; - - Rect rtext = { text_y - ascent - 2, text_x - 2, - text_y + descent + 2, text_x + text_width + 2 }; - EraseRect(&rtext); - - MoveTo(text_x, text_y); - DrawText(_install_label.data(), 0, _install_label.size()); + MoveTo(text_x, text_y); + DrawText(_install_label.data(), 0, _install_label.size()); + } if (portChanged) { QDSwapPort(portSave, NULL); diff --git a/direct/src/plugin/p3dPythonObject.cxx b/direct/src/plugin/p3dPythonObject.cxx index f2136d596e..638e8a5f77 100644 --- a/direct/src/plugin/p3dPythonObject.cxx +++ b/direct/src/plugin/p3dPythonObject.cxx @@ -235,7 +235,6 @@ P3D_object *P3DPythonObject:: call(const string &method_name, bool needs_response, P3D_object *params[], int num_params) { TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "pyobj"); xcommand->SetAttribute("op", "call"); @@ -252,7 +251,6 @@ call(const string &method_name, bool needs_response, xcommand->LinkEndChild(xparams); } - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); // If no response is requested, send the command out in a vacuum, diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index 266f12fd6f..1151f5477a 100755 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -335,10 +335,8 @@ handle_command(TiXmlDocument *doc) { if (needs_response) { // Better send a response. TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xresponse = new TiXmlElement("response"); xresponse->SetAttribute("response_id", want_response_id); - doc.LinkEndChild(decl); doc.LinkEndChild(xresponse); write_xml(_pipe_write, &doc, nout); } @@ -359,10 +357,8 @@ void P3DPythonRun:: handle_pyobj_command(TiXmlElement *xcommand, bool needs_response, int want_response_id) { TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xresponse = new TiXmlElement("response"); xresponse->SetAttribute("response_id", want_response_id); - doc.LinkEndChild(decl); doc.LinkEndChild(xresponse); const char *op = xcommand->Attribute("op"); @@ -601,7 +597,7 @@ handle_pyobj_command(TiXmlElement *xcommand, bool needs_response, //////////////////////////////////////////////////////////////////// void P3DPythonRun:: check_comm() { - // nout << ":" << flush; + // nout << ":"; ACQUIRE_LOCK(_commands_lock); while (!_commands.empty()) { TiXmlDocument *doc = _commands.front(); @@ -647,7 +643,7 @@ st_check_comm(PyObject *, PyObject *args) { //////////////////////////////////////////////////////////////////// TiXmlDocument *P3DPythonRun:: wait_script_response(int response_id) { - // nout << "waiting script_response " << response_id << "\n" << flush; + // nout << "waiting script_response " << response_id << "\n"; while (true) { Commands::iterator ci; @@ -694,7 +690,7 @@ wait_script_response(int response_id) { // This is the response we were waiting for. _responses.erase(ci); _responses_lock.release(); - // nout << "got script_response " << unique_id << "\n" << flush; + // nout << "got script_response " << unique_id << "\n"; return doc; } } @@ -716,7 +712,7 @@ wait_script_response(int response_id) { PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD); #endif // _WIN32 - // nout << "." << flush; + // nout << "."; // It hasn't shown up yet. Give the sub-thread a chance to // process the input and append it to the queue. @@ -771,11 +767,9 @@ py_request_func(PyObject *args) { } TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xrequest = new TiXmlElement("request"); xrequest->SetAttribute("instance_id", instance_id); xrequest->SetAttribute("rtype", request_type); - doc.LinkEndChild(decl); doc.LinkEndChild(xrequest); if (strcmp(request_type, "notify") == 0) { diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index c4dacb1392..3d94851086 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -104,10 +104,8 @@ shutdown() { if (_p3dpython_running) { // Tell the process we're going away. TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "exit"); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -124,7 +122,7 @@ shutdown() { // Now give the process a chance to terminate itself cleanly. if (WaitForSingleObject(_p3dpython_handle, max_wait_ms) == WAIT_TIMEOUT) { // It didn't shut down cleanly, so kill it the hard way. - nout << "Force-killing python process.\n" << flush; + nout << "Force-killing python process.\n"; TerminateProcess(_p3dpython_handle, 2); } @@ -153,7 +151,7 @@ shutdown() { if (elapsed > max_wait_ms) { // Tired of waiting. Kill the process. nout << "Force-killing python process, pid " << _p3dpython_pid - << "\n" << flush; + << "\n"; kill(_p3dpython_pid, SIGKILL); start_ms = now_ms; } @@ -218,12 +216,10 @@ start_instance(P3DInstance *inst) { assert(inserted); TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "start_instance"); TiXmlElement *xinstance = inst->make_xml(); - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); xcommand->LinkEndChild(xinstance); @@ -252,12 +248,10 @@ start_instance(P3DInstance *inst) { void P3DSession:: terminate_instance(P3DInstance *inst) { TiXmlDocument *doc = new TiXmlDocument; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "terminate_instance"); xcommand->SetAttribute("instance_id", inst->get_instance_id()); - doc->LinkEndChild(decl); doc->LinkEndChild(xcommand); send_command(doc); @@ -621,11 +615,9 @@ void P3DSession:: drop_pyobj(int object_id) { if (_p3dpython_running) { TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "drop_pyobj"); xcommand->SetAttribute("object_id", object_id); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); } @@ -735,27 +727,25 @@ start_p3dpython() { #endif if (!started_p3dpython) { - nout << "Failed to create process.\n" << flush; + nout << "Failed to create process.\n"; return; } _p3dpython_running = true; if (!_pipe_read) { - nout << "unable to open read pipe\n" << flush; + nout << "unable to open read pipe\n"; } if (!_pipe_write) { - nout << "unable to open write pipe\n" << flush; + nout << "unable to open write pipe\n"; } spawn_read_thread(); // The very first command we send to the process is its session_id. TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "init"); xcommand->SetAttribute("session_id", _session_id); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -822,7 +812,7 @@ rt_thread_run() { rt_handle_request(doc); } - logfile << "Exiting rt_thread_run in " << this << "\n" << flush; + logfile << "Exiting rt_thread_run in " << this << "\n"; } //////////////////////////////////////////////////////////////////// @@ -918,7 +908,7 @@ win_create_process(const string &program, const string &start_dir, // Create the pipe to the process. if (!CreatePipe(&r_to, &w_to, NULL, 0)) { - nout << "failed to create pipe\n" << flush; + nout << "failed to create pipe\n"; } else { // Make sure the right end of the pipe is inheritable. SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); @@ -927,7 +917,7 @@ win_create_process(const string &program, const string &start_dir, // Create the pipe from the process. if (!CreatePipe(&r_from, &w_from, NULL, 0)) { - nout << "failed to create pipe\n" << flush; + nout << "failed to create pipe\n"; } else { // Make sure the right end of the pipe is inheritable. SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); @@ -947,7 +937,7 @@ win_create_process(const string &program, const string &start_dir, error_handle = handle; SetHandleInformation(error_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); } else { - nout << "Unable to open " << output_filename << "\n" << flush; + nout << "Unable to open " << output_filename << "\n"; } } @@ -1046,7 +1036,7 @@ posix_create_process(const string &program, const string &start_dir, int logfile_fd = open(output_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666); if (logfile_fd < 0) { - nout << "Unable to open " << output_filename << "\n" << flush; + nout << "Unable to open " << output_filename << "\n"; } else { dup2(logfile_fd, STDERR_FILENO); close(logfile_fd); @@ -1061,7 +1051,7 @@ posix_create_process(const string &program, const string &start_dir, close(from_fd[0]); if (chdir(start_dir.c_str()) < 0) { - nout << "Could not chdir to " << start_dir << "\n" << flush; + nout << "Could not chdir to " << start_dir << "\n"; _exit(1); } @@ -1077,7 +1067,7 @@ posix_create_process(const string &program, const string &start_dir, ptrs.push_back((char *)NULL); execle(program.c_str(), program.c_str(), (char *)0, &ptrs[0]); - nout << "Failed to exec " << program << "\n" << flush; + nout << "Failed to exec " << program << "\n"; _exit(1); } diff --git a/direct/src/plugin/p3dSplashWindow.cxx b/direct/src/plugin/p3dSplashWindow.cxx index cbe4fbfd63..03b8cb3267 100755 --- a/direct/src/plugin/p3dSplashWindow.cxx +++ b/direct/src/plugin/p3dSplashWindow.cxx @@ -144,8 +144,7 @@ read_image(const string &image_filename, bool image_filename_temp, // ever support. FILE *fp = fopen(image_filename.c_str(), "rb"); if (fp == NULL) { - nout << "Couldn't open splash file image: " << image_filename << "\n" - << flush; + nout << "Couldn't open splash file image: " << image_filename << "\n"; if (image_filename_temp) { unlink(image_filename.c_str()); } @@ -164,8 +163,7 @@ read_image(const string &image_filename, bool image_filename_temp, // Establish the setjmp return context for my_error_exit to use if (setjmp(jerr.setjmp_buffer)) { // If we get here, the JPEG code has signaled an error. - nout << "JPEG error decoding " << image_filename << "\n" - << flush; + nout << "JPEG error decoding " << image_filename << "\n"; // We need to clean up the JPEG object, close the input file, and return. jpeg_destroy_decompress(&cinfo); diff --git a/direct/src/plugin/p3dWinSplashWindow.cxx b/direct/src/plugin/p3dWinSplashWindow.cxx index 9341cb3fd6..e0446cf4c5 100755 --- a/direct/src/plugin/p3dWinSplashWindow.cxx +++ b/direct/src/plugin/p3dWinSplashWindow.cxx @@ -560,8 +560,7 @@ update_image_filename(const string &image_filename, bool image_filename_temp) { delete[] new_data; - nout << "Loaded splash file image: " << image_filename << "\n" - << flush; + nout << "Loaded splash file image: " << image_filename << "\n"; } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dX11SplashWindow.cxx b/direct/src/plugin/p3dX11SplashWindow.cxx index 4b03f9d8b0..7cbd5af1f8 100755 --- a/direct/src/plugin/p3dX11SplashWindow.cxx +++ b/direct/src/plugin/p3dX11SplashWindow.cxx @@ -106,12 +106,10 @@ set_image_filename(const string &image_filename, } TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "set_image_filename"); xcommand->SetAttribute("image_filename", image_filename); xcommand->SetAttribute("image_filename_temp", (int)image_filename_temp); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -131,11 +129,9 @@ set_install_label(const string &install_label) { } TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "set_install_label"); xcommand->SetAttribute("install_label", install_label); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -154,11 +150,9 @@ set_install_progress(double install_progress) { } TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "set_install_progress"); xcommand->SetDoubleAttribute("install_progress", install_progress); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -223,10 +217,8 @@ stop_subprocess() { // Ask the subprocess to stop. TiXmlDocument doc; - TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); TiXmlElement *xcommand = new TiXmlElement("command"); xcommand->SetAttribute("cmd", "exit"); - doc.LinkEndChild(decl); doc.LinkEndChild(xcommand); write_xml(_pipe_write, &doc, nout); @@ -257,7 +249,7 @@ stop_subprocess() { if (elapsed > max_wait_ms) { // Tired of waiting. Kill the process. nout << "Force-killing splash window process, pid " << _subprocess_pid - << "\n" << flush; + << "\n"; kill(_subprocess_pid, SIGKILL); start_ms = now_ms; } diff --git a/direct/src/plugin/p3d_plugin.cxx b/direct/src/plugin/p3d_plugin.cxx index 49a96c9957..95c66e80b0 100644 --- a/direct/src/plugin/p3d_plugin.cxx +++ b/direct/src/plugin/p3d_plugin.cxx @@ -57,6 +57,7 @@ P3D_initialize(int api_version, const char *output_filename) { if (!plugin_output_filename.empty()) { logfile.open(plugin_output_filename.c_str(), ios::out | ios::trunc); if (logfile) { + logfile.setf(ios::unitbuf); nout_stream = &logfile; } } diff --git a/direct/src/plugin_npapi/nppanda3d_common.h b/direct/src/plugin_npapi/nppanda3d_common.h index 57f7726ba6..0d06b65311 100644 --- a/direct/src/plugin_npapi/nppanda3d_common.h +++ b/direct/src/plugin_npapi/nppanda3d_common.h @@ -28,8 +28,9 @@ using namespace std; -// Appears in nppanda3d_startup.cxx. -extern ofstream logfile; +// Appears in startup.cxx. +extern ostream *nout_stream; +#define nout (*nout_stream) #ifdef _WIN32 diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 77891edf5b..b47094f3e2 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -209,7 +209,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) { default: // Don't know what this is. - logfile << "Unexpected request " << (int)req->_rtype << "\n"; + nout << "Unexpected request " << (int)req->_rtype << "\n"; } return NPERR_GENERIC_ERROR; @@ -224,7 +224,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) { int PPInstance:: write_stream(NPStream *stream, int offset, int len, void *buffer) { if (stream->notifyData == NULL) { - logfile << "Unexpected write_stream on " << stream->url << "\n"; + nout << "Unexpected write_stream on " << stream->url << "\n"; return 0; } @@ -237,7 +237,7 @@ write_stream(NPStream *stream, int offset, int len, void *buffer) { return len; default: - logfile << "Unexpected write_stream on " << stream->url << "\n"; + nout << "Unexpected write_stream on " << stream->url << "\n"; break; } @@ -254,7 +254,7 @@ write_stream(NPStream *stream, int offset, int len, void *buffer) { NPError PPInstance:: destroy_stream(NPStream *stream, NPReason reason) { if (stream->notifyData == NULL) { - logfile << "Unexpected destroy_stream on " << stream->url << "\n"; + nout << "Unexpected destroy_stream on " << stream->url << "\n"; return NPERR_GENERIC_ERROR; } @@ -301,7 +301,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) { // We shouldn't have gotten here without notifying the stream // unless the stream never got started (and hence we never // called destroy_stream(). - logfile << "Failure starting stream\n" << flush; + nout << "Failure starting stream\n"; assert(reason != NPRES_DONE); P3D_instance_feed_url_stream(_p3d_inst, req->_user_id, @@ -312,7 +312,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) { case PPDownloadRequest::RT_contents_file: if (reason != NPRES_DONE) { - logfile << "Failure downloading " << url << "\n"; + nout << "Failure downloading " << url << "\n"; // TODO: fail } break; @@ -333,7 +333,7 @@ url_notify(const char *url, NPReason reason, void *notifyData) { void PPInstance:: stream_as_file(NPStream *stream, const char *fname) { if (stream->notifyData == NULL) { - logfile << "Unexpected stream_as_file on " << stream->url << "\n"; + nout << "Unexpected stream_as_file on " << stream->url << "\n"; return; } @@ -454,7 +454,7 @@ handle_request(P3D_request *request) { default: // Some request types are not handled. - logfile << "Unhandled request: " << request->_request_type << "\n"; + nout << "Unhandled request: " << request->_request_type << "\n"; break; }; @@ -724,8 +724,8 @@ read_contents_file(const string &filename) { } // Couldn't find the coreapi package description. - logfile << "No coreapi package defined in contents file for " - << P3D_PLUGIN_PLATFORM << "\n" << flush; + nout << "No coreapi package defined in contents file for " + << P3D_PLUGIN_PLATFORM << "\n"; return false; } @@ -766,7 +766,7 @@ downloaded_file(PPDownloadRequest *req, const string &filename) { // Now we have the contents.xml file. Read this to get the // filename and md5 hash of our core API DLL. if (!read_contents_file(filename)) { - logfile << "Unable to read contents file\n"; + nout << "Unable to read contents file\n"; // TODO: fail } break; @@ -794,7 +794,7 @@ downloaded_file(PPDownloadRequest *req, const string &filename) { default: // Don't know what this is. - logfile << "Unexpected downloaded file, type " << (int)req->_rtype << "\n"; + nout << "Unexpected downloaded file, type " << (int)req->_rtype << "\n"; } } @@ -879,7 +879,7 @@ downloaded_plugin(const string &filename) { } if (!out) { - logfile << "Could not write " << pathname << "\n"; + nout << "Could not write " << pathname << "\n"; // TODO: fail return; } @@ -892,7 +892,7 @@ downloaded_plugin(const string &filename) { return; } - logfile << "After download, " << pathname << " is no good.\n"; + nout << "After download, " << pathname << " is no good.\n"; // TODO: fail } @@ -920,7 +920,7 @@ do_load_plugin() { #endif // P3D_PLUGIN_P3D_PLUGIN if (!load_plugin(pathname)) { - logfile << "Unable to launch core API in " << pathname << "\n" << flush; + nout << "Unable to launch core API in " << pathname << "\n"; return; } create_instance(); @@ -960,7 +960,7 @@ create_instance() { P3D_instance_set_browser_script_object(_p3d_inst, pobj); browser->releaseobject(window_object); } else { - logfile << "Couldn't get window_object\n" << flush; + nout << "Couldn't get window_object\n"; } if (_script_object != NULL) { diff --git a/direct/src/plugin_npapi/startup.cxx b/direct/src/plugin_npapi/startup.cxx index f79786860a..a2227d8818 100644 --- a/direct/src/plugin_npapi/startup.cxx +++ b/direct/src/plugin_npapi/startup.cxx @@ -20,7 +20,8 @@ #include #endif -ofstream logfile; +static ofstream logfile; +ostream *nout_stream = &logfile; NPNetscapeFuncs *browser; @@ -47,6 +48,7 @@ open_logfile() { #endif // _WIN32 } logfile.open(logfilename.c_str()); + logfile.setf(ios::unitbuf); logfile_is_open = true; } } @@ -85,7 +87,7 @@ NP_GetValue(void*, NPPVariable variable, void* value) { *((PRBool *)value) = PR_FALSE; break; default: - logfile << "Ignoring GetValue request " << variable << "\n" << flush; + nout << "Ignoring GetValue request " << variable << "\n"; return NPERR_INVALID_PARAM; } @@ -115,9 +117,9 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs, browser = browserFuncs; open_logfile(); - logfile << "initializing\n" << flush; + nout << "initializing\n"; - logfile << "browserFuncs = " << browserFuncs << "\n" << flush; + nout << "browserFuncs = " << browserFuncs << "\n"; // On Unix, we have to use the pluginFuncs argument // to pass our entry points. @@ -141,8 +143,7 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs, NPError OSCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) { open_logfile(); - logfile << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n" - << flush; + nout << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n"; pluginFuncs->version = 11; pluginFuncs->size = sizeof(pluginFuncs); pluginFuncs->newp = NPP_New; @@ -170,7 +171,7 @@ NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) { //////////////////////////////////////////////////////////////////// NPError OSCALL NP_Shutdown(void) { - logfile << "shutdown\n" << flush; + nout << "shutdown\n"; unload_plugin(); // Not clear whether there's a return value or not. Some versions @@ -186,7 +187,7 @@ NP_Shutdown(void) { NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved) { - logfile << "new instance\n" << flush; + nout << "new instance\n"; PPInstance *inst = new PPInstance(pluginType, instance, mode, argc, argn, argv, saved); @@ -210,8 +211,8 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, //////////////////////////////////////////////////////////////////// NPError NPP_Destroy(NPP instance, NPSavedData **save) { - logfile << "destroy instance " << instance << "\n"; - logfile << "save = " << (void *)save << "\n" << flush; + nout << "destroy instance " << instance << "\n"; + nout << "save = " << (void *)save << "\n"; // (*save) = NULL; delete (PPInstance *)(instance->pdata); instance->pdata = NULL; @@ -229,9 +230,9 @@ NPP_Destroy(NPP instance, NPSavedData **save) { //////////////////////////////////////////////////////////////////// NPError NPP_SetWindow(NPP instance, NPWindow *window) { - logfile << "SetWindow " << window->x << ", " << window->y + nout << "SetWindow " << window->x << ", " << window->y << ", " << window->width << ", " << window->height - << "\n" << flush; + << "\n"; PPInstance *inst = (PPInstance *)(instance->pdata); assert(inst != NULL); @@ -251,10 +252,10 @@ NPP_SetWindow(NPP instance, NPWindow *window) { NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype) { - logfile << "NewStream " << type << ", " << stream->url - << ", " << stream->end - << ", notifyData = " << stream->notifyData - << "\n" << flush; + nout << "NewStream " << type << ", " << stream->url + << ", " << stream->end + << ", notifyData = " << stream->notifyData + << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); assert(inst != NULL); @@ -269,11 +270,11 @@ NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, //////////////////////////////////////////////////////////////////// NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) { - logfile << "DestroyStream " << stream->url - << ", " << stream->end - << ", notifyData = " << stream->notifyData - << ", reason = " << reason - << "\n" << flush; + nout << "DestroyStream " << stream->url + << ", " << stream->end + << ", notifyData = " << stream->notifyData + << ", reason = " << reason + << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); @@ -304,7 +305,7 @@ NPP_WriteReady(NPP instance, NPStream *stream) { int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) { - // logfile << "Write " << stream->url << ", " << len << "\n" << flush; + // nout << "Write " << stream->url << ", " << len << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); assert(inst != NULL); @@ -321,10 +322,10 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset, //////////////////////////////////////////////////////////////////// void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) { - logfile << "StreamAsFile " << stream->url - << ", " << stream->end - << ", notifyData = " << stream->notifyData - << "\n" << flush; + nout << "StreamAsFile " << stream->url + << ", " << stream->end + << ", notifyData = " << stream->notifyData + << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); @@ -340,7 +341,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) { //////////////////////////////////////////////////////////////////// void NPP_Print(NPP instance, NPPrint *platformPrint) { - logfile << "Print\n"; + nout << "Print\n"; } //////////////////////////////////////////////////////////////////// @@ -350,7 +351,7 @@ NPP_Print(NPP instance, NPPrint *platformPrint) { //////////////////////////////////////////////////////////////////// int16 NPP_HandleEvent(NPP instance, void *event) { - // logfile << "HandleEvent\n" << flush; + // nout << "HandleEvent\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); @@ -367,10 +368,10 @@ NPP_HandleEvent(NPP instance, void *event) { void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData) { - logfile << "URLNotify: " << url - << ", notifyData = " << notifyData - << ", reason = " << reason - << "\n" << flush; + nout << "URLNotify: " << url + << ", notifyData = " << notifyData + << ", reason = " << reason + << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); @@ -386,7 +387,7 @@ NPP_URLNotify(NPP instance, const char *url, //////////////////////////////////////////////////////////////////// NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { - logfile << "GetValue " << variable << "\n"; + nout << "GetValue " << variable << "\n"; PPInstance::generic_browser_call(); PPInstance *inst = (PPInstance *)(instance->pdata); assert(inst != NULL); @@ -410,7 +411,7 @@ NPP_GetValue(NPP instance, NPPVariable variable, void *value) { //////////////////////////////////////////////////////////////////// NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) { - logfile << "SetValue " << variable << "\n"; + nout << "SetValue " << variable << "\n"; PPInstance::generic_browser_call(); return NPERR_GENERIC_ERROR; }