Skip to content

Commit

Permalink
initial try of build adaptations for python 3 support, see #36 on blo…
Browse files Browse the repository at this point in the history
…ckage, due to missing boost python3 nuget package
  • Loading branch information
chcg committed Nov 7, 2018
1 parent 583addd commit 06b698b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 53 deletions.
12 changes: 6 additions & 6 deletions PythonScript/project/PythonScript2010.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python36.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(HtmlHelpBase)\lib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
Expand All @@ -303,7 +303,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python36.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(HtmlHelpBase)\lib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
Expand All @@ -327,7 +327,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python36.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(HtmlHelpBase)\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -348,7 +348,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>python27.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>python36.lib;NppPlugin.lib;shlwapi.lib;comctl32.lib;htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(HtmlHelpBase)\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -426,7 +426,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<ClCompile Include="..\src\GILManager.cpp" />
<ClCompile Include="..\src\GroupNotFoundException.cpp" />
<ClCompile Include="..\src\HelpController.cpp" />
<ClCompile Include="..\src\InvalidValueProvidedException.cpp" />
<ClCompile Include="..\src\InvalidValueProvidedException.cpp" />
<ClCompile Include="..\src\MainThread.cpp" />
<ClCompile Include="..\src\Match.cpp" />
<ClCompile Include="..\src\MatchPython.cpp" />
Expand Down Expand Up @@ -483,7 +483,7 @@ xcopy $(ProjectDir)..\python_tests\*.* "e:\notepadtest\unicode\plugins\config\py
<ClInclude Include="..\src\GroupNotFoundException.h" />
<ClInclude Include="..\src\HelpController.h" />
<ClInclude Include="..\src\IDAllocator.h" />
<ClInclude Include="..\src\InvalidValueProvidedException.h" />
<ClInclude Include="..\src\InvalidValueProvidedException.h" />
<ClInclude Include="..\src\MainThread.h" />
<ClInclude Include="..\src\Match.h" />
<ClInclude Include="..\src\MatchPython.h" />
Expand Down
4 changes: 2 additions & 2 deletions PythonScript/project/PythonSettings_appveyor.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<PropertyGroup Label="UserMacros">
<BoostBase></BoostBase>
<BoostPythonLibPath></BoostPythonLibPath>
<PythonBase>$(SolutionDir)/packages/python2x86.2.7.15/tools</PythonBase>
<PythonBaseX64>$(SolutionDir)/packages/python2.2.7.15/tools</PythonBaseX64>
<PythonBase>$(SolutionDir)/packages/pythonx86.3.6.5/tools</PythonBase>
<PythonBaseX64>$(SolutionDir)/packages/python.3.6.5/tools</PythonBaseX64>
<PythonLibPath>$(PythonBase)\libs</PythonLibPath>
<PythonLibPathX64>$(PythonBaseX64)\libs</PythonLibPathX64>
<HtmlHelpBase>C:\Program Files (x86)\HTML Help Workshop</HtmlHelpBase>
Expand Down
4 changes: 2 additions & 2 deletions PythonScript/project/packages_appveyor.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<package id="boost" version="1.66.0.0" targetFramework="native" />
<package id="boost_python-vc140" version="1.66.0.0" targetFramework="native" />
<package id="boost_regex-vc140" version="1.66.0.0" targetFramework="native" />
<package id="python2" version="2.7.15" targetFramework="native" />
<package id="python2x86" version="2.7.15" targetFramework="native" />
<package id="python" version="3.6.5" targetFramework="native" />
<package id="pythonx86" version="3.6.5" targetFramework="native" />
</packages>
4 changes: 2 additions & 2 deletions PythonScript/src/Match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ boost::python::str Match::py_group_name(boost::python::str pyGroupName)

