RE: [Python-checkins] python/dist/src/Modules _randommodule.c,1.1,1.2

[nnorwitz@users.sourceforge.net]
And then, for example, before:
! PyObject_GenericGetAttr, /*tp_getattro*/
and after:
! 0, /*tp_getattro*/
followed by:
in the module init function. Please don't make this kind of change -- it makes the code so much harder to follow. If this is needed for Cygwin, then, e.g., do #define DEFERRED(x) 0 /* some boxes can't resolve addresses at compile-time */ and make the "after" line DEFERRED(PyObject_GenericGetAttr), /*tp_getattro*/ IOW, the type slots should be readable on their own, as a static unit.

On Tue, Dec 31, 2002 at 05:14:17PM -0500, Tim Peters wrote:
I agree, this makes sense. The only problem is that the functions/methods will have to be specified twice. It would be nice if we only had to specify each once. Any ideas? There are several places this has already been done (and at least one more coming). Do you want a global Py_DEFERRED() or some other name? Neal

... DEFERRED(PyObject_GenericGetAttr), /*tp_getattro*/
[NealN]
None beyond not making A Project out of it -- tricks with the C preprocessor are usually worse than the diseases they're trying to cure, so KISS.
There are several places this has already been done (and at least one more coming). Do you want a global Py_DEFERRED() or some other name?
Py_DEFERRED would be fine. So would a pile of local DEFERREDs: a trivial one-line one-token macro that can't be screwed up isn't really aching for generalization or factorization, although it may be nice to have a longer comment explaining the need for it in just one place.

How about having specific markers such as DEFERRED_GenericGetAttr and then having PyType_Ready scan for them and replace them with the appropriate pointers? ----- Original Message ----- From: "Tim Peters" <tim.one@comcast.net> To: <neal@metaslash.com> Cc: <jlt63@users.sourceforge.net>; "PythonDev" <python-dev@python.org> Sent: Wednesday, January 01, 2003 8:43 PM Subject: [Python-Dev] RE: [Python-checkins] python/dist/src/Modules _randommodule.c,1.1,1.2

