##// END OF EJS Templates
mpatch.c: Added preliminary support for py3k....
Renato Cunha -
r11360:2ac98313 default
parent child Browse files
Show More
@@ -24,6 +24,8 b''
24 #include <stdlib.h>
24 #include <stdlib.h>
25 #include <string.h>
25 #include <string.h>
26
26
27 #include "util.h"
28
27 /* Definitions to get compatibility with python 2.4 and earlier which
29 /* Definitions to get compatibility with python 2.4 and earlier which
28 does not have Py_ssize_t. See also PEP 353.
30 does not have Py_ssize_t. See also PEP 353.
29 Note: msvc (8 or earlier) does not have ssize_t, so we use Py_ssize_t.
31 Note: msvc (8 or earlier) does not have ssize_t, so we use Py_ssize_t.
@@ -373,12 +375,12 b' patches(PyObject *self, PyObject *args)'
373 result = NULL;
375 result = NULL;
374 goto cleanup;
376 goto cleanup;
375 }
377 }
376 result = PyString_FromStringAndSize(NULL, outlen);
378 result = PyBytes_FromStringAndSize(NULL, outlen);
377 if (!result) {
379 if (!result) {
378 result = NULL;
380 result = NULL;
379 goto cleanup;
381 goto cleanup;
380 }
382 }
381 out = PyString_AsString(result);
383 out = PyBytes_AsString(result);
382 if (!apply(out, in, inlen, patch)) {
384 if (!apply(out, in, inlen, patch)) {
383 Py_DECREF(result);
385 Py_DECREF(result);
384 result = NULL;
386 result = NULL;
@@ -435,10 +437,34 b' static PyMethodDef methods[] = {'
435 {NULL, NULL}
437 {NULL, NULL}
436 };
438 };
437
439
440 #ifdef IS_PY3K
441 static struct PyModuleDef mpatch_module = {
442 PyModuleDef_HEAD_INIT,
443 "mpatch",
444 mpatch_doc,
445 -1,
446 methods
447 };
448
449 PyMODINIT_FUNC PyInit_mpatch(void)
450 {
451 PyObject *m;
452
453 m = PyModule_Create(&mpatch_module);
454 if (m == NULL)
455 return NULL;
456
457 mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
458 Py_INCREF(mpatch_Error);
459 PyModule_AddObject(m, "mpatchError", mpatch_Error);
460
461 return m;
462 }
463 #else
438 PyMODINIT_FUNC
464 PyMODINIT_FUNC
439 initmpatch(void)
465 initmpatch(void)
440 {
466 {
441 Py_InitModule3("mpatch", methods, mpatch_doc);
467 Py_InitModule3("mpatch", methods, mpatch_doc);
442 mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
468 mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
443 }
469 }
444
470 #endif
General Comments 0
You need to be logged in to leave comments. Login now