Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct STRINGNULL handling #1678

Closed
p6rt opened this issue Apr 11, 2010 · 5 comments
Closed

Correct STRINGNULL handling #1678

p6rt opened this issue Apr 11, 2010 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 11, 2010

Migrated from rt.perl.org#74272 (status was 'resolved')

Searchable as RT74272$

@p6rt
Copy link
Author

p6rt commented Apr 11, 2010

From plobsing@gmail.com

Hi,

Attached is a patch correcting the problem described below.

Parrot has a symbol STRINGNULL used as a null string value, much like
PMCNULL for pmcs. In the past it didn't get a lot of use, most null
strings simply being set to NULL. I have recently created a branch in
parrot to use STRINGNULL more extensively. My changes cause problems
in C code that erroneously assumes null parrot strings are NULL, such
as rakudo's binder.c.

- Peter Lobsinger

@p6rt
Copy link
Author

p6rt commented Apr 11, 2010

From plobsing@gmail.com

stringnull.patch
diff --git a/src/binder/bind.c b/src/binder/bind.c
index 6f03372..f75fb92 100644
--- a/src/binder/bind.c
+++ b/src/binder/bind.c
@@ -237,7 +237,7 @@ Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_inf
         Rakudo_binding_bind_type_captures(interp, lexpad, sig_info, value);
 
     /* Do a coercion, if one is needed. */
-    if (sig_info->coerce_to) {
+    if (!STRING_IS_NULL(sig_info->coerce_to)) {
         PMC *coerce_meth = VTABLE_find_method(interp, value, sig_info->coerce_to);
         if (!PMC_IS_NULL(coerce_meth)) {
             Parrot_ext_call(interp, coerce_meth, "Pi->P", value, &value);
@@ -265,17 +265,17 @@ Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_inf
         /* Is it "is rw"? */
         if (sig_info->flags & SIG_ELEM_IS_RW) {
             /* XXX TODO Check if rw flag is set. */
-            if (sig_info->variable_name)
+            if (!STRING_IS_NULL(sig_info->variable_name))
                 VTABLE_set_pmc_keyed_str(interp, lexpad, sig_info->variable_name, value);
         }
         else if (sig_info->flags & SIG_ELEM_IS_PARCEL) {
             /* Just bind the thing as is into the lexpad. */
-            if (sig_info->variable_name)
+            if (!STRING_IS_NULL(sig_info->variable_name))
                 VTABLE_set_pmc_keyed_str(interp, lexpad, sig_info->variable_name, value);
         }
         else if (sig_info->flags & SIG_ELEM_IS_COPY) {
             /* Clone the value appropriately, wrap it into an ObjectRef, and bind it. */
-            if (sig_info->variable_name) {
+            if (!STRING_IS_NULL(sig_info->variable_name)) {
                 PMC *copy, *ref, *store_meth;
                 if (sig_info->flags & SIG_ELEM_ARRAY_SIGIL) {
                     STRING *STORE = string_from_literal(interp, "!STORE");
@@ -301,7 +301,7 @@ Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_inf
         }
         else {
             /* Read only. Wrap it into a ObjectRef, mark readonly and bind it. */
-            if (sig_info->variable_name) {
+            if (!STRING_IS_NULL(sig_info->variable_name)) {
                 PMC *ref  = pmc_new_init(interp, or_id, value);
                 if (!(sig_info->flags & (SIG_ELEM_ARRAY_SIGIL | SIG_ELEM_HASH_SIGIL)))
                     VTABLE_setprop(interp, ref, string_from_literal(interp, "scalar"), ref);
@@ -373,7 +373,7 @@ Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_inf
                         string_from_literal(interp, " in sub-signature"));
                 
                 /* Have we a variable name? */
-                if (sig_info->variable_name) {
+                if (!STRING_IS_NULL(sig_info->variable_name)) {
                     *error = Parrot_str_append(interp, *error,
                             string_from_literal(interp, " of parameter "));
                     *error = Parrot_str_append(interp, *error, sig_info->variable_name);
@@ -483,7 +483,7 @@ Rakudo_binding_bind_signature(PARROT_INTERP, PMC *lexpad, PMC *signature,
                 continue;
 
             /* Provided it has a name... */
-            if (elements[i]->variable_name) {
+            if (!STRING_IS_NULL(elements[i]->variable_name)) {
                 /* Strip any sigil, then stick in named to positional array. */
                 STRING *store = elements[i]->variable_name;
                 STRING *sigil = Parrot_str_substr(interp, store, 0, 1, NULL, 0);

@p6rt
Copy link
Author

p6rt commented Apr 12, 2010

From @moritz

Applied as 0334df67e4e041c0e1fe6941ae5d85b95e0a8af1, thanks.

@p6rt
Copy link
Author

p6rt commented Apr 12, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 12, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Apr 12, 2010
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant