egad, it's really working

This commit is contained in:
David Rose 2009-06-24 06:40:30 +00:00
parent 36eb5bc08a
commit 42704cd357
6 changed files with 59 additions and 39 deletions

View File

@ -255,7 +255,8 @@ 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";
nout << "Unexpected feed_url_stream for " << unique_id << "\n"
<< flush;
// Don't know this request.
return false;
}
@ -267,7 +268,7 @@ feed_url_stream(int unique_id,
if (!download_ok || download->get_download_finished()) {
// All done.
nout << "completed download " << unique_id << "\n";
nout << "completed download " << unique_id << "\n" << flush;
_downloads.erase(di);
delete download;
}
@ -313,7 +314,7 @@ start_download(P3DDownload *download) {
assert(inserted);
nout << "beginning download " << download_id << ": " << download->get_url()
<< "\n";
<< "\n" << flush;
P3D_request *request = new P3D_request;
request->_instance = this;

View File

@ -35,7 +35,6 @@ P3DInstanceManager *P3DInstanceManager::_global_ptr;
////////////////////////////////////////////////////////////////////
P3DInstanceManager::
P3DInstanceManager() {
nout << "creating instance manager\n";
_is_initialized = false;
_unique_session_index = 0;
@ -93,10 +92,10 @@ initialize() {
_platform = P3D_PLUGIN_PLATFORM;
nout << "_root_dir = " << _root_dir << ", download = "
<< _download_url << "\n";
<< _download_url << "\n" << flush;
if (_root_dir.empty()) {
nout << "Could not find root directory.\n";
nout << "Could not find root directory.\n" << flush;
return false;
}
@ -131,7 +130,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";
nout << "Instance started twice: " << inst << "\n" << flush;
return false;
}
inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens));
@ -159,6 +158,7 @@ start_instance(P3DInstance *inst, const string &p3d_filename,
////////////////////////////////////////////////////////////////////
void P3DInstanceManager::
finish_instance(P3DInstance *inst) {
nout << "finish_instance(" << inst << ")\n" << flush;
Instances::iterator ii;
ii = _instances.find(inst);
assert(ii != _instances.end());
@ -541,7 +541,7 @@ find_root_dir() const {
}
// Couldn't find a directory. Bail.
nout << "Couldn't find a root directory.\n";
nout << "Couldn't find a root directory.\n" << flush;
return string();
#else // _WIN32

View File

@ -86,13 +86,16 @@ P3DSession::
// Also close the pipe, to help underscore the point.
_pipe_write.close();
_pipe_read.close();
// Closing _pipe_read before the thread has stopped can result in
// a hang. Don't need to close it yet.
// _pipe_read.close();
#ifdef _WIN32
// Now give the process a chance to terminate itself cleanly.
if (WaitForSingleObject(_p3dpython_handle, 2000) == WAIT_TIMEOUT) {
// It didn't shut down cleanly, so kill it the hard way.
nout << "Terminating process.\n";
nout << "Terminating process.\n" << flush;
TerminateProcess(_p3dpython_handle, 2);
}
@ -298,18 +301,18 @@ start_p3dpython() {
#endif
if (!started_p3dpython) {
nout << "Failed to create process.\n";
nout << "Failed to create process.\n" << flush;
return;
}
_p3dpython_running = true;
nout << "Created child process\n";
nout << "Created child process\n" << flush;
if (!_pipe_read) {
nout << "unable to open read pipe\n";
nout << "unable to open read pipe\n" << flush;
}
if (!_pipe_write) {
nout << "unable to open write pipe\n";
nout << "unable to open write pipe\n" << flush;
}
spawn_read_thread();
@ -366,7 +369,6 @@ join_read_thread() {
return;
}
nout << "session waiting for thread\n";
_read_thread_continue = false;
_pipe_read.close();
@ -379,7 +381,6 @@ join_read_thread() {
void *return_val;
pthread_join(_read_thread, &return_val);
#endif
nout << "session done waiting for thread\n";
_started_read_thread = false;
}
@ -391,20 +392,20 @@ join_read_thread() {
////////////////////////////////////////////////////////////////////
void P3DSession::
rt_thread_run() {
nout << "session thread reading.\n";
nout << "session thread reading.\n" << flush;
while (_read_thread_continue) {
TiXmlDocument *doc = new TiXmlDocument;
_pipe_read >> *doc;
if (!_pipe_read || _pipe_read.eof()) {
// Some error on reading. Abort.
nout << "Error on session reading.\n";
nout << "Error on session reading.\n" << flush;
rt_terminate();
return;
}
// Successfully read an XML document.
nout << "Session got request: " << *doc << "\n";
nout << "Session got request: " << *doc << "\n" << flush;
// TODO: feed the request up to the parent.
delete doc;
@ -486,7 +487,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";
nout << "failed to create pipe\n" << flush;
} else {
// Make sure the right end of the pipe is inheritable.
SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@ -495,7 +496,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";
nout << "failed to create pipe\n" << flush;
} else {
// Make sure the right end of the pipe is inheritable.
SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@ -515,7 +516,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";
nout << "Unable to open " << output_filename << "\n" << flush;
}
}
@ -614,7 +615,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";
nout << "Unable to open " << output_filename << "\n" << flush;
} else {
dup2(logfile_fd, STDERR_FILENO);
close(logfile_fd);
@ -629,7 +630,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";
nout << "Could not chdir to " << start_dir << "\n" << flush;
_exit(1);
}
@ -645,7 +646,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";
nout << "Failed to exec " << program << "\n" << flush;
_exit(1);
}

View File

@ -68,7 +68,7 @@ PPInstance(NPMIMEType pluginType, NPP instance, uint16 mode,
PPInstance::
~PPInstance() {
logfile
<< "destructing " << this << "\n" << flush;
<< "destructing " << this << ", " << _p3d_inst << "\n" << flush;
if (_p3d_inst != NULL) {
P3D_instance_finish(_p3d_inst);
@ -124,6 +124,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) {
if (!_started_instance_data) {
stream->notifyData = new PPDownloadRequest(PPDownloadRequest::RT_instance_data);
*stype = NP_ASFILEONLY;
_started_instance_data = true;
return NPERR_NO_ERROR;
}
@ -433,8 +434,12 @@ send_window() {
parent_window._hwnd = (HWND)(_window.window);
#endif
// Actually, we set up the window starting at (0, 0), instead of
// whatever Mozilla tells us, because the window handle we get is a
// specially created window that is already aligned to where we want
// our window to be.
P3D_instance_setup_window
(_p3d_inst, P3D_WT_toplevel,
_window.x, _window.y, _window.width, _window.height,
(_p3d_inst, P3D_WT_embedded,
0, 0, _window.width, _window.height,
parent_window);
}

View File

@ -213,8 +213,12 @@ NP_Shutdown(void) {
RELEASE_LOCK(_timer_lock);
DESTROY_LOCK(_timer_lock);
logfile << "unloading plugin\n" << flush;
unload_plugin();
logfile << "done shutdown\n" << flush;
// Not clear whether there's a return value or not. Some versions
// of the API have different opinions on this.
return NPERR_NO_ERROR;

View File

@ -101,7 +101,7 @@ class VFSLoader:
code = self._read_code()
if not code:
raise ImportError
raise ImportError, 'No Python code in %s' % (fullname)
mod = sys.modules.setdefault(fullname, new.module(fullname))
mod.__file__ = self.filename.cStr()
@ -128,7 +128,7 @@ class VFSLoader:
def _read_source(self):
""" Returns the Python source for this file, if it is
available, or None if it is not. """
available, or None if it is not. May raise IOError. """
if self.fileType == FTPythonCompiled or \
self.fileType == FTCompiledModule:
@ -136,10 +136,7 @@ class VFSLoader:
filename = Filename(self.filename)
filename.setExtension('py')
try:
file = open(filename, 'rU')
except IOError:
return None
file = open(filename, 'rU')
return file.read()
def _import_compiled_module(self, fullname):
@ -179,14 +176,16 @@ class VFSLoader:
def _read_code(self):
""" Returns the Python compiled code object for this file, if
it is available, or None if it is not. """
it is available, or None if it is not. May raise IOError,
ValueError, SyntaxError, or a number of other errors generated
by the low-level system. """
if self.fileType == FTPythonCompiled:
# It's a pyc file; just read it directly.
pycVfile = vfs.getFile(self.filename, False)
if pycVfile:
return self._loadPyc(pycVfile, None)
return None
raise IOError, 'Could not read %s' % (self.filename)
elif self.fileType == FTCompiledModule:
return None
@ -205,7 +204,10 @@ class VFSLoader:
code = None
if t_pyc and t_pyc >= self.timestamp:
code = self._loadPyc(pycVfile, self.timestamp)
try:
code = self._loadPyc(pycVfile, self.timestamp)
except ValueError:
code = None
if not code:
source = self._read_source()
@ -216,20 +218,27 @@ class VFSLoader:
return code
def _loadPyc(self, vfile, timestamp):
""" Reads and returns the marshal data from a .pyc file. """
""" Reads and returns the marshal data from a .pyc file.
Raises ValueError if there is a problem. """
code = None
f = open(vfile, 'rb')
if f.read(4) == imp.get_magic():
t = struct.unpack('<I', f.read(4))[0]
if not timestamp or t == timestamp:
code = marshal.loads(f.read())
else:
raise ValueError, 'Timestamp wrong on %s' % (vfile)
else:
raise ValueError, 'Bad magic number in %s' % (vfile)
f.close()
return code
def _compile(self, filename, source):
""" Compiles the Python source code to a code object and
attempts to write it to an appropriate .pyc file. """
attempts to write it to an appropriate .pyc file. May raise
SyntaxError or other errors generated by the compiler. """
if source and source[-1] != '\n':
source = source + '\n'