/* * The beginnings of a destroy function */ void destroy_pair(Pair* p) { // Ensure p points to something if (p != 0) { destroy_value(p->left); destroy_value(p->right); free(p); } }
variant &operator = (variant const &other) { if (which() == other.which()) { static std::array<void(*)(variant &, variant const &), sizeof...(T)> const assign = {{ ©_assign<T>... }}; assign[which()](*this, other); } else { destroy_value(); try { m_which = other.m_which; copy_construct_value(other); } catch (...) { m_which = invalid_which; throw; } } return *this; }
static void destroy_list(struct lp_list *l) { int c; for(c = 0; c < l->values_len; c++) if(l->values[c]) destroy_value(l->values[c]); free(l->values); free(l); }
static void reply_readh_result (byte *body, char *error_msg) { struct_smtsock_readh_reply *readh_reply; GGCODE_TCB *gsl_tcb = tcb-> gsl_thread-> tcb; VALUE value; char *error_text; /* Pick up read value */ get_smtsock_readh_reply (body, & readh_reply); init_value (& value); if (readh_reply-> size > 0) { assign_string (& value, memt_alloc (NULL, readh_reply-> size + 1)); memcpy (value. s, readh_reply-> data, readh_reply-> size); value. s [readh_reply-> size] = '\0'; } /* Store the value */ if (! store_symbol_definition (& gsl_tcb-> scope_stack, gsl_tcb-> gsl-> ignorecase, tcb-> buffer, &value, &error_text)) { lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL, NULL, NULL, NULL, 0, NULL, 0, error_text); return; } destroy_value (& value); /* Build return value */ assign_number (& tcb-> result-> value, readh_reply-> size); free_smtsock_readh_reply (& readh_reply); if (store_sock_error (tcb-> sock_handle, tcb-> gsl_thread, tcb-> context, tcb-> error, error_msg, &error_text)) lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL, NULL, NULL, NULL, 0, NULL, 0, error_text); else lsend_ggcode_call_ok (& tcb-> gsl_thread-> queue-> qid, NULL, NULL, NULL, NULL, 0); }
static inline void destroy_array(JsonArray array) { JsonArrayElement element; element = array.start; while (element != NULL) { destroy_value(element->value); element = element->next; } }
static inline void destroy_object(JsonObject object) { JsonObjectField field; field = object.start; while (field != NULL) { pfree(field->key); destroy_value(field->value); field = field->next; } }
/* * return any value from memory */ BOOL get_value(Interpreter* interpreter, Value* value, int address) { Value* tmp; if (address > OOM_LOWER_BOUND && address < OOM_UPPER_BOUND) { interpreter->out_of_memory = TRUE; } if (address >= ADDR_PERIPHERALS) { tmp = get_peripheral_value(interpreter, (address-ADDR_PERIPHERALS) >> 2); if (tmp == 0) tmp = create_unsigned(0, value->size); memcpy(value->data, tmp->data, value->size); destroy_value(tmp); return TRUE; } else if (interpreter->memory_size >= address + value->size && address >= 0) {
static inline void destroy_container(JsonContainer container) { switch (container->type) { case JSON_OBJECT: destroy_object(container->via.object); break; case JSON_ARRAY: destroy_array(container->via.array); break; case JSON_TOP_LEVEL: destroy_value(container->via.top_level.value); break; } pfree(container); }
static int regexp_match (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread) { RESULT_NODE *pattern = argc > 0 ? argv [0] : NULL; RESULT_NODE *subject = argc > 1 ? argv [1] : NULL; if (! pattern) { strcpy (object_error, "Missing argument: pattern"); return -1; } if (pattern-> value. type == TYPE_UNDEFINED) { result-> culprit = pattern-> culprit; pattern-> culprit = NULL; return 0; } if (! subject) { strcpy (object_error, "Missing argument: subject"); return -1; } if (subject-> value. type == TYPE_UNDEFINED) { result-> culprit = subject-> culprit; subject-> culprit = NULL; return 0; } { GGCODE_TCB *tcb = gsl_thread-> tcb; pcre *re; char *error; int erroffset; int *ovector; int oveccount, rc, i, start, len; VALUE value; re = pcre_compile (string_value (&pattern-> value), 0, (const char **) &error, &erroffset, NULL); if (! re) { snprintf (object_error, LINE_MAX, "Regular expression pattern error: %s\n%s\n%*c", error, pattern-> value. s, erroffset + 1, '^'); return -1; } rc = pcre_fullinfo (re, NULL, PCRE_INFO_CAPTURECOUNT, &oveccount); oveccount = (oveccount + 1) * 3; ovector = mem_alloc (oveccount * sizeof (int)); string_value (&subject-> value); rc = pcre_exec (re, NULL, subject-> value. s, (int) strlen (subject-> value. s), 0, 0, ovector, oveccount); (pcre_free) (re); if (rc == PCRE_ERROR_NOMATCH) rc = 0; else if (rc < 0) { snprintf (object_error, LINE_MAX, "Regular expression matching error: %d", rc); mem_free (ovector); return -1; } else if (rc == 1) rc = -1; else rc -= 1; result-> value. type = TYPE_NUMBER; result-> value. n = rc; i = 1; while (i < argc - 1) { if (argv [i + 1]) { init_value (& value); if (i <= rc) { start = ovector [i * 2]; len = ovector [i * 2 + 1] - start; value. type = TYPE_STRING; value. s = mem_alloc (len + 1); memcpy (value. s, subject-> value. s + start, len); value. s [len] = 0; } if (! store_symbol_definition (& tcb-> scope_stack, tcb-> gsl-> ignorecase, argv [i + 1], &value, &error)) { strncpy (object_error, error, LINE_MAX); mem_free (value.s); mem_free (ovector); return -1; } destroy_value (& value); } i++; } mem_free (ovector); } return 0; /* Just in case */ }
static void destroy_param(struct lp_param *p) { free(p->name); destroy_value(p->v); free(p); }
/// \effects Same as `destroy_value()`. void create_value(std::nullptr_t) noexcept { destroy_value(); }
~variant() noexcept { destroy_value(); }