int ossl_prop_defn_set(OPENSSL_CTX *ctx, const char *prop,
                       OSSL_PROPERTY_LIST *pl)
{
    PROPERTY_DEFN_ELEM elem, *old, *p = NULL;
    size_t len;
    LHASH_OF(PROPERTY_DEFN_ELEM) *property_defns;
    property_defns = openssl_ctx_get_data(ctx, OPENSSL_CTX_PROPERTY_DEFN_INDEX,
                                          &property_defns_method);
    if (property_defns == NULL)
        return 0;
    if (prop == NULL)
        return 1;
    if (pl == NULL) {
        elem.prop = prop;
        lh_PROPERTY_DEFN_ELEM_delete(property_defns, &elem);
        return 1;
    }
    len = strlen(prop);
    p = OPENSSL_malloc(sizeof(*p) + len);
    if (p != NULL) {
        p->prop = p->body;
        p->defn = pl;
        memcpy(p->body, prop, len + 1);
        old = lh_PROPERTY_DEFN_ELEM_insert(property_defns, p);
        if (old != NULL) {
            property_defn_free(old);
            return 1;
        }
        if (!lh_PROPERTY_DEFN_ELEM_error(property_defns))
            return 1;
    }
    OPENSSL_free(p);
    return 0;
}
['static int test_query_cache_stochastic(void)\n{\n    const int max = 10000, tail = 10;\n    OSSL_METHOD_STORE *store;\n    int i, res = 0;\n    char buf[50];\n    void *result;\n    int errors = 0;\n    int v[10001];\n    if (!TEST_ptr(store = ossl_method_store_new(NULL))\n        || !add_property_names("n", NULL))\n        goto err;\n    for (i = 1; i <= max; i++) {\n        v[i] = 2 * i;\n        BIO_snprintf(buf, sizeof(buf), "n=%d\\n", i);\n        if (!TEST_true(ossl_method_store_add(store, i, buf, "abc", NULL))\n                || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i))\n                || !TEST_true(ossl_method_store_cache_set(store, i, "n=1234",\n                                                          "miss"))) {\n            TEST_note("iteration %d", i);\n            goto err;\n        }\n    }\n    for (i = 1; i <= max; i++) {\n        BIO_snprintf(buf, sizeof(buf), "n=%d\\n", i);\n        if (!ossl_method_store_cache_get(store, i, buf, &result)\n            || result != v + i)\n            errors++;\n    }\n    res = TEST_int_gt(errors, tail) && TEST_int_lt(errors, max - tail);\nerr:\n    ossl_method_store_free(store);\n    return res;\n}', 'int ossl_method_store_add(OSSL_METHOD_STORE *store,\n                          int nid, const char *properties,\n                          void *method, void (*method_destruct)(void *))\n{\n    ALGORITHM *alg = NULL;\n    IMPLEMENTATION *impl;\n    int ret = 0;\n    if (nid <= 0 || method == NULL || store == NULL)\n        return 0;\n    if (properties == NULL)\n        properties = "";\n    impl = OPENSSL_malloc(sizeof(*impl));\n    if (impl == NULL)\n        return 0;\n    impl->method = method;\n    impl->method_destruct = method_destruct;\n    ossl_property_write_lock(store);\n    ossl_method_cache_flush(store, nid);\n    if ((impl->properties = ossl_prop_defn_get(store->ctx, properties)) == NULL) {\n        impl->properties = ossl_parse_property(store->ctx, properties);\n        if (impl->properties == NULL)\n            goto err;\n        ossl_prop_defn_set(store->ctx, properties, impl->properties);\n    }\n    alg = ossl_method_store_retrieve(store, nid);\n    if (alg == NULL) {\n        if ((alg = OPENSSL_zalloc(sizeof(*alg))) == NULL\n                || (alg->impls = sk_IMPLEMENTATION_new_null()) == NULL\n                || (alg->cache = lh_QUERY_new(&query_hash, &query_cmp)) == NULL)\n            goto err;\n        alg->nid = nid;\n        if (!ossl_method_store_insert(store, alg))\n            goto err;\n    }\n    if (sk_IMPLEMENTATION_push(alg->impls, impl))\n        ret = 1;\n    ossl_property_unlock(store);\n    if (ret == 0)\n        impl_free(impl);\n    return ret;\nerr:\n    ossl_property_unlock(store);\n    alg_cleanup(0, alg);\n    impl_free(impl);\n    return 0;\n}', 'int ossl_prop_defn_set(OPENSSL_CTX *ctx, const char *prop,\n                       OSSL_PROPERTY_LIST *pl)\n{\n    PROPERTY_DEFN_ELEM elem, *old, *p = NULL;\n    size_t len;\n    LHASH_OF(PROPERTY_DEFN_ELEM) *property_defns;\n    property_defns = openssl_ctx_get_data(ctx, OPENSSL_CTX_PROPERTY_DEFN_INDEX,\n                                          &property_defns_method);\n    if (property_defns == NULL)\n        return 0;\n    if (prop == NULL)\n        return 1;\n    if (pl == NULL) {\n        elem.prop = prop;\n        lh_PROPERTY_DEFN_ELEM_delete(property_defns, &elem);\n        return 1;\n    }\n    len = strlen(prop);\n    p = OPENSSL_malloc(sizeof(*p) + len);\n    if (p != NULL) {\n        p->prop = p->body;\n        p->defn = pl;\n        memcpy(p->body, prop, len + 1);\n        old = lh_PROPERTY_DEFN_ELEM_insert(property_defns, p);\n        if (old != NULL) {\n            property_defn_free(old);\n            return 1;\n        }\n        if (!lh_PROPERTY_DEFN_ELEM_error(property_defns))\n            return 1;\n    }\n    OPENSSL_free(p);\n    return 0;\n}']