- add 2 paragraphs about who the paste buffer is allocated and freed
- a few weeks ago I changed the gui code so that it always made a copy of the clipboard data using new Bit8u[] and passed it into the keyboard code. But I didn't get the keyboard code quite right, and Christophe noticed the incorrect malloc that I had forgotten to remove. I changed it to work as I intended: 1. gui code allocates paste buffer (new), copies clipboard data in 2. gui code passes the buffer to the keyboard code, and forgets about it 3. keyboard code uses the buffer, then frees it when finished (delete) - modified: iodev/keyboard.h iodev/keyboard.cc
This commit is contained in:
parent
5b0df32692
commit
85b6fa7c8d
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: keyboard.cc,v 1.64 2002-09-24 23:09:52 cbothamy Exp $
|
||||
// $Id: keyboard.cc,v 1.65 2002-09-24 23:52:54 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 MandrakeSoft S.A.
|
||||
@ -70,7 +70,7 @@ bx_keyb_c::bx_keyb_c(void)
|
||||
memset( &s, 0, sizeof(s) );
|
||||
BX_KEY_THIS put("KBD");
|
||||
BX_KEY_THIS settype(KBDLOG);
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.64 2002-09-24 23:09:52 cbothamy Exp $"));
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.65 2002-09-24 23:52:54 bdenney Exp $"));
|
||||
}
|
||||
|
||||
bx_keyb_c::~bx_keyb_c(void)
|
||||
@ -110,7 +110,7 @@ bx_keyb_c::resetinternals(Boolean powerup)
|
||||
void
|
||||
bx_keyb_c::init(bx_devices_c *d, bx_cmos_c *cmos)
|
||||
{
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.64 2002-09-24 23:09:52 cbothamy Exp $"));
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.65 2002-09-24 23:52:54 bdenney Exp $"));
|
||||
Bit32u i;
|
||||
|
||||
BX_KEY_THIS devices = d;
|
||||
@ -683,7 +683,7 @@ bx_keyb_c::service_paste_buf ()
|
||||
BX_KEY_THIS pastebuf_ptr++;
|
||||
}
|
||||
// reached end of pastebuf. free the memory it was using.
|
||||
free(BX_KEY_THIS pastebuf);
|
||||
delete [] BX_KEY_THIS pastebuf;
|
||||
BX_KEY_THIS pastebuf = NULL;
|
||||
}
|
||||
|
||||
@ -699,15 +699,12 @@ bx_keyb_c::paste_bytes (Bit8u *bytes, Bit32s length)
|
||||
if (BX_KEY_THIS pastebuf) {
|
||||
BX_ERROR (("previous paste was not completed! %d chars lost",
|
||||
BX_KEY_THIS pastebuf_len - BX_KEY_THIS pastebuf_ptr));
|
||||
free(BX_KEY_THIS pastebuf);
|
||||
delete [] BX_KEY_THIS pastebuf; // free the old paste buffer
|
||||
}
|
||||
BX_KEY_THIS pastebuf = (Bit8u *) malloc (length);
|
||||
memcpy (BX_KEY_THIS pastebuf, bytes, length);
|
||||
BX_KEY_THIS pastebuf = bytes;
|
||||
BX_KEY_THIS pastebuf_ptr = 0;
|
||||
BX_KEY_THIS pastebuf_len = length;
|
||||
BX_KEY_THIS service_paste_buf ();
|
||||
|
||||
delete [] bytes;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: keyboard.h,v 1.15 2002-08-27 19:54:46 bdenney Exp $
|
||||
// $Id: keyboard.h,v 1.16 2002-09-24 23:52:53 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001 MandrakeSoft S.A.
|
||||
@ -190,9 +190,24 @@ private:
|
||||
// The paste buffer does NOT exist in the hardware. It is a bochs
|
||||
// construction that allows the user to "paste" arbitrary length sequences of
|
||||
// keystrokes into the emulated machine. Since the hardware buffer is only
|
||||
// 16 bytes, a very amount of data can be added to the hardware buffer at a
|
||||
// time. The paste buffer keeps track of the bytes that have not yet been
|
||||
// pasted.
|
||||
// 16 bytes, a very small amount of data can be added to the hardware buffer
|
||||
// at a time. The paste buffer keeps track of the bytes that have not yet
|
||||
// been pasted.
|
||||
//
|
||||
// Lifetime of a paste buffer: The paste data comes from the system
|
||||
// clipboard, which must be accessed using platform independent code in the
|
||||
// gui. Because every gui has its own way of managing the clipboard memory
|
||||
// (in X windows, you're supposed to call Xfree for example), in the platform
|
||||
// specific code we make a copy of the clipboard buffer with
|
||||
// "new Bit8u[length]". Then the pointer is passed into
|
||||
// bx_keyb_c::paste_bytes, along with the length. The gui code never touches
|
||||
// the pastebuf again, and does not free it. The keyboard code is
|
||||
// responsible for deallocating the paste buffer using delete [] buf. The
|
||||
// paste buffer is binary data, and it is probably NOT null terminated.
|
||||
//
|
||||
// Summary: A paste buffer is allocated (new) in the platform-specific gui
|
||||
// code, passed to the keyboard model, and is freed (delete[]) when it is no
|
||||
// longer needed.
|
||||
Bit8u *pastebuf; // ptr to bytes to be pasted, or NULL if none in progress
|
||||
Bit32u pastebuf_len; // length of pastebuf
|
||||
Bit32u pastebuf_ptr; // ptr to next byte to be added to hw buffer
|
||||
|
Loading…
Reference in New Issue
Block a user