[runtime] Use MonoError for mono_string_new_size
[mono.git] / mono / metadata / string-icalls.c
1 /*
2  * string-icalls.c: String internal calls for the corlib
3  *
4  * Author:
5  *   Patrik Torstensson (patrik.torstensson@labs2.com)
6  *   Duncan Mak  (duncan@ximian.com)
7  *
8  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
10  */
11 #include <config.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include "mono/utils/mono-membar.h"
16 #include <mono/metadata/string-icalls.h>
17 #include <mono/metadata/class-internals.h>
18 #include <mono/metadata/appdomain.h>
19 #include <mono/metadata/tabledefs.h>
20 #include <mono/metadata/loader.h>
21 #include <mono/metadata/object.h>
22 #include <mono/metadata/exception.h>
23 #include <mono/metadata/debug-helpers.h>
24 #include <mono/metadata/profiler.h>
25 #include <mono/metadata/profiler-private.h>
26 #include <mono/metadata/gc-internals.h>
27
28 /* This function is redirected to String.CreateString ()
29    by mono_marshal_get_native_wrapper () */
30 void
31 ves_icall_System_String_ctor_RedirectToCreateString (void)
32 {
33         g_assert_not_reached ();
34 }
35
36 MonoString *
37 ves_icall_System_String_InternalAllocateStr (gint32 length)
38 {
39         MonoError error;
40         MonoString *str = mono_string_new_size_checked (mono_domain_get (), length, &error);
41         mono_error_raise_exception (&error);
42
43         return str;
44 }
45
46 MonoString  *
47 ves_icall_System_String_InternalIntern (MonoString *str)
48 {
49         MonoString *res;
50
51         res = mono_string_intern(str);
52         if (!res) {
53                 mono_set_pending_exception (mono_domain_get ()->out_of_memory_ex);
54                 return NULL;
55         }
56         return res;
57 }
58
59 MonoString * 
60 ves_icall_System_String_InternalIsInterned (MonoString *str)
61 {
62         return mono_string_is_interned(str);
63 }
64
65 int
66 ves_icall_System_String_GetLOSLimit (void)
67 {
68         int limit = mono_gc_get_los_limit ();
69
70         return (limit - 2 - G_STRUCT_OFFSET (MonoString, chars)) / 2;
71 }
72