comparison src/utils.h @ 132:537cf7deadc9

Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
author Atul Varma <varmaa@toolness.com>
date Sun, 23 Aug 2009 18:43:46 -0700
parents 00e874d9a6a7
children dd32a92f6b4f
comparison
equal deleted inserted replaced
131:f956a6dea16c 132:537cf7deadc9
40 #include "context.h" 40 #include "context.h"
41 41
42 #include <jsapi.h> 42 #include <jsapi.h>
43 #include <jsdhash.h> 43 #include <jsdhash.h>
44 #include <Python.h> 44 #include <Python.h>
45
46 // Simple class that holds on to a UTF-16 string created by
47 // PyArg_ParseTuple() for as long as it's in scope. It also
48 // provides easy BOM-stripping accessors for JS-land.
49 class PYM_UTF16String {
50 public:
51 PYM_UTF16String(char *buffer, int size) : jsbuffer((jschar *) (buffer + 2)),
52 jslen(size / 2 - 1), pybuffer(buffer), pysize(size) {
53 }
54
55 ~PYM_UTF16String() {
56 PyMem_Free(pybuffer);
57 }
58
59 jschar *jsbuffer;
60 size_t jslen;
61
62 protected:
63 char *pybuffer;
64 int pysize;
65 };
45 66
46 // Simple class that holds the Python global interpreter lock (GIL) 67 // Simple class that holds the Python global interpreter lock (GIL)
47 // for as long as it's in scope. 68 // for as long as it's in scope.
48 class PYM_PyAutoEnsureGIL { 69 class PYM_PyAutoEnsureGIL {
49 public: 70 public: