director method - PHP NULL gets returned by the subclassed method
in this case, so the directorout typemap needs to allow that (at
least if an exception is active).
Hi
Would it be possible to add the following 2 typedefs to std_ios.i?
typedef basic_ios<char> ios;
typedef basic_ios<wchar_t> wios;
at present, it contains only
%template(ios) basic_ios<char>;
%template(wios) basic_ios<wchar_t>;
This means however that things like std::ios::openmode are currently not
recognised by SWIG. With the above typedefs, they are. Similar typedefs
should probably be added in std_iostream.i for ostream etc.
Also, while checking std_ios.i, it seems that the definition of basic_ios
has a copy-paste error in the private section (the constructor is still as
ios_base). To avoid confusion, I suggest to change that. Below is a diff
with the suggested changes.
Kris
* Renamed SWIG_Lua_equal to SWIG_Lua_class_equal
* If class has no __eq implemented, then default __eq is provided.
Default __eq compares actual pointers stored inside Lua userdata
JSObjectMakeError automatically populates the "message" field, and possibly other fields I don't know about. This seems to be the most robust way to create an exception object.
Thanks to Brian Barnes again for the tip on JSObjectMakeError.
It is unclear what the correct handling is for JavaScriptCore. (Nobody bothers to document this in JSCore.) Unlike our other problem where we incorrectly assume JSObjectRef when the functions want JSValueRef, this time Apple is demanding the JSObjectRef. Like our other problem, I assume it is unsafe to try to convert Undefined into a JSObjectRef.
So reverting to NULL seems like the safer bet for this specific case. Perhaps the other alternative is to return an exception object or an error object. But I would like to see JSCore document this before trying.
According to this:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
Returning NULL instead of an actual JSValueRef for a return value of a function could lead to crashes. I think I have seen related weirdness in the past when I failed to return a proper type to JSCore which resulted in very hard to understand behavior.
So this patch changes those return NULLs to return JSValueMakeUndefined().
I thought about JSObjectMakeError, but I don't fully understand the intent of the Error object and can't find any relevant real world examples of it being used. However, everybody seems to be using JSValueMakeUndefined().
This patch should be low impact since this is only triggered on an error condition.
The current implementation only returns an error string. But this is insufficient for debugging (what file and line number did it fail at?).
As documented here:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
converting the JSValueRef of string to an JSObjectRef (via JSValueToObject) will trigger JSCore into filling the "sourceURL" and "line" properties into the object so they can be inspected by the caller.
Additionally, JavaScriptCore has a "message" property which contains the message string. JSCore doesn't seem to be filling this in for us automatically, unlike "sourceURL" and "line". So this patch also fills that property in too.
Thanks to Brian Barnes for the detailed information about "sourceURL", "line", and "message".
Below is an example (derived from Brian Barnes's information) on how you typically use/extract these exception details.
void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
{
JSObjectRef exception_object;
JSValueRef value_ref;
JSStringRef jsstring_property_name = NULL;
JSValueRef temporary_exception = NULL;
JSStringRef js_return_string = NULL;
size_t bytes_needed;
char* c_result_string = NULL;
exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
// source and line numbers
strcpy(return_error_string,"[");
jsstring_property_name = JSStringCreateWithUTF8CString("sourceURL");
value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
JSStringRelease(jsstring_property_name);
js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
c_result_string = (char*)calloc(bytes_needed, sizeof(char));
JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
SDL_Log("c_result_string: %s\n", c_result_string);
JSStringRelease(js_return_string);
strncat(return_error_string, c_result_string, return_error_string_max_length-1);
free(c_result_string);
strncat(return_error_string, ":", return_error_string_max_length-1);
jsstring_property_name = JSStringCreateWithUTF8CString("line");
value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
JSStringRelease(jsstring_property_name);
js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
c_result_string = (char*)calloc(bytes_needed, sizeof(char));
JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
SDL_Log("c_result_string: %s\n", c_result_string);
JSStringRelease(js_return_string);
strncat(return_error_string, c_result_string, return_error_string_max_length-1);
//SDL_Log("c_result_string: %s\n", c_result_string);
free(c_result_string);
strncat(return_error_string, "]", return_error_string_max_length-1);
/* get message */
jsstring_property_name = JSStringCreateWithUTF8CString("message");
value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
JSStringRelease(jsstring_property_name);
if(NULL == value_ref)
{
strncat(return_error_string, "Unknown Error", return_error_string_max_length-1);
}
else
{
js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
c_result_string = (char*)calloc(bytes_needed, sizeof(char));
JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
SDL_Log("c_result_string: %s\n", c_result_string);
JSStringRelease(js_return_string);
strncat(return_error_string, c_result_string, return_error_string_max_length-1);
//SDL_Log("c_result_string: %s\n", c_result_string);
free(c_result_string);
}
}
To use:
if(js_exception)
{
char return_error_string[256];
script_exception_to_string(js_context, js_exception, return_error_string, 256);
SDL_Log("Compile error is %s", return_error_string);
}
... if available on the version of Python that's in use. This allows
obtaining the original byte string (and potentially trying a fallback
encoding) if the bytes can't be decoded as UTF-8.
Previously, a UnicodeDecodeError would be raised with no way to treat
the data as bytes or try another codec.
It is common in C to accept NULL to functions for pointer parameters.
extern void DoSomething(struct Foo* foo);
...
DoSomething(NULL);
Thus, JavaScript null should be allowed:
module.DoSomething(null);
But the current ConvertPtr definition accepts only objects. This modifies it to allow null.
It is common in C to accept NULL to functions for pointer parameters.
extern void DoSomething(struct Foo* foo);
...
DoSomething(NULL);
Thus, JavaScript null should be allowed:
module.DoSomething(null);
But the current ConvertPtr definition accepts only objects. This modifies it to allow null.
- memory allocated with malloc() was then being freed with delete[],
which is overridden by Javascript libraries (jsc), leading to segfault
- replacing malloc with %new_array seems to work though
- in configure.ac: modify sed expression to only look at first line of
gccgo --version, extract the last numeric token, and remove periods;
this parses e.g. "gccgo (Debian 4.7.2-5) 4.7.2"
- in goruntime.swg: fix typo in __GNUC_PATCHLEVEL__ (SF Bug #1298)
- in Lib/gcj/cni.i: remove JvAllocObject(), change
JvCreateJavaVM() argument from void* to JvVMInitArgs*
- in Examples/{python|perl5|ruby|tcl}/java/Makefile:
pass full class name to gcjh, add Example.h as dependency,
do not override CXX for compiling C++ sources
- in Examples/python/java/example.i:
add destructor to class to prevent memory loss complaint
- some of the %.clean rules in the test-suite Makefiles were using a single tab
as an empty rule, dangerous! I've replaced these with the safer '@exit 0'.
- source files and Makefiles need never be executable
- scripts are run directly by their interpreters in the
test suites, so also do not need to be executable