Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29c1ea5

Browse files
committed
Got the new structure working with MSVC 4.2.
main_nt.c is gone -- we can use Modules/python.c now. Added Mark Hammond's module msvcrt.c (untested). Added several new symbols.
1 parent fb84255 commit 29c1ea5

5 files changed

Lines changed: 812 additions & 3940 deletions

File tree

PC/config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ extern void inittime();
6060
extern void initthread();
6161
extern void initcStringIO();
6262
extern void initcPickle();
63+
#ifdef WIN32
64+
extern void initmsvcrt();
65+
#endif
6366

6467
/* -- ADDMODULE MARKER 1 -- */
6568

@@ -98,6 +101,9 @@ struct _inittab _PyImport_Inittab[] = {
98101
#endif
99102
{"cStringIO", initcStringIO},
100103
{"cPickle", initcPickle},
104+
#ifdef WIN32
105+
{"msvcrt", initmsvcrt},
106+
#endif
101107

102108
/* -- ADDMODULE MARKER 2 -- */
103109

PC/main_nt.c

Lines changed: 0 additions & 42 deletions
This file was deleted.

PC/msvcrtmodule.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*********************************************************
2+
3+
msvcrtmodule.c
4+
5+
A Python interface to the Microsoft Visual C Runtime
6+
Library, providing access to those non-portable, but
7+
still useful routines.
8+
9+
Only ever compiled with an MS compiler, so no attempt
10+
has been made to avoid MS language extensions, etc...
11+
12+
***********************************************************/
13+
#include "Python.h"
14+
#include "malloc.h"
15+
// Perform locking operations on a file.
16+
static PyObject *msvcrt_locking(PyObject *self, PyObject *args)
17+
{
18+
int mode;
19+
long nBytes;
20+
PyObject *obFile;
21+
FILE *pFile;
22+
if (!PyArg_ParseTuple(args,"O!il:locking", &obFile, PyFile_Type, &mode, &nBytes))
23+
return NULL;
24+
if (NULL==(pFile = PyFile_AsFile(obFile)))
25+
return NULL;
26+
if (0 != _locking(_fileno(pFile), mode, nBytes))
27+
return PyErr_SetFromErrno(PyExc_IOError);
28+
Py_INCREF(Py_None);
29+
return Py_None;
30+
}
31+
32+
// Forces the malloc heap to clean itself up, and free unused blocks
33+
// back to the OS.
34+
static PyObject *msvcrt_heapmin(PyObject *self, PyObject *args)
35+
{
36+
if (!PyArg_ParseTuple(args,":heapmin"))
37+
return NULL;
38+
if (_heapmin()!=0)
39+
return PyErr_SetFromErrno(PyExc_MemoryError); // Is this the correct error???
40+
Py_INCREF(Py_None);
41+
return Py_None;
42+
}
43+
44+
/*******
45+
Left this out for now...
46+
47+
// Convert an OS file handle to a Python file object (yay!).
48+
// This may only work on NT
49+
static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
50+
{
51+
// Note that we get the underlying handle using the long
52+
// "abstract" interface. This will allow either a native integer
53+
// or else a Win32 extension PyHANDLE object, which implements an
54+
// int() converter.
55+
PyObject *obHandle;
56+
PyObject *obInt;
57+
int flags;
58+
long handle;
59+
if (!PyArg_ParseTuple(args,"Oi:open_osfhandle", &obHandle, &flags))
60+
return NULL;
61+
62+
if (NULL==(obInt = PyNumber_Int(obHandle))) {
63+
PyErr_Clear();
64+
PyErr_SetString(PyExc_TypeError, "The handle param must be an integer, =
65+
or an object able to be converted to an integer");
66+
return NULL;
67+
}
68+
handle = PyInt_AsLong(obInt);
69+
Py_DECREF(obInt);
70+
rtHandle = _open_osfhandle(handle, flags);
71+
if (rtHandle==-1)
72+
return PyErr_SetFromErrno(PyExc_IOError);
73+
74+
what mode? Should I just return here, and expose _fdopen
75+
and setvbuf?
76+
77+
f1=_fdopen(fd1, "w");
78+
setvbuf(f1, NULL, _IONBF, 0);
79+
f=PyFile_FromFile(f1, cmdstring, "w", fclose);
80+
81+
}
82+
*****/
83+
84+
/* List of functions exported by this module */
85+
static struct PyMethodDef msvcrt_functions[] = {
86+
{"locking", msvcrt_locking, 1},
87+
{"heapmin", msvcrt_heapmin, 1},
88+
{NULL, NULL}
89+
};
90+
91+
__declspec(dllexport) void
92+
initmsvcrt(void)
93+
{
94+
Py_InitModule("msvcrt", msvcrt_functions);
95+
}

PC/python_nt.def

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ EXPORTS
5454
PySlice_Type DATA
5555
Py_InteractiveFlag DATA
5656
PyCObject_Type DATA
57+
Py_input_hook DATA
58+
PyOS_ReadlineFunctionPointer DATA
5759

5860
_PyObject_New
5961
_PyObject_NewVar
@@ -196,21 +198,19 @@ EXPORTS
196198
PyEval_ReleaseThread
197199
PyEval_RestoreThread
198200
PyEval_SaveThread
201+
PyEval_AcquireLock
202+
PyEval_ReleaseLock
199203
PyTraceBack_Here
200204
PyTraceBack_Print
201205
PyImport_AddModule
202-
PyImport_Cleanup
203206
PyImport_GetModuleDict
204207
PyImport_GetMagicNumber
205208
PyImport_ImportModule
206209
PyImport_ImportFrozenModule
207-
PyImport_Init
208210
PyImport_ReloadModule
209211
PyNumber_Coerce
210-
PyBuiltin_Init
211212
PyMarshal_Init
212213
Py_InitModule4
213-
PySys_Init
214214
PySys_SetArgv
215215
PySys_SetPath
216216
PySys_GetObject
@@ -219,7 +219,6 @@ EXPORTS
219219
Py_CompileString
220220
Py_FatalError
221221
Py_Exit
222-
Py_Cleanup
223222
Py_Initialize
224223
PyErr_Print
225224
PyParser_SimpleParseFile
@@ -350,9 +349,17 @@ EXPORTS
350349
PyThread_free_sema
351350
PyThread_down_sema
352351
PyThread_up_sema
353-
PyThread_exit_prog
354-
PyThread__exit_prog
355-
PyThread_create_key
356-
PyThread_delete_key
357-
PyThread_get_key_value
358-
PyThread_set_key_value
352+
Py_NewInterpreter
353+
Py_EndInterpreter
354+
Py_Malloc
355+
Py_Realloc
356+
Py_Free
357+
PyMem_Malloc
358+
PyMem_Realloc
359+
PyMem_Free
360+
PyThreadState_New
361+
PyThreadState_Clear
362+
PyThreadState_Delete
363+
PyInterpreterState_New
364+
PyInterpreterState_Clear
365+
PyInterpreterState_Delete

0 commit comments

Comments
 (0)