MCPcopy Create free account
hub / github.com/MariaDB/server / register_var

Function register_var

sql/sql_plugin.cc:3067–3142  ·  view source on GitHub ↗

returns a bookmark for thd-local variables, creating if neccessary. Requires that a write lock is obtained on LOCK_system_variables_hash */

Source from the content-addressed store, hash-verified

3065 Requires that a write lock is obtained on LOCK_system_variables_hash
3066*/
3067static st_bookmark *register_var(const char *plugin, const char *name,
3068 int flags)
3069{
3070 size_t length= strlen(plugin) + strlen(name) + 3, size, offset, new_size;
3071 st_bookmark *result;
3072 char *varname, *p;
3073
3074 DBUG_ASSERT(flags & PLUGIN_VAR_THDLOCAL);
3075
3076 size= var_storage_size(flags);
3077 varname= ((char*) my_alloca(length));
3078 strxmov(varname + 1, plugin, "_", name, NullS);
3079 for (p= varname + 1; *p; p++)
3080 if (*p == '-')
3081 *p= '_';
3082
3083 if (!(result= find_bookmark(NULL, varname + 1, flags)))
3084 {
3085 result= (st_bookmark*) alloc_root(&plugin_vars_mem_root,
3086 sizeof(struct st_bookmark) + length-1);
3087 varname[0]= plugin_var_bookmark_key(flags);
3088 memcpy(result->key, varname, length);
3089 result->name_len= (uint)(length - 2);
3090 result->offset= -1;
3091
3092 DBUG_ASSERT(size && !(size & (size-1))); /* must be power of 2 */
3093
3094 offset= global_system_variables.dynamic_variables_size;
3095 offset= (offset + size - 1) & ~(size - 1);
3096 result->offset= (int) offset;
3097
3098 new_size= (offset + size + 63) & ~63;
3099
3100 if (new_size > global_variables_dynamic_size)
3101 {
3102 global_system_variables.dynamic_variables_ptr= (char*)
3103 my_realloc(key_memory_global_system_variables,
3104 global_system_variables.dynamic_variables_ptr, new_size,
3105 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
3106 max_system_variables.dynamic_variables_ptr= (char*)
3107 my_realloc(key_memory_global_system_variables,
3108 max_system_variables.dynamic_variables_ptr, new_size,
3109 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
3110 /*
3111 Clear the new variable value space. This is required for string
3112 variables. If their value is non-NULL, it must point to a valid
3113 string.
3114 */
3115 bzero(global_system_variables.dynamic_variables_ptr +
3116 global_variables_dynamic_size,
3117 new_size - global_variables_dynamic_size);
3118 bzero(max_system_variables.dynamic_variables_ptr +
3119 global_variables_dynamic_size,
3120 new_size - global_variables_dynamic_size);
3121 global_variables_dynamic_size= new_size;
3122 }
3123
3124 global_system_variables.dynamic_variables_head= (uint)offset;

Callers 2

construct_optionsFunction · 0.85
thd_key_createFunction · 0.85

Calls 7

var_storage_sizeFunction · 0.85
strxmovFunction · 0.85
find_bookmarkFunction · 0.85
alloc_rootFunction · 0.85
plugin_var_bookmark_keyFunction · 0.85
my_reallocFunction · 0.85
my_hash_insertFunction · 0.85

Tested by

no test coverage detected