Skip to content

Commit f8de942

Browse files
committed
vs2015 编译支持
kbengine#292
1 parent d993b7b commit f8de942

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎kbe/src/lib/pyscript/script.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,28 +352,28 @@ void Script::setenv(const std::string& name, const std::string& value)
352352

353353
if(osModule)
354354
{
355-
PyObject* environ = NULL;
355+
PyObject* py_environ = NULL;
356356
PyObject* py_name = NULL;
357357
PyObject* py_value = NULL;
358358

359359
PyObject* supports_bytes_environ = PyObject_GetAttrString(osModule, "supports_bytes_environ");
360360
if(Py_True == supports_bytes_environ)
361361
{
362-
environ = PyObject_GetAttrString(osModule, "environb");
362+
py_environ = PyObject_GetAttrString(osModule, "environb");
363363
py_name = PyBytes_FromString(name.c_str());
364364
py_value = PyBytes_FromString(value.c_str());
365365
}
366366
else
367367
{
368-
environ = PyObject_GetAttrString(osModule, "environ");
368+
py_environ = PyObject_GetAttrString(osModule, "environ");
369369
py_name = PyUnicode_FromString(name.c_str());
370370
py_value = PyUnicode_FromString(value.c_str());
371371
}
372372

373373
Py_DECREF(supports_bytes_environ);
374374
Py_DECREF(osModule);
375375

376-
if (!environ)
376+
if (!py_environ)
377377
{
378378
ERROR_MSG("Script::setenv: get os.environ is error!\n");
379379
PyErr_PrintEx(0);
@@ -382,21 +382,21 @@ void Script::setenv(const std::string& name, const std::string& value)
382382
return;
383383
}
384384

385-
PyObject* environData = PyObject_GetAttrString(environ, "_data");
385+
PyObject* environData = PyObject_GetAttrString(py_environ, "_data");
386386
if (!environData)
387387
{
388388
ERROR_MSG("Script::setenv: os.environ._data not exist!\n");
389389
PyErr_PrintEx(0);
390390
Py_DECREF(py_value);
391391
Py_DECREF(py_name);
392-
Py_DECREF(environ);
392+
Py_DECREF(py_environ);
393393
return;
394394
}
395395

396396
int ret = PyDict_SetItem(environData, py_name, py_value);
397397

398398
Py_DECREF(environData);
399-
Py_DECREF(environ);
399+
Py_DECREF(py_environ);
400400
Py_DECREF(py_value);
401401
Py_DECREF(py_name);
402402

‎kbe/src/lib/python/Modules/main.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,16 @@ Py_Main(int argc, wchar_t **argv)
511511
#ifdef MS_WINDOWS
512512
if (!Py_IgnoreEnvironmentFlag && (wp = _wgetenv(L"PYTHONWARNINGS")) &&
513513
*wp != L'\0') {
514-
wchar_t *buf, *warning;
514+
wchar_t *buf, *warning, *context = NULL;
515515

516516
buf = (wchar_t *)PyMem_RawMalloc((wcslen(wp) + 1) * sizeof(wchar_t));
517517
if (buf == NULL)
518518
Py_FatalError(
519519
"not enough memory to copy PYTHONWARNINGS");
520520
wcscpy(buf, wp);
521-
for (warning = wcstok(buf, L",");
521+
for (warning = wcstok_s(buf, L",", &context);
522522
warning != NULL;
523-
warning = wcstok(NULL, L",")) {
523+
warning = wcstok_s(NULL, L",", &context)) {
524524
PySys_AddWarnOption(warning);
525525
}
526526
PyMem_RawFree(buf);

‎kbe/src/lib/python/PC/getpathp.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,12 @@ find_env_config_value(FILE * env_file, const wchar_t * key, wchar_t * value)
451451
tmpbuffer, MAXPATHLEN * 2);
452452
Py_DECREF(decoded);
453453
if (k >= 0) {
454-
wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n");
454+
wchar_t * context = NULL;
455+
wchar_t * tok = wcstok_s(tmpbuffer, L" \t\r\n", &context);
455456
if ((tok != NULL) && !wcscmp(tok, key)) {
456-
tok = wcstok(NULL, L" \t");
457+
tok = wcstok_s(NULL, L" \t", &context);
457458
if ((tok != NULL) && !wcscmp(tok, L"=")) {
458-
tok = wcstok(NULL, L"\r\n");
459+
tok = wcstok_s(NULL, L"\r\n", &context);
459460
if (tok != NULL) {
460461
wcsncpy(value, tok, MAXPATHLEN);
461462
result = 1;

‎kbe/src/lib/python/PC/pyconfig.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ typedef int pid_t;
218218
#define HAVE_SXS 1
219219
#endif
220220

221+
/* VS 2015 defines these names with a leading underscore */
222+
#if _MSC_VER >= 1900
223+
#define timezone _timezone
224+
#define daylight _daylight
225+
#define tzname _tzname
226+
#endif
227+
221228
/* define some ANSI types that are not defined in earlier Win headers */
222229
#if _MSC_VER >= 1200
223230
/* This file only exists in VC 6.0 or higher */

0 commit comments

Comments
 (0)