Merge branch 'collectd-4.9' into collectd-4.10
authorSven Trenkel <collectd@semidefinite.de>
Wed, 19 May 2010 08:58:01 +0000 (10:58 +0200)
committerFlorian Forster <octo@noris.net>
Wed, 19 May 2010 08:58:01 +0000 (10:58 +0200)
Conflicts:
src/python.c

1  2 
configure.in
src/python.c

diff --cc configure.in
Simple merge
diff --cc src/python.c
@@@ -374,70 -372,13 +375,71 @@@ static int cpy_write_callback(const dat
                                CPY_RETURN_FROM_THREADS 0;
                        }
                }
 -              v = PyObject_CallFunction((void *) &ValuesType, "sOssssdi", value_list->type,
 -                              list, value_list->plugin_instance, value_list->type_instance,
 -                              value_list->plugin, value_list->host, (double) value_list->time,
 -                              value_list->interval); /* New reference. */
 -              Py_DECREF(list);
 +              dict = PyDict_New();
 +              if (value_list->meta) {
 +                      int i, num;
 +                      char **table;
 +                      meta_data_t *meta = value_list->meta;
 +
 +                      num = meta_data_toc(meta, &table);
 +                      for (i = 0; i < num; ++i) {
 +                              int type;
 +                              char *string;
 +                              int64_t si;
 +                              uint64_t ui;
 +                              double d;
 +                              _Bool b;
 +                              
 +                              type = meta_data_type(meta, table[i]);
 +                              if (type == MD_TYPE_STRING) {
 +                                      if (meta_data_get_string(meta, table[i], &string))
 +                                              continue;
 +                                      temp = cpy_string_to_unicode_or_bytes(string);
 +                                      free(string);
 +                                      PyDict_SetItemString(dict, table[i], temp);
 +                                      Py_XDECREF(temp);
 +                              } else if (type == MD_TYPE_SIGNED_INT) {
 +                                      if (meta_data_get_signed_int(meta, table[i], &si))
 +                                              continue;
 +                                      temp = PyObject_CallFunctionObjArgs((void *) &SignedType, PyLong_FromLongLong(si), (void *) 0);
 +                                      PyDict_SetItemString(dict, table[i], temp);
 +                                      Py_XDECREF(temp);
 +                              } else if (type == MD_TYPE_UNSIGNED_INT) {
 +                                      if (meta_data_get_unsigned_int(meta, table[i], &ui))
 +                                              continue;
 +                                      temp = PyObject_CallFunctionObjArgs((void *) &UnsignedType, PyLong_FromUnsignedLongLong(ui), (void *) 0);
 +                                      PyDict_SetItemString(dict, table[i], temp);
 +                                      Py_XDECREF(temp);
 +                              } else if (type == MD_TYPE_DOUBLE) {
 +                                      if (meta_data_get_double(meta, table[i], &d))
 +                                              continue;
 +                                      temp = PyFloat_FromDouble(d);
 +                                      PyDict_SetItemString(dict, table[i], temp);
 +                                      Py_XDECREF(temp);
 +                              } else if (type == MD_TYPE_BOOLEAN) {
 +                                      if (meta_data_get_boolean(meta, table[i], &b))
 +                                              continue;
 +                                      if (b)
 +                                              PyDict_SetItemString(dict, table[i], Py_True);
 +                                      else
 +                                              PyDict_SetItemString(dict, table[i], Py_False);
 +                              }
 +                              free(table[i]);
 +                      }
 +                      free(table);
 +              }
-               v = PyObject_New(Values, (void *) &ValuesType);
++              v = PyObject_New(Values, (void *) &ValuesType); /* New reference. */
 +              sstrncpy(v->data.host, value_list->host, sizeof(v->data.host));
 +              sstrncpy(v->data.type, value_list->type, sizeof(v->data.type));
 +              sstrncpy(v->data.type_instance, value_list->type_instance, sizeof(v->data.type_instance));
 +              sstrncpy(v->data.plugin, value_list->plugin, sizeof(v->data.plugin));
 +              sstrncpy(v->data.plugin_instance, value_list->plugin_instance, sizeof(v->data.plugin_instance));
 +              v->data.time = value_list->time;
 +              v->interval = value_list->interval;
 +              v->values = list;
 +              v->meta = dict;
                ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */
+               Py_XDECREF(v);
                if (ret == NULL) {
                        cpy_log_exception("write callback");
                } else {
  
  static int cpy_notification_callback(const notification_t *notification, user_data_t *data) {
        cpy_callback_t *c = data->data;
 -      PyObject *ret, *n;
 +      PyObject *ret;
 +      Notification *n;
  
        CPY_LOCK_THREADS
-               n = PyObject_New(Notification, (void *) &NotificationType);
 -              n = PyObject_CallFunction((void *) &NotificationType, "ssssssdi", notification->type, notification->message,
 -                              notification->plugin_instance, notification->type_instance, notification->plugin,
 -                              notification->host, (double) notification->time, notification->severity); /* New reference. */
++              n = PyObject_New(Notification, (void *) &NotificationType); /* New reference. */
 +              sstrncpy(n->data.host, notification->host, sizeof(n->data.host));
 +              sstrncpy(n->data.type, notification->type, sizeof(n->data.type));
 +              sstrncpy(n->data.type_instance, notification->type_instance, sizeof(n->data.type_instance));
 +              sstrncpy(n->data.plugin, notification->plugin, sizeof(n->data.plugin));
 +              sstrncpy(n->data.plugin_instance, notification->plugin_instance, sizeof(n->data.plugin_instance));
 +              n->data.time = notification->time;
 +              sstrncpy(n->message, notification->message, sizeof(n->message));
 +              n->severity = notification->severity;
                ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */
+               Py_XDECREF(n);
                if (ret == NULL) {
                        cpy_log_exception("notification callback");
                } else {