boost::python::str Match::getGroup(boost::python::object groupIdentifier)
{
if (PyInt_Check(groupIdentifier.ptr()))
if (PyLong_Check(groupIdentifier.ptr()))
{
return py_group_number(boost::python::extract<int>(groupIdentifier));
}
else if (PyString_Check(groupIdentifier.ptr()))
else if (PyUnicode_Check(groupIdentifier.ptr()))
{
return py_group_name(boost::python::extract<boost::python::str>(groupIdentifier));
}
Expand Down
42 changes: 4 additions & 38 deletions PythonScript/src/PythonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,51 +303,17 @@ void PythonHandler::runScriptWorker(const std::shared_ptr<RunScriptArgs>& args)
}
else
{
std::shared_ptr<char> filenameUFT8 = WcharMbcsConverter::tchar2char(args->m_filename.c_str());
FILE* pyFile = _tfopen(args->m_filename.c_str(), _T("r"));

if (containsExtendedChars(filenameUFT8.get()))
{
// First obtain the size needed by passing NULL and 0.
const long initLength = GetShortPathName(args->m_filename.c_str(), NULL, 0);
if (initLength > 0)
{
// Dynamically allocate the correct size
// (terminating null char was included in length)
tstring buffer(initLength, 0);

// Now simply call again using same long path.

long length = GetShortPathName(args->m_filename.c_str(), const_cast<LPWSTR>(buffer.c_str()), initLength);
if (length > 0)
{
filenameUFT8 = WcharMbcsConverter::tchar2char(buffer.c_str());
}
}
}

// We assume PyFile_FromString won't modify the file name passed in param
// (that would be quite troubling) and that the missing 'const' is simply an oversight
// from the Python API developers.
// We also assume the second parameter, "r" won't be modified by the function call.
//lint -e{1776} Converting a string literal to char * is not const safe (arg. no. 2)
PyObject* pyFile = PyFile_FromString(filenameUFT8.get(), "r");

if (pyFile)
{
if (PyRun_SimpleFile(PyFile_AsFile(pyFile), filenameUFT8.get()) == -1)
{
if (ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1"))
{
mp_console->writeText(boost::python::str("\n"));
}

if (ConfigFile::getInstance()->getSetting(_T("OPENCONSOLEONERROR")) == _T("1"))
{
mp_console->pythonShowDialog();
}
}
Py_DECREF(pyFile);
PyRun_SimpleFile(pyFile, WcharMbcsConverter::tchar2char(args->m_filename.c_str()).get());
}

fclose(pyFile);
}

if (NULL != args->m_completedEvent)
Expand Down
11 changes: 10 additions & 1 deletion PythonScript/src/ScintillaPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,18 @@ BOOST_PYTHON_MODULE(Npp)
export_match();
}

//see https://github.com/TNG/boost-python-examples/blob/master/10-Embedding/embedding.cpp
#if PY_MAJOR_VERSION >= 3
# define INIT_MODULE PyInit_Npp
extern "C" PyObject* INIT_MODULE();
#else
# define INIT_MODULE initNpp
extern "C" void INIT_MODULE();
#endif

void preinitScintillaModule()
{
PyImport_AppendInittab("Npp", &initNpp);
PyImport_AppendInittab("Npp", INIT_MODULE);
}

void importScintilla(boost::shared_ptr<ScintillaWrapper> editor, boost::shared_ptr<ScintillaWrapper> editor1, boost::shared_ptr<ScintillaWrapper> editor2)
Expand Down
4 changes: 2 additions & 2 deletions PythonScript/src/ScintillaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,13 @@ void ScintillaWrapper::forEachLine(PyObject* function)

boost::python::object result = boost::python::call<boost::python::object>(function, GetLine(line), line, lineCount);

if (result.is_none() || !PyInt_Check(result.ptr()))
if (result.is_none() || !PyLong_Check(result.ptr()))
{
++line;
}
else
{
line += PyInt_AsLong(result.ptr());
line += PyLong_AsLong(result.ptr());
}

lineCount = GetLineCount();
Expand Down

0 comments on commit 06b698b

Please sign in to comment.