mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05:00 
			
		
		
		
	Port lzma_binding plugin to build on python2/python3
This commit is contained in:
		
							parent
							
								
									9139fccbf4
								
							
						
					
					
						commit
						1a687a3d57
					
				@ -393,6 +393,8 @@ exit:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// }}}
 | 
					// }}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static char lzma_binding_doc[] = "Bindings to the LZMA (de)compression C code";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyMethodDef lzma_binding_methods[] = {
 | 
					static PyMethodDef lzma_binding_methods[] = {
 | 
				
			||||||
    {"decompress2", decompress2, METH_VARARGS,
 | 
					    {"decompress2", decompress2, METH_VARARGS,
 | 
				
			||||||
        "Decompress an LZMA2 encoded block, of unknown compressed size (reads till LZMA2 EOS marker)"
 | 
					        "Decompress an LZMA2 encoded block, of unknown compressed size (reads till LZMA2 EOS marker)"
 | 
				
			||||||
@ -417,24 +419,54 @@ static PyMethodDef lzma_binding_methods[] = {
 | 
				
			|||||||
    {NULL, NULL, 0, NULL}
 | 
					    {NULL, NULL, 0, NULL}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if PY_MAJOR_VERSION >= 3
 | 
				
			||||||
 | 
					#define INITERROR return NULL
 | 
				
			||||||
 | 
					#define INITMODULE PyModule_Create(&lzma_binding_module)
 | 
				
			||||||
 | 
					static struct PyModuleDef lzma_binding_module = {
 | 
				
			||||||
 | 
					    /* m_base     */ PyModuleDef_HEAD_INIT,
 | 
				
			||||||
 | 
					    /* m_name     */ "lzma_binding",
 | 
				
			||||||
 | 
					    /* m_doc      */ lzma_binding_doc,
 | 
				
			||||||
 | 
					    /* m_size     */ -1,
 | 
				
			||||||
 | 
					    /* m_methods  */ lzma_binding_methods,
 | 
				
			||||||
 | 
					    /* m_slots    */ 0,
 | 
				
			||||||
 | 
					    /* m_traverse */ 0,
 | 
				
			||||||
 | 
					    /* m_clear    */ 0,
 | 
				
			||||||
 | 
					    /* m_free     */ 0,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					CALIBRE_MODINIT_FUNC PyInit_lzma_binding(void) {
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define INITERROR return
 | 
				
			||||||
 | 
					#define INITMODULE Py_InitModule3("lzma_binding", lzma_binding_methods, lzma_binding_doc)
 | 
				
			||||||
 | 
					CALIBRE_MODINIT_FUNC initlzma_binding(void) {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CALIBRE_MODINIT_FUNC
 | 
					 | 
				
			||||||
initlzma_binding(void) {
 | 
					 | 
				
			||||||
    PyObject *m = NULL, *preset_map = NULL, *temp = NULL;
 | 
					    PyObject *m = NULL, *preset_map = NULL, *temp = NULL;
 | 
				
			||||||
    int i = 0;
 | 
					    int i = 0;
 | 
				
			||||||
    init_crc_table();
 | 
					    init_crc_table();
 | 
				
			||||||
    LZMAError = PyErr_NewException("lzma_binding.error", NULL, NULL);
 | 
					    LZMAError = PyErr_NewException("lzma_binding.error", NULL, NULL);
 | 
				
			||||||
    if (!LZMAError) return;
 | 
					    if (!LZMAError) {
 | 
				
			||||||
    m = Py_InitModule3("lzma_binding", lzma_binding_methods, "Bindings to the LZMA (de)compression C code");
 | 
					        INITERROR;
 | 
				
			||||||
    if (m == NULL) return;
 | 
					    }
 | 
				
			||||||
 | 
					    m = INITMODULE;
 | 
				
			||||||
 | 
					    if (m == NULL) {
 | 
				
			||||||
 | 
					        INITERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    preset_map = PyTuple_New(10);
 | 
					    preset_map = PyTuple_New(10);
 | 
				
			||||||
    if (preset_map == NULL) return;
 | 
					    if (preset_map == NULL) {
 | 
				
			||||||
 | 
					        INITERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for (i = 0; i < 10; i++) {
 | 
					    for (i = 0; i < 10; i++) {
 | 
				
			||||||
        temp = get_lzma2_properties(i);
 | 
					        temp = get_lzma2_properties(i);
 | 
				
			||||||
        if (temp == NULL) return;
 | 
					        if (temp == NULL) {
 | 
				
			||||||
 | 
					            INITERROR;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        PyTuple_SET_ITEM(preset_map, i, temp);
 | 
					        PyTuple_SET_ITEM(preset_map, i, temp);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    PyModule_AddObject(m, "preset_map", preset_map);
 | 
					    PyModule_AddObject(m, "preset_map", preset_map);
 | 
				
			||||||
    Py_INCREF(LZMAError);
 | 
					    Py_INCREF(LZMAError);
 | 
				
			||||||
    PyModule_AddObject(m, "error", LZMAError);
 | 
					    PyModule_AddObject(m, "error", LZMAError);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if PY_MAJOR_VERSION >= 3
 | 
				
			||||||
 | 
					    return m;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user