Skip to content

Commit

Permalink
ODBC uses correct null-tolerant rebSpellWideMaybe()
Browse files Browse the repository at this point in the history
As a convenience, routines like rebSpell() used to give back a C nullptr if
the code you passed it produced a Rebol NULL.

But in usermode Rebol in general, nulls are designed to create disruptions
and warnings of something not being right.  You have to use MAYBE to turn
them into voids to get the opt out behavior.

    >> third [a b]
    == ~null~  ; anti

    >> length of third [a b]
    ** Error: LENGTH doesn't take NULL

    >> maybe third [a b]
    == ~void~  ; anti

    >> length of maybe third [a b]
    == ~null~  ; anti

This "void-in-null-out" concept gives you the ability to streamline operations
in a chain but still have good error locality anytime you didn't think
that nulls could happen.

It was decided that the API should have a similar level of safety vs. giving
back nullptr that could crash C code that wasn't expecting it.  So functions
like rebSpell() were split into two variants:

    rebSpell() -> triggers interpreter failure when given null
    rebSpellMaybe() -> gives back nullptr when given null

You could accomplish what rebSpellMaybe() does with just:

    rebSpell("maybe", ...)

But this offers slightly more efficiency, as well as robustness when the term
"maybe" may have been redefined in the applicable Rebol module.

In any case, there was a straggling call to rebSpellWide() which hadn't been
updated to be a call to rebSpellWideMaybe().
  • Loading branch information
hostilefork committed Aug 21, 2024
1 parent e965f6b commit 8516f0f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extensions/odbc/mod-odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ DECLARE_NATIVE(open_connection)
INCLUDE_PARAMS_OF_OPEN_CONNECTION;

// We treat ODBC's SQLWCHAR type (wide SQL char) as 2 bytes per wchar, even
//on platforms where wchar_t is larger. This gives unixODBC compatibility:
// on platforms where wchar_t is larger. This gives unixODBC compatibility:
//
// https://stackoverflow.com/a/7552533/211160
//
Expand Down Expand Up @@ -862,7 +862,7 @@ SQLRETURN Get_ODBC_Catalog(
blockscope {
int index;
for (index = 2; index != 6; ++index) {
pattern[index - 2] = rebSpellWide( // gives nullptr if BLANK!
pattern[index - 2] = rebSpellWideMaybe( // returns nullptr if NULL
"ensure [~null~ text!]",
"pick ensure block!", block, rebI(index)
);
Expand Down

0 comments on commit 8516f0f

Please sign in to comment.