Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
4419ceb8
Commit
4419ceb8
authored
Mar 05, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move PyBuffer_* funcs from capi.cpp to abstract.cpp
parent
732bbc40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
113 deletions
+110
-113
src/capi/abstract.cpp
src/capi/abstract.cpp
+110
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+0
-113
No files found.
src/capi/abstract.cpp
View file @
4419ceb8
...
...
@@ -31,10 +31,120 @@ extern "C" Py_ssize_t _PyObject_LengthHint(PyObject* o, Py_ssize_t defaultvalue)
Py_FatalError
(
"unimplemented"
);
}
static
int
_IsFortranContiguous
(
Py_buffer
*
view
)
{
Py_ssize_t
sd
,
dim
;
int
i
;
if
(
view
->
ndim
==
0
)
return
1
;
if
(
view
->
strides
==
NULL
)
return
(
view
->
ndim
==
1
);
sd
=
view
->
itemsize
;
if
(
view
->
ndim
==
1
)
return
(
view
->
shape
[
0
]
==
1
||
sd
==
view
->
strides
[
0
]);
for
(
i
=
0
;
i
<
view
->
ndim
;
i
++
)
{
dim
=
view
->
shape
[
i
];
if
(
dim
==
0
)
return
1
;
if
(
view
->
strides
[
i
]
!=
sd
)
return
0
;
sd
*=
dim
;
}
return
1
;
}
static
int
_IsCContiguous
(
Py_buffer
*
view
)
{
Py_ssize_t
sd
,
dim
;
int
i
;
if
(
view
->
ndim
==
0
)
return
1
;
if
(
view
->
strides
==
NULL
)
return
1
;
sd
=
view
->
itemsize
;
if
(
view
->
ndim
==
1
)
return
(
view
->
shape
[
0
]
==
1
||
sd
==
view
->
strides
[
0
]);
for
(
i
=
view
->
ndim
-
1
;
i
>=
0
;
i
--
)
{
dim
=
view
->
shape
[
i
];
if
(
dim
==
0
)
return
1
;
if
(
view
->
strides
[
i
]
!=
sd
)
return
0
;
sd
*=
dim
;
}
return
1
;
}
extern
"C"
int
PyBuffer_IsContiguous
(
Py_buffer
*
view
,
char
fort
)
noexcept
{
if
(
view
->
suboffsets
!=
NULL
)
return
0
;
if
(
fort
==
'C'
)
return
_IsCContiguous
(
view
);
else
if
(
fort
==
'F'
)
return
_IsFortranContiguous
(
view
);
else
if
(
fort
==
'A'
)
return
(
_IsCContiguous
(
view
)
||
_IsFortranContiguous
(
view
));
return
0
;
}
extern
"C"
int
PyBuffer_ToContiguous
(
void
*
buf
,
Py_buffer
*
view
,
Py_ssize_t
len
,
char
fort
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
extern
"C"
int
PyBuffer_FillInfo
(
Py_buffer
*
view
,
PyObject
*
obj
,
void
*
buf
,
Py_ssize_t
len
,
int
readonly
,
int
flags
)
noexcept
{
if
(
view
==
NULL
)
return
0
;
if
(((
flags
&
PyBUF_WRITABLE
)
==
PyBUF_WRITABLE
)
&&
(
readonly
==
1
))
{
// Don't support PyErr_SetString yet:
assert
(
0
);
// PyErr_SetString(PyExc_BufferError, "Object is not writable.");
// return -1;
}
view
->
obj
=
obj
;
if
(
obj
)
Py_INCREF
(
obj
);
view
->
buf
=
buf
;
view
->
len
=
len
;
view
->
readonly
=
readonly
;
view
->
itemsize
=
1
;
view
->
format
=
NULL
;
if
((
flags
&
PyBUF_FORMAT
)
==
PyBUF_FORMAT
)
view
->
format
=
"B"
;
view
->
ndim
=
1
;
view
->
shape
=
NULL
;
if
((
flags
&
PyBUF_ND
)
==
PyBUF_ND
)
view
->
shape
=
&
(
view
->
len
);
view
->
strides
=
NULL
;
if
((
flags
&
PyBUF_STRIDES
)
==
PyBUF_STRIDES
)
view
->
strides
=
&
(
view
->
itemsize
);
view
->
suboffsets
=
NULL
;
view
->
internal
=
NULL
;
return
0
;
}
extern
"C"
void
PyBuffer_Release
(
Py_buffer
*
view
)
noexcept
{
if
(
!
view
->
buf
)
{
assert
(
!
view
->
obj
);
return
;
}
PyObject
*
obj
=
view
->
obj
;
if
(
obj
)
{
assert
(
obj
->
cls
==
str_cls
);
if
(
obj
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
)
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
(
obj
,
view
);
Py_XDECREF
(
obj
);
}
view
->
obj
=
NULL
;
}
static
PyObject
*
type_error
(
const
char
*
msg
,
PyObject
*
obj
)
noexcept
{
PyErr_Format
(
PyExc_TypeError
,
msg
,
Py_TYPE
(
obj
)
->
tp_name
);
return
NULL
;
...
...
src/runtime/capi.cpp
View file @
4419ceb8
...
...
@@ -86,58 +86,6 @@ Box* BoxedWrapperDescriptor::__get__(BoxedWrapperDescriptor* self, Box* inst, Bo
return
new
BoxedWrapperObject
(
self
,
inst
);
}
// copied from CPython's getargs.c:
extern
"C"
int
PyBuffer_FillInfo
(
Py_buffer
*
view
,
PyObject
*
obj
,
void
*
buf
,
Py_ssize_t
len
,
int
readonly
,
int
flags
)
noexcept
{
if
(
view
==
NULL
)
return
0
;
if
(((
flags
&
PyBUF_WRITABLE
)
==
PyBUF_WRITABLE
)
&&
(
readonly
==
1
))
{
// Don't support PyErr_SetString yet:
assert
(
0
);
// PyErr_SetString(PyExc_BufferError, "Object is not writable.");
// return -1;
}
view
->
obj
=
obj
;
if
(
obj
)
Py_INCREF
(
obj
);
view
->
buf
=
buf
;
view
->
len
=
len
;
view
->
readonly
=
readonly
;
view
->
itemsize
=
1
;
view
->
format
=
NULL
;
if
((
flags
&
PyBUF_FORMAT
)
==
PyBUF_FORMAT
)
view
->
format
=
"B"
;
view
->
ndim
=
1
;
view
->
shape
=
NULL
;
if
((
flags
&
PyBUF_ND
)
==
PyBUF_ND
)
view
->
shape
=
&
(
view
->
len
);
view
->
strides
=
NULL
;
if
((
flags
&
PyBUF_STRIDES
)
==
PyBUF_STRIDES
)
view
->
strides
=
&
(
view
->
itemsize
);
view
->
suboffsets
=
NULL
;
view
->
internal
=
NULL
;
return
0
;
}
extern
"C"
void
PyBuffer_Release
(
Py_buffer
*
view
)
noexcept
{
if
(
!
view
->
buf
)
{
assert
(
!
view
->
obj
);
return
;
}
PyObject
*
obj
=
view
->
obj
;
if
(
obj
)
{
assert
(
obj
->
cls
==
str_cls
);
if
(
obj
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
&&
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
)
Py_TYPE
(
obj
)
->
tp_as_buffer
->
bf_releasebuffer
(
obj
,
view
);
Py_XDECREF
(
obj
);
}
view
->
obj
=
NULL
;
}
extern
"C"
void
_PyErr_BadInternalCall
(
const
char
*
filename
,
int
lineno
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
...
...
@@ -925,67 +873,6 @@ extern "C" void PyMem_Free(void* ptr) noexcept {
gc_compat_free
(
ptr
);
}
static
int
_IsFortranContiguous
(
Py_buffer
*
view
)
{
Py_ssize_t
sd
,
dim
;
int
i
;
if
(
view
->
ndim
==
0
)
return
1
;
if
(
view
->
strides
==
NULL
)
return
(
view
->
ndim
==
1
);
sd
=
view
->
itemsize
;
if
(
view
->
ndim
==
1
)
return
(
view
->
shape
[
0
]
==
1
||
sd
==
view
->
strides
[
0
]);
for
(
i
=
0
;
i
<
view
->
ndim
;
i
++
)
{
dim
=
view
->
shape
[
i
];
if
(
dim
==
0
)
return
1
;
if
(
view
->
strides
[
i
]
!=
sd
)
return
0
;
sd
*=
dim
;
}
return
1
;
}
static
int
_IsCContiguous
(
Py_buffer
*
view
)
{
Py_ssize_t
sd
,
dim
;
int
i
;
if
(
view
->
ndim
==
0
)
return
1
;
if
(
view
->
strides
==
NULL
)
return
1
;
sd
=
view
->
itemsize
;
if
(
view
->
ndim
==
1
)
return
(
view
->
shape
[
0
]
==
1
||
sd
==
view
->
strides
[
0
]);
for
(
i
=
view
->
ndim
-
1
;
i
>=
0
;
i
--
)
{
dim
=
view
->
shape
[
i
];
if
(
dim
==
0
)
return
1
;
if
(
view
->
strides
[
i
]
!=
sd
)
return
0
;
sd
*=
dim
;
}
return
1
;
}
extern
"C"
int
PyBuffer_IsContiguous
(
Py_buffer
*
view
,
char
fort
)
noexcept
{
if
(
view
->
suboffsets
!=
NULL
)
return
0
;
if
(
fort
==
'C'
)
return
_IsCContiguous
(
view
);
else
if
(
fort
==
'F'
)
return
_IsFortranContiguous
(
view
);
else
if
(
fort
==
'A'
)
return
(
_IsCContiguous
(
view
)
||
_IsFortranContiguous
(
view
));
return
0
;
}
extern
"C"
int
PyOS_snprintf
(
char
*
str
,
size_t
size
,
const
char
*
format
,
...)
noexcept
{
int
rc
;
va_list
va
;
...
...
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