int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad,
                         int idx)
{
    EX_CALLBACK *f;
    EX_CALLBACKS *ip;
    void *curval;
    curval = CRYPTO_get_ex_data(ad, idx);
    if (curval != NULL)
        return 1;
    ip = get_and_lock(class_index);
    if (ip == NULL)
        return 0;
    f = sk_EX_CALLBACK_value(ip->meth, idx);
    CRYPTO_THREAD_unlock(ex_data_lock);
    if (f->new_func == NULL)
        return 0;
    f->new_func(obj, curval, ad, idx, f->argl, f->argp);
    return 1;
}
['int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad,\n                         int idx)\n{\n    EX_CALLBACK *f;\n    EX_CALLBACKS *ip;\n    void *curval;\n    curval = CRYPTO_get_ex_data(ad, idx);\n    if (curval != NULL)\n        return 1;\n    ip = get_and_lock(class_index);\n    if (ip == NULL)\n        return 0;\n    f = sk_EX_CALLBACK_value(ip->meth, idx);\n    CRYPTO_THREAD_unlock(ex_data_lock);\n    if (f->new_func == NULL)\n        return 0;\n    f->new_func(obj, curval, ad, idx, f->argl, f->argp);\n    return 1;\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n    if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n        return NULL;\n    return sk_void_value(ad->sk, idx);\n}', 'static EX_CALLBACKS *get_and_lock(int class_index)\n{\n    EX_CALLBACKS *ip;\n    if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {\n        CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);\n        return NULL;\n    }\n    if (!RUN_ONCE(&ex_data_init, do_ex_data_init)) {\n        CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    if (ex_data_lock == NULL) {\n         return NULL;\n    }\n    ip = &ex_data[class_index];\n    CRYPTO_THREAD_write_lock(ex_data_lock);\n    return ip;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_wrlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_lock(lock) != 0)\n        return 0;\n# endif\n    return 1;\n}', 'DEFINE_STACK_OF(EX_CALLBACK)', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n    if (st == NULL || i < 0 || i >= st->num)\n        return NULL;\n    return (void *)st->data[i];\n}', 'int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_unlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_unlock(lock) != 0)\n        return 0;\n# endif\n    return 1;\n}']