-1. Violates the KISS principle in many ways. --Guido van Rossum (home page: http://www.python.org/~guido/)

On Tue, Dec 31, 2002 at 05:14:17PM -0500, Tim Peters wrote:
I believe that I have found a cleaner solution to this problem. Cygwin's ld can auto-import functions: http://www.cygwin.com/ml/cygwin-apps/2001-08/msg00024.html Specifically, the following snippet is the most pertinent: We "always" have allowed 'auto-import' of *functions* that are exported by the DLL (as long as the DLL contains the appropriate symbols). Note I don't believe that "always" pertained when I first started down this path in the Python 2.0 time frame. Anyway, with the attached patch to pyport.h, I was able to build Cygwin Python without any errors. Note this includes the new datetime module from CVS -- not the patched one in sandbox. I feel this is the best approach because modules should build under Cygwin without the standard Cygwin style patch that I have been submitting for years. Do others concur? If so, then I will begin to clean up the "mess" that I have created. Now if SF could search for patches by the submitter, my job would be a little easier... Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

On Thu, Jan 02, 2003 at 04:40:21PM -0500, Jason Tishler wrote:
I think you can simplify the patch by doing: #if !defined(__CYGWIN__) #define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE #endif (ie, just don't define PyAPI_FUNC on line 432) PyAPI_FUNC will still get defined in the next block (445).
Now if SF could search for patches by the submitter, my job would be a little easier...
You can look for patches closed and assigned to you. That should help. But the line below (which has 35 hits) is probably faster/easier: egrep '\.tp_.* =' */*.c It may not be everything, but should be a pretty good start. Or you could grep all your checkins. :-) Neal --

On Thu, Jan 02, 2003 at 05:25:24PM -0500, Neal Norwitz wrote:
I will modify my patch to use the above instead.
But the line below (which has 35 hits) is probably faster/easier:
egrep '\.tp_.* =' */*.c
I will submit a patch to the SF Python collector to fix the following: Modules/arraymodule.c: Arraytype.tp_getattro = PyObject_GenericGetAttr; Modules/arraymodule.c: Arraytype.tp_alloc = PyType_GenericAlloc; Modules/arraymodule.c: Arraytype.tp_free = PyObject_Del; Modules/bz2module.c: BZ2File_Type.tp_base = &PyFile_Type; Modules/bz2module.c: BZ2File_Type.tp_new = PyFile_Type.tp_new; Modules/bz2module.c: BZ2File_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2File_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2File_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2File_Type.tp_free = _PyObject_Del; Modules/bz2module.c: BZ2Comp_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2Comp_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2Comp_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2Comp_Type.tp_new = PyType_GenericNew; Modules/bz2module.c: BZ2Comp_Type.tp_free = _PyObject_Del; Modules/bz2module.c: BZ2Decomp_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2Decomp_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2Decomp_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2Decomp_Type.tp_new = PyType_GenericNew; Modules/bz2module.c: BZ2Decomp_Type.tp_free = _PyObject_Del; Modules/cPickle.c: Picklertype.tp_getattro = PyObject_GenericGetAttr; Modules/cPickle.c: Picklertype.tp_setattro = PyObject_GenericSetAttr; Modules/posixmodule.c: StatResultType.tp_new = statresult_new; Modules/socketmodule.c: sock_type.tp_getattro = PyObject_GenericGetAttr; Modules/socketmodule.c: sock_type.tp_alloc = PyType_GenericAlloc; Modules/socketmodule.c: sock_type.tp_free = PyObject_Del; Modules/threadmodule.c: Locktype.tp_doc = lock_doc; Modules/xxsubtype.c: spamdict_type.tp_base = &PyDict_Type; Modules/xxsubtype.c: spamlist_type.tp_base = &PyList_Type; Modules/_hotshot.c: LogReaderType.tp_getattro = PyObject_GenericGetAttr; Modules/_hotshot.c: ProfilerType.tp_getattro = PyObject_GenericGetAttr; Modules/_randommodule.c: Random_Type.tp_getattro = PyObject_GenericGetAttr; Modules/_randommodule.c: Random_Type.tp_alloc = PyType_GenericAlloc; Modules/_randommodule.c: Random_Type.tp_free = _PyObject_Del; Modules/_tkinter.c: PyTclObject_Type.tp_getattro = &PyObject_GenericGetAttr; Note that I intend to skip PC/_winreg.c unless someone feels strongly that I should change this one too. Thanks, Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

Jason Tishler <jason@tishler.net> writes:
This is what I thought a reasonable operating system and compiler should do by default, without even asking. I certainly agree that it is desirable that you can put function pointers into static structures, so if it takes additional compiler flags to make it so, then use those flags. I'm unclear why you have to *omit* the declspec, though, to make it work - I thought that __declspec(dllimport) is precisely the magic incantation that makes the compiler emit the necessary thunks.
Now if SF could search for patches by the submitter, my job would be a little easier...
Doing a full-text search on Cygwin should give a pretty good hit ratio. regards, Martin

On Thu, Jan 02, 2003 at 11:29:33PM +0100, Martin v. Löwis wrote:
Well then, I guess Windows, Cygwin, and/or gcc are not "reasonable." :,)
Back when I first submitted my Cygwin Python DLL and Shared Extension Patch: http://sf.net/tracker/?group_id=5470&atid=305470&func=detail&aid=402409 there were no such options. Since then Cygwin ld has been significantly enhanced to support the following options: --enable-auto-import (currently defaults to enabled) --enable-runtime-pseudo-reloc (currently defaults to disabled) See the Cygwin ld man page for more details, if interested. Since Python's source already had the __declspec(dllexport) and __declspec(dllimport) indicators for Win32, I never pursued leveraging off of the new functionality. That is, until Tim informed me that MSVC could deal with __declspec(dllimport) function pointers as static initializers. I had erroneously concluded from the following: http://python.org/doc/FAQ.html#3.24 that it couldn't.
Before --enable-auto-import was added to Cygwin ld, both __declspec(dllexport) and __declspec(dllimport) were necessary for successful linking. After --enable-auto-import was added, the linker could automatically import functions as long as the function was exported by any of the various methods (e.g., __declspec(dllexport), --export-all-symbols, .def file, etc.). Since the __declspec(dllimport) indicators are causing compilation problems with shared extension modules and they are no longer needed, it seems that the simplest (and best) solution is to just remove them. Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

