Skip to content

Commit

Permalink
xkbcomp: Use steal for better memory handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Nov 24, 2023
1 parent ba85e25 commit 90dedc6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ libxkbcommon_sources = [
'src/text.h',
'src/utf8.c',
'src/utf8.h',
'src/util-mem.h',
'src/utils.c',
'src/utils.h',
]
Expand Down
7 changes: 3 additions & 4 deletions src/xkbcomp/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "action.h"
#include "vmod.h"
#include "include.h"
#include "util-mem.h"

enum si_field {
SI_FIELD_VIRTUAL_MOD = (1 << 0),
Expand Down Expand Up @@ -393,8 +394,7 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
into->mods = from->mods;

if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
into->name = steal(&from->name);
}

if (darray_empty(into->interps)) {
Expand Down Expand Up @@ -440,8 +440,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)

InitCompatInfo(&included, info->ctx, 0 /* unused */,
info->actions, &info->mods);
included.name = include->stmt;
include->stmt = NULL;
included.name = steal(&include->stmt);

for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
CompatInfo next_incl;
Expand Down
7 changes: 3 additions & 4 deletions src/xkbcomp/keycodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "text.h"
#include "expr.h"
#include "include.h"
#include "util-mem.h"

typedef struct {
enum merge_mode merge;
Expand Down Expand Up @@ -268,8 +269,7 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
}

if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
into->name = steal(&from->name);
}

/* Merge key names. */
Expand Down Expand Up @@ -348,8 +348,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *include)
}

InitKeyNamesInfo(&included, info->ctx, 0 /* unused */);
included.name = include->stmt;
include->stmt = NULL;
included.name = steal(&include->stmt);

for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyNamesInfo next_incl;
Expand Down
7 changes: 3 additions & 4 deletions src/xkbcomp/symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "vmod.h"
#include "include.h"
#include "keysym.h"
#include "util-mem.h"


enum key_repeat {
Expand Down Expand Up @@ -518,8 +519,7 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
into->mods = from->mods;

if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
into->name = steal(&from->name);
}

group_names_in_both = MIN(darray_size(into->group_names),
Expand Down Expand Up @@ -579,8 +579,7 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include)

InitSymbolsInfo(&included, info->keymap, 0 /* unused */,
info->actions, &info->mods);
included.name = include->stmt;
include->stmt = NULL;
included.name = steal(&include->stmt);

for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
SymbolsInfo next_incl;
Expand Down
7 changes: 3 additions & 4 deletions src/xkbcomp/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vmod.h"
#include "expr.h"
#include "include.h"
#include "util-mem.h"

enum type_field {
TYPE_FIELD_MASK = (1 << 0),
Expand Down Expand Up @@ -192,8 +193,7 @@ MergeIncludedKeyTypes(KeyTypesInfo *into, KeyTypesInfo *from,
into->mods = from->mods;

if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
into->name = steal(&from->name);
}

if (darray_empty(into->types)) {
Expand Down Expand Up @@ -228,8 +228,7 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *include)
}

InitKeyTypesInfo(&included, info->ctx, 0 /* unused */, &info->mods);
included.name = include->stmt;
include->stmt = NULL;
included.name = steal(&include->stmt);

for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyTypesInfo next_incl;
Expand Down

0 comments on commit 90dedc6

Please sign in to comment.