Merge pull request #2545 from ermshiperete/Xamarin-24974
[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  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12 #include <config.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include "mono/utils/mono-membar.h"
17 #include <mono/metadata/string-icalls.h>
18 #include <mono/metadata/class-internals.h>
19 #include <mono/metadata/appdomain.h>
20 #include <mono/metadata/tabledefs.h>
21 #include <mono/metadata/loader.h>
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/exception.h>
24 #include <mono/metadata/debug-helpers.h>
25 #include <mono/metadata/profiler.h>
26 #include <mono/metadata/profiler-private.h>
27 #include <mono/metadata/gc-internals.h>
28
29 /* This function is redirected to String.CreateString ()
30    by mono_marshal_get_native_wrapper () */
31 void
32 ves_icall_System_String_ctor_RedirectToCreateString (void)
33 {
34         g_assert_not_reached ();
35 }
36
37 MonoString *
38 ves_icall_System_String_InternalAllocateStr (gint32 length)
39 {
40         MonoError error;
41         MonoString *str = mono_string_new_size_checked (mono_domain_get (), length, &error);
42         mono_error_raise_exception (&error);
43
44         return str;
45 }
46
47 MonoString  *
48 ves_icall_System_String_InternalIntern (MonoString *str)
49 {
50         MonoError error;
51         MonoString *res;
52
53         res = mono_string_intern_checked (str, &error);
54         if (!res) {
55                 mono_error_set_pending_exception (&error);
56                 return NULL;
57         }
58         return res;
59 }
60
61 MonoString * 
62 ves_icall_System_String_InternalIsInterned (MonoString *str)
63 {
64         return mono_string_is_interned (str);
65 }
66
67 int
68 ves_icall_System_String_GetLOSLimit (void)
69 {
70         int limit = mono_gc_get_los_limit ();
71
72         return (limit - 2 - G_STRUCT_OFFSET (MonoString, chars)) / 2;
73 }
74