mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-10-31 15:38:57 +08:00 
			
		
		
		
	mdbx-windows: поддержка char-версии mdbx_env_get_path().
				
					
				
			This commit is contained in:
		
							
								
								
									
										3
									
								
								mdbx.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								mdbx.h
									
									
									
									
									
								
							| @@ -3003,9 +3003,8 @@ LIBMDBX_API int mdbx_env_get_flags(const MDBX_env *env, unsigned *flags); | |||||||
|  * \returns A non-zero error value on failure and 0 on success, |  * \returns A non-zero error value on failure and 0 on success, | ||||||
|  *          some possible errors are: |  *          some possible errors are: | ||||||
|  * \retval MDBX_EINVAL  An invalid parameter was specified. */ |  * \retval MDBX_EINVAL  An invalid parameter was specified. */ | ||||||
| #if !(defined(_WIN32) || defined(_WIN64)) |  | ||||||
| LIBMDBX_API int mdbx_env_get_path(const MDBX_env *env, const char **dest); | LIBMDBX_API int mdbx_env_get_path(const MDBX_env *env, const char **dest); | ||||||
| #else | #if defined(_WIN32) || defined(_WIN64) | ||||||
| LIBMDBX_API int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **dest); | LIBMDBX_API int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **dest); | ||||||
| #endif /* Windows */ | #endif /* Windows */ | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										68
									
								
								src/core.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								src/core.c
									
									
									
									
									
								
							| @@ -14779,6 +14779,9 @@ __cold int mdbx_env_open(MDBX_env *env, const char *pathname, | |||||||
|   if (likely(rc == MDBX_SUCCESS)) { |   if (likely(rc == MDBX_SUCCESS)) { | ||||||
|     rc = mdbx_env_openW(env, pathnameW, flags, mode); |     rc = mdbx_env_openW(env, pathnameW, flags, mode); | ||||||
|     osal_free(pathnameW); |     osal_free(pathnameW); | ||||||
|  |     if (rc == MDBX_SUCCESS) | ||||||
|  |       /* force to make cache of the multi-byte pathname representation */ | ||||||
|  |       mdbx_env_get_path(env, &pathname); | ||||||
|   } |   } | ||||||
|   return rc; |   return rc; | ||||||
| } | } | ||||||
| @@ -15334,6 +15337,12 @@ __cold static int env_close(MDBX_env *env) { | |||||||
|     osal_free(env->me_pathname); |     osal_free(env->me_pathname); | ||||||
|     env->me_pathname = nullptr; |     env->me_pathname = nullptr; | ||||||
|   } |   } | ||||||
|  | #if defined(_WIN32) || defined(_WIN64) | ||||||
|  |   if (env->me_pathname_char) { | ||||||
|  |     osal_free(env->me_pathname_char); | ||||||
|  |     env->me_pathname_char = nullptr; | ||||||
|  |   } | ||||||
|  | #endif /* Windows */ | ||||||
|   if (env->me_txn0) { |   if (env->me_txn0) { | ||||||
|     dpl_free(env->me_txn0); |     dpl_free(env->me_txn0); | ||||||
|     txl_free(env->me_txn0->tw.lifo_reclaimed); |     txl_free(env->me_txn0->tw.lifo_reclaimed); | ||||||
| @@ -21929,19 +21938,7 @@ __cold int mdbx_env_set_assert(MDBX_env *env, MDBX_assert_func *func) { | |||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
| #if !(defined(_WIN32) || defined(_WIN64)) | #if defined(_WIN32) || defined(_WIN64) | ||||||
| __cold int mdbx_env_get_path(const MDBX_env *env, const char **arg) { |  | ||||||
|   int rc = check_env(env, true); |  | ||||||
|   if (unlikely(rc != MDBX_SUCCESS)) |  | ||||||
|     return rc; |  | ||||||
|  |  | ||||||
|   if (unlikely(!arg)) |  | ||||||
|     return MDBX_EINVAL; |  | ||||||
|  |  | ||||||
|   *arg = env->me_pathname; |  | ||||||
|   return MDBX_SUCCESS; |  | ||||||
| } |  | ||||||
| #else |  | ||||||
| __cold int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **arg) { | __cold int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **arg) { | ||||||
|   int rc = check_env(env, true); |   int rc = check_env(env, true); | ||||||
|   if (unlikely(rc != MDBX_SUCCESS)) |   if (unlikely(rc != MDBX_SUCCESS)) | ||||||
| @@ -21955,6 +21952,51 @@ __cold int mdbx_env_get_pathW(const MDBX_env *env, const wchar_t **arg) { | |||||||
| } | } | ||||||
| #endif /* Windows */ | #endif /* Windows */ | ||||||
|  |  | ||||||
|  | __cold int mdbx_env_get_path(const MDBX_env *env, const char **arg) { | ||||||
|  |   int rc = check_env(env, true); | ||||||
|  |   if (unlikely(rc != MDBX_SUCCESS)) | ||||||
|  |     return rc; | ||||||
|  |  | ||||||
|  |   if (unlikely(!arg)) | ||||||
|  |     return MDBX_EINVAL; | ||||||
|  |  | ||||||
|  | #if defined(_WIN32) || defined(_WIN64) | ||||||
|  |   if (!env->me_pathname_char) { | ||||||
|  |     *arg = nullptr; | ||||||
|  |     DWORD flags = /* WC_ERR_INVALID_CHARS */ 0x80; | ||||||
|  |     size_t mb_len = WideCharToMultiByte(CP_THREAD_ACP, flags, env->me_pathname, | ||||||
|  |                                         -1, nullptr, 0, nullptr, nullptr); | ||||||
|  |     rc = mb_len ? MDBX_SUCCESS : (int)GetLastError(); | ||||||
|  |     if (rc == ERROR_INVALID_FLAGS) { | ||||||
|  |       mb_len = WideCharToMultiByte(CP_THREAD_ACP, flags = 0, env->me_pathname, | ||||||
|  |                                    -1, nullptr, 0, nullptr, nullptr); | ||||||
|  |       rc = mb_len ? MDBX_SUCCESS : (int)GetLastError(); | ||||||
|  |     } | ||||||
|  |     if (unlikely(rc != MDBX_SUCCESS)) | ||||||
|  |       return rc; | ||||||
|  |  | ||||||
|  |     char *const mb_pathname = osal_malloc(mb_len); | ||||||
|  |     if (!mb_pathname) | ||||||
|  |       return MDBX_ENOMEM; | ||||||
|  |     if (mb_len != (size_t)WideCharToMultiByte(CP_THREAD_ACP, flags, | ||||||
|  |                                               env->me_pathname, -1, mb_pathname, | ||||||
|  |                                               (int)mb_len, nullptr, nullptr)) { | ||||||
|  |       rc = (int)GetLastError(); | ||||||
|  |       osal_free(mb_pathname); | ||||||
|  |       return rc; | ||||||
|  |     } | ||||||
|  |     if (env->me_pathname_char || | ||||||
|  |         InterlockedCompareExchangePointer( | ||||||
|  |             (PVOID volatile *)&env->me_pathname_char, mb_pathname, nullptr)) | ||||||
|  |       osal_free(mb_pathname); | ||||||
|  |   } | ||||||
|  |   *arg = env->me_pathname_char; | ||||||
|  | #else | ||||||
|  |   *arg = env->me_pathname; | ||||||
|  | #endif /* Windows */ | ||||||
|  |   return MDBX_SUCCESS; | ||||||
|  | } | ||||||
|  |  | ||||||
| __cold int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *arg) { | __cold int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *arg) { | ||||||
|   int rc = check_env(env, true); |   int rc = check_env(env, true); | ||||||
|   if (unlikely(rc != MDBX_SUCCESS)) |   if (unlikely(rc != MDBX_SUCCESS)) | ||||||
|   | |||||||
| @@ -1463,6 +1463,8 @@ struct MDBX_env { | |||||||
|   osal_srwlock_t me_remap_guard; |   osal_srwlock_t me_remap_guard; | ||||||
|   /* Workaround for LockFileEx and WriteFile multithread bug */ |   /* Workaround for LockFileEx and WriteFile multithread bug */ | ||||||
|   CRITICAL_SECTION me_windowsbug_lock; |   CRITICAL_SECTION me_windowsbug_lock; | ||||||
|  |   char *me_pathname_char; /* cache of multi-byte representation of pathname | ||||||
|  |                              to the DB files */ | ||||||
| #else | #else | ||||||
|   osal_fastmutex_t me_remap_guard; |   osal_fastmutex_t me_remap_guard; | ||||||
| #endif | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user