Пример #1
0
/*
 * Load library and get all pointers.
 * Parameter 'libname' provides name of DLL.
 * Return OK or FAIL.
 */
    static int
py3_runtime_link_init(char *libname, int verbose)
{
    int i;
    void *ucs_from_string, *ucs_from_string_and_size;

#if defined(UNIX) && defined(FEAT_PYTHON)
    /* Can't have Python and Python3 loaded at the same time, it may cause a
     * crash. */
    if (python_loaded())
    {
	EMSG(_("E999: Python: Cannot use :py and :py3 in one session"));
	return FAIL;
    }
#endif

    if (hinstPy3 != 0)
	return OK;
    hinstPy3 = load_dll(libname);

    if (!hinstPy3)
    {
	if (verbose)
	    EMSG2(_(e_loadlib), libname);
	return FAIL;
    }

    for (i = 0; py3_funcname_table[i].ptr; ++i)
    {
	if ((*py3_funcname_table[i].ptr = symbol_from_dll(hinstPy3,
			py3_funcname_table[i].name)) == NULL)
	{
	    close_dll(hinstPy3);
	    hinstPy3 = 0;
	    if (verbose)
		EMSG2(_(e_loadfunc), py3_funcname_table[i].name);
	    return FAIL;
	}
    }

    /* Load unicode functions separately as only the ucs2 or the ucs4 functions
     * will be present in the library. */
    ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
    ucs_from_string_and_size = symbol_from_dll(hinstPy3,
	    "PyUnicodeUCS2_FromStringAndSize");
    if (!ucs_from_string || !ucs_from_string_and_size)
    {
	ucs_from_string = symbol_from_dll(hinstPy3,
		"PyUnicodeUCS4_FromString");
	ucs_from_string_and_size = symbol_from_dll(hinstPy3,
		"PyUnicodeUCS4_FromStringAndSize");
    }
    if (ucs_from_string && ucs_from_string_and_size)
    {
	py3_PyUnicode_FromString = ucs_from_string;
	py3_PyUnicode_FromStringAndSize = ucs_from_string_and_size;
    }
    else
    {
	close_dll(hinstPy3);
	hinstPy3 = 0;
	if (verbose)
	    EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*");
	return FAIL;
    }

    return OK;
}
Пример #2
0
/*
 * Load library and get all pointers.
 * Parameter 'libname' provides name of DLL.
 * Return OK or FAIL.
 */
static int
py3_runtime_link_init(char *libname, int verbose)
{
	int i;
	void *ucs_from_string, *ucs_decode, *ucs_as_encoded_string;

# if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
	/* Can't have Python and Python3 loaded at the same time.
	 * It cause a crash, because RTLD_GLOBAL is needed for
	 * standard C extension libraries of one or both python versions. */
	if (python_loaded()) {
		if (verbose)
			EMSG(_("E837: This Vim cannot execute :py3 after using :python"));
		return FAIL;
	}
# endif

	if (hinstPy3 != 0)
		return OK;
	hinstPy3 = load_dll(libname);

	if (!hinstPy3) {
		if (verbose)
			EMSG2(_(e_loadlib), libname);
		return FAIL;
	}

	for (i = 0; py3_funcname_table[i].ptr; ++i) {
		if ((*py3_funcname_table[i].ptr = symbol_from_dll(hinstPy3,
										  py3_funcname_table[i].name)) == NULL) {
			close_dll(hinstPy3);
			hinstPy3 = 0;
			if (verbose)
				EMSG2(_(e_loadfunc), py3_funcname_table[i].name);
			return FAIL;
		}
	}

	/* Load unicode functions separately as only the ucs2 or the ucs4 functions
	 * will be present in the library. */
# if PY_VERSION_HEX >= 0x030300f0
	ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString");
	ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode");
	ucs_as_encoded_string = symbol_from_dll(hinstPy3,
											"PyUnicode_AsEncodedString");
# else
	ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
	ucs_decode = symbol_from_dll(hinstPy3,
								 "PyUnicodeUCS2_Decode");
	ucs_as_encoded_string = symbol_from_dll(hinstPy3,
											"PyUnicodeUCS2_AsEncodedString");
	if (!ucs_from_string || !ucs_decode || !ucs_as_encoded_string) {
		ucs_from_string = symbol_from_dll(hinstPy3,
										  "PyUnicodeUCS4_FromString");
		ucs_decode = symbol_from_dll(hinstPy3,
									 "PyUnicodeUCS4_Decode");
		ucs_as_encoded_string = symbol_from_dll(hinstPy3,
												"PyUnicodeUCS4_AsEncodedString");
	}
# endif
	if (ucs_from_string && ucs_decode && ucs_as_encoded_string) {
		py3_PyUnicode_FromString = ucs_from_string;
		py3_PyUnicode_Decode = ucs_decode;
		py3_PyUnicode_AsEncodedString = ucs_as_encoded_string;
	} else {
		close_dll(hinstPy3);
		hinstPy3 = 0;
		if (verbose)
			EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*");
		return FAIL;
	}

	return OK;
}