~pythonregexp2.7/python/issue2636

« back to all changes in this revision

Viewing changes to Mac/Modules/file/_Filemodule.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:36:32 UTC
  • mfrom: (39021.1.402 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609143632-wwwkx92u1t5l7yd3
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
#include "pymactoolbox.h"
9
9
 
 
10
#ifndef HAVE_MACOS105_SDK
 
11
typedef SInt16  FSIORefNum;
 
12
#endif
 
13
 
10
14
/* Macro to test whether a weak-loaded CFM function exists */
11
15
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
12
16
        PyErr_SetString(PyExc_NotImplementedError, \
18
22
#include <Carbon/Carbon.h>
19
23
 
20
24
#ifdef USE_TOOLBOX_OBJECT_GLUE
 
25
 
 
26
#ifndef __LP64__
21
27
extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
 
28
extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
 
29
#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
 
30
#endif /* __LP64__*/
 
31
 
22
32
extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
23
 
extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
24
33
extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
25
 
 
 
34
#define PyMac_BuildFSRef _PyMac_BuildFSRef
26
35
#define PyMac_GetFSSpec _PyMac_GetFSSpec
27
36
#define PyMac_GetFSRef _PyMac_GetFSRef
28
 
#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
29
 
#define PyMac_BuildFSRef _PyMac_BuildFSRef
30
 
#else
 
37
 
 
38
#else   /* !USE_TOOLBOX_OBJECT_GLUE */
 
39
 
 
40
#ifndef __LP64__
31
41
extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
 
42
extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
 
43
#endif /* !__LP64__*/
 
44
 
32
45
extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
33
 
extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
34
46
extern PyObject *PyMac_BuildFSRef(FSRef *spec);
35
 
#endif
 
47
 
 
48
#endif  /* !USE_TOOLBOX_OBJECT_GLUE */
36
49
 
37
50
/* Forward declarations */
 
51
static PyObject *FSRef_New(FSRef *itself);
 
52
#ifndef __LP64__
38
53
static PyObject *FInfo_New(FInfo *itself);
39
 
static PyObject *FSRef_New(FSRef *itself);
 
54
 
40
55
static PyObject *FSSpec_New(FSSpec *itself);
 
56
#define FSSpec_Convert PyMac_GetFSSpec
 
57
#endif /* !__LP64__ */
 
58
 
41
59
static PyObject *Alias_New(AliasHandle itself);
 
60
#ifndef __LP64__
42
61
static int FInfo_Convert(PyObject *v, FInfo *p_itself);
 
62
#endif /* !__LP64__ */
43
63
#define FSRef_Convert PyMac_GetFSRef
44
 
#define FSSpec_Convert PyMac_GetFSSpec
45
64
static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
46
65
 
47
66
/*
62
81
/*
63
82
** Optional fsspec and fsref pointers. None will pass NULL
64
83
*/
 
84
#ifndef __LP64__
65
85
static int
66
86
myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
67
87
{
71
91
        }
72
92
        return PyMac_GetFSSpec(v, *spec);
73
93
}
 
94
#endif /* !__LP64__ */
74
95
 
75
96
static int
76
97
myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
92
113
        return Py_BuildValue("u#", itself->unicode, itself->length);
93
114
}
94
115
 
 
116
#ifndef __LP64__
95
117
static OSErr
96
118
_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
97
119
{
135
157
        }
136
158
        return 0;
137
159
}
 
160
#endif /* !__LP64__ */
138
161
 
139
162
 
140
163
static PyObject *File_Error;
282
305
 
283
306
static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
284
307
{
285
 
        return Py_BuildValue("(llll)", self->ob_itself.permissions[0], self->ob_itself.permissions[1], self->ob_itself.permissions[2], self->ob_itself.permissions[3]);
 
308
        FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
 
309
        return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
286
310
}
287
311
 
288
312
static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
289
313
{
290
 
        return PyArg_Parse(v, "(llll)", &self->ob_itself.permissions[0], &self->ob_itself.permissions[1], &self->ob_itself.permissions[2], &self->ob_itself.permissions[3])-1;
 
314
        long userID;
 
315
        long groupID;
 
316
        long userAccess;
 
317
        long mode;
 
318
        int r;
 
319
 
 
320
        FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
 
321
 
 
322
        r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
 
323
        if (!r) {
 
324
                return -1;
 
325
        }
 
326
        info->userID = userID;
 
327
        info->groupID = groupID;
 
328
        info->userAccess = userAccess;
 
329
        info->mode = mode;
291
330
        return 0;
292
331
}
293
332
 
501
540
 
502
541
/* ----------------------- Object type FInfo ------------------------ */
503
542
 
 
543
#ifndef __LP64__
 
544
 
504
545
static PyTypeObject FInfo_Type;
505
546
 
506
547
#define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
682
723
        FInfo_tp_free, /* tp_free */
683
724
};
684
725
 
 
726
#endif /* !__LP64__ */
685
727
/* --------------------- End object type FInfo ---------------------- */
686
728
 
687
729
 
729
771
        self->ob_type->tp_free((PyObject *)self);
730
772
}
731
773
 
 
774
#ifndef __LP64__
732
775
static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
733
776
{
734
777
        PyObject *_res = NULL;
818
861
                             wasChanged);
819
862
        return _res;
820
863
}
 
864
#endif /* !__LP64__ */
821
865
 
822
866
static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
823
867
{
891
935
}
892
936
 
893
937
static PyMethodDef Alias_methods[] = {
 
938
#ifndef __LP64__
894
939
        {"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
895
940
         PyDoc_STR("(FSSpec fromFile) -> (FSSpec target, Boolean wasChanged)")},
896
941
        {"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
899
944
         PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
900
945
        {"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
901
946
         PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
 
947
#endif /* !__LP64__ */
902
948
        {"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
903
949
         PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
904
950
        {"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
1033
1079
 
1034
1080
 
1035
1081
/* ----------------------- Object type FSSpec ----------------------- */
 
1082
#ifndef __LP64__
1036
1083
 
1037
1084
static PyTypeObject FSSpec_Type;
1038
1085
 
1488
1535
        FSSpec_tp_free, /* tp_free */
1489
1536
};
1490
1537
 
 
1538
#endif /* !__LP64__ */
1491
1539
/* --------------------- End object type FSSpec --------------------- */
1492
1540
 
1493
1541
 
1568
1616
        FSCatalogInfoBitmap whichInfo;
1569
1617
        FSCatalogInfo catalogInfo;
1570
1618
        FSRef newRef;
 
1619
#ifndef __LP64__
1571
1620
        FSSpec newSpec;
 
1621
#endif
1572
1622
        if (!PyArg_ParseTuple(_args, "u#lO&",
1573
1623
                              &nameLength__in__, &nameLength__in_len__,
1574
1624
                              &whichInfo,
1580
1630
                                   whichInfo,
1581
1631
                                   &catalogInfo,
1582
1632
                                   &newRef,
1583
 
                                   &newSpec);
 
1633
#ifndef __LP64__
 
1634
                                   &newSpec
 
1635
#else   /* __LP64__ */
 
1636
                                   NULL
 
1637
#endif /* __LP64__*/
 
1638
                                  );
1584
1639
        if (_err != noErr) return PyMac_Error(_err);
 
1640
 
 
1641
#ifndef __LP64__
1585
1642
        _res = Py_BuildValue("O&O&",
1586
1643
                             FSRef_New, &newRef,
1587
1644
                             FSSpec_New, &newSpec);
 
1645
#else /* __LP64__ */
 
1646
        _res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
 
1647
#endif /* __LP64__ */
 
1648
 
1588
1649
        return _res;
1589
1650
}
1590
1651
 
1598
1659
        FSCatalogInfoBitmap whichInfo;
1599
1660
        FSCatalogInfo catalogInfo;
1600
1661
        FSRef newRef;
 
1662
#ifndef __LP64__
1601
1663
        FSSpec newSpec;
 
1664
#endif /* !__LP64__ */
1602
1665
        UInt32 newDirID;
1603
1666
        if (!PyArg_ParseTuple(_args, "u#lO&",
1604
1667
                              &nameLength__in__, &nameLength__in_len__,
1611
1674
                                        whichInfo,
1612
1675
                                        &catalogInfo,
1613
1676
                                        &newRef,
 
1677
#ifndef __LP64__
1614
1678
                                        &newSpec,
 
1679
#else /* !__LP64__ */
 
1680
                                        NULL,
 
1681
#endif /* !__LP64__ */
1615
1682
                                        &newDirID);
1616
1683
        if (_err != noErr) return PyMac_Error(_err);
 
1684
 
 
1685
#ifndef __LP64__
1617
1686
        _res = Py_BuildValue("O&O&l",
1618
1687
                             FSRef_New, &newRef,
1619
1688
                             FSSpec_New, &newSpec,
1620
1689
                             newDirID);
 
1690
#else   /* __LP64__ */
 
1691
        _res = Py_BuildValue("O&Ol",
 
1692
                             FSRef_New, &newRef,
 
1693
                             Py_None,
 
1694
                             newDirID);
 
1695
#endif /* __LP64__ */
1621
1696
        return _res;
1622
1697
}
1623
1698
 
1699
1774
        FSCatalogInfoBitmap whichInfo;
1700
1775
        FSCatalogInfo catalogInfo;
1701
1776
        HFSUniStr255 outName;
 
1777
#ifndef __LP64__
1702
1778
        FSSpec fsSpec;
 
1779
#endif /* !__LP64__ */
1703
1780
        FSRef parentRef;
1704
1781
        if (!PyArg_ParseTuple(_args, "l",
1705
1782
                              &whichInfo))
1708
1785
                                whichInfo,
1709
1786
                                &catalogInfo,
1710
1787
                                &outName,
 
1788
#ifndef __LP64__
1711
1789
                                &fsSpec,
 
1790
#else   /* __LP64__ */
 
1791
                                NULL,
 
1792
#endif /* __LP64__ */
1712
1793
                                &parentRef);
1713
1794
        if (_err != noErr) return PyMac_Error(_err);
 
1795
 
 
1796
#ifndef __LP64__
1714
1797
        _res = Py_BuildValue("O&O&O&O&",
1715
1798
                             FSCatalogInfo_New, &catalogInfo,
1716
1799
                             PyMac_BuildHFSUniStr255, &outName,
1717
1800
                             FSSpec_New, &fsSpec,
1718
1801
                             FSRef_New, &parentRef);
 
1802
#else   /* __LP64__ */
 
1803
        _res = Py_BuildValue("O&O&OO&",
 
1804
                             FSCatalogInfo_New, &catalogInfo,
 
1805
                             PyMac_BuildHFSUniStr255, &outName,
 
1806
                             Py_None,
 
1807
                             FSRef_New, &parentRef);
 
1808
#endif /* __LP64__ */
1719
1809
        return _res;
1720
1810
}
1721
1811
 
1784
1874
        UniCharCount forkNameLength__len__;
1785
1875
        int forkNameLength__in_len__;
1786
1876
        SInt8 permissions;
1787
 
        SInt16 forkRefNum;
 
1877
        FSIORefNum forkRefNum;
1788
1878
        if (!PyArg_ParseTuple(_args, "u#b",
1789
1879
                              &forkNameLength__in__, &forkNameLength__in_len__,
1790
1880
                              &permissions))
2034
2124
 
2035
2125
/* --------------------- End object type FSRef ---------------------- */
2036
2126
 
2037
 
 
 
2127
#ifndef __LP64__
2038
2128
static PyObject *File_UnmountVol(PyObject *_self, PyObject *_args)
2039
2129
{
2040
2130
        PyObject *_res = NULL;
2562
2652
                             FSSpec_New, &spec);
2563
2653
        return _res;
2564
2654
}
 
2655
#endif /* !__LP64__ */
2565
2656
 
2566
2657
static PyObject *File_FSGetForkPosition(PyObject *_self, PyObject *_args)
2567
2658
{
2785
2876
        return _res;
2786
2877
}
2787
2878
 
 
2879
#ifndef __LP64__
2788
2880
static PyObject *File_NewAlias(PyObject *_self, PyObject *_args)
2789
2881
{
2790
2882
        PyObject *_res = NULL;
2933
3025
                             wasAliased);
2934
3026
        return _res;
2935
3027
}
 
3028
#endif /* !__LP64__ */
2936
3029
 
2937
3030
static PyObject *File_FSNewAlias(PyObject *_self, PyObject *_args)
2938
3031
{
3050
3143
}
3051
3144
 
3052
3145
static PyMethodDef File_methods[] = {
 
3146
#ifndef __LP64__
3053
3147
        {"UnmountVol", (PyCFunction)File_UnmountVol, 1,
3054
3148
         PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
3055
3149
        {"FlushVol", (PyCFunction)File_FlushVol, 1,
3100
3194
         PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, long newDirID, Str255 newName) -> None")},
3101
3195
        {"FSMakeFSSpec", (PyCFunction)File_FSMakeFSSpec, 1,
3102
3196
         PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FSSpec spec)")},
 
3197
#endif /* !__LP64__*/
3103
3198
        {"FSGetForkPosition", (PyCFunction)File_FSGetForkPosition, 1,
3104
3199
         PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 position)")},
3105
3200
        {"FSSetForkPosition", (PyCFunction)File_FSSetForkPosition, 1,
3124
3219
         PyDoc_STR("(UInt8 * path, FNMessage message, OptionBits flags) -> None")},
3125
3220
        {"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
3126
3221
         PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
 
3222
#ifndef  __LP64__
3127
3223
        {"NewAlias", (PyCFunction)File_NewAlias, 1,
3128
3224
         PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
3129
3225
        {"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
3136
3232
         PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
3137
3233
        {"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
3138
3234
         PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
 
3235
#endif /* !__LP64__ */
3139
3236
        {"FSNewAlias", (PyCFunction)File_FSNewAlias, 1,
3140
3237
         PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
3141
3238
        {"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
3150
3247
};
3151
3248
 
3152
3249
 
3153
 
 
 
3250
#ifndef __LP64__
3154
3251
int
3155
3252
PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
3156
3253
{
3188
3285
        }
3189
3286
        return 0;
3190
3287
}
 
3288
#endif /* !__LP64__ */
3191
3289
 
3192
3290
int
3193
3291
PyMac_GetFSRef(PyObject *v, FSRef *fsr)
3194
3292
{
3195
3293
        OSStatus err;
 
3294
#ifndef __LP64__
3196
3295
        FSSpec fss;
 
3296
#endif /* !__LP64__ */
3197
3297
 
3198
3298
        if (FSRef_Check(v)) {
3199
3299
                *fsr = ((FSRefObject *)v)->ob_itself;
3205
3305
                char *path = NULL;
3206
3306
                if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
3207
3307
                        return 0;
3208
 
                if ( (err=FSPathMakeRef(path, fsr, NULL)) )
 
3308
                if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
3209
3309
                        PyMac_Error(err);
3210
3310
                PyMem_Free(path);
3211
3311
                return !err;
3212
3312
        }
3213
3313
        /* XXXX Should try unicode here too */
 
3314
 
 
3315
#ifndef __LP64__
3214
3316
        /* Otherwise we try to go via an FSSpec */
3215
3317
        if (FSSpec_Check(v)) {
3216
3318
                fss = ((FSSpecObject *)v)->ob_itself;
3219
3321
                PyMac_Error(err);
3220
3322
                return 0;
3221
3323
        }
 
3324
#endif /* !__LP64__ */
 
3325
 
3222
3326
        PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
3223
3327
        return 0;
3224
3328
}
3225
3329
 
 
3330
#ifndef __LP64__
3226
3331
extern PyObject *
3227
3332
PyMac_BuildFSSpec(FSSpec *spec)
3228
3333
{
3229
3334
        return FSSpec_New(spec);
3230
3335
}
 
3336
#endif /* !__LP64__ */
3231
3337
 
3232
3338
extern PyObject *
3233
3339
PyMac_BuildFSRef(FSRef *spec)
3242
3348
        PyObject *d;
3243
3349
 
3244
3350
 
3245
 
 
 
3351
#ifndef __LP64__
3246
3352
        PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
 
3353
        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
 
3354
#endif /* !__LP64__ */
 
3355
 
3247
3356
        PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
3248
 
        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
3249
3357
        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
3250
3358
 
3251
3359
 
3262
3370
        /* Backward-compatible name */
3263
3371
        Py_INCREF(&FSCatalogInfo_Type);
3264
3372
        PyModule_AddObject(m, "FSCatalogInfoType", (PyObject *)&FSCatalogInfo_Type);
 
3373
 
 
3374
#ifndef __LP64__
3265
3375
        FInfo_Type.ob_type = &PyType_Type;
3266
3376
        if (PyType_Ready(&FInfo_Type) < 0) return;
3267
3377
        Py_INCREF(&FInfo_Type);
3269
3379
        /* Backward-compatible name */
3270
3380
        Py_INCREF(&FInfo_Type);
3271
3381
        PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
 
3382
#endif /* !__LP64__ */
3272
3383
        Alias_Type.ob_type = &PyType_Type;
3273
3384
        if (PyType_Ready(&Alias_Type) < 0) return;
3274
3385
        Py_INCREF(&Alias_Type);
3276
3387
        /* Backward-compatible name */
3277
3388
        Py_INCREF(&Alias_Type);
3278
3389
        PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
 
3390
 
 
3391
#ifndef __LP64__
3279
3392
        FSSpec_Type.ob_type = &PyType_Type;
3280
3393
        if (PyType_Ready(&FSSpec_Type) < 0) return;
3281
3394
        Py_INCREF(&FSSpec_Type);
3283
3396
        /* Backward-compatible name */
3284
3397
        Py_INCREF(&FSSpec_Type);
3285
3398
        PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
 
3399
#endif /* !__LP64__ */
3286
3400
        FSRef_Type.ob_type = &PyType_Type;
3287
3401
        if (PyType_Ready(&FSRef_Type) < 0) return;
3288
3402
        Py_INCREF(&FSRef_Type);