Spain drug laws tend to be more lenient compared to the United States' laws. The overall concept of "War against drugs" is not used in most of Europe. Generally speaking, drugs are seen as a health concern as opposed to a serious criminal offense.
Spanish law states that the possession of soft drugs for personal use,is not a criminal offense and is not punishable.
The only criminal offenses are those related to manufacturing, cultivating, and trafficing drugs.
Even with the more leniant Spanish drug laws, any time you use illicit chemicals you are putting yourself at risk. If you are caught with the possession of cannabis, like the popular Morrocan hashish or kif, the judge on the case could rule that you had the intent of distribution. That could wind you up with up to six years in jail.
If you are traveling only for the use of drugs, re-route your European trip towards Amsterdam.
So, if you are traveling to Spain, play it safe and be drug free. As an alternative if necessary, choose to exploit the drinking laws.