Show More
@@ -23,6 +23,8 b'' | |||||
23 | #include <unistd.h> |
|
23 | #include <unistd.h> | |
24 | #endif |
|
24 | #endif | |
25 |
|
25 | |||
|
26 | #include "util.h" | |||
|
27 | ||||
26 | /* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */ |
|
28 | /* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */ | |
27 | #ifndef PATH_MAX |
|
29 | #ifndef PATH_MAX | |
28 | #define PATH_MAX 4096 |
|
30 | #define PATH_MAX 4096 | |
@@ -95,8 +97,7 b' static void listdir_stat_dealloc(PyObjec' | |||||
95 | } |
|
97 | } | |
96 |
|
98 | |||
97 | static PyTypeObject listdir_stat_type = { |
|
99 | static PyTypeObject listdir_stat_type = { | |
98 | PyObject_HEAD_INIT(NULL) |
|
100 | PyVarObject_HEAD_INIT(NULL, 0) | |
99 | 0, /*ob_size*/ |
|
|||
100 | "osutil.stat", /*tp_name*/ |
|
101 | "osutil.stat", /*tp_name*/ | |
101 | sizeof(struct listdir_stat), /*tp_basicsize*/ |
|
102 | sizeof(struct listdir_stat), /*tp_basicsize*/ | |
102 | 0, /*tp_itemsize*/ |
|
103 | 0, /*tp_itemsize*/ | |
@@ -392,7 +393,7 b' static PyObject *listdir(PyObject *self,' | |||||
392 | wantstat = statobj && PyObject_IsTrue(statobj); |
|
393 | wantstat = statobj && PyObject_IsTrue(statobj); | |
393 |
|
394 | |||
394 | if (skipobj && skipobj != Py_None) { |
|
395 | if (skipobj && skipobj != Py_None) { | |
395 |
skip = Py |
|
396 | skip = PyBytes_AsString(skipobj); | |
396 | if (!skip) |
|
397 | if (!skip) | |
397 | return NULL; |
|
398 | return NULL; | |
398 | } |
|
399 | } | |
@@ -486,12 +487,13 b' static PyObject *posixfile(PyObject *sel' | |||||
486 | } |
|
487 | } | |
487 |
|
488 | |||
488 | fd = _open_osfhandle((intptr_t)handle, flags); |
|
489 | fd = _open_osfhandle((intptr_t)handle, flags); | |
|
490 | ||||
489 | if (fd == -1) { |
|
491 | if (fd == -1) { | |
490 | CloseHandle(handle); |
|
492 | CloseHandle(handle); | |
491 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
|
493 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); | |
492 | goto bail; |
|
494 | goto bail; | |
493 | } |
|
495 | } | |
494 |
|
496 | #ifndef IS_PY3K | ||
495 | fp = _fdopen(fd, fpmode); |
|
497 | fp = _fdopen(fd, fpmode); | |
496 | if (fp == NULL) { |
|
498 | if (fp == NULL) { | |
497 | _close(fd); |
|
499 | _close(fd); | |
@@ -506,6 +508,11 b' static PyObject *posixfile(PyObject *sel' | |||||
506 | } |
|
508 | } | |
507 |
|
509 | |||
508 | PyFile_SetBufSize(file_obj, bufsize); |
|
510 | PyFile_SetBufSize(file_obj, bufsize); | |
|
511 | #else | |||
|
512 | file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1); | |||
|
513 | if (file_obj == NULL) | |||
|
514 | goto bail; | |||
|
515 | #endif | |||
509 | bail: |
|
516 | bail: | |
510 | PyMem_Free(name); |
|
517 | PyMem_Free(name); | |
511 | return file_obj; |
|
518 | return file_obj; | |
@@ -525,6 +532,23 b' static PyMethodDef methods[] = {' | |||||
525 | {NULL, NULL} |
|
532 | {NULL, NULL} | |
526 | }; |
|
533 | }; | |
527 |
|
534 | |||
|
535 | #ifdef IS_PY3K | |||
|
536 | static struct PyModuleDef osutil_module = { | |||
|
537 | PyModuleDef_HEAD_INIT, | |||
|
538 | "osutil", | |||
|
539 | osutil_doc, | |||
|
540 | -1, | |||
|
541 | methods | |||
|
542 | }; | |||
|
543 | ||||
|
544 | PyMODINIT_FUNC PyInit_osutil(void) | |||
|
545 | { | |||
|
546 | if (PyType_Ready(&listdir_stat_type) < 0) | |||
|
547 | return NULL; | |||
|
548 | ||||
|
549 | return PyModule_Create(&osutil_module); | |||
|
550 | } | |||
|
551 | #else | |||
528 | PyMODINIT_FUNC initosutil(void) |
|
552 | PyMODINIT_FUNC initosutil(void) | |
529 | { |
|
553 | { | |
530 | if (PyType_Ready(&listdir_stat_type) == -1) |
|
554 | if (PyType_Ready(&listdir_stat_type) == -1) | |
@@ -532,3 +556,4 b' PyMODINIT_FUNC initosutil(void)' | |||||
532 |
|
556 | |||
533 | Py_InitModule3("osutil", methods, osutil_doc); |
|
557 | Py_InitModule3("osutil", methods, osutil_doc); | |
534 | } |
|
558 | } | |
|
559 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now