| 16486 | } |
| 16487 | |
| 16488 | ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, |
| 16489 | ZSTD_dictLoadMethod_e dictLoadMethod, |
| 16490 | ZSTD_dictContentType_e dictContentType, |
| 16491 | ZSTD_compressionParameters cParams, ZSTD_customMem customMem) |
| 16492 | { |
| 16493 | DEBUGLOG(3, "ZSTD_createCDict_advanced, mode %u", (unsigned)dictContentType); |
| 16494 | if (!customMem.customAlloc ^ !customMem.customFree) return NULL; |
| 16495 | |
| 16496 | { size_t const workspaceSize = |
| 16497 | ZSTD_cwksp_alloc_size(sizeof(ZSTD_CDict)) + |
| 16498 | ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE) + |
| 16499 | ZSTD_sizeof_matchState(&cParams, /* forCCtx */ 0) + |
| 16500 | (dictLoadMethod == ZSTD_dlm_byRef ? 0 |
| 16501 | : ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(dictSize, sizeof(void*)))); |
| 16502 | void* const workspace = ZSTD_malloc(workspaceSize, customMem); |
| 16503 | ZSTD_cwksp ws; |
| 16504 | ZSTD_CDict* cdict; |
| 16505 | |
| 16506 | if (!workspace) { |
| 16507 | ZSTD_free(workspace, customMem); |
| 16508 | return NULL; |
| 16509 | } |
| 16510 | |
| 16511 | ZSTD_cwksp_init(&ws, workspace, workspaceSize); |
| 16512 | |
| 16513 | cdict = (ZSTD_CDict*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CDict)); |
| 16514 | assert(cdict != NULL); |
| 16515 | ZSTD_cwksp_move(&cdict->workspace, &ws); |
| 16516 | cdict->customMem = customMem; |
| 16517 | cdict->compressionLevel = 0; /* signals advanced API usage */ |
| 16518 | |
| 16519 | if (ZSTD_isError( ZSTD_initCDict_internal(cdict, |
| 16520 | dictBuffer, dictSize, |
| 16521 | dictLoadMethod, dictContentType, |
| 16522 | cParams) )) { |
| 16523 | ZSTD_freeCDict(cdict); |
| 16524 | return NULL; |
| 16525 | } |
| 16526 | |
| 16527 | return cdict; |
| 16528 | } |
| 16529 | } |
| 16530 | |
| 16531 | ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel) |
| 16532 | { |
no test coverage detected