| File: | _librsyncmodule.c |
| Warning: | line 188, column 8 PyObject ownership leak with reference count of 1 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* ----------------------------------------------------------------------- * | |||
| 2 | * | |||
| 3 | * Copyright 2002 2003 Ben Escoto <ben@emerose.org> | |||
| 4 | * Copyright 2007 Kenneth Loafman <kenneth@loafman.com> | |||
| 5 | * | |||
| 6 | * This file is part of duplicity. | |||
| 7 | * | |||
| 8 | * duplicity is free software; you can redistribute it and/or modify | |||
| 9 | * it under the terms of the GNU General Public License as published | |||
| 10 | * by the Free Software Foundation; either version 2 of the License, | |||
| 11 | * or (at your option) any later version. | |||
| 12 | * | |||
| 13 | * duplicity is distributed in the hope that it will be useful, but | |||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 16 | * General Public License for more details. | |||
| 17 | * | |||
| 18 | * You should have received a copy of the GNU General Public License | |||
| 19 | * along with duplicity; if not, write to the Free Software | |||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |||
| 21 | * 02111-1307 USA | |||
| 22 | * | |||
| 23 | * ----------------------------------------------------------------------- */ | |||
| 24 | ||||
| 25 | #define PY_SSIZE_T_CLEAN | |||
| 26 | #include <Python.h> | |||
| 27 | #include <errno(*__errno_location ()).h> | |||
| 28 | #include <librsync.h> | |||
| 29 | #define RS_JOB_BLOCKSIZE65536 65536 | |||
| 30 | ||||
| 31 | static PyObject *librsyncError; | |||
| 32 | ||||
| 33 | /* Sets python error string from result */ | |||
| 34 | static void | |||
| 35 | _librsync_seterror(rs_result result, char *location) | |||
| 36 | { | |||
| 37 | char error_string[200]; | |||
| 38 | sprintf(error_string, "librsync error %d while in %s", result, location)__builtin___sprintf_chk (error_string, 2 - 1, __builtin_object_size (error_string, 2 > 1), "librsync error %d while in %s", result , location); | |||
| 39 | PyErr_SetString(librsyncError, error_string); | |||
| 40 | } | |||
| 41 | ||||
| 42 | ||||
| 43 | /* --------------- SigMaker Object for incremental signatures */ | |||
| 44 | static PyTypeObject _librsync_SigMakerType; | |||
| 45 | ||||
| 46 | typedef struct { | |||
| 47 | PyObject_HEADPyObject ob_base; | |||
| 48 | rs_job_t *sig_job; | |||
| 49 | } _librsync_SigMakerObject; | |||
| 50 | ||||
| 51 | static PyObject* | |||
| 52 | _librsync_new_sigmaker(PyObject* self, PyObject* args) | |||
| 53 | { | |||
| 54 | _librsync_SigMakerObject* sm; | |||
| 55 | long blocklen; | |||
| 56 | ||||
| 57 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "l:new_sigmaker", &blocklen)) | |||
| 58 | return NULL((void*)0); | |||
| 59 | ||||
| 60 | sm = PyObject_New(_librsync_SigMakerObject, &_librsync_SigMakerType)( (_librsync_SigMakerObject *) _PyObject_New(&_librsync_SigMakerType ) ); | |||
| 61 | if (sm == NULL((void*)0)) return NULL((void*)0); | |||
| 62 | ||||
| 63 | #ifdef RS_DEFAULT_STRONG_LEN /* librsync < 1.0.0 */ | |||
| 64 | sm->sig_job = rs_sig_begin((size_t)blocklen, | |||
| 65 | (size_t)RS_DEFAULT_STRONG_LEN); | |||
| 66 | #else /* librsync >= 1.0.0 */ | |||
| 67 | sm->sig_job = rs_sig_begin((size_t)blocklen, | |||
| 68 | (size_t)8, RS_MD4_SIG_MAGIC); | |||
| 69 | #endif | |||
| 70 | return (PyObject*)sm; | |||
| 71 | } | |||
| 72 | ||||
| 73 | static void | |||
| 74 | _librsync_sigmaker_dealloc(PyObject* self) | |||
| 75 | { | |||
| 76 | rs_job_free(((_librsync_SigMakerObject *)self)->sig_job); | |||
| 77 | PyObject_DelPyObject_Free(self); | |||
| 78 | } | |||
| 79 | ||||
| 80 | /* Take an input string, and generate a signature from it. The output | |||
| 81 | will be a triple (done, bytes_used, signature_string), where done | |||
| 82 | is true iff there is no more data coming and bytes_used is the | |||
| 83 | number of bytes of the input string processed. | |||
| 84 | */ | |||
| 85 | static PyObject * | |||
| 86 | _librsync_sigmaker_cycle(_librsync_SigMakerObject *self, PyObject *args) | |||
| 87 | { | |||
| 88 | char *inbuf, outbuf[RS_JOB_BLOCKSIZE65536]; | |||
| 89 | Py_ssize_t inbuf_length; | |||
| 90 | rs_buffers_t buf; | |||
| 91 | rs_result result; | |||
| 92 | ||||
| 93 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 94 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "y#:cycle", &inbuf, &inbuf_length)) | |||
| 95 | #else | |||
| 96 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "s#:cycle", &inbuf, &inbuf_length)) | |||
| 97 | #endif | |||
| 98 | return NULL((void*)0); | |||
| 99 | ||||
| 100 | buf.next_in = inbuf; | |||
| 101 | buf.avail_in = (size_t)inbuf_length; | |||
| 102 | buf.next_out = outbuf; | |||
| 103 | buf.avail_out = (size_t)RS_JOB_BLOCKSIZE65536; | |||
| 104 | buf.eof_in = (inbuf_length == 0); | |||
| 105 | ||||
| 106 | result = rs_job_iter(self->sig_job, &buf); | |||
| 107 | ||||
| 108 | if (result != RS_DONE && result != RS_BLOCKED) { | |||
| 109 | _librsync_seterror(result, "signature cycle"); | |||
| 110 | return NULL((void*)0); | |||
| 111 | } | |||
| 112 | ||||
| 113 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 114 | return Py_BuildValue_Py_BuildValue_SizeT("(ily#)", (result == RS_DONE), | |||
| 115 | #else | |||
| 116 | return Py_BuildValue_Py_BuildValue_SizeT("(ils#)", (result == RS_DONE), | |||
| 117 | #endif | |||
| 118 | (long)inbuf_length - (long)buf.avail_in, | |||
| 119 | outbuf, RS_JOB_BLOCKSIZE65536 - (long)buf.avail_out); | |||
| 120 | } | |||
| 121 | ||||
| 122 | static PyMethodDef _librsync_sigmaker_methods[] = { | |||
| 123 | {"cycle", (PyCFunction)_librsync_sigmaker_cycle, METH_VARARGS0x0001}, | |||
| 124 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} /* sentinel */ | |||
| 125 | }; | |||
| 126 | ||||
| 127 | static PyTypeObject _librsync_SigMakerType = { | |||
| 128 | PyVarObject_HEAD_INIT(NULL, 0){ { 1, ((void*)0) }, 0 }, | |||
| 129 | "sigmaker", | |||
| 130 | sizeof(_librsync_SigMakerObject), | |||
| 131 | 0, | |||
| 132 | _librsync_sigmaker_dealloc, /*tp_dealloc*/ | |||
| 133 | 0, /*tp_print*/ | |||
| 134 | 0, /*tp_getattr*/ | |||
| 135 | 0, /*tp_setattr*/ | |||
| 136 | 0, /*tp_compare*/ | |||
| 137 | 0, /*tp_repr*/ | |||
| 138 | 0, /*tp_as_number*/ | |||
| 139 | 0, /*tp_as_sequence*/ | |||
| 140 | 0, /*tp_as_mapping*/ | |||
| 141 | 0, /*tp_hash */ | |||
| 142 | 0, /*tp_call*/ | |||
| 143 | 0, /*tp_str*/ | |||
| 144 | PyObject_GenericGetAttr, /*tp_getattro*/ | |||
| 145 | PyObject_GenericSetAttr, /*tp_setattro*/ | |||
| 146 | 0, /*tp_as_buffer*/ | |||
| 147 | Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0), /*tp_flags*/ | |||
| 148 | 0, /*tp_doc*/ | |||
| 149 | 0, /*tp_traverse*/ | |||
| 150 | 0, /*tp_clear*/ | |||
| 151 | 0, /*tp_richcompare*/ | |||
| 152 | 0, /*tp_weaklistoffset*/ | |||
| 153 | 0, /*tp_iter*/ | |||
| 154 | 0, /*tp_iternext*/ | |||
| 155 | _librsync_sigmaker_methods, /*tp_methods*/ | |||
| 156 | }; | |||
| 157 | ||||
| 158 | ||||
| 159 | /* --------------- DeltaMaker Object for incremental deltas */ | |||
| 160 | ||||
| 161 | static PyTypeObject _librsync_DeltaMakerType; | |||
| 162 | ||||
| 163 | typedef struct { | |||
| 164 | PyObject_HEADPyObject ob_base; | |||
| 165 | rs_job_t *delta_job; | |||
| 166 | rs_signature_t *sig_ptr; | |||
| 167 | } _librsync_DeltaMakerObject; | |||
| 168 | ||||
| 169 | /* Call with the entire signature loaded into one big string */ | |||
| 170 | static PyObject* | |||
| 171 | _librsync_new_deltamaker(PyObject* self, PyObject* args) | |||
| 172 | { | |||
| 173 | _librsync_DeltaMakerObject* dm; | |||
| 174 | char *sig_string, outbuf[RS_JOB_BLOCKSIZE65536]; | |||
| 175 | Py_ssize_t sig_length; | |||
| 176 | rs_job_t *sig_loader; | |||
| 177 | rs_signature_t *sig_ptr; | |||
| 178 | rs_buffers_t buf; | |||
| 179 | rs_result result; | |||
| 180 | ||||
| 181 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 182 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args,"y#:new_deltamaker", &sig_string, &sig_length)) | |||
| ||||
| 183 | #else | |||
| 184 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args,"s#:new_deltamaker", &sig_string, &sig_length)) | |||
| 185 | #endif | |||
| 186 | return NULL((void*)0); | |||
| 187 | ||||
| 188 | dm = PyObject_New(_librsync_DeltaMakerObject, &_librsync_DeltaMakerType)( (_librsync_DeltaMakerObject *) _PyObject_New(&_librsync_DeltaMakerType ) ); | |||
| ||||
| 189 | if (dm == NULL((void*)0)) return NULL((void*)0); | |||
| 190 | ||||
| 191 | /* Put signature at sig_ptr and build hash */ | |||
| 192 | sig_loader = rs_loadsig_begin(&sig_ptr); | |||
| 193 | buf.next_in = sig_string; | |||
| 194 | buf.avail_in = (size_t)sig_length; | |||
| 195 | buf.next_out = outbuf; | |||
| 196 | buf.avail_out = (size_t)RS_JOB_BLOCKSIZE65536; | |||
| 197 | buf.eof_in = 1; | |||
| 198 | result = rs_job_iter(sig_loader, &buf); | |||
| 199 | rs_job_free(sig_loader); | |||
| 200 | if (result != RS_DONE) { | |||
| 201 | _librsync_seterror(result, "delta rs_signature_t builder"); | |||
| 202 | return NULL((void*)0); | |||
| 203 | } | |||
| 204 | if ((result = rs_build_hash_table(sig_ptr)) != RS_DONE) { | |||
| 205 | _librsync_seterror(result, "delta rs_build_hash_table"); | |||
| 206 | return NULL((void*)0); | |||
| 207 | } | |||
| 208 | ||||
| 209 | dm->sig_ptr = sig_ptr; | |||
| 210 | dm->delta_job = rs_delta_begin(sig_ptr); | |||
| 211 | return (PyObject*)dm; | |||
| 212 | } | |||
| 213 | ||||
| 214 | static void | |||
| 215 | _librsync_deltamaker_dealloc(PyObject* self) | |||
| 216 | { | |||
| 217 | _librsync_DeltaMakerObject *dm = (_librsync_DeltaMakerObject *)self; | |||
| 218 | rs_signature_t *sig_ptr = dm->sig_ptr; | |||
| 219 | ||||
| 220 | rs_free_sumset(sig_ptr); | |||
| 221 | rs_job_free(dm->delta_job); | |||
| 222 | PyObject_DelPyObject_Free(self); | |||
| 223 | } | |||
| 224 | ||||
| 225 | /* Take a chunk of the new file in an input string, and return a | |||
| 226 | triple (done bytes_used, delta_string), where done is true iff no | |||
| 227 | more data is coming and bytes_used is the number of bytes of the | |||
| 228 | input string processed. | |||
| 229 | */ | |||
| 230 | static PyObject * | |||
| 231 | _librsync_deltamaker_cycle(_librsync_DeltaMakerObject *self, PyObject *args) | |||
| 232 | { | |||
| 233 | char *inbuf, outbuf[RS_JOB_BLOCKSIZE65536]; | |||
| 234 | Py_ssize_t inbuf_length; | |||
| 235 | rs_buffers_t buf; | |||
| 236 | rs_result result; | |||
| 237 | ||||
| 238 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 239 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "y#:cycle", &inbuf, &inbuf_length)) | |||
| 240 | #else | |||
| 241 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "s#:cycle", &inbuf, &inbuf_length)) | |||
| 242 | #endif | |||
| 243 | return NULL((void*)0); | |||
| 244 | ||||
| 245 | buf.next_in = inbuf; | |||
| 246 | buf.avail_in = (size_t)inbuf_length; | |||
| 247 | buf.next_out = outbuf; | |||
| 248 | buf.avail_out = (size_t)RS_JOB_BLOCKSIZE65536; | |||
| 249 | buf.eof_in = (inbuf_length == 0); | |||
| 250 | ||||
| 251 | result = rs_job_iter(self->delta_job, &buf); | |||
| 252 | if (result != RS_DONE && result != RS_BLOCKED) { | |||
| 253 | _librsync_seterror(result, "delta cycle"); | |||
| 254 | return NULL((void*)0); | |||
| 255 | } | |||
| 256 | ||||
| 257 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 258 | return Py_BuildValue_Py_BuildValue_SizeT("(ily#)", (result == RS_DONE), | |||
| 259 | #else | |||
| 260 | return Py_BuildValue_Py_BuildValue_SizeT("(ils#)", (result == RS_DONE), | |||
| 261 | #endif | |||
| 262 | (long)inbuf_length - (long)buf.avail_in, | |||
| 263 | outbuf, RS_JOB_BLOCKSIZE65536 - (long)buf.avail_out); | |||
| 264 | } | |||
| 265 | ||||
| 266 | static PyMethodDef _librsync_deltamaker_methods[] = { | |||
| 267 | {"cycle", (PyCFunction)_librsync_deltamaker_cycle, METH_VARARGS0x0001}, | |||
| 268 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} /* sentinel */ | |||
| 269 | }; | |||
| 270 | ||||
| 271 | static PyTypeObject _librsync_DeltaMakerType = { | |||
| 272 | PyVarObject_HEAD_INIT(NULL, 0){ { 1, ((void*)0) }, 0 }, | |||
| 273 | "deltamaker", | |||
| 274 | sizeof(_librsync_DeltaMakerObject), | |||
| 275 | 0, | |||
| 276 | _librsync_deltamaker_dealloc, /*tp_dealloc*/ | |||
| 277 | 0, /*tp_print*/ | |||
| 278 | 0, /*tp_getattr*/ | |||
| 279 | 0, /*tp_setattr*/ | |||
| 280 | 0, /*tp_compare*/ | |||
| 281 | 0, /*tp_repr*/ | |||
| 282 | 0, /*tp_as_number*/ | |||
| 283 | 0, /*tp_as_sequence*/ | |||
| 284 | 0, /*tp_as_mapping*/ | |||
| 285 | 0, /*tp_hash */ | |||
| 286 | 0, /*tp_call*/ | |||
| 287 | 0, /*tp_str*/ | |||
| 288 | PyObject_GenericGetAttr, /*tp_getattro*/ | |||
| 289 | PyObject_GenericSetAttr, /*tp_setattro*/ | |||
| 290 | 0, /*tp_as_buffer*/ | |||
| 291 | Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0), /*tp_flags*/ | |||
| 292 | 0, /*tp_doc*/ | |||
| 293 | 0, /*tp_traverse*/ | |||
| 294 | 0, /*tp_clear*/ | |||
| 295 | 0, /*tp_richcompare*/ | |||
| 296 | 0, /*tp_weaklistoffset*/ | |||
| 297 | 0, /*tp_iter*/ | |||
| 298 | 0, /*tp_iternext*/ | |||
| 299 | _librsync_deltamaker_methods, /*tp_methods*/ | |||
| 300 | }; | |||
| 301 | ||||
| 302 | ||||
| 303 | /* --------------- PatchMaker Object for incremental patching */ | |||
| 304 | ||||
| 305 | ||||
| 306 | static PyTypeObject _librsync_PatchMakerType; | |||
| 307 | ||||
| 308 | typedef struct { | |||
| 309 | PyObject_HEADPyObject ob_base; | |||
| 310 | rs_job_t *patch_job; | |||
| 311 | PyObject *basis_file; | |||
| 312 | FILE *cfile; | |||
| 313 | } _librsync_PatchMakerObject; | |||
| 314 | ||||
| 315 | /* Call with the basis file */ | |||
| 316 | static PyObject* | |||
| 317 | _librsync_new_patchmaker(PyObject* self, PyObject* args) | |||
| 318 | { | |||
| 319 | _librsync_PatchMakerObject* pm; | |||
| 320 | PyObject *python_file; | |||
| 321 | int fd; | |||
| 322 | ||||
| 323 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O:new_patchmaker", &python_file)) | |||
| 324 | return NULL((void*)0); | |||
| 325 | fd = PyObject_AsFileDescriptor(python_file); | |||
| 326 | if (fd == -1) { | |||
| 327 | PyErr_SetString(PyExc_TypeError, "Need true file object"); | |||
| 328 | return NULL((void*)0); | |||
| 329 | } | |||
| 330 | /* get our own private copy of the file, so we can close it later. */ | |||
| 331 | fd = dup(fd); | |||
| 332 | if (fd == -1) { | |||
| 333 | char buf[256]; | |||
| 334 | strerror_r(errno(*__errno_location ()), buf, sizeof(buf)); | |||
| 335 | PyErr_SetString(PyExc_TypeError, buf); | |||
| 336 | return NULL((void*)0); | |||
| 337 | } | |||
| 338 | Py_INCREF(python_file)_Py_INCREF(((PyObject*)(python_file))); | |||
| 339 | ||||
| 340 | pm = PyObject_New(_librsync_PatchMakerObject, &_librsync_PatchMakerType)( (_librsync_PatchMakerObject *) _PyObject_New(&_librsync_PatchMakerType ) ); | |||
| 341 | if (pm == NULL((void*)0)) return NULL((void*)0); | |||
| 342 | ||||
| 343 | pm->basis_file = python_file; | |||
| 344 | pm->cfile = fdopen(fd, "rb"); | |||
| 345 | pm->patch_job = rs_patch_begin(rs_file_copy_cb, pm->cfile); | |||
| 346 | ||||
| 347 | return (PyObject*)pm; | |||
| 348 | } | |||
| 349 | ||||
| 350 | static void | |||
| 351 | _librsync_patchmaker_dealloc(PyObject* self) | |||
| 352 | { | |||
| 353 | _librsync_PatchMakerObject *pm = (_librsync_PatchMakerObject *)self; | |||
| 354 | Py_DECREF(pm->basis_file)_Py_DECREF(((PyObject*)(pm->basis_file))); | |||
| 355 | rs_job_free(pm->patch_job); | |||
| 356 | if (pm->cfile) { | |||
| 357 | fclose(pm->cfile); | |||
| 358 | } | |||
| 359 | PyObject_DelPyObject_Free(self); | |||
| 360 | } | |||
| 361 | ||||
| 362 | /* Take a chunk of the delta file in an input string, and return a | |||
| 363 | triple (done, bytes_used, patched_string), where done is true iff | |||
| 364 | there is no more data coming out and bytes_used is the number of | |||
| 365 | bytes of the input string processed. | |||
| 366 | */ | |||
| 367 | static PyObject * | |||
| 368 | _librsync_patchmaker_cycle(_librsync_PatchMakerObject *self, PyObject *args) | |||
| 369 | { | |||
| 370 | char *inbuf, outbuf[RS_JOB_BLOCKSIZE65536]; | |||
| 371 | Py_ssize_t inbuf_length; | |||
| 372 | rs_buffers_t buf; | |||
| 373 | rs_result result; | |||
| 374 | ||||
| 375 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 376 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "y#:cycle", &inbuf, &inbuf_length)) | |||
| 377 | #else | |||
| 378 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "s#:cycle", &inbuf, &inbuf_length)) | |||
| 379 | #endif | |||
| 380 | return NULL((void*)0); | |||
| 381 | ||||
| 382 | buf.next_in = inbuf; | |||
| 383 | buf.avail_in = (size_t)inbuf_length; | |||
| 384 | buf.next_out = outbuf; | |||
| 385 | buf.avail_out = (size_t)RS_JOB_BLOCKSIZE65536; | |||
| 386 | buf.eof_in = (inbuf_length == 0); | |||
| 387 | ||||
| 388 | result = rs_job_iter(self->patch_job, &buf); | |||
| 389 | if (result != RS_DONE && result != RS_BLOCKED) { | |||
| 390 | _librsync_seterror(result, "patch cycle"); | |||
| 391 | return NULL((void*)0); | |||
| 392 | } | |||
| 393 | ||||
| 394 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 395 | return Py_BuildValue_Py_BuildValue_SizeT("(ily#)", (result == RS_DONE), | |||
| 396 | #else | |||
| 397 | return Py_BuildValue_Py_BuildValue_SizeT("(ils#)", (result == RS_DONE), | |||
| 398 | #endif | |||
| 399 | (long)inbuf_length - (long)buf.avail_in, | |||
| 400 | outbuf, RS_JOB_BLOCKSIZE65536 - (long)buf.avail_out); | |||
| 401 | } | |||
| 402 | ||||
| 403 | static PyMethodDef _librsync_patchmaker_methods[] = { | |||
| 404 | {"cycle", (PyCFunction)_librsync_patchmaker_cycle, METH_VARARGS0x0001}, | |||
| 405 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} /* sentinel */ | |||
| 406 | }; | |||
| 407 | ||||
| 408 | static PyTypeObject _librsync_PatchMakerType = { | |||
| 409 | PyVarObject_HEAD_INIT(NULL, 0){ { 1, ((void*)0) }, 0 }, | |||
| 410 | "patchmaker", | |||
| 411 | sizeof(_librsync_PatchMakerObject), | |||
| 412 | 0, | |||
| 413 | _librsync_patchmaker_dealloc, /*tp_dealloc*/ | |||
| 414 | 0, /*tp_print*/ | |||
| 415 | 0, /*tp_getattr*/ | |||
| 416 | 0, /*tp_setattr*/ | |||
| 417 | 0, /*tp_compare*/ | |||
| 418 | 0, /*tp_repr*/ | |||
| 419 | 0, /*tp_as_number*/ | |||
| 420 | 0, /*tp_as_sequence*/ | |||
| 421 | 0, /*tp_as_mapping*/ | |||
| 422 | 0, /*tp_hash */ | |||
| 423 | 0, /*tp_call*/ | |||
| 424 | 0, /*tp_str*/ | |||
| 425 | PyObject_GenericGetAttr, /*tp_getattro*/ | |||
| 426 | PyObject_GenericSetAttr, /*tp_setattro*/ | |||
| 427 | 0, /*tp_as_buffer*/ | |||
| 428 | Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0), /*tp_flags*/ | |||
| 429 | 0, /*tp_doc*/ | |||
| 430 | 0, /*tp_traverse*/ | |||
| 431 | 0, /*tp_clear*/ | |||
| 432 | 0, /*tp_richcompare*/ | |||
| 433 | 0, /*tp_weaklistoffset*/ | |||
| 434 | 0, /*tp_iter*/ | |||
| 435 | 0, /*tp_iternext*/ | |||
| 436 | _librsync_patchmaker_methods, /*tp_methods*/ | |||
| 437 | }; | |||
| 438 | ||||
| 439 | ||||
| 440 | /* --------------- _librsync module definition */ | |||
| 441 | ||||
| 442 | #if PY_MAJOR_VERSION3 >= 3 | |||
| 443 | #define MOD_DEF(ob, name, doc, methods)static struct PyModuleDef moduledef = { { { 1, ((void*)0) }, ( (void*)0), 0, ((void*)0), }, name, doc, -1, methods, }; ob = PyModule_Create2 (&moduledef, 1013); \ | |||
| 444 | static struct PyModuleDef moduledef = { \ | |||
| 445 | PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), }, name, doc, -1, methods, }; \ | |||
| 446 | ob = PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013); | |||
| 447 | #else | |||
| 448 | #define MOD_DEF(ob, name, doc, methods)static struct PyModuleDef moduledef = { { { 1, ((void*)0) }, ( (void*)0), 0, ((void*)0), }, name, doc, -1, methods, }; ob = PyModule_Create2 (&moduledef, 1013); \ | |||
| 449 | ob = Py_InitModule3(name, methods, doc); | |||
| 450 | #endif | |||
| 451 | ||||
| 452 | static PyMethodDef _librsyncMethods[] = { | |||
| 453 | {"new_sigmaker", _librsync_new_sigmaker, METH_VARARGS0x0001, | |||
| 454 | "Return a sigmaker object, for finding the signature of an object"}, | |||
| 455 | {"new_deltamaker", _librsync_new_deltamaker, METH_VARARGS0x0001, | |||
| 456 | "Return a deltamaker object, for computing deltas"}, | |||
| 457 | {"new_patchmaker", _librsync_new_patchmaker, METH_VARARGS0x0001, | |||
| 458 | "Return a patchmaker object, for patching basis files"}, | |||
| 459 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} | |||
| 460 | }; | |||
| 461 | ||||
| 462 | static PyObject * | |||
| 463 | moduleinit(void) | |||
| 464 | { | |||
| 465 | PyObject *m, *d; | |||
| 466 | ||||
| 467 | #if PY_MAJOR_VERSION3 >= 3 && PY_MINOR_VERSION8 >= 10 | |||
| 468 | Py_SET_TYPE(&_librsync_SigMakerType, &PyType_Type); | |||
| 469 | Py_SET_TYPE(&_librsync_DeltaMakerType, &PyType_Type); | |||
| 470 | #else | |||
| 471 | Py_TYPE(&_librsync_SigMakerType)(((PyObject*)(&_librsync_SigMakerType))->ob_type) = &PyType_Type; | |||
| 472 | Py_TYPE(&_librsync_DeltaMakerType)(((PyObject*)(&_librsync_DeltaMakerType))->ob_type) = &PyType_Type; | |||
| 473 | #endif | |||
| 474 | ||||
| 475 | MOD_DEF(m, "_librsync", "", _librsyncMethods)static struct PyModuleDef moduledef = { { { 1, ((void*)0) }, ( (void*)0), 0, ((void*)0), }, "_librsync", "", -1, _librsyncMethods , }; m = PyModule_Create2(&moduledef, 1013); | |||
| 476 | if (m == NULL((void*)0)) | |||
| 477 | return NULL((void*)0); | |||
| 478 | ||||
| 479 | d = PyModule_GetDict(m); | |||
| 480 | librsyncError = PyErr_NewException("_librsync.librsyncError", NULL((void*)0), NULL((void*)0)); | |||
| 481 | PyDict_SetItemString(d, "librsyncError", librsyncError); | |||
| 482 | PyDict_SetItemString(d, "RS_JOB_BLOCKSIZE", | |||
| 483 | Py_BuildValue_Py_BuildValue_SizeT("l", (long)RS_JOB_BLOCKSIZE65536)); | |||
| 484 | PyDict_SetItemString(d, "RS_DEFAULT_BLOCK_LEN", | |||
| 485 | Py_BuildValue_Py_BuildValue_SizeT("l", (long)RS_DEFAULT_BLOCK_LEN2048)); | |||
| 486 | ||||
| 487 | return m; | |||
| 488 | } | |||
| 489 | ||||
| 490 | #if PY_MAJOR_VERSION3 < 3 | |||
| 491 | void init_librsync(void) | |||
| 492 | { | |||
| 493 | moduleinit(); | |||
| 494 | } | |||
| 495 | #else | |||
| 496 | PyObject *PyInit__librsync(void) | |||
| 497 | { | |||
| 498 | return moduleinit(); | |||
| 499 | } | |||
| 500 | #endif |
| 1 | #ifndef _PyObject_New |
| 2 | struct _object; |
| 3 | typedef struct _object PyObject; |
| 4 | PyObject* clang_analyzer_PyObject_New_Reference(); |
| 5 | PyObject* _PyObject_New(PyTypeObject *type) { |
| 6 | return clang_analyzer_PyObject_New_Reference(); |
| 7 | } |
| 8 | #else |
| 9 | #warning "API _PyObject_New is defined as a macro." |
| 10 | #endif |