On Tue, Dec 31, 2002 at 05:14:17PM -0500, Tim Peters wrote:
I agree, this makes sense. The only problem is that the functions/methods will have to be specified twice. It would be nice if we only had to specify each once. Any ideas? There are several places this has already been done (and at least one more coming). Do you want a global Py_DEFERRED() or some other name? Neal

... DEFERRED(PyObject_GenericGetAttr), /*tp_getattro*/
[NealN]
None beyond not making A Project out of it -- tricks with the C preprocessor are usually worse than the diseases they're trying to cure, so KISS.
There are several places this has already been done (and at least one more coming). Do you want a global Py_DEFERRED() or some other name?
Py_DEFERRED would be fine. So would a pile of local DEFERREDs: a trivial one-line one-token macro that can't be screwed up isn't really aching for generalization or factorization, although it may be nice to have a longer comment explaining the need for it in just one place.

How about having specific markers such as DEFERRED_GenericGetAttr and then having PyType_Ready scan for them and replace them with the appropriate pointers? ----- Original Message ----- From: "Tim Peters" <tim.one@comcast.net> To: <neal@metaslash.com> Cc: <jlt63@users.sourceforge.net>; "PythonDev" <python-dev@python.org> Sent: Wednesday, January 01, 2003 8:43 PM Subject: [Python-Dev] RE: [Python-checkins] python/dist/src/Modules _randommodule.c,1.1,1.2

