Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b173604f
Commit
b173604f
authored
May 07, 2002
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More support for bridging between Python and CoreFoundation objects. Still untested.
parent
f66500b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
6 deletions
+131
-6
Mac/Modules/cf/_CFmodule.c
Mac/Modules/cf/_CFmodule.c
+38
-0
Mac/Modules/cf/cfsupport.py
Mac/Modules/cf/cfsupport.py
+33
-0
Mac/Modules/cf/pycfbridge.c
Mac/Modules/cf/pycfbridge.c
+60
-6
No files found.
Mac/Modules/cf/_CFmodule.c
View file @
b173604f
...
...
@@ -31,6 +31,8 @@
#include <CoreServices/CoreServices.h>
#endif
#include "pycfbridge.h"
#ifdef USE_TOOLBOX_OBJECT_GLUE
extern
PyObject
*
_CFTypeRefObj_New
(
CFTypeRef
);
extern
int
_CFTypeRefObj_Convert
(
PyObject
*
,
CFTypeRef
*
);
...
...
@@ -287,6 +289,14 @@ static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
return
_res
;
}
static
PyObject
*
CFTypeRefObj_toPython
(
CFTypeRefObject
*
_self
,
PyObject
*
_args
)
{
PyObject
*
_res
=
NULL
;
return
PyCF_CF2Python
(
_self
->
ob_itself
);
}
static
PyMethodDef
CFTypeRefObj_methods
[]
=
{
{
"CFGetTypeID"
,
(
PyCFunction
)
CFTypeRefObj_CFGetTypeID
,
1
,
"() -> (CFTypeID _rv)"
},
...
...
@@ -304,6 +314,8 @@ static PyMethodDef CFTypeRefObj_methods[] = {
"() -> (CFStringRef _rv)"
},
{
"CFShow"
,
(
PyCFunction
)
CFTypeRefObj_CFShow
,
1
,
"() -> None"
},
{
"toPython"
,
(
PyCFunction
)
CFTypeRefObj_toPython
,
1
,
"() -> (python_object)"
},
{
NULL
,
NULL
,
0
}
};
...
...
@@ -3695,6 +3707,30 @@ static PyObject *CF_CFURLCreateFromFSRef(PyObject *_self, PyObject *_args)
return
_res
;
}
static
PyObject
*
CF_toCF
(
PyObject
*
_self
,
PyObject
*
_args
)
{
PyObject
*
_res
=
NULL
;
CFTypeRef
rv
;
CFTypeID
typeid
;
if
(
!
PyArg_ParseTuple
(
_args
,
"O&"
,
PyCF_Python2CF
,
&
rv
))
return
NULL
;
typeid
=
CFGetTypeID
(
rv
);
if
(
typeid
==
CFStringGetTypeID
())
return
Py_BuildValue
(
"O&"
,
CFStringRefObj_New
,
rv
);
if
(
typeid
==
CFArrayGetTypeID
())
return
Py_BuildValue
(
"O&"
,
CFArrayRefObj_New
,
rv
);
if
(
typeid
==
CFDictionaryGetTypeID
())
return
Py_BuildValue
(
"O&"
,
CFDictionaryRefObj_New
,
rv
);
if
(
typeid
==
CFURLGetTypeID
())
return
Py_BuildValue
(
"O&"
,
CFURLRefObj_New
,
rv
);
return
Py_BuildValue
(
"O&"
,
CFTypeRefObj_New
,
rv
);
}
static
PyMethodDef
CF_methods
[]
=
{
{
"__CFRangeMake"
,
(
PyCFunction
)
CF___CFRangeMake
,
1
,
"(CFIndex loc, CFIndex len) -> (CFRange _rv)"
},
...
...
@@ -3778,6 +3814,8 @@ static PyMethodDef CF_methods[] = {
"(Buffer buffer, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)"
},
{
"CFURLCreateFromFSRef"
,
(
PyCFunction
)
CF_CFURLCreateFromFSRef
,
1
,
"(FSRef fsRef) -> (CFURLRef _rv)"
},
{
"toCF"
,
(
PyCFunction
)
CF_toCF
,
1
,
"(python_object) -> (CF_object)"
},
{
NULL
,
NULL
,
0
}
};
...
...
Mac/Modules/cf/cfsupport.py
View file @
b173604f
...
...
@@ -53,6 +53,8 @@ includestuff = includestuff + """
#include <CoreServices/CoreServices.h>
#endif
#include "pycfbridge.h"
#ifdef USE_TOOLBOX_OBJECT_GLUE
extern PyObject *_CFTypeRefObj_New(CFTypeRef);
extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
...
...
@@ -485,6 +487,37 @@ f = ManualGenerator("CFStringGetUnicode", getasunicode_body);
f
.
docstring
=
lambda
:
"() -> (unicode _rv)"
CFStringRef_object
.
add
(
f
)
toPython_body
=
"""
return PyCF_CF2Python(_self->ob_itself);
"""
f
=
ManualGenerator
(
"toPython"
,
toPython_body
);
f
.
docstring
=
lambda
:
"() -> (python_object)"
CFTypeRef_object
.
add
(
f
)
toCF_body
=
"""
CFTypeRef rv;
CFTypeID typeid;
if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
return NULL;
typeid = CFGetTypeID(rv);
if (typeid == CFStringGetTypeID())
return Py_BuildValue("O&", CFStringRefObj_New, rv);
if (typeid == CFArrayGetTypeID())
return Py_BuildValue("O&", CFArrayRefObj_New, rv);
if (typeid == CFDictionaryGetTypeID())
return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
if (typeid == CFURLGetTypeID())
return Py_BuildValue("O&", CFURLRefObj_New, rv);
return Py_BuildValue("O&", CFTypeRefObj_New, rv);
"""
f
=
ManualGenerator
(
"toCF"
,
toCF_body
);
f
.
docstring
=
lambda
:
"(python_object) -> (CF_object)"
module
.
add
(
f
)
# ADD add forloop here
# generate output (open the output file as late as possible)
...
...
Mac/Modules/cf/pycfbridge.c
View file @
b173604f
...
...
@@ -26,6 +26,10 @@ PyObject *
PyCF_CF2Python
(
CFTypeRef
src
)
{
CFTypeID
typeid
;
if
(
src
==
NULL
)
{
Py_INCREF
(
Py_None
);
return
Py_None
;
}
typeid
=
CFGetTypeID
(
src
);
if
(
typeid
==
CFArrayGetTypeID
())
return
PyCF_CF2Python_sequence
((
CFArrayRef
)
src
);
...
...
@@ -36,13 +40,63 @@ PyCF_CF2Python(CFTypeRef src) {
PyObject
*
PyCF_CF2Python_sequence
(
CFArrayRef
src
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Not yet implemented"
);
int
size
=
CFArrayGetCount
(
src
);
PyObject
*
rv
;
CFTypeRef
item_cf
;
PyObject
*
item_py
=
NULL
;
int
i
;
if
(
(
rv
=
PyList_New
(
size
))
==
NULL
)
return
NULL
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
item_cf
=
CFArrayGetValueAtIndex
(
src
,
i
);
if
(
item_cf
==
NULL
)
goto
err
;
item_py
=
PyCF_CF2Python
(
item_cf
);
if
(
item_py
==
NULL
)
goto
err
;
if
(
!
PyList_SetItem
(
rv
,
i
,
item_py
))
goto
err
;
item_py
=
NULL
;
}
return
rv
;
err:
Py_XDECREF
(
item_py
);
Py_DECREF
(
rv
);
return
NULL
;
}
PyObject
*
PyCF_CF2Python_mapping
(
CFTypeRef
src
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Not yet implemented"
);
int
size
=
CFDictionaryGetCount
(
src
);
PyObject
*
rv
;
CFTypeRef
*
allkeys
,
*
allvalues
;
CFTypeRef
key_cf
,
value_cf
;
PyObject
*
key_py
=
NULL
,
*
value_py
=
NULL
;
int
i
;
allkeys
=
malloc
(
size
*
sizeof
(
CFTypeRef
*
));
if
(
allkeys
==
NULL
)
return
PyErr_NoMemory
();
allvalues
=
malloc
(
size
*
sizeof
(
CFTypeRef
*
));
if
(
allvalues
==
NULL
)
return
PyErr_NoMemory
();
if
(
(
rv
=
PyDict_New
())
==
NULL
)
return
NULL
;
CFDictionaryGetKeysAndValues
(
src
,
allkeys
,
allvalues
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
key_cf
=
allkeys
[
i
];
value_cf
=
allvalues
[
i
];
key_py
=
PyCF_CF2Python
(
key_cf
);
if
(
key_py
==
NULL
)
goto
err
;
value_py
=
PyCF_CF2Python
(
value_py
);
if
(
value_py
==
NULL
)
goto
err
;
if
(
!
PyDict_SetItem
(
rv
,
key_py
,
value_py
))
goto
err
;
key_py
=
NULL
;
value_py
=
NULL
;
}
return
rv
;
err:
Py_XDECREF
(
key_py
);
Py_XDECREF
(
value_py
);
Py_DECREF
(
rv
);
free
(
allkeys
);
free
(
allvalues
);
return
NULL
;
}
...
...
@@ -90,7 +144,7 @@ PyCF_Python2CF(PyObject *src, CFTypeRef *dst) {
int
PyCF_Python2CF_sequence
(
PyObject
*
src
,
CFArrayRef
*
dst
)
{
CFArrayRef
rv
=
NULL
;
CF
Mutable
ArrayRef
rv
=
NULL
;
CFTypeRef
item_cf
=
NULL
;
PyObject
*
item_py
=
NULL
;
int
size
,
i
;
...
...
@@ -122,7 +176,7 @@ err:
int
PyCF_Python2CF_mapping
(
PyObject
*
src
,
CFDictionaryRef
*
dst
)
{
CFDictionaryRef
rv
=
NULL
;
CF
Mutable
DictionaryRef
rv
=
NULL
;
PyObject
*
aslist
=
NULL
;
CFTypeRef
key_cf
=
NULL
,
value_cf
=
NULL
;
PyObject
*
item_py
=
NULL
,
*
key_py
=
NULL
,
*
value_py
=
NULL
;
...
...
@@ -130,7 +184,7 @@ PyCF_Python2CF_mapping(PyObject *src, CFDictionaryRef *dst) {
size
=
PyMapping_Size
(
src
);
rv
=
CFDictionaryCreateMutable
((
CFAllocatorRef
)
NULL
,
size
,
&
kCFTypeDictionaryKeyCallBacks
,
&
kCFTypeDictionaryKeyCallBacks
,
&
kCFTypeDictionaryValueCallBacks
);
if
(
rv
==
NULL
)
{
PyMac_Error
(
resNotFound
);
...
...
@@ -144,7 +198,7 @@ PyCF_Python2CF_mapping(PyObject *src, CFDictionaryRef *dst) {
if
(
!
PyArg_ParseTuple
(
item_py
,
"OO"
,
key_py
,
value_py
))
goto
err
;
if
(
!
PyCF_Python2CF
(
key_py
,
&
key_cf
)
)
goto
err
;
Py_DECREF
(
key_py
);
if
(
!
PyCF_Python2CF
(
value_
cf
,
&
key
_cf
)
)
goto
err
;
if
(
!
PyCF_Python2CF
(
value_
py
,
&
value
_cf
)
)
goto
err
;
Py_DECREF
(
value_py
);
CFDictionaryAddValue
(
rv
,
key_cf
,
value_cf
);
CFRelease
(
key_cf
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment