/* Marshalling and unmarshalling.
- Copyright (C) 2014-2016 Free Software Foundation, Inc.
+ Copyright (C) 2014-2019 Free Software Foundation, Inc.
This file is part of GCC.
return conn->get (result, sizeof (*result));
}
-cc1_plugin::status
-cc1_plugin::unmarshall (connection *conn, enum gcc_c_symbol_kind *result)
-{
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_c_symbol_kind) p;
- return OK;
-}
-
-cc1_plugin::status
-cc1_plugin::unmarshall (connection *conn, enum gcc_c_oracle_request *result)
-{
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_c_oracle_request) p;
- return OK;
-}
-
-cc1_plugin::status
-cc1_plugin::unmarshall (connection *conn, enum gcc_qualifiers *result)
-{
- protocol_int p;
- if (!unmarshall_intlike (conn, &p))
- return FAIL;
- *result = (enum gcc_qualifiers) p;
- return OK;
-}
-
cc1_plugin::status
cc1_plugin::marshall (connection *conn, const char *str)
{
}
cc1_plugin::status
-cc1_plugin::marshall (connection *conn, const gcc_type_array *a)
+cc1_plugin::marshall_array_start (connection *conn, char id,
+ size_t n_elements)
{
- if (!conn->send ('a'))
+ if (!conn->send (id))
return FAIL;
- unsigned long long r = a->n_elements;
+ unsigned long long r = n_elements;
if (!conn->send (&r, sizeof (r)))
return FAIL;
- return conn->send (a->elements, r * sizeof (a->elements[0]));
+ return OK;
}
cc1_plugin::status
-cc1_plugin::unmarshall (connection *conn, gcc_type_array **result)
+cc1_plugin::marshall_array_elmts (connection *conn, size_t n_bytes,
+ void *elements)
+{
+ return conn->send (elements, n_bytes);
+}
+
+cc1_plugin::status
+cc1_plugin::unmarshall_array_start (connection *conn, char id,
+ size_t *n_elements)
{
unsigned long long len;
- if (!conn->require ('a'))
+ if (!conn->require (id))
return FAIL;
if (!conn->get (&len, sizeof (len)))
return FAIL;
- *result = new gcc_type_array;
+ *n_elements = len;
+
+ return OK;
+}
+
+cc1_plugin::status
+cc1_plugin::unmarshall_array_elmts (connection *conn, size_t n_bytes,
+ void *elements)
+{
+ return conn->get (elements, n_bytes);
+}
+
+cc1_plugin::status
+cc1_plugin::marshall (connection *conn, const gcc_type_array *a)
+{
+ size_t len;
+
+ if (a)
+ len = a->n_elements;
+ else
+ len = (size_t)-1;
+
+ if (!marshall_array_start (conn, 'a', len))
+ return FAIL;
+
+ if (!a)
+ return OK;
+
+ return marshall_array_elmts (conn, len * sizeof (a->elements[0]),
+ a->elements);
+}
+
+cc1_plugin::status
+cc1_plugin::unmarshall (connection *conn, gcc_type_array **result)
+{
+ size_t len;
+
+ if (!unmarshall_array_start (conn, 'a', &len))
+ return FAIL;
+
+ if (len == (size_t)-1)
+ {
+ *result = NULL;
+ return OK;
+ }
+
+ gcc_type_array *gta = new gcc_type_array;
- (*result)->n_elements = len;
- (*result)->elements = new gcc_type[len];
+ gta->n_elements = len;
+ gta->elements = new gcc_type[len];
- if (!conn->get ((*result)->elements, len * sizeof ((*result)->elements[0])))
+ if (!unmarshall_array_elmts (conn,
+ len * sizeof (gta->elements[0]),
+ gta->elements))
{
- delete[] (*result)->elements;
+ delete[] gta->elements;
delete *result;
return FAIL;
}
+ *result = gta;
+
return OK;
}