Extension Class patch for 1.5.2 (and C++)

Greg Couch %CGL gregc at cgl.ucsf.edu
Tue Jun 29 03:16:39 CEST 1999


Enclosed is a patch file for Jim Fulton's Extension Class package that
makes it work with the new PyTypeObject structure in Python 1.5.2.
I've also included changes to ExtensionClass.h that make it work with
C++.  The source that the patch is based on is the 1.2 release that
is available from http://www.digicool.com/releases/ExtensionClass/.

	Greg Couch
	gregc at cgl.ucsf.edu

===================================================================
RCS file: RCS/ExtensionClass.h,v
retrieving revision 1.12
diff -c -r1.12 ExtensionClass.h
*** ExtensionClass.h	1998/11/17 19:53:27	1.12
--- ExtensionClass.h	1999/06/29 00:38:22
***************
*** 1,6 ****
  /*
  
!   $Id: ExtensionClass.h,v 1.12 1998/11/17 19:53:27 jim Exp $
  
    Extension Class Definitions
  
--- 1,6 ----
  /*
  
!   $Id: ExtensionClass.h,v 1.12 1998/11/17 19:53:27 jim Exp gregc $
  
    Extension Class Definitions
  
***************
*** 144,153 ****
--- 144,164 ----
  	getattrofunc tp_getattro;
  	setattrofunc tp_setattro;
  	/* Space for future expansion */
+ #if PY_VERSION_HEX < 0x01050200
  	long tp_xxx3;
  	long tp_xxx4;
+ #else
+ 	PyBufferProcs *tp_as_buffer;
+ 	long tp_flags;
+ #endif
  
  	char *tp_doc; /* Documentation string */
+ #if PY_VERSION_HEX >= 0x01050200
+ 	long tp_xxx5;
+ 	long tp_xxx6;
+ 	long tp_xxx7;
+ 	long tp_xxx8;
+ #endif
  
  #ifdef COUNT_ALLOCS
  	/* these must be last */
***************
*** 278,299 ****
  
  /* Import the ExtensionClass CAPI */
  #define ExtensionClassImported \
!   (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
  
  /* Make sure the C interface has been imported and import it if necessary.
     This can be used in an if.
     */
  #define MakeSureExtensionClassImported \
!   (PyExtensionClassCAPI || \
!    (PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI")))
! 
  
  /* Export an Extension Base class in a given module dictionary with a
     given name and ExtensionClass structure.
     */
  #define PyExtensionClass_Export(D,N,T) \
!  if(PyExtensionClassCAPI || \
!    (PyExtensionClassCAPI= PyCObject_Import("ExtensionClass","CAPI"))) \
     { PyExtensionClassCAPI->Export(D,N,&T); }
  
  /* Convert a method list to a method chain.  */
--- 289,308 ----
  
  /* Import the ExtensionClass CAPI */
  #define ExtensionClassImported \
!   (PyExtensionClassCAPI= (struct ExtensionClassCAPIstruct *) \
!     PyCObject_Import("ExtensionClass","CAPI"))
  
  /* Make sure the C interface has been imported and import it if necessary.
     This can be used in an if.
     */
  #define MakeSureExtensionClassImported \
!   (PyExtensionClassCAPI || ExtensionClassImported)
  
  /* Export an Extension Base class in a given module dictionary with a
     given name and ExtensionClass structure.
     */
  #define PyExtensionClass_Export(D,N,T) \
!  if(MakeSureExtensionClassImported) \
     { PyExtensionClassCAPI->Export(D,N,&T); }
  
  /* Convert a method list to a method chain.  */
***************
*** 328,338 ****
--- 337,360 ----
  
  /* The following macro can be used to define an extension base class
     that only provides method and that is used as a pure mix-in class. */
+ #if PY_VERSION_HEX < 0x01050200 && !defined(COUNT_ALLOCS)
  #define PURE_MIXIN_CLASS(NAME,DOC,METHODS) \
  static PyExtensionClass NAME ## Type = { PyObject_HEAD_INIT(NULL) \
  	0, # NAME, sizeof(PyPureMixinObject), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
  	0, 0, 0, 0, 0, 0, 0, DOC, {METHODS, NULL}, \
          EXTENSIONCLASS_BASICNEW_FLAG}
+ #elif PY_VERSION_HEX >= 0x01050200 && defined(COUNT_ALLOCS)
+ static PyExtensionClass NAME ## Type = { PyObject_HEAD_INIT(NULL) \
+ 	0, # NAME, sizeof(PyPureMixinObject), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 	0, 0, 0, 0, 0, 0, 0, DOC, 0, 0, 0, 0, 0, 0, 0, 0, {METHODS, NULL}, \
+         EXTENSIONCLASS_BASICNEW_FLAG}
+ #else /* either PY_VERSION_HEX >= 0x01050200 or defined(COUNT_ALLOCS) */
+ #define PURE_MIXIN_CLASS(NAME,DOC,METHODS) \
+ static PyExtensionClass NAME ## Type = { PyObject_HEAD_INIT(NULL) \
+ 	0, # NAME, sizeof(PyPureMixinObject), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 	0, 0, 0, 0, 0, 0, 0, DOC, 0, 0, 0, 0, {METHODS, NULL}, \
+         EXTENSIONCLASS_BASICNEW_FLAG}
+ #endif
  
  /* The following macros provide limited access to extension-class
     method facilities. */
===================================================================
RCS file: RCS/ExtensionClass.c,v
retrieving revision 1.30
diff -c -r1.30 ExtensionClass.c
*** ExtensionClass.c	1998/11/17 19:48:32	1.30
--- ExtensionClass.c	1999/06/29 00:40:47
***************
*** 33,39 ****
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: ExtensionClass.c,v 1.30 1998/11/17 19:48:32 jim Exp $
  
    If you have questions regarding this software,
    contact:
--- 33,39 ----
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: ExtensionClass.c,v 1.30 1998/11/17 19:48:32 jim Exp gregc $
  
    If you have questions regarding this software,
    contact:
***************
*** 54,60 ****
  "  - They provide access to unbound methods,\n"
  "  - They can be called to create instances.\n"
  "\n"
! "$Id: ExtensionClass.c,v 1.30 1998/11/17 19:48:32 jim Exp $\n"
  ;
  
  #include <stdio.h>
--- 54,60 ----
  "  - They provide access to unbound methods,\n"
  "  - They can be called to create instances.\n"
  "\n"
! "$Id: ExtensionClass.c,v 1.30 1998/11/17 19:48:32 jim Exp gregc $\n"
  ;
  
  #include <stdio.h>
***************
*** 3325,3330 ****
--- 3325,3336 ----
    /* Space for future expansion */
    0L,0L,
    "C classes", /* Documentation string */
+ #if PY_VERSION_HEX >= 0x01050200
+   0, 0, 0, 0,
+ #endif
+ #ifdef COUNT_ALLOCS
+   0, 0, 0, 0,
+ #endif
    METHOD_CHAIN(ExtensionClass_methods)
  };
  
===================================================================
RCS file: RCS/Acquisition.c,v
retrieving revision 1.24
diff -c -r1.24 Acquisition.c
*** Acquisition.c	1998/11/17 19:49:43	1.24
--- Acquisition.c	1999/06/29 00:43:01
***************
*** 33,39 ****
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: Acquisition.c,v 1.24 1998/11/17 19:49:43 jim Exp $
  
    If you have questions regarding this software,
    contact:
--- 33,39 ----
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: Acquisition.c,v 1.24 1998/11/17 19:49:43 jim Exp gregc $
  
    If you have questions regarding this software,
    contact:
***************
*** 807,812 ****
--- 807,818 ----
    /* Space for future expansion */
    0L,0L,
    "Wrapper object for implicit acquisition", /* Documentation string */
+ #if PY_VERSION_HEX >= 0x01050200
+   0, 0, 0, 0,
+ #endif
+ #ifdef COUNT_ALLOCS
+   0, 0, 0, 0,
+ #endif
    METHOD_CHAIN(Wrapper_methods),
    EXTENSIONCLASS_BINDABLE_FLAG,
  };
***************
*** 836,841 ****
--- 842,853 ----
    /* Space for future expansion */
    0L,0L,
    "Wrapper object for explicit acquisition", /* Documentation string */
+ #if PY_VERSION_HEX >= 0x01050200
+   0, 0, 0, 0,
+ #endif
+ #ifdef COUNT_ALLOCS
+   0, 0, 0, 0,
+ #endif
    METHOD_CHAIN(Wrapper_methods),
    EXTENSIONCLASS_BINDABLE_FLAG,
  };
***************
*** 913,919 ****
    /* Create the module and add the functions */
    m = Py_InitModule4("Acquisition", methods,
  	   "Provide base classes for acquiring objects\n\n"
! 	   "$Id: Acquisition.c,v 1.24 1998/11/17 19:49:43 jim Exp $\n",
  		     OBJECT(NULL),PYTHON_API_VERSION);
  
    d = PyModule_GetDict(m);
--- 925,931 ----
    /* Create the module and add the functions */
    m = Py_InitModule4("Acquisition", methods,
  	   "Provide base classes for acquiring objects\n\n"
! 	   "$Id: Acquisition.c,v 1.24 1998/11/17 19:49:43 jim Exp gregc $\n",
  		     OBJECT(NULL),PYTHON_API_VERSION);
  
    d = PyModule_GetDict(m);
===================================================================
RCS file: RCS/Missing.c,v
retrieving revision 1.8
diff -c -r1.8 Missing.c
*** Missing.c	1998/11/17 19:54:33	1.8
--- Missing.c	1999/06/29 00:44:12
***************
*** 33,39 ****
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: Missing.c,v 1.8 1998/11/17 19:54:33 jim Exp $
  
    If you have questions regarding this software,
    contact:
--- 33,39 ----
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: Missing.c,v 1.8 1998/11/17 19:54:33 jim Exp gregc $
  
    If you have questions regarding this software,
    contact:
***************
*** 47,53 ****
  
  static char Missing_module_documentation[] = 
  ""
! "\n$Id: Missing.c,v 1.8 1998/11/17 19:54:33 jim Exp $"
  ;
  
  #include "ExtensionClass.h"
--- 47,53 ----
  
  static char Missing_module_documentation[] = 
  ""
! "\n$Id: Missing.c,v 1.8 1998/11/17 19:54:33 jim Exp gregc $"
  ;
  
  #include "ExtensionClass.h"
***************
*** 271,276 ****
--- 271,282 ----
    "Missing values are used to represent numberic quantities that are\n"
    "unknown.  They support all mathematical operations except\n"
    "conversions by returning themselves.\n",
+ #if PY_VERSION_HEX >= 0x01050200
+   0, 0, 0, 0,
+ #endif
+ #ifdef COUNT_ALLOCS
+   0, 0, 0, 0,
+ #endif
    METHOD_CHAIN(NULL)
  };
  
===================================================================
RCS file: RCS/MultiMapping.c,v
retrieving revision 1.7
diff -c -r1.7 MultiMapping.c
*** MultiMapping.c	1998/11/17 20:20:17	1.7
--- MultiMapping.c	1999/06/29 00:45:21
***************
*** 33,39 ****
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: MultiMapping.c,v 1.7 1998/11/17 20:20:17 jim Exp $
  
    If you have questions regarding this software,
    contact:
--- 33,39 ----
    USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGE.
  
!   $Id: MultiMapping.c,v 1.7 1998/11/17 20:20:17 jim Exp gregc $
  
    If you have questions regarding this software,
    contact:
***************
*** 222,227 ****
--- 222,233 ----
  	/* Space for future expansion */
  	0L,0L,0L,0L,
  	MMtype__doc__, /* Documentation string */
+ #if PY_VERSION_HEX >= 0x01050200
+ 	0, 0, 0, 0,
+ #endif
+ #ifdef COUNT_ALLOCS
+ 	0, 0, 0, 0,
+ #endif
  	METHOD_CHAIN(MM_methods)
  };
  
***************
*** 239,245 ****
        "MultiMapping", MultiMapping_methods,
        "MultiMapping -- Wrap multiple mapping objects for lookup"
        "\n\n"
!       "$Id: MultiMapping.c,v 1.7 1998/11/17 20:20:17 jim Exp $\n",
        (PyObject*)NULL,PYTHON_API_VERSION);
    d = PyModule_GetDict(m);
    PyExtensionClass_Export(d,"MultiMapping",MMtype);
--- 245,251 ----
        "MultiMapping", MultiMapping_methods,
        "MultiMapping -- Wrap multiple mapping objects for lookup"
        "\n\n"
!       "$Id: MultiMapping.c,v 1.7 1998/11/17 20:20:17 jim Exp gregc $\n",
        (PyObject*)NULL,PYTHON_API_VERSION);
    d = PyModule_GetDict(m);
    PyExtensionClass_Export(d,"MultiMapping",MMtype);
===================================================================
RCS file: RCS/ThreadLock.c,v
retrieving revision 1.5
diff -c -r1.5 ThreadLock.c
*** ThreadLock.c	1998/11/17 21:43:50	1.5
--- ThreadLock.c	1999/06/29 00:56:32
***************
*** 72,78 ****
    int count;
    long id;
  #ifdef WITH_THREAD
!   type_lock lock;
  #endif
  } ThreadLockObject;
  
--- 72,78 ----
    int count;
    long id;
  #ifdef WITH_THREAD
!   PyThread_type_lock lock;
  #endif
  } ThreadLockObject;
  
***************
*** 248,254 ****
    UNLESS(self = PyObject_NEW(ThreadLockObject, &ThreadLockType)) return NULL;
    self->count=-1;
  #ifdef WITH_THREAD
!   self->lock = allocate_lock();
    if (self->lock == NULL) {
      PyMem_DEL(self);
      self = NULL;
--- 248,254 ----
    UNLESS(self = PyObject_NEW(ThreadLockObject, &ThreadLockType)) return NULL;
    self->count=-1;
  #ifdef WITH_THREAD
!   self->lock = PyThread_allocate_lock();
    if (self->lock == NULL) {
      PyMem_DEL(self);
      self = NULL;
===================================================================
RCS file: RCS/Makefile.pre.in-1.5,v
retrieving revision 1.1
diff -c -r1.1 Makefile.pre.in-1.5
*** Makefile.pre.in-1.5	1999/06/29 00:48:26	1.1
--- Makefile.pre.in-1.5	1999/06/29 00:48:33
***************
*** 136,141 ****
--- 136,145 ----
  # Install prefix for architecture-dependent files
  exec_prefix=	$(prefix)
  
+ # Uncomment the following two lines for AIX
+ #LINKCC= 	$(LIBPL)/makexp_aix $(LIBPL)/python.exp "" $(LIBRARY); $(PURIFY) $(CC)
+ #LDSHARED=	$(LIBPL)/ld_so_aix $(CC) -bI:$(LIBPL)/python.exp
+ 
  # === Fixed definitions ===
  
  # Shell used by make (some versions default to the login shell, which is bad)
***************
*** 164,170 ****
  MAKEFILE=	$(LIBPL)/Makefile
  CONFIGC=	$(LIBPL)/config.c
  CONFIGCIN=	$(LIBPL)/config.c.in
! SETUP=		$(LIBPL)/Setup
  
  SYSLIBS=	$(LIBM) $(LIBC)
  
--- 168,174 ----
  MAKEFILE=	$(LIBPL)/Makefile
  CONFIGC=	$(LIBPL)/config.c
  CONFIGCIN=	$(LIBPL)/config.c.in
! SETUP=		$(LIBPL)/Setup.thread $(LIBPL)/Setup.local $(LIBPL)/Setup
  
  SYSLIBS=	$(LIBM) $(LIBC)
  
***************
*** 251,256 ****
--- 255,261 ----
  	 -e '/^LINKCC=/s/^LINKCC=[ 	]*\(.*\)/s%@LINKCC[@]%\1%/p' \
  	 -e '/^OPT=/s/^OPT=[ 	]*\(.*\)/s%@OPT[@]%\1%/p' \
  	 -e '/^LDFLAGS=/s/^LDFLAGS=[ 	]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
+ 	 -e '/^LDLAST=/s/^LDLAST=[      ]*\(.*\)/s%@LDLAST[@]%\1%/p' \
  	 -e '/^DEFS=/s/^DEFS=[ 	]*\(.*\)/s%@DEFS[@]%\1%/p' \
  	 -e '/^LIBS=/s/^LIBS=[ 	]*\(.*\)/s%@LIBS[@]%\1%/p' \
  	 -e '/^LIBM=/s/^LIBM=[ 	]*\(.*\)/s%@LIBM[@]%\1%/p' \
***************
*** 260,265 ****
--- 265,271 ----
  	 -e '/^SO=/s/^SO=[ 	]*\(.*\)/s%@SO[@]%\1%/p' \
  	 -e '/^LDSHARED=/s/^LDSHARED=[ 	]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
  	 -e '/^CCSHARED=/s/^CCSHARED=[ 	]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
+ 	 -e '/^SGI_ABI=/s/^SGI_ABI=[ 	]*\(.*\)/s%@SGI_ABI[@]%\1%/p' \
  	 -e '/^$L=/s/^$L=[ 	]*\(.*\)/s%@$L[@]%\1%/p' \
  	 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
  	 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \




More information about the Python-list mailing list