This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Need support to avoid Windows CRT compatibility issue.
Type: crash Stage:
Components: Interpreter Core, Windows Versions: Python 3.3
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, debarshig, loewis, pitrou
Priority: normal Keywords:

Created on 2013-10-18 10:19 by debarshig, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg200238 - (view) Author: Debarshi Goswami (debarshig) Date: 2013-10-18 10:19
Some support is needed to avoid compatibility issues in different version of CRT in Windows.
I have an application which embeds Python interpreter and the application is build on MSVC11, whereas I am using Python 3.3.2 which is build on MSVC10. I know there are some compatibility issues which are addressed in Issue10082 and Issue1003535. But even other Python APIs which uses FILE pointer inside are failing too. I tried the following things – 
1.	PyRun_FileExFlags with MSVC11 FILE*. It crashes as expected.
2.	PyRun_FileExFlags with MSVC10 FILE* using _Py_fopen() directly passing to it. It is also crashing whereas _Py_fopen() returns FILE* of MSVC10 type.
3.	Py_CompileString() also crashes. I don’t know the reason, but here my application is not providing FILE* from outside. It uses FILE* of Python library which is of MSVC10 type.
I did some investigation and found if I provide FILE* of MSVC10 type from my application in PyRun_File() or if I call Py_CompileString(), it crashes after parsing the file (I am not totally sure, but it seems to me). Here is the call stack – 
python33.dll!PyUnicode_InternInPlace(_object * * p) Line 14220 C
python33.dll!new_identifier(const char * n, compiling * c) Line 570 C
python33.dll!alias_for_import_name(compiling * c, const _node * n, int store) Line 2808 C
python33.dll!ast_for_import_stmt(compiling * c, const _node * n) Line 2892  C
python33.dll!PyAST_FromNode(const _node * n, PyCompilerFlags * flags, const char * filename, _arena * arena) Line 724   C
python33.dll!PyParser_ASTFromFile(_iobuf * fp, const char * filename, const char * enc, int start, char * ps1, char * ps2, PyCompilerFlags * flags, int * errcode, _arena * arena) Line 2124    C
python33.dll!PyRun_FileExFlags(_iobuf * fp, const char * filename, int start, _object * globals, _object * locals, int closeit, PyCompilerFlags * flags) Line 1931  C

It fails in PyDict_GetItem() call in PyUnicode_InternInPlace() function. Here is the snippet - 

/* It might be that the GetItem call fails even
   though the key is present in the dictionary,
   namely when this happens during a stack overflow. */
t = PyDict_GetItem(interned, s);

I am not sure why PyDict_GetItem() is failing because of FILE*. It seems to me that Python is able to parse file provided successfully.

I am initializing interpreter successfully and PyRun_String() API works fine. But I dont want to use PyRun_String() as it performs everything virtually and provide no debug support.
msg200239 - (view) Author: Debarshi Goswami (debarshig) Date: 2013-10-18 10:21
If any workaround is available. It is also fine.
msg200240 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-18 10:32
The easy answer is: don't execute a script, import a module instead (and either do something at that module's top-level, or execute a function inside the module).

Also, as for ABI issues, take a look at:
msg200242 - (view) Author: Debarshi Goswami (debarshig) Date: 2013-10-18 12:02
My question is, even a FILE* of MSVC10 type is provided, why these APIs are crashing, after all it expects MSVC10 type.
msg222660 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-10 12:27
Is there a specific Python question here?
msg222664 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2014-07-10 13:17
In any case, this issue has too little information to be able to reproduce it in a meaningful way. Closing as out-of-date.
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63482
2014-07-10 13:17:51loewissetstatus: open -> closed
resolution: out of date
messages: + msg222664
2014-07-10 12:27:42BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222660
2013-10-18 12:02:36debarshigsetmessages: + msg200242
2013-10-18 10:32:06pitrousetnosy: + loewis, pitrou
messages: + msg200240
2013-10-18 10:21:15debarshigsettype: crash
messages: + msg200239
2013-10-18 10:19:47debarshigcreate