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.

classification
Title: MSVC Compiler warning in Python\import.c
Type: compile error Stage: resolved
Components: Build, Interpreter Core, Windows Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: stutzbach Nosy List: amaury.forgeotdarc, brian.curtin, janglin, stutzbach
Priority: low Keywords: easy, patch

Created on 2010-09-03 09:42 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
9752.diff janglin, 2010-09-08 04:37 patch for issue 9752
no-macro.diff janglin, 2010-09-08 14:01
Messages (10)
msg115428 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-03 09:42
7>..\Python\import.c(1158) : warning C4013: 'mkdir' undefined; assuming extern returning int
msg115846 - (view) Author: Jon Anglin (janglin) Date: 2010-09-08 04:36
Windows provides two versions of mkdir in direct.h:
    int mkdir(const char* dirname)
    int _mkdir(const char* dirname)
The latter is the preferred function because it is conformant to the ISO C++ standard.  As you can see, neither function has a mode parameter like the Unix system call.  The directory permissions are inherited from the parent directory.

I simply defined a macro that expands to the correct version of mkdir for the system that Python is being compiled upon.  I found other instances in the Python source where similar things were done so I hope my solution is acceptable.

I have tested my solution on 32 and 64 bit builds of Python from the py3k svn trunk.
msg115847 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-08 04:49
What about using CreateDirectory?
msg115850 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-08 05:27
As far as I can tell, _mkdir(name) is equivalent to CreateDirectoryA(name, NULL), except one uses errno and the other uses GetLastErrno.  It is definitely possible that there's something I don't know, though, and the documentation doesn't explicitly state that they're equivalent.

With regard to the mode parameter, I noticed that the implementation of os.mkdir for Windows doesn't do anything with it, which probably means we can not worry about the mode parameter here as well?

os.mkdir's implementation just calls CreateDirectory(path, NULL).  The code is in a #ifdef MS_WINDOWS in posix_mkdir() in Modules/posixmodule.c.
msg115862 - (view) Author: Jon Anglin (janglin) Date: 2010-09-08 12:24
Visual Studio ships with the source code for the CRT (\Program Files\Microsoft Visual Studio 9.0\VC\crt\src). I looked up _mkdir. It does just call CreateDirectory(path, NULL).  If no error occurs it returns zero. If an error occurs, it then converts the result of GetLastError to an appropriate errno code and returns -1.

Thus the following calls are equivalent:
    _mkdir(dirname);
    CreateDirectory(dirname, NULL);
msg115869 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-08 13:35
Thanks for looking into that.

Since we now know that there is no use for the mode parameter on Windows, let's just remove the mode related stuff (of course leaving it for other OSes). We could then remove the macro and do the #ifdef dance around the mkdir/_mkdir call.
msg115874 - (view) Author: Jon Anglin (janglin) Date: 2010-09-08 14:01
How about this: see no-macro.diff
BTW: should I be using the .patch extension or .diff extension?
msg115970 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-09 20:33
The patch is good, and fixes an incorrect call to the mkdir function.
msg115972 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-09 20:34
> BTW: should I be using the .patch extension or .diff extension?
Both extensions are fine and handled the same way
msg115975 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-09 21:18
Committed as r84659.  Thanks for the patch!
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 53961
2010-09-09 21:18:48stutzbachsetstatus: open -> closed
type: compile error
messages: + msg115975

stage: patch review -> resolved
2010-09-09 20:34:53amaury.forgeotdarcsetmessages: + msg115972
2010-09-09 20:33:50amaury.forgeotdarcsetresolution: accepted

messages: + msg115970
nosy: + amaury.forgeotdarc
2010-09-08 14:01:25janglinsetfiles: + no-macro.diff

messages: + msg115874
2010-09-08 13:35:15brian.curtinsetmessages: + msg115869
stage: needs patch -> patch review
2010-09-08 12:24:39janglinsetmessages: + msg115862
2010-09-08 05:27:41stutzbachsetmessages: + msg115850
2010-09-08 04:49:12brian.curtinsetnosy: + brian.curtin
messages: + msg115847
components: + Build
2010-09-08 04:37:05janglinsetfiles: + 9752.diff

nosy: + janglin
messages: + msg115846

keywords: + patch
2010-09-03 09:42:31stutzbachcreate