-1. Violates the KISS principle in many ways. --Guido van Rossum (home page: http://www.python.org/~guido/)

On Tue, Dec 31, 2002 at 05:14:17PM -0500, Tim Peters wrote:
I believe that I have found a cleaner solution to this problem. Cygwin's ld can auto-import functions: http://www.cygwin.com/ml/cygwin-apps/2001-08/msg00024.html Specifically, the following snippet is the most pertinent: We "always" have allowed 'auto-import' of *functions* that are exported by the DLL (as long as the DLL contains the appropriate symbols). Note I don't believe that "always" pertained when I first started down this path in the Python 2.0 time frame. Anyway, with the attached patch to pyport.h, I was able to build Cygwin Python without any errors. Note this includes the new datetime module from CVS -- not the patched one in sandbox. I feel this is the best approach because modules should build under Cygwin without the standard Cygwin style patch that I have been submitting for years. Do others concur? If so, then I will begin to clean up the "mess" that I have created. Now if SF could search for patches by the submitter, my job would be a little easier... Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

On Thu, Jan 02, 2003 at 04:40:21PM -0500, Jason Tishler wrote:
I think you can simplify the patch by doing: #if !defined(__CYGWIN__) #define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE #endif (ie, just don't define PyAPI_FUNC on line 432) PyAPI_FUNC will still get defined in the next block (445).
Now if SF could search for patches by the submitter, my job would be a little easier...
You can look for patches closed and assigned to you. That should help. But the line below (which has 35 hits) is probably faster/easier: egrep '\.tp_.* =' */*.c It may not be everything, but should be a pretty good start. Or you could grep all your checkins. :-) Neal --

On Thu, Jan 02, 2003 at 05:25:24PM -0500, Neal Norwitz wrote:
I will modify my patch to use the above instead.
But the line below (which has 35 hits) is probably faster/easier:
egrep '\.tp_.* =' */*.c
I will submit a patch to the SF Python collector to fix the following: Modules/arraymodule.c: Arraytype.tp_getattro = PyObject_GenericGetAttr; Modules/arraymodule.c: Arraytype.tp_alloc = PyType_GenericAlloc; Modules/arraymodule.c: Arraytype.tp_free = PyObject_Del; Modules/bz2module.c: BZ2File_Type.tp_base = &PyFile_Type; Modules/bz2module.c: BZ2File_Type.tp_new = PyFile_Type.tp_new; Modules/bz2module.c: BZ2File_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2File_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2File_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2File_Type.tp_free = _PyObject_Del; Modules/bz2module.c: BZ2Comp_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2Comp_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2Comp_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2Comp_Type.tp_new = PyType_GenericNew; Modules/bz2module.c: BZ2Comp_Type.tp_free = _PyObject_Del; Modules/bz2module.c: BZ2Decomp_Type.tp_getattro = PyObject_GenericGetAttr; Modules/bz2module.c: BZ2Decomp_Type.tp_setattro = PyObject_GenericSetAttr; Modules/bz2module.c: BZ2Decomp_Type.tp_alloc = PyType_GenericAlloc; Modules/bz2module.c: BZ2Decomp_Type.tp_new = PyType_GenericNew; Modules/bz2module.c: BZ2Decomp_Type.tp_free = _PyObject_Del; Modules/cPickle.c: Picklertype.tp_getattro = PyObject_GenericGetAttr; Modules/cPickle.c: Picklertype.tp_setattro = PyObject_GenericSetAttr; Modules/posixmodule.c: StatResultType.tp_new = statresult_new; Modules/socketmodule.c: sock_type.tp_getattro = PyObject_GenericGetAttr; Modules/socketmodule.c: sock_type.tp_alloc = PyType_GenericAlloc; Modules/socketmodule.c: sock_type.tp_free = PyObject_Del; Modules/threadmodule.c: Locktype.tp_doc = lock_doc; Modules/xxsubtype.c: spamdict_type.tp_base = &PyDict_Type; Modules/xxsubtype.c: spamlist_type.tp_base = &PyList_Type; Modules/_hotshot.c: LogReaderType.tp_getattro = PyObject_GenericGetAttr; Modules/_hotshot.c: ProfilerType.tp_getattro = PyObject_GenericGetAttr; Modules/_randommodule.c: Random_Type.tp_getattro = PyObject_GenericGetAttr; Modules/_randommodule.c: Random_Type.tp_alloc = PyType_GenericAlloc; Modules/_randommodule.c: Random_Type.tp_free = _PyObject_Del; Modules/_tkinter.c: PyTclObject_Type.tp_getattro = &PyObject_GenericGetAttr; Note that I intend to skip PC/_winreg.c unless someone feels strongly that I should change this one too. Thanks, Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

Jason Tishler <jason@tishler.net> writes:
This is what I thought a reasonable operating system and compiler should do by default, without even asking. I certainly agree that it is desirable that you can put function pointers into static structures, so if it takes additional compiler flags to make it so, then use those flags. I'm unclear why you have to *omit* the declspec, though, to make it work - I thought that __declspec(dllimport) is precisely the magic incantation that makes the compiler emit the necessary thunks.
Now if SF could search for patches by the submitter, my job would be a little easier...
Doing a full-text search on Cygwin should give a pretty good hit ratio. regards, Martin

On Thu, Jan 02, 2003 at 11:29:33PM +0100, Martin v. Löwis wrote:
Well then, I guess Windows, Cygwin, and/or gcc are not "reasonable." :,)
Back when I first submitted my Cygwin Python DLL and Shared Extension Patch: http://sf.net/tracker/?group_id=5470&atid=305470&func=detail&aid=402409 there were no such options. Since then Cygwin ld has been significantly enhanced to support the following options: --enable-auto-import (currently defaults to enabled) --enable-runtime-pseudo-reloc (currently defaults to disabled) See the Cygwin ld man page for more details, if interested. Since Python's source already had the __declspec(dllexport) and __declspec(dllimport) indicators for Win32, I never pursued leveraging off of the new functionality. That is, until Tim informed me that MSVC could deal with __declspec(dllimport) function pointers as static initializers. I had erroneously concluded from the following: http://python.org/doc/FAQ.html#3.24 that it couldn't.
Before --enable-auto-import was added to Cygwin ld, both __declspec(dllexport) and __declspec(dllimport) were necessary for successful linking. After --enable-auto-import was added, the linker could automatically import functions as long as the function was exported by any of the various methods (e.g., __declspec(dllexport), --export-all-symbols, .def file, etc.). Since the __declspec(dllimport) indicators are causing compilation problems with shared extension modules and they are no longer needed, it seems that the simplest (and best) solution is to just remove them. Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6
participants (6)
-
Guido van Rossum
-
Jason Tishler
-
martin@v.loewis.de
-
Neal Norwitz
-
Raymond Hettinger
-
Tim Peters