本文整理汇总了C++中QDECREF函数的典型用法代码示例。如果您正苦于以下问题:C++ QDECREF函数的具体用法?C++ QDECREF怎么用?C++ QDECREF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QDECREF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openfile
static int openfile(char *name, int flags, bool writethrough, bool force_share,
QDict *opts)
{
Error *local_err = NULL;
if (qemuio_blk) {
error_report("file open already, try 'help close'");
QDECREF(opts);
return 1;
}
if (force_share) {
if (!opts) {
opts = qdict_new();
}
if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
&& !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
error_report("-U conflicts with image options");
QDECREF(opts);
return 1;
}
qdict_put_bool(opts, BDRV_OPT_FORCE_SHARE, true);
}
qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err);
if (!qemuio_blk) {
error_reportf_err(local_err, "can't open%s%s: ",
name ? " device " : "", name ?: "");
return 1;
}
示例2: test_usb_storage_hotplug
static void test_usb_storage_hotplug(void)
{
QDict *response;
response = qmp("{'execute': 'device_add',"
" 'arguments': {"
" 'driver': 'usb-storage',"
" 'drive': 'drive0',"
" 'id': 'usbdev0'"
"}}");
g_assert(response);
g_assert(!qdict_haskey(response, "error"));
QDECREF(response);
response = qmp("{'execute': 'device_del',"
" 'arguments': {"
" 'id': 'usbdev0'"
"}}");
g_assert(response);
g_assert(!qdict_haskey(response, "error"));
QDECREF(response);
response = qmp("");
g_assert(response);
g_assert(qdict_haskey(response, "event"));
g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
QDECREF(response);
}
示例3: qnull_visit_test
static void qnull_visit_test(void)
{
QObject *obj;
Visitor *v;
QNull *null;
/*
* Most tests of interactions between QObject and visitors are in
* test-qmp-*-visitor; but these tests live here because they
* depend on layering violations to check qnull_ refcnt.
*/
g_assert(qnull_.base.refcnt == 1);
obj = QOBJECT(qnull());
v = qobject_input_visitor_new(obj);
qobject_decref(obj);
visit_type_null(v, NULL, &null, &error_abort);
g_assert(obj == QOBJECT(&qnull_));
QDECREF(null);
visit_free(v);
null = NULL;
v = qobject_output_visitor_new(&obj);
visit_type_null(v, NULL, &null, &error_abort);
visit_complete(v, &obj);
g_assert(obj == QOBJECT(&qnull_));
QDECREF(null);
qobject_decref(obj);
visit_free(v);
g_assert(qnull_.base.refcnt == 1);
}
示例4: qdict_crumple_test_bad_inputs
static void qdict_crumple_test_bad_inputs(void)
{
QDict *src;
Error *error = NULL;
src = qdict_new();
/* rule.0 can't be both a string and a dict */
qdict_put(src, "rule.0", qstring_from_str("fred"));
qdict_put(src, "rule.0.policy", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* rule can't be both a list and a dict */
qdict_put(src, "rule.0", qstring_from_str("fred"));
qdict_put(src, "rule.a", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* The input should be flat, ie no dicts or lists */
qdict_put(src, "rule.a", qdict_new());
qdict_put(src, "rule.b", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* List indexes must not have gaps */
qdict_put(src, "rule.0", qstring_from_str("deny"));
qdict_put(src, "rule.3", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* List indexes must be in %zu format */
qdict_put(src, "rule.0", qstring_from_str("deny"));
qdict_put(src, "rule.+1", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
}
示例5: test_dispatch_cmd_failure
/* test commands that return an error due to invalid parameters */
static void test_dispatch_cmd_failure(void)
{
QDict *req = qdict_new();
QDict *args = qdict_new();
QObject *resp;
qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
assert(qdict_haskey(qobject_to_qdict(resp), "error"));
qobject_decref(resp);
QDECREF(req);
/* check that with extra arguments it throws an error */
req = qdict_new();
qdict_put(args, "a", qint_from_int(66));
qdict_put(req, "arguments", args);
qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
assert(qdict_haskey(qobject_to_qdict(resp), "error"));
qobject_decref(resp);
QDECREF(req);
}
示例6: hotplug
static void hotplug(void)
{
QDict *response;
QOSState *qs;
qs = qvirtio_scsi_start(
"-drive id=drv1,if=none,file=null-co://,format=raw");
response = qmp("{\"execute\": \"device_add\","
" \"arguments\": {"
" \"driver\": \"scsi-hd\","
" \"id\": \"scsi-hd\","
" \"drive\": \"drv1\""
"}}");
g_assert(response);
g_assert(!qdict_haskey(response, "error"));
QDECREF(response);
response = qmp("{\"execute\": \"device_del\","
" \"arguments\": {"
" \"id\": \"scsi-hd\""
"}}");
g_assert(response);
g_assert(!qdict_haskey(response, "error"));
g_assert(qdict_haskey(response, "event"));
g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
QDECREF(response);
qvirtio_scsi_stop(qs);
}
示例7: send_response
static int send_response(GAState *s, QObject *payload)
{
const char *buf;
QString *payload_qstr, *response_qstr;
GIOStatus status;
g_assert(payload && s->channel);
payload_qstr = qobject_to_json(payload);
if (!payload_qstr) {
return -EINVAL;
}
if (s->delimit_response) {
s->delimit_response = false;
response_qstr = qstring_new();
qstring_append_chr(response_qstr, QGA_SENTINEL_BYTE);
qstring_append(response_qstr, qstring_get_str(payload_qstr));
QDECREF(payload_qstr);
} else {
response_qstr = payload_qstr;
}
qstring_append_chr(response_qstr, '\n');
buf = qstring_get_str(response_qstr);
status = ga_channel_write_all(s->channel, buf, strlen(buf));
QDECREF(response_qstr);
if (status != G_IO_STATUS_NORMAL) {
return -EIO;
}
return 0;
}
示例8: test_drive_add_empty
static void test_drive_add_empty(void)
{
QDict *response;
const char *response_return;
/* Start with an empty drive */
qtest_start("-drive if=none,id=drive0");
/* Delete the drive */
response = qmp("{\"execute\": \"human-monitor-command\","
" \"arguments\": {"
" \"command-line\": \"drive_del drive0\""
"}}");
g_assert(response);
response_return = qdict_get_try_str(response, "return");
g_assert(response_return);
g_assert(strcmp(response_return, "") == 0);
QDECREF(response);
/* Ensure re-adding the drive works - there should be no duplicate ID error
* because the old drive must be gone.
*/
response = qmp("{\"execute\": \"human-monitor-command\","
" \"arguments\": {"
" \"command-line\": \"drive_add 0 if=none,id=drive0\""
"}}");
g_assert(response);
response_return = qdict_get_try_str(response, "return");
g_assert(response_return);
g_assert(strcmp(response_return, "OK\r\n") == 0);
QDECREF(response);
qtest_end();
}
示例9: qdict_crumple_test_recursive
static void qdict_crumple_test_recursive(void)
{
QDict *src, *dst, *rule, *vnc, *acl, *listen;
QList *rules;
src = qdict_new();
qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1"));
qdict_put(src, "vnc.listen.port", qstring_from_str("5901"));
qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred"));
qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow"));
qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob"));
qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny"));
qdict_put(src, "vnc.acl.default", qstring_from_str("deny"));
qdict_put(src, "vnc.acl..name", qstring_from_str("acl0"));
qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0"));
dst = qobject_to_qdict(qdict_crumple(src, &error_abort));
g_assert(dst);
g_assert_cmpint(qdict_size(dst), ==, 1);
vnc = qdict_get_qdict(dst, "vnc");
g_assert(vnc);
g_assert_cmpint(qdict_size(vnc), ==, 3);
listen = qdict_get_qdict(vnc, "listen");
g_assert(listen);
g_assert_cmpint(qdict_size(listen), ==, 2);
g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr"));
g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port"));
acl = qdict_get_qdict(vnc, "acl");
g_assert(acl);
g_assert_cmpint(qdict_size(acl), ==, 3);
rules = qdict_get_qlist(acl, "rules");
g_assert(rules);
g_assert_cmpint(qlist_size(rules), ==, 2);
rule = qobject_to_qdict(qlist_pop(rules));
g_assert(rule);
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));
QDECREF(rule);
rule = qobject_to_qdict(qlist_pop(rules));
g_assert(rule);
g_assert_cmpint(qdict_size(rule), ==, 2);
g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match"));
g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
QDECREF(rule);
/* With recursive crumpling, we should see all names unescaped */
g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name"));
g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));
QDECREF(src);
QDECREF(dst);
}
示例10: qdict_crumple_test_empty
static void qdict_crumple_test_empty(void)
{
QDict *src, *dst;
src = qdict_new();
dst = (QDict *)qdict_crumple(src, &error_abort);
g_assert_cmpint(qdict_size(dst), ==, 0);
QDECREF(src);
QDECREF(dst);
}
示例11: test_dispatch_cmd_io
/* test commands that involve both input parameters and return values */
static void test_dispatch_cmd_io(void)
{
QDict *req = qdict_new();
QDict *args = qdict_new();
QDict *args3 = qdict_new();
QDict *ud1a = qdict_new();
QDict *ud1b = qdict_new();
QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef;
QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
QNum *ret3;
int64_t val;
qdict_put_int(ud1a, "integer", 42);
qdict_put_str(ud1a, "string", "hello");
qdict_put_int(ud1b, "integer", 422);
qdict_put_str(ud1b, "string", "hello2");
qdict_put(args, "ud1a", ud1a);
qdict_put(args, "ud1b", ud1b);
qdict_put(req, "arguments", args);
qdict_put_str(req, "execute", "user_def_cmd2");
ret = qobject_to_qdict(test_qmp_dispatch(req));
assert(!strcmp(qdict_get_str(ret, "string0"), "blah1"));
ret_dict = qdict_get_qdict(ret, "dict1");
assert(!strcmp(qdict_get_str(ret_dict, "string1"), "blah2"));
ret_dict_dict = qdict_get_qdict(ret_dict, "dict2");
ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef");
assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42);
assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello"));
assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3"));
ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict3");
ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef");
assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422);
assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2"));
assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4"));
QDECREF(ret);
qdict_put_int(args3, "a", 66);
qdict_put(req, "arguments", args3);
qdict_put_str(req, "execute", "guest-get-time");
ret3 = qobject_to_qnum(test_qmp_dispatch(req));
g_assert(qnum_get_try_int(ret3, &val));
g_assert_cmpint(val, ==, 66);
QDECREF(ret3);
QDECREF(req);
}
示例12: process_event
/* handle requests/control events coming in over the channel */
static void process_event(JSONMessageParser *parser, QList *tokens)
{
GAState *s = container_of(parser, GAState, parser);
QObject *obj;
QDict *qdict;
Error *err = NULL;
int ret;
g_assert(s && parser);
g_debug("process_event: called");
obj = json_parser_parse_err(tokens, NULL, &err);
if (err || !obj || qobject_type(obj) != QTYPE_QDICT) {
qobject_decref(obj);
qdict = qdict_new();
if (!err) {
g_warning("failed to parse event: unknown error");
error_set(&err, QERR_JSON_PARSING);
} else {
g_warning("failed to parse event: %s", error_get_pretty(err));
}
qdict_put_obj(qdict, "error", error_get_qobject(err));
error_free(err);
} else {
qdict = qobject_to_qdict(obj);
}
g_assert(qdict);
/* handle host->guest commands */
if (qdict_haskey(qdict, "execute")) {
process_command(s, qdict);
} else {
if (!qdict_haskey(qdict, "error")) {
QDECREF(qdict);
qdict = qdict_new();
g_warning("unrecognized payload format");
error_set(&err, QERR_UNSUPPORTED);
qdict_put_obj(qdict, "error", error_get_qobject(err));
error_free(err);
}
ret = conn_channel_send_payload(s->conn_channel, QOBJECT(qdict));
if (ret) {
g_warning("error sending payload: %s", strerror(ret));
}
}
QDECREF(qdict);
}
示例13: test_dispatch_cmd_io
/* test commands that involve both input parameters and return values */
static void test_dispatch_cmd_io(void)
{
QDict *req = qdict_new();
QDict *args = qdict_new();
QDict *ud1a = qdict_new();
QDict *ud1b = qdict_new();
QObject *resp;
qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42)));
qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello")));
qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422)));
qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2")));
qdict_put_obj(args, "ud1a", QOBJECT(ud1a));
qdict_put_obj(args, "ud1b", QOBJECT(ud1b));
qdict_put_obj(req, "arguments", QOBJECT(args));
qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
/* TODO: put in full payload and check for errors */
resp = qmp_dispatch(QOBJECT(req));
assert(resp != NULL);
assert(!qdict_haskey(qobject_to_qdict(resp), "error"));
g_print("\nresp: %s\n", qstring_get_str(qobject_to_json_pretty(resp)));
qobject_decref(resp);
QDECREF(req);
}
示例14: qobject_to_qdict_test
static void qobject_to_qdict_test(void)
{
QDict *tests_dict = qdict_new();
g_assert(qobject_to_qdict(QOBJECT(tests_dict)) == tests_dict);
QDECREF(tests_dict);
}
示例15: test_dealloc_partial
/* test generated deallocation on an object whose construction was prematurely
* terminated due to an error */
static void test_dealloc_partial(void)
{
static const char text[] = "don't leak me";
UserDefTwo *ud2 = NULL;
Error *err = NULL;
/* create partial object */
{
QDict *ud2_dict;
QmpInputVisitor *qiv;
ud2_dict = qdict_new();
qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
qiv = qmp_input_visitor_new(QOBJECT(ud2_dict));
visit_type_UserDefTwo(qmp_input_get_visitor(qiv), &ud2, NULL, &err);
qmp_input_visitor_cleanup(qiv);
QDECREF(ud2_dict);
}
/* verify partial success */
assert(ud2 != NULL);
assert(ud2->string0 != NULL);
assert(strcmp(ud2->string0, text) == 0);
assert(ud2->dict1 == NULL);
/* confirm & release construction error */
assert(err != NULL);
error_free(err);
/* tear down partial object */
qapi_free_UserDefTwo(ud2);
}