Kaydet (Commit) 29c1ea5a authored tarafından Guido van Rossum's avatar Guido van Rossum

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.
üst fb84255e
...@@ -60,6 +60,9 @@ extern void inittime(); ...@@ -60,6 +60,9 @@ extern void inittime();
extern void initthread(); extern void initthread();
extern void initcStringIO(); extern void initcStringIO();
extern void initcPickle(); extern void initcPickle();
#ifdef WIN32
extern void initmsvcrt();
#endif
/* -- ADDMODULE MARKER 1 -- */ /* -- ADDMODULE MARKER 1 -- */
...@@ -98,6 +101,9 @@ struct _inittab _PyImport_Inittab[] = { ...@@ -98,6 +101,9 @@ struct _inittab _PyImport_Inittab[] = {
#endif #endif
{"cStringIO", initcStringIO}, {"cStringIO", initcStringIO},
{"cPickle", initcPickle}, {"cPickle", initcPickle},
#ifdef WIN32
{"msvcrt", initmsvcrt},
#endif
/* -- ADDMODULE MARKER 2 -- */ /* -- ADDMODULE MARKER 2 -- */
......
/* -*- C -*- ***********************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Python interpreter main program */
extern int Py_Main(int, char **);
int
main(argc, argv)
int argc;
char **argv;
{
return Py_Main(argc, argv);
}
/*********************************************************
msvcrtmodule.c
A Python interface to the Microsoft Visual C Runtime
Library, providing access to those non-portable, but
still useful routines.
Only ever compiled with an MS compiler, so no attempt
has been made to avoid MS language extensions, etc...
***********************************************************/
#include "Python.h"
#include "malloc.h"
// Perform locking operations on a file.
static PyObject *msvcrt_locking(PyObject *self, PyObject *args)
{
int mode;
long nBytes;
PyObject *obFile;
FILE *pFile;
if (!PyArg_ParseTuple(args,"O!il:locking", &obFile, PyFile_Type, &mode, &nBytes))
return NULL;
if (NULL==(pFile = PyFile_AsFile(obFile)))
return NULL;
if (0 != _locking(_fileno(pFile), mode, nBytes))
return PyErr_SetFromErrno(PyExc_IOError);
Py_INCREF(Py_None);
return Py_None;
}
// Forces the malloc heap to clean itself up, and free unused blocks
// back to the OS.
static PyObject *msvcrt_heapmin(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args,":heapmin"))
return NULL;
if (_heapmin()!=0)
return PyErr_SetFromErrno(PyExc_MemoryError); // Is this the correct error???
Py_INCREF(Py_None);
return Py_None;
}
/*******
Left this out for now...
// Convert an OS file handle to a Python file object (yay!).
// This may only work on NT
static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
{
// Note that we get the underlying handle using the long
// "abstract" interface. This will allow either a native integer
// or else a Win32 extension PyHANDLE object, which implements an
// int() converter.
PyObject *obHandle;
PyObject *obInt;
int flags;
long handle;
if (!PyArg_ParseTuple(args,"Oi:open_osfhandle", &obHandle, &flags))
return NULL;
if (NULL==(obInt = PyNumber_Int(obHandle))) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "The handle param must be an integer, =
or an object able to be converted to an integer");
return NULL;
}
handle = PyInt_AsLong(obInt);
Py_DECREF(obInt);
rtHandle = _open_osfhandle(handle, flags);
if (rtHandle==-1)
return PyErr_SetFromErrno(PyExc_IOError);
what mode? Should I just return here, and expose _fdopen
and setvbuf?
f1=_fdopen(fd1, "w");
setvbuf(f1, NULL, _IONBF, 0);
f=PyFile_FromFile(f1, cmdstring, "w", fclose);
}
*****/
/* List of functions exported by this module */
static struct PyMethodDef msvcrt_functions[] = {
{"locking", msvcrt_locking, 1},
{"heapmin", msvcrt_heapmin, 1},
{NULL, NULL}
};
__declspec(dllexport) void
initmsvcrt(void)
{
Py_InitModule("msvcrt", msvcrt_functions);
}
...@@ -54,6 +54,8 @@ EXPORTS ...@@ -54,6 +54,8 @@ EXPORTS
PySlice_Type DATA PySlice_Type DATA
Py_InteractiveFlag DATA Py_InteractiveFlag DATA
PyCObject_Type DATA PyCObject_Type DATA
Py_input_hook DATA
PyOS_ReadlineFunctionPointer DATA
_PyObject_New _PyObject_New
_PyObject_NewVar _PyObject_NewVar
...@@ -196,21 +198,19 @@ EXPORTS ...@@ -196,21 +198,19 @@ EXPORTS
PyEval_ReleaseThread PyEval_ReleaseThread
PyEval_RestoreThread PyEval_RestoreThread
PyEval_SaveThread PyEval_SaveThread
PyEval_AcquireLock
PyEval_ReleaseLock
PyTraceBack_Here PyTraceBack_Here
PyTraceBack_Print PyTraceBack_Print
PyImport_AddModule PyImport_AddModule
PyImport_Cleanup
PyImport_GetModuleDict PyImport_GetModuleDict
PyImport_GetMagicNumber PyImport_GetMagicNumber
PyImport_ImportModule PyImport_ImportModule
PyImport_ImportFrozenModule PyImport_ImportFrozenModule
PyImport_Init
PyImport_ReloadModule PyImport_ReloadModule
PyNumber_Coerce PyNumber_Coerce
PyBuiltin_Init
PyMarshal_Init PyMarshal_Init
Py_InitModule4 Py_InitModule4
PySys_Init
PySys_SetArgv PySys_SetArgv
PySys_SetPath PySys_SetPath
PySys_GetObject PySys_GetObject
...@@ -219,7 +219,6 @@ EXPORTS ...@@ -219,7 +219,6 @@ EXPORTS
Py_CompileString Py_CompileString
Py_FatalError Py_FatalError
Py_Exit Py_Exit
Py_Cleanup
Py_Initialize Py_Initialize
PyErr_Print PyErr_Print
PyParser_SimpleParseFile PyParser_SimpleParseFile
...@@ -350,9 +349,17 @@ EXPORTS ...@@ -350,9 +349,17 @@ EXPORTS
PyThread_free_sema PyThread_free_sema
PyThread_down_sema PyThread_down_sema
PyThread_up_sema PyThread_up_sema
PyThread_exit_prog Py_NewInterpreter
PyThread__exit_prog Py_EndInterpreter
PyThread_create_key Py_Malloc
PyThread_delete_key Py_Realloc
PyThread_get_key_value Py_Free
PyThread_set_key_value PyMem_Malloc
PyMem_Realloc
PyMem_Free
PyThreadState_New
PyThreadState_Clear
PyThreadState_Delete
PyInterpreterState_New
PyInterpreterState_Clear
PyInterpreterState_Delete
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment