Ignore:
Timestamp:
Sep 23, 2017 1:47:05 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
9e308a3
Parents:
7b50f14
Message:

add python 3 support for C modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/pr/c_extensions/Cinvertor.c

    rcb62bd5 rd04ac05  
    5252    invertor_dealloc(&(self->params)); 
    5353 
    54     self->ob_type->tp_free((PyObject*)self); 
     54    Py_TYPE(self)->tp_free((PyObject*)self); 
    5555 
    5656} 
     
    10541054 
    10551055static PyTypeObject CinvertorType = { 
    1056     PyObject_HEAD_INIT(NULL) 
    1057     0,                         /*ob_size*/ 
     1056    //PyObject_HEAD_INIT(NULL) 
     1057    //0,                         /*ob_size*/ 
     1058    PyVarObject_HEAD_INIT(NULL, 0) 
    10581059    "Cinvertor",             /*tp_name*/ 
    10591060    sizeof(Cinvertor),             /*tp_basicsize*/ 
     
    11191120 
    11201121 
    1121 #ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */ 
    1122 #define PyMODINIT_FUNC void 
     1122#define MODULE_DOC "C extension module for inversion to P(r)." 
     1123#define MODULE_NAME "pr_inversion" 
     1124#define MODULE_INIT2 initpr_inversion 
     1125#define MODULE_INIT3 PyInit_pr_inversion 
     1126#define MODULE_METHODS module_methods 
     1127 
     1128/* ==== boilerplate python 2/3 interface bootstrap ==== */ 
     1129 
     1130 
     1131#if defined(WIN32) && !defined(__MINGW32__) 
     1132    #define DLL_EXPORT __declspec(dllexport) 
     1133#else 
     1134    #define DLL_EXPORT 
    11231135#endif 
    1124 PyMODINIT_FUNC 
    1125 initpr_inversion(void) 
    1126 { 
    1127     PyObject* m; 
    1128  
    1129     m = Py_InitModule3("pr_inversion", module_methods, 
    1130                        "C extension module for inversion to P(r)."); 
    1131  
    1132     addCinvertor(m); 
    1133 } 
     1136 
     1137#if PY_MAJOR_VERSION >= 3 
     1138 
     1139  DLL_EXPORT PyMODINIT_FUNC MODULE_INIT3(void) 
     1140  { 
     1141    static struct PyModuleDef moduledef = { 
     1142      PyModuleDef_HEAD_INIT, 
     1143      MODULE_NAME,         /* m_name */ 
     1144      MODULE_DOC,          /* m_doc */ 
     1145      -1,                  /* m_size */ 
     1146      MODULE_METHODS,      /* m_methods */ 
     1147      NULL,                /* m_reload */ 
     1148      NULL,                /* m_traverse */ 
     1149      NULL,                /* m_clear */ 
     1150      NULL,                /* m_free */ 
     1151    }; 
     1152        PyObject* m = PyModule_Create(&moduledef); 
     1153        addCinvertor(m); 
     1154        return m; 
     1155  } 
     1156 
     1157#else /* !PY_MAJOR_VERSION >= 3 */ 
     1158 
     1159  DLL_EXPORT PyMODINIT_FUNC MODULE_INIT2(void) 
     1160  { 
     1161    PyObject* m = Py_InitModule4(MODULE_NAME, 
     1162                 MODULE_METHODS, 
     1163                 MODULE_DOC, 
     1164                 0, 
     1165                 PYTHON_API_VERSION 
     1166                 ); 
     1167        addCinvertor(m); 
     1168  } 
     1169 
     1170#endif /* !PY_MAJOR_VERSION >= 3 */ 
Note: See TracChangeset for help on using the changeset viewer.