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

Integer truncation -- regression between 3.1 and 3.2 (and different from ruby sass) #1216

Closed
asottile opened this issue May 15, 2015 · 8 comments

Comments

@asottile
Copy link
Member

EDIT This post has been edited to reflect the actual worldstate and not the erroneous state when I originally created the ticket. I had some wackiness in my environment which mislead me :(

Input:

a { width: 3.0px }

Output (libsass 3.1):

a {
  width: 3px; }

Output (libsass 3.2.4):

a {
  width: 3.0px; }

Ruby sass 3.4.12:

a {
  width: 3.0px; }
@asottile
Copy link
Member Author

I've bisected it to this commit: 925220c

Looking at the commit it's not obvious to me what changed...

@xzyfer any ideas?

Using this (yes it leaks memory):

// entries/main1.cpp
#include "sass_context.h"
#include <cstring>
#include <iostream>
#include <string>


int main() {
    char* src = (char*)malloc(sizeof(char) * 50);
    strcpy(src, "a { width: 3.0px }");
    struct Sass_Data_Context* context = sass_make_data_context(src);
    sass_compile_data_context(context);
    struct Sass_Context* ctx = sass_data_context_get_context(context);
    std::string output = sass_context_get_output_string(ctx);
    std::cout << output << std::endl;
    return static_cast<int>(output != "a {\n  width: 3px; }\n");
}
C_SOURCES := $(wildcard *.c)
C_OBJECTS = $(patsubst %.c,build2/c/%.o,$(C_SOURCES))
CPP_SOURCES := $(wildcard *.cpp)
CPP_OBJECTS = $(patsubst %.cpp,build2/cpp/%.o,$(CPP_SOURCES))
MAIN_SOURCES := $(wildcard entries/*.cpp)
OUTS = $(patsubst entries/%.cpp,%.out,$(MAIN_SOURCES))

all: main1.out

build2/c/%.o: %.c
    @mkdir -p build2/c/
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./ -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses

build2/cpp/%.o: %.cpp
    @mkdir -p build2/cpp/
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./ -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses

build2/mains/%.o: entries/%.cpp
    @mkdir -p build2/mains
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./ -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses

main1.out: build2/mains/main1.o $(C_OBJECTS) $(CPP_OBJECTS)
    g++ -pthread -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro $^ -L./libsass -o $@ -fPIC -lstdc++ -ldl

.PHONY: clean
clean:
    rm -rf build2 main1.out
# script.sh
(make -f Makefile2 clean && make -f Makefile2 -j 12 && ./main1.out) || false
$ git bisect start
$ git bisect good 3.1.0
$ git bisect bad 3.2.4
$ git bisect run ./script.sh

@xzyfer
Copy link
Contributor

xzyfer commented May 17, 2015

Hmm that doesn't sound right. There were some refactors around number output in the previous release.

We'll try get this into the next patch. Since this difference doesn't change the semantics of the output it's not a high priority, but should be an easy enough fix.

@xzyfer xzyfer added this to the 3.2.5 milestone May 17, 2015
@xzyfer xzyfer self-assigned this May 17, 2015
@asottile
Copy link
Member Author

Well, now I can't reproduce the ruby behaviour. I seem to consistently be getting the 3.0px output in ruby-sass, though I'm on a different machine...

@drewwells
Copy link
Contributor

http://sassmeister.com/gist/de3195efdb01319e4cf7 confirms regression

@asottile
Copy link
Member Author

Seems I had my binaries confused :S ruby-sass actually compiles the same as libsass, so this is less of a regression and more of a match-ruby I guess :)

@xzyfer xzyfer reopened this May 26, 2015
@xzyfer
Copy link
Contributor

xzyfer commented May 26, 2015

more of a match-ruby

This is important to us. A deviation from this behaviour in a new version is still a regression.

@asottile
Copy link
Member Author

I should clarify, I made a mistake when creating the ticket (probably two terminals, with one where I accidentally had alias sass=sassc and the other where it was unaliased).

The behaviour in 3.1 was "wrong" or "not matching ruby sass", and in 3.2 it now matches-sass. So ignoring ruby-sass it looks like a regression, but in reality it's actually a bugfix. I'll update the original post so it makes more sense.

@max-ch9i
Copy link
Contributor

Seems like static_value treats values like 3.0px as const strings preventing the trailing zero reduction.

A related issue is #550, where it is favoured to treat values like .01px as strings, otherwise they get transformed into 0.01px.

max-ch9i pushed a commit to max-ch9i/sass-spec that referenced this issue Dec 4, 2018
xzyfer pushed a commit to sass/sass-spec that referenced this issue Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants