In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about how to achieve cross-platform in PostgreSQL, many people may not know much about it. In order to make you understand better, the editor summarized the following content for you. I hope you can get something according to this article.
# include "dynloader.h" mysql_dll_handle = dlopen (_ MYSQL_LIBNAME, RTLD_LAZY | RTLD_DEEPBIND); change to mysql_dll_handle = dlopen (_ MYSQL_LIBNAME, 1)
A more formal way of writing is
# if defined (_ _ APPLE__) | | defined (_ _ FreeBSD__) mysql_dll_handle = dlopen (_ MYSQL_LIBNAME, RTLD_LAZY); # elif defined WIN32 mysql_dll_handle = pg_dlopen (_ MYSQL_LIBNAME, 1); # else mysql_dll_handle = dlopen (_ MYSQL_LIBNAME, RTLD_LAZY | RTLD_DEEPBIND); # endif
There are no changes to the original two lines, just to show how it should be written, the cross-platform nature of the module code will be better.
Dynloader.h will point to the correct header file according to the platform before compilation, and point to src/backend/port/dynloader/win32.h under Windows
# define pg_dlopen (f) dlopen ((f), 1) # define pg_dlsym dlsym#define pg_dlclose dlclose#define pg_dlerror dlerrorchar * dlerror (void); int dlclose (void * handle); void * dlsym (void * handle, const char * symbol); void * dlopen (const char * path, int mode)
Windows encapsulates a series of functions loaded by the library, which are implemented in src/backend/port/dynloader/win32.c, excerpt:
Void * dlopen (const char * path, int mode) {HMODULE h; int prevmode; / * Disable popup error messages when loading DLLs * / prevmode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); h = LoadLibrary (path); SetErrorMode (prevmode); if (! h) {set_dl_error (); return NULL;} last_dyn_error [0] = 0; return (void *) h;}
In the end, the traditional Windows function LoadLibrary is still called.
It was also mentioned earlier that Solution.pm was modified to only add libraries and header file paths for mysql_fdw to avoid affecting other modules. Because some header files in mysql conflict with the definition of PG, we are all relational databases, so it is inevitable that some things will be named the same @ _ @.
What is said above is that the compiler system automatically recognizes the current platform and compiles different source files. * the nix platform is in the configure script.
Platform judgment:
Case $host_os in aix*) template=aix;; cygwin*) template=cygwin;; darwin*) template=darwin; dragonfly*) template=netbsd;; freebsd*) template=freebsd;; hpux*) template=hpux;; linux* | gnu* | k*bsd*-gnu) template=linux;; mingw*) template=win32;; netbsd*) template=netbsd;; openbsd*) template=openbsd;; solaris*) template=solaris;; esac
Specify a soft chain file (for example, macOS will point to src/backend/port/dynloader/darwin.h)
"src/include/dynloader.h") CONFIG_LINKS= "$CONFIG_LINKS src/include/dynloader.h:src/backend/port/dynloader/$ {template} .h"
Let's take a look at Windows (in Solution.pm), which uses the copy method:
If (IsNewer ('src/include/dynloader.h',' src/backend/port/dynloader/win32.h')) {copyFile ('src/backend/port/dynloader/win32.h',' src/include/dynloader.h');}
Of course, there is more traditional preprocessor in the code:
# ifdef WIN32 / * Win32 does not have UTF-8, so we need to map to UTF-16 * / if (GetDatabaseEncoding () = = PG_UTF8 & & (! mylocale | | mylocale- > provider = = COLLPROVIDER_LIBC)) {. # endif / * WIN32 * / after reading the above, do you have any further understanding of how to implement cross-platform in PostgreSQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.