void _PG_init(void) { int **bitmask_ptr; const int **version_ptr; /* * Set up a shared bitmask variable telling which Python version(s) are * loaded into this process's address space. If there's more than one, we * cannot call into libpython for fear of causing crashes. But postpone * the actual failure for later, so that operations like pg_restore can * load more than one plpython library so long as they don't try to do * anything much with the language. */ bitmask_ptr = (int **) find_rendezvous_variable("plpython_version_bitmask"); if (!(*bitmask_ptr)) /* am I the first? */ *bitmask_ptr = &plpython_version_bitmask; /* Retain pointer to the agreed-on shared variable ... */ plpython_version_bitmask_ptr = *bitmask_ptr; /* ... and announce my presence */ *plpython_version_bitmask_ptr |= (1 << PY_MAJOR_VERSION); /* * This should be safe even in the presence of conflicting plpythons, and * it's necessary to do it here for the next error to be localized. */ pg_bindtextdomain(TEXTDOMAIN); /* * We used to have a scheme whereby PL/Python would fail immediately if * loaded into a session in which a conflicting libpython is already * present. We don't like to do that anymore, but it seems possible that * a plpython library adhering to the old convention is present in the * session, in which case we have to fail. We detect an old library if * plpython_python_version is already defined but the indicated version * isn't reflected in plpython_version_bitmask. Otherwise, set the * variable so that the right thing happens if an old library is loaded * later. */ version_ptr = (const int **) find_rendezvous_variable("plpython_python_version"); if (!(*version_ptr)) *version_ptr = &plpython_python_version; else { if ((*plpython_version_bitmask_ptr & (1 << **version_ptr)) == 0) ereport(FATAL, (errmsg("Python major version mismatch in session"), errdetail("This session has previously used Python major version %d, and it is now attempting to use Python major version %d.", **version_ptr, plpython_python_version), errhint("Start a new session to use a different Python major version."))); } /* Register SIGINT/SIGTERM handler for python */ prev_cancel_pending_hook = cancel_pending_hook; cancel_pending_hook = PLy_handle_cancel_interrupt; pg_bindtextdomain(TEXTDOMAIN); }
/* * _PG_init() - library load-time initialization * * DO NOT make this static nor change its name! */ void _PG_init(void) { /* Be sure we do initialization only once (should be redundant now) */ static bool inited = false; if (inited) return; pg_bindtextdomain(TEXTDOMAIN); DefineCustomEnumVariable("plpgsql.variable_conflict", gettext_noop("Sets handling of conflicts between PL/pgSQL variable names and table column names."), NULL, &plpgsql_variable_conflict, PLPGSQL_RESOLVE_ERROR, variable_conflict_options, PGC_SUSET, 0, NULL, NULL, NULL); EmitWarningsOnPlaceholders("plpgsql"); plpgsql_HashTableInit(); RegisterXactCallback(plpgsql_xact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL); /* Set up a rendezvous point with optional instrumentation plugin */ plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); inited = true; }
/* * _PG_init * * Load point of library. */ void _PG_init(void) { /* Set up a rendezvous point with instrumentation plugin */ PLpgSQL_plugin ** var_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); *var_ptr = &plugin_funcs; }
/* * _PG_init() - library load-time initialization * * DO NOT make this static nor change its name! */ void _PG_init(void) { /* Be sure we do initialization only once (should be redundant now) */ static bool inited = false; if (inited) return; plpgsql_HashTableInit(); RegisterXactCallback(plpgsql_xact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL); /* Set up a rendezvous point with optional instrumentation plugin */ plugin_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); inited = true; }
void _PG_init(void) { PLpgSQL_plugin ** var_ptr = (PLpgSQL_plugin **) find_rendezvous_variable( "PLpgSQL_plugin" ); /* Be sure we do initialization only once (should be redundant now) */ static bool inited = false; if (inited) return; *var_ptr = &plugin_funcs; #if PG_VERSION_NUM >= 90100 DefineCustomBoolVariable("plpgsql.enable_lint", "when is true, then plpgsql_lint is active", NULL, &plpgsql_lint_enable, true, PGC_SUSET, 0, NULL, NULL, NULL); #else DefineCustomBoolVariable("plpgsql.enable_lint", "when is true, then plpgsql_lint is active", NULL, &plpgsql_lint_enable, true, PGC_SUSET, 0, NULL, NULL); #endif inited = true; }