aboutsummaryrefslogtreecommitdiff
path: root/backends/testdev.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-21 23:44:44 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:07:59 +0100
commit41ac54b253f41df924c350ef63564df8e1d8ad88 (patch)
treea6d8fdcb913b558c4f5ecc698bd82ae1a195705c /backends/testdev.c
parent5ebd67030c4e4bc702d07a3e10c909be4520f170 (diff)
downloadqemu-41ac54b253f41df924c350ef63564df8e1d8ad88.zip
qemu-41ac54b253f41df924c350ef63564df8e1d8ad88.tar.gz
qemu-41ac54b253f41df924c350ef63564df8e1d8ad88.tar.bz2
char: allocate CharDriverState as a single object
Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver. Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init(). The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'backends/testdev.c')
-rw-r--r--backends/testdev.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/backends/testdev.c b/backends/testdev.c
index 2339693..dfa4fe1 100644
--- a/backends/testdev.c
+++ b/backends/testdev.c
@@ -30,7 +30,8 @@
#define BUF_SIZE 32
typedef struct {
- CharDriverState *chr;
+ CharDriverState parent;
+
uint8_t in_buf[32];
int in_buf_used;
} TestdevCharState;
@@ -79,7 +80,7 @@ static int testdev_eat_packet(TestdevCharState *testdev)
/* The other end is writing some data. Store it and try to interpret */
static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)
{
- TestdevCharState *testdev = chr->opaque;
+ TestdevCharState *testdev = (TestdevCharState *)chr;
int tocopy, eaten, orig_len = len;
while (len) {
@@ -102,13 +103,6 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)
return orig_len;
}
-static void testdev_free(struct CharDriverState *chr)
-{
- TestdevCharState *testdev = chr->opaque;
-
- g_free(testdev);
-}
-
static CharDriverState *chr_testdev_init(const CharDriver *driver,
const char *id,
ChardevBackend *backend,
@@ -116,14 +110,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,
bool *be_opened,
Error **errp)
{
- TestdevCharState *testdev;
- CharDriverState *chr;
-
- testdev = g_new0(TestdevCharState, 1);
- testdev->chr = chr = g_new0(CharDriverState, 1);
+ TestdevCharState *testdev = g_new0(TestdevCharState, 1);;
+ CharDriverState *chr = (CharDriverState *)testdev;
chr->driver = driver;
- chr->opaque = testdev;
return chr;
}
@@ -131,10 +121,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,
static void register_types(void)
{
static const CharDriver driver = {
+ .instance_size = sizeof(TestdevCharState),
.kind = CHARDEV_BACKEND_KIND_TESTDEV,
.create = chr_testdev_init,
.chr_write = testdev_write,
- .chr_free = testdev_free,
};
register_char_driver(&driver);
}