Skip to content

Commit

Permalink
More RAII plzkthx.
Browse files Browse the repository at this point in the history
Moving towards implementing simplifications using C++ RAII awesomeness.
  • Loading branch information
davisp committed Jul 27, 2009
1 parent 80b5ab7 commit 3eec0ef
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 588 deletions.
2 changes: 1 addition & 1 deletion spidermonkey/convert/array.cpp
@@ -1,4 +1,4 @@
#include <spidermonkey.h>
#include "convert.h"

PyObject*
js2py_array(Context* cx, jsval val)
Expand Down
4 changes: 3 additions & 1 deletion spidermonkey/convert/convert.cpp
Expand Up @@ -6,7 +6,9 @@
*
*/

#include <spidermonkey.h>
#include <jsapi.h>
#include "convert.h"
#include "python/python.h"

jsval
py2js(Context* cx, PyObject* obj)
Expand Down
2 changes: 1 addition & 1 deletion spidermonkey/convert/double.cpp
Expand Up @@ -6,7 +6,7 @@
*
*/

#include <spidermonkey.h>
#include "convert.h"

jsval
py2js_double(Context* cx, PyObject* obj)
Expand Down
2 changes: 1 addition & 1 deletion spidermonkey/convert/function.cpp
@@ -1,5 +1,5 @@

#include <spidermonkey.h>
#include "convert.h"

PyObject*
js2py_function(Context* cx, jsval val, jsval parent)
Expand Down
2 changes: 1 addition & 1 deletion spidermonkey/convert/integer.cpp
Expand Up @@ -6,7 +6,7 @@
*
*/

#include <spidermonkey.h>
#include "convert.h"

jsval
py2js_integer(Context* cx, PyObject* obj)
Expand Down
3 changes: 2 additions & 1 deletion spidermonkey/convert/object.cpp
@@ -1,5 +1,6 @@

#include <spidermonkey.h>
#include "convert.h"
#include "javascript/javascript.h"

jsval
py2js_object(Context* cx, PyObject* pyobj)
Expand Down
2 changes: 1 addition & 1 deletion spidermonkey/convert/string.cpp
Expand Up @@ -6,7 +6,7 @@
*
*/

#include <spidermonkey.h>
#include "convert.h"

JSString*
py2js_string_obj(Context* cx, PyObject* str)
Expand Down
76 changes: 31 additions & 45 deletions spidermonkey/javascript/error.cpp
Expand Up @@ -9,66 +9,52 @@
#include <spidermonkey.h>
#include "frameobject.h"

JSBool
js_error(JSContext* cx, const char* err)
{
JS_ReportError(cx, err);
return JS_FALSE;
}

void
add_frame(const char* srcfile, const char* funcname, int linenum)
{
PyObject* src = NULL;
PyObject* func = NULL;
PyObject* glbl = NULL;
PyObject* tpl = NULL;
PyObject* str = NULL;
PyCodeObject* code = NULL;
PyFrameObject* frame = NULL;
PyObjectXDR src = PyString_FromString(srcfile);
PyObjectXDR func = PyString_FromString(funcname);
PyObjectXDR tpl = PyTuple_New(0);
PyObjectXDR str = PyString_FromString("");

src = PyString_FromString(srcfile);
if(src == NULL) goto error;

func = PyString_FromString(funcname);
if(func == NULL) goto error;

glbl = PyModule_GetDict(SpidermonkeyModule);
if(glbl == NULL) goto error;
// This is a borrowed reference, hence no PyObjectXDR so we
// don't decref it.
PyPtr<PyObject> glbl = PyModule_GetDict(SpidermonkeyModule);

tpl = PyTuple_New(0);
if(tpl == NULL) goto error;
if(!src || !func || !glbl || !tpl || !str) return;

str = PyString_FromString("");
if(str == NULL) goto error;

code = PyCode_New(
PyCodeXDR code = PyCode_New(
0, /*co_argcount*/
0, /*co_nlocals*/
0, /*co_stacksize*/
0, /*co_flags*/
str, /*co_code*/
tpl, /*co_consts*/
tpl, /*co_names*/
tpl, /*co_varnames*/
tpl, /*co_freevars*/
tpl, /*co_cellvars*/
src, /*co_filename*/
func, /*co_name*/
str.get(), /*co_code*/
tpl.get(), /*co_consts*/
tpl.get(), /*co_names*/
tpl.get(), /*co_varnames*/
tpl.get(), /*co_freevars*/
tpl.get(), /*co_cellvars*/
src.get(), /*co_filename*/
func.get(), /*co_name*/
linenum, /*co_firstlineno*/
str /*co_lnotab*/
str.get() /*co_lnotab*/
);
if(code == NULL) goto error;
if(!code) return;

frame = PyFrame_New(PyThreadState_Get(), code, glbl, NULL);
if(frame == NULL) goto error;
PyFrameXDR frame = PyFrame_New(
PyThreadState_Get(), code.get(), glbl.get(), NULL
);
if(!frame) return;

frame->f_lineno = linenum;
PyTraceBack_Here(frame);

goto success;

error:
success:
Py_XDECREF(func);
Py_XDECREF(src);
Py_XDECREF(tpl);
Py_XDECREF(str);
Py_XDECREF(code);
Py_XDECREF(frame);
PyTraceBack_Here(frame.get());
}

void
Expand Down

0 comments on commit 3eec0ef

Please sign in to comment.