Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: swig/Lib/python/pybuffer.i

Issue 553095: Checkin swig binaries for win, linux and Mac... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « swig/Lib/python/pybackward.swg ('k') | swig/Lib/python/pyclasses.swg » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: swig/Lib/python/pybuffer.i
===================================================================
--- swig/Lib/python/pybuffer.i (revision 0)
+++ swig/Lib/python/pybuffer.i (revision 0)
@@ -0,0 +1,107 @@
+/* Implementing buffer protocol typemaps */
+
+/* %pybuffer_mutable_binary(TYPEMAP, SIZE)
+ *
+ * Macro for functions accept mutable buffer pointer with a size.
+ * This can be used for both input and output. For example:
+ *
+ * %pybuffer_mutable_binary(char *buff, int size);
+ * void foo(char *buff, int size) {
+ * for(int i=0; i<size; ++i)
+ * buff[i]++;
+ * }
+ */
+
+%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
+%typemap(in) (TYPEMAP, SIZE)
+ (int res, Py_ssize_t size = 0, void *buf = 0) {
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ if (res<0) {
+ PyErr_Clear();
+ %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
+ }
+ $1 = ($1_ltype) buf;
+ $2 = ($2_ltype) (size/sizeof($*1_type));
+}
+%enddef
+
+/* %pybuffer_mutable_string(TYPEMAP, SIZE)
+ *
+ * Macro for functions accept mutable zero terminated string pointer.
+ * This can be used for both input and output. For example:
+ *
+ * %pybuffer_mutable_string(char *str);
+ * void foo(char *str) {
+ * while(*str) {
+ * *str = toupper(*str);
+ * str++;
+ * }
+ */
+
+%define %pybuffer_mutable_string(TYPEMAP)
+%typemap(in) (TYPEMAP)
+ (int res, Py_ssize_t size = 0, void *buf = 0) {
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ if (res<0) {
+ PyErr_Clear();
+ %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
+ }
+ $1 = ($1_ltype) buf;
+}
+%enddef
+
+/* pybuffer_binary(TYPEMAP, SIZE)
+ *
+ * Macro for functions accept read only buffer pointer with a size.
+ * This must be used for input. For example:
+ *
+ * %pybuffer_binary(char *buff, int size);
+ * int foo(char *buff, int size) {
+ * int count = 0;
+ * for(int i=0; i<size; ++i)
+ * if (0==buff[i]) count++;
+ * return count;
+ * }
+ */
+
+%define %pybuffer_binary(TYPEMAP, SIZE)
+%typemap(in) (TYPEMAP, SIZE)
+ (int res, Py_ssize_t size = 0, const void *buf = 0) {
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ if (res<0) {
+ PyErr_Clear();
+ %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
+ }
+ $1 = ($1_ltype) buf;
+ $2 = ($2_ltype) (size / sizeof($*1_type));
+}
+%enddef
+
+/* %pybuffer_string(TYPEMAP, SIZE)
+ *
+ * Macro for functions accept read only zero terminated string pointer.
+ * This can be used for input. For example:
+ *
+ * %pybuffer_string(char *str);
+ * int foo(char *str) {
+ * int count = 0;
+ * while(*str) {
+ * if (isalnum(*str))
+ * count++;
+ * str++;
+ * }
+ */
+
+%define %pybuffer_string(TYPEMAP)
+%typemap(in) (TYPEMAP)
+ (int res, Py_ssize_t size = 0, const void *buf = 0) {
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ if (res<0) {
+ %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
+ }
+ $1 = ($1_ltype) buf;
+}
+%enddef
+
+
+
« no previous file with comments | « swig/Lib/python/pybackward.swg ('k') | swig/Lib/python/pyclasses.